Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capturing Mac OS X System Audio output with Python

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?

like image 300
richbs Avatar asked May 21 '10 14:05

richbs


People also ask

How do you record audio in Python?

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.

How do I select a device for audio Output on Mac?

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.

How do I set audio Output as MIC input Mac?

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.


1 Answers

I found that an open-source project called SoundFlower got me quickly to the place I needed to be.

  1. I installed the SoundFlower package from Google Code.
  2. Opened System Preferences -> Sound
  3. Chose Soundflower as my Output device
  4. Chose Soundflower as my Input device

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.

like image 53
richbs Avatar answered Oct 17 '22 19:10

richbs