如何使用PyAudio选择特定的输入设备 [英] How to select a specific input device with PyAudio
问题描述
通过PyAudio录制音频时,如何指定要使用的确切输入设备?
When recording audio via PyAudio, how do you specify the exact input device to use?
我的计算机有两个麦克风,一个是内置麦克风,一个是通过USB麦克风,我想用USB麦克风录音. 流类具有用于选择设备的input_device_index
,但尚不清楚此索引与设备之间的关系.例如,如何知道哪个设备索引0是指?如果我不得不猜测,我会说0表示内置设备,而1表示USB设备,但是我想找到一些编程的方式来确认这一点.在Linux上,是否可以获取这些索引及其引用的设备的列表?
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?
推荐答案
,您可以使用: get_device_info_by_host_api_device_index. 例如:
you can use: get_device_info_by_host_api_device_index. For instance:
import pyaudio
p = pyaudio.PyAudio()
info = p.get_host_api_info_by_index(0)
numdevices = info.get('deviceCount')
for i in range(0, numdevices):
if (p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0:
print "Input Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0, i).get('name')
这篇关于如何使用PyAudio选择特定的输入设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!