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')
从下面的输出中可以看到,当我将耳机插入麦克风插孔时,Index 1可用作输入。
1 Jack Mic (IDT High Definition A, MME (2 in, 0 out)
而默认的笔记本电脑音频麦克风显示为index 2
2 Microphone Array (IDT High Defi, MME (2 in, 0 out)
输出
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
0 Microsoft Sound Mapper - Input, MME (2 in, 0 out)
> 1 Jack Mic (IDT High Definition A, MME (2 in, 0 out)
2 Microphone Array (IDT High Defi, MME (2 in, 0 out)
3 Microsoft Sound Mapper - Output, MME (0 in, 2 out)
< 4 Speakers / Headphones (IDT High, MME (0 in, 2 out)
5 Communication Headphones (IDT H, MME (0 in, 2 out)
6 Primary Sound Capture Driver, Windows DirectSound (2 in, 0 out)
7 Jack Mic (IDT High Definition Audio CODEC), Windows DirectSound (2 in, 0 out)
8 Microphone Array (IDT High Definition Audio CODEC), Windows DirectSound (2 in, 0 out)
9 Primary Sound Driver, Windows DirectSound (0 in, 2 out)
10 Speakers / Headphones (IDT High Definition Audio CODEC), Windows DirectSound (0 in, 2 out)
11 Communication Headphones (IDT High Definition Audio CODEC), Windows DirectSound (0 in, 2 out)
12 Communication Headphones (IDT High Definition Audio CODEC), Windows WASAPI (0 in, 2 out)
13 Speakers / Headphones (IDT High Definition Audio CODEC), Windows WASAPI (0 in, 2 out)
14 Jack Mic (IDT High Definition Audio CODEC), Windows WASAPI (2 in, 0 out)
15 Microphone Array (IDT High Definition Audio CODEC), Windows WASAPI (2 in, 0 out)
16 Headset Microphone (Bluetooth Hands-free Audio), Windows WDM-KS (1 in, 0 out)
17 Headphones (Bluetooth Hands-free Audio), Windows WDM-KS (0 in, 2 out)
18 Headphones (HpOut), Windows WDM-KS (0 in, 2 out)
19 Microphone Array (MicIn2), Windows WDM-KS (2 in, 0 out)
20 Jack Mic (MuxedIn), Windows WDM-KS (2 in, 0 out)
21 Dock Mic (MuxedIn), Windows WDM-KS (2 in, 0 out)
22 Rec. Playback (MuxedIn), Windows WDM-KS (2 in, 0 out)
23 Speakers (Speaker/HP), Windows WDM-KS (0 in, 2 out)
我不知道PyAudio,但是对于sounddevice模块,它是这样的:
您可以使用: 按主机api设备索引获取设备信息。 例如:
我没有看过
pyaudio
,但我也在少数情况下使用过sounddevice。下面是一个示例代码,列出了可用的
input
和output
audio devices
。从下面的输出中可以看到,当我将耳机插入麦克风插孔时,
Index 1
可用作输入。1 Jack Mic (IDT High Definition A, MME (2 in, 0 out)
而默认的笔记本电脑音频麦克风显示为
index 2
2 Microphone Array (IDT High Defi, MME (2 in, 0 out)
输出
相关问题 更多 >
编程相关推荐