I'm trying to list my audio devices, but PyAudio is showing some duplicate devices, i think.
Here is the result(2 and 6, 4 and 5):
1. {'type': 'input', 'name': 'Microsoft Sound Mapper - Input'}
2. {'type': 'input', 'name': 'Microphone (Realtek High Defini'}
3. {'type': 'output', 'name': 'Microsoft Sound Mapper - Output'}
4. {'type': 'output', 'name': 'Speakers (Realtek High Definiti'}
5. {'type': 'output', 'name': 'Speakers (Realtek High Definition Audio)'}
6. {'type': 'input', 'name': 'Microphone (Realtek High Definition Audio)'}
This is my code:
def get_devices(self):
self.p = pyaudio.PyAudio()
devices = {}
for x in range(self.p.get_device_count()):
d = self.get_device_info(x)
devices[x] = { 'name' : d['name'] , 'type' : 'output' if d['maxInputChannels'] == 0 else 'input' }
return devices
The duplicate device has the name cutted. What is wrong with my code. Or this is a bug?
I'm using MS Windows 8.
They are not duplicates. Some of them probably come from MME hostApi, some other may come from DirectSound hostApi, some other may come from Windows-KS, or WASAPI, or even ASIO.
I had the same situation, and I chose to keep from this device list only those coming from DirectSound and ASIO (when on Windows). You can filter the list with the key "hostApi" for the dict (0=mme, 1=directsound, etc. please check in the pyaudio doc).