I've been trying to "hijack" the Mac OS X system audio using PyAudio and save to a wav in python. That is, I do not want to record from an input device such as a microphone. I want to grab the sound output from any or all applications.
I have followed the tutorials on the PyAudio site but these do not appear to cover my use case and when I try to read from the output stream I unsurprisingly get the paCanNotReadFromAnOutputOnlyStream exception. Fair enough! Is there a way to do what I am proposing with the PyAudio or other FOSS Python Library?
Recording AudioThe python-sounddevice and pyaudio libraries provide ways to record audio with Python. python-sounddevice records to NumPy arrays and pyaudio records to bytes objects. Both of these can be stored as WAV files using the scipy and wave libraries, respectively.
Available devices appear in the sidebar of the Audio Devices window. To use a device for sound input or sound output, or to play system sounds, select the device, click the Action pop-up menu at the bottom of the sidebar, then choose an option.
On your Mac, choose Apple menu > System Settings, then click Sound in the sidebar. (You may need to scroll down.) Click Input on the right, then select the device you want to use in the list of sound input devices. All sound input devices available to your Mac are listed.
I found that an open-source project called SoundFlower got me quickly to the place I needed to be.
I was then able to record system audio from the default device using PyAudio. No sound comes from the speakers/headphones in this situation though. I wonder if you could use Jack OS X to route audio out of SoundFlower to the system audio out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With