2

I'm currently facing a hard problem. I need to use Pyaudio on a french windows environnement and the name of the audio devices contains é or è by default.

This is the error I get when a special character is present:

   u=self.p.get_device_info_by_index(e)
  File "C:\Python27\lib\site-packages\pyaudio.py", line 977, in get_device_info_
by_index
    pa.get_device_info(device_index)
  File "C:\Python27\lib\site-packages\pyaudio.py", line 987, in _make_device_inf
o_dictionary
    print device_info.name
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 13: invalid
continuation byte

This wouldn't be a problem if I could access the code (I would need to add a u"..." in front of the string chain I guess).

The problem is that I looked inside the Pyaudio code and the method causing the bug is defined in an pyd file (_portaudio.pyd), therefor, I can't modify it!

I tried to download _portaudio to compile it myself, but the distribution I found is coded in C and quite heavy (I don't know the first thing about C). Maybe I could do something there but I don't know exactly where and how.

I could also handle the problem by just commenting the line getting the name of the audio devices, but it's much harder to identify a specific audio input without its name to show to the user.

EDIT :

Here is the overall process : I call the function from pyaudio :

      import pyaudio

      self.p= pyaudio.PyAudio()

      i=self.p.get_device_count()

      for e in range(i):
          u=self.p.get_device_info_by_index(e)

This will lead me into the pyaudio module which calls the method :

device_info.name

device_info being an object defined in _portaudio.pyd. Since the name of particular audio devices contain "é" or "è" (Thank you windows), and the _portaudio.pyd is not encoded to handle those characters. It returns the error :

UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 13: invalid
    continuation byte
Jdawleer
  • 165
  • 3
  • 9

1 Answers1

-1

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 .