spatialaudio / python-sounddevice

:sound: Play and Record Sound with Python :snake:
https://python-sounddevice.readthedocs.io/
MIT License
1.02k stars 149 forks source link

Continuous stream output to device #1 and input stream from device #2 #465

Open josephernest opened 1 year ago

josephernest commented 1 year ago

Hi,

How to use 2 devices at the same time with sounddevice?

I'd like to use device #1 for output, and device #2 for input, both with their callback.

What is the recommended way to do this?

HaHeho commented 1 year ago

Based on your operating system, there may be different solutions available. On macOS, something like an "aggregate device" can be configured in the system settings. On Linux, something similar should be possible via ALSA configuration. This would be the easiest way since the code to record from and play to the device may be simpler.

If this is not an option, it should also be possible to create independent streams for two different devices. E.g., based on https://github.com/spatialaudio/python-sounddevice/issues/338#issuecomment-867131063, but with an InputStream and OutputStream with a single queue in between. Taka also a look at the rest of the thread for alternative (more complex) solutions including threading.