If you are creating an application on a Windows platform, you can use the default stereo mixer virtual device to record the output of your PC.
1) turn on the stereo mixer
2) connect PyAudio to your stereo mixer as follows:
p = pyaudio.PyAudio() stream = p.open(format = FORMAT, channels = CHANNELS, rate = RATE, input = True, input_device_index = dev_index, frames_per_buffer = CHUNK)
where dev_index is the index of your stereo mixer .
3) to get the necessary index, you can list your devices:
for i in range(p.get_device_count()): print p.get_device_info_by_index(i)
You can also add the following code to automatically retrieve the index by device name:
for i in range(p.get_device_count()): dev = p.get_device_info_by_index(i) if (dev['name'] == 'Stereo Mix (Realtek(R) Audio' and dev['hostApi'] == 0): dev_index = dev['index'];
4) continue to work with pyAudio, as in the case of recording from a microphone
data = stream.read(CHUNK)
source share