When recording audio via PyAudio, how do you specify the exact input device to use?
My computer has two microphones, one built-in and one via USB, and I want to record using the USB mic. The Stream class has an input_device_index
for selecting the device, but it's unclear how this index correlates to the devices. For example, how do I know which device index 0 refers to? If I had to guess, I'd say 0 refers to the built-in device while 1 refers to the USB device, but I'd like to find some programmatic way of confirming this. On Linux, is there a way to get a list of these indexes and the devices they refer to?
you can use: get_device_info_by_host_api_device_index. For instance:
I havent looked at
pyaudio
but I've used sounddevice as well on few occasions.Here is an example code that lists available
input
andoutput
audio devices
.As you can see from below output, when I put my headset to mic jack ,
Index 1
is available as input.1 Jack Mic (IDT High Definition A, MME (2 in, 0 out)
While default laptop audio microphone comes up as
index 2
2 Microphone Array (IDT High Defi, MME (2 in, 0 out)
Output
I don't know about PyAudio, but with the sounddevice module it goes like that:
In the PyAudio Documentation it states that you can define an
input_device_index
.To find out what that device index is, you can follow the code provided in this Github Gist or by following the code found on the Raspberry Pi Forum which provides an example of the outputted code.
Just use
arecord -l
to list all available input devices.