tôi havent nhìn pyaudio
nhưng tôi đã sử dụng sounddevice cũng trên vài dịp.
Dưới đây là mã ví dụ có sẵn input
và output
audio devices
.
import sounddevice as sd
print sd.query_devices()
Như bạn có thể thấy từ đầu ra bên dưới, khi tôi đặt tai nghe vào giắc micrô, Index 1
có sẵn làm đầu vào. 1 Jack Mic (IDT High Definition A, MME (2 in, 0 out)
Trong khi máy tính xách tay mặc định micro âm thanh đi lên như index 2
2 Microphone Array (IDT High Defi, MME (2 in, 0 out)
Output
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)
Mã này không thành công cho tôi. Cũng cần thêm: info = p.get_host_api_info_by_index (0) và sau đó numdevices = info.get ('deviceCount'). Ngoài ra tôi cần sử dụng p thay vì self.p, và sau đó nó hoạt động. Vui lòng sửa câu trả lời của bạn và tôi sẽ upvote nó sau đó. Cảm ơn. –
@WaynePiekarski Xong. Cảm ơn! – slegroux