加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – PyAudio重复设备

发布时间:2020-12-20 13:39:22 所属栏目:Python 来源:网络整理
导读:我想尝试列出我的音频设备,但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': 'Micros
我想尝试列出我的音频设备,但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.

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读