The output device is typically used for audio playback but in this case I want to record/read/capture the system audio (or other output device) for use in transcription. I've heard this is called "Loopback" but it's not supported by pyaudio library. Is there another solution to easily capture both streams?
if not record_thread:
stream_in = None
stream_out = None
if device_index is not None:
stream_in = pa.open(
format=pyaudio.paInt16,
channels=1,
rate=sample_rate,
input=True,
frames_per_buffer=chunk_size,
input_device_index=device_index,
)
else:
stream_in = None
if output_index is not None:
stream_out = pyaudio.PyAudio().open(
format=pyaudio.paInt16,
channels=2, #usually 2 because stereo
frames_per_buffer=chunk_size,
rate=sample_rate,
input=True,
input_device_index=output_index,
)
else:
stream_out = None
out_data = stream_out.read(chunk_size)
record_thread = Thread(target=recording_thread, args=[stream_in, out_data])
run_record_thread = True
record_thread.start()
```