I\'m trying to record the output from my computer speakers with PyAudio.
I tried to modify the code example given in the PyAudio documentation, but it doesn\'t work.
If you create an application on windows platform, you can use default stereo mixer virtual device to record your PC's output.
1) enable stereo mixer
2) connect PyAudio to your stereo mixer, this way:
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 an index of your stereo mixer.
3) to get required index you can list your devices:
for i in range(p.get_device_count()):
print p.get_device_info_by_index(i)
Also, you can add the next code to automatically get 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'];
print('dev_index', dev_index)
4) continue to work with pyAudio as in the case of recording from a microphone
data = stream.read(CHUNK)