PyAudio复制设备

时间:2014-01-06 05:48:50

标签: python pyaudio

我正在尝试列出我的音频设备,但我认为PyAudio正在展示一些重复的设备。

以下是结果(2和6,4和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)'}

这是我的代码:

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

重复设备的名称是cutted。我的代码有什么问题。或者这是一个错误?

我正在使用MS Windows 8。

1 个答案:

答案 0 :(得分:1)

它们不是重复的。其中一些可能来自MME hostApi,其他一些可能来自DirectSound hostApi,其他一些可能来自Windows-KS,或WASAPI,甚至ASIO。

我遇到了同样的情况,我选择从这个设备列表中仅保留来自DirectSound和ASIO的(在Windows上时)。 您可以使用dict的键“hostApi”过滤列表(0 = mme,1 = directsound等,请查看pyaudio doc)。