Special characters in audio devices name : Pyaudio

天涯浪子 提交于 2019-12-06 10:33:51

I'm facing exactly the same problem. In my case, there are Chinese charactors in the name of audio device, and UnicodeDecodeError occured when I print device_info.name

Here is my solution.

Use pymedia instead of pyaudio. Try this:

>>> import pymedia 
>>> dict_list = pymedia.audio.sound.getIDevices()
>>> print dict_list
({'name': '\xc2\xf3\xbf\xcb\xb7\xe7 (Realtek High Definition', 'channels': 2, 'manufId': '1', 'formats': 1048575, 'id': 0, 'productId': '65'},)
>>> dict_list = pymedia.audio.sound.getODevices()
>>> print dict_list
({'name': '\xd1\xef\xc9\xf9\xc6\xf7 (MV USB AUDIO)', 'channels': 2, 'manufId': 'ffff', 'formats': 1048575, 'id': 0, 'productId': 'ffff'}, {'name': '\xd1\xef\xc9\xf9\xc6\xf7 (Realtek High Definition', 'channels': 2, 'manufId': '1', 'formats': 1048575, 'id': 1, 'productId': '64'})

I'm using python 2.7 .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!