I want to process the audio data from sound card (i.e. USB external sound card). For example: I can record all sound while playing a Youtube clip along with PC game. However, I have tried Pyaudio which only allows me to record audio from microphone. Can someone suggest me any library to try? Thanks so much!
Related
I am writing a bit of python code that plays a sound file (MP3 or the equivalent) and should cut that sound off if the user strikes a (hardware) button that is wired into the system. This will be on a Raspberry Pi running Raspbian. The libraries I’ve used historically for playing sound all play to completion. The closest approach I can think of would be using an external sound player (OMXplayer perhaps) and then searching for and killing its process if the button is pressed, but this feels inelegant. Can anybody suggest a better approach?
Using Pyaudio you could simply check a flag before writing each buffer to the stream, and if the audio should stop, fade out the current buffer and then either continue the stream with silence (write 0's) or stop the stream and exit the program. This could be easily be achieved with a latency of ~1/10s after button press.
You would also need to create a UI thread in the application to handle commands since the stopping flag is switched on user input.
I am very new to the cv2 library, and since I recently discovered it is unable to play audio I wanted to know if there is another library that will allow me to play the audio in sync with the video itself (preferably without needing an audio file, just using the video's audio)
Turns out there is a very simple method that I will found after researching later, unfortunately, it requires a separate audio file that matches the video:
First, import simpleaudio as sa (install it with pip if necessary) and then add this piece of code to your cv2 video player. Add it before the while loop but after the line of code that defines the video file:
wave_obj = sa.WaveObject.from_wave_file("AudioFile.wav")
wave_obj.play()
Then you must manually adjust the waitKey until the audio matches the video, otherwise it might be too fast or too slow. Generally a value close to 25 must be used, and if the audio abruptly ends, try adding one to the value until it matches
I'm wondering if there are libraries in Python for audio recording.
Ideally, I need to get a cross-platform solution, how can I record audio through Python.
Ideally, in order that in this library I can either pause with the ability to listen to the recorded fragment and remove it from the audio recording, or record several audio files and after the program work, glue it into 1 audio file.
If someone knows such a decision, I will be happy to receive help.
Thanks in advance!
I would look into python-sounddevice.
https://python-sounddevice.readthedocs.io/en/0.3.11/
It can record and play as well as convert your music into a numpy array if that every interested you. It is a python handler of the PortAudio which is cross-platform.
http://portaudio.com
I need to record a rtsp video stream to file in python, I want to stop the recording at anytime depending on the situation. I used subprocess to interact with ffmpeg command line, but it breaks sometimes, the video keep recording, resulting in a huge file.
Is there any good way to dump a rtsp video stream to file, with the capability that you can stop the recording anytime after you start recording?
Any help is much appreciated.
ADDED:
Preferably the similar API as the PiCamera like so:
import picamera
from time import sleep
camera = picamera.PiCamera()
camera.start_recording('video.h264')
sleep(5)
camera.stop_recording()
But the only difference is that the source of video is the IP camera.
I am searching for a way/framework to play at least 3 music files at one in a python application. It should run at least under ubuntu and mac as well as on the raspberry pi.
I need per channel/music file/"deck" that is played:
Control of the Volume of the Playback
Control of the start position of the playback
Play and Pause/Resume functionality
Should support mp3 (Not a must but would be great!)
Great would be built in repeat functionality really great would be a fade to the next iteration when the song is over.
If I can also play at least two video files with audio over the same framework, this would be great, but is not a must.
Has anyone an Idea? I already tried pygame but their player can play just one music file at once or has no control over the playback position.
I need that for a theatre where a background sound should be played (and started simultaneosly with the light) and when it is over, a next file fades over. while that is happening there are some effects (e.g. a bell) at a third audio layer.
I finally got an answer/workaround.
I am using pythons multiprocessing class/functionality to run multiple pygame instances.
So i can play more than one music file at a time with fully control over playmode and playback position.