PyAudio works, but every time it displays error messages

I am using PyAudio to record microphone input.

Since sound is being recorded well for me, should I try to just suppress its error messages? Or would there be a way to resolve them?

ALSA lib pcm.c:2212:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear ALSA lib pcm.c:2212:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe ALSA lib pcm.c:2212:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side ALSA lib audio/pcm_bluetooth.c:1613:(audioservice_expect) BT_GET_CAPABILITIES failed : Input/output error(5) ALSA lib audio/pcm_bluetooth.c:1613:(audioservice_expect) BT_GET_CAPABILITIES failed : Input/output error(5) ALSA lib audio/pcm_bluetooth.c:1613:(audioservice_expect) BT_GET_CAPABILITIES failed : Input/output error(5) ALSA lib audio/pcm_bluetooth.c:1613:(audioservice_expect) BT_GET_CAPABILITIES failed : Input/output error(5) ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports only playback stream ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave Cannot connect to server socket err = No such file or directory Cannot connect to server socket jack server is not running or cannot be started 
+27
python alsa pyaudio
Aug 17 '11 at 6:19 06:19
source share
6 answers

You can try to clear the ALSA configuration, for example,

 ALSA lib pcm.c:2212:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear ALSA lib pcm.c:2212:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe ALSA lib pcm.c:2212:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side 

called by /usr/share/alsa/alsa.conf :

 pcm.rear cards.pcm.rear pcm.center_lfe cards.pcm.center_lfe pcm.side cards.pcm.side 

As soon as you comment on these lines, this error message will disappear. You can also check ~/.asoundrc and /etc/asound.conf .

However, some of these messages say that something is wrong with your configuration, although they do not pose any real problems. I do not recommend you clear alsa.conf , because initially from ALSA it can be overwritten by updating alsa-lib.

There is a way to suppress a message in Python, here is a sample code:

 #!/usr/bin/env python from ctypes import * import pyaudio # From alsa-lib Git 3fd4ab9be0db7c7430ebd258f2717a976381715d # $ grep -rn snd_lib_error_handler_t # include/error.h:59:typedef void (*snd_lib_error_handler_t)(const char *file, int line, const char *function, int err, const char *fmt, ...) /* __attribute__ ((format (printf, 5, 6))) */; # Define our error handler type ERROR_HANDLER_FUNC = CFUNCTYPE(None, c_char_p, c_int, c_char_p, c_int, c_char_p) def py_error_handler(filename, line, function, err, fmt): print 'messages are yummy' c_error_handler = ERROR_HANDLER_FUNC(py_error_handler) asound = cdll.LoadLibrary('libasound.so') # Set error handler asound.snd_lib_error_set_handler(c_error_handler) # Initialize PyAudio p = pyaudio.PyAudio() p.terminate() print '-'*40 # Reset to default error handler asound.snd_lib_error_set_handler(None) # Re-initialize p = pyaudio.PyAudio() p.terminate() 

Output from my computer:

 messages are yummy messages are yummy messages are yummy messages are yummy messages are yummy messages are yummy ---------------------------------------- ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports only playback stream ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave 

These messages are printed by alsa-lib, not PyAudio or PortAudio. The code directly uses the alsa-lib snd_lib_error_set_handler to set the py_error_handler error py_error_handler , which you can use to delete any message.

I checked the other ALSA bindings of Python, pyalsa and PyAlsaAudio, they do not support the installation of an error handler. However, there is a problem in PortAudio, all ALSA error messages seem to have been suppressed before.

+22
Nov 19 '12 at 11:50
source share

All of the above is true and is a good solution. I just came here to offer a more convenient way to reuse the error handler code:

 from ctypes import * from contextlib import contextmanager import pyaudio ERROR_HANDLER_FUNC = CFUNCTYPE(None, c_char_p, c_int, c_char_p, c_int, c_char_p) def py_error_handler(filename, line, function, err, fmt): pass c_error_handler = ERROR_HANDLER_FUNC(py_error_handler) @contextmanager def noalsaerr(): asound = cdll.LoadLibrary('libasound.so') asound.snd_lib_error_set_handler(c_error_handler) yield asound.snd_lib_error_set_handler(None) 

After that, you can reuse the error handler using the noalsaerr context:

 with noalsaerr(): p = pyaudio.PyAudio() stream = p.open(format=pyaudio.paFloat32, channels=1, rate=44100, output=1) ... 
+13
Jul 16 '13 at 9:37 on
source share

They look like regular debugging messages, since they determine how to work on your system. I see no reason why you should not suppress them.

You may possibly turn off the detection of jack servers, Bluetooth devices, surround sound, etc., but this is not necessary and you can damage things. Do not interfere with work that works!

+3
Aug 17 '11 at 6:25
source share

The sounddevice module will suppress these messages, see https://github.com/spatialaudio/python-sounddevice/issues/11 .

0
Mar 20 '16 at 16:30
source share

If your default sound subsystem is Pulseaudio (common with Fedora, Ubuntu, Debian), it is better to recompile PyAudio and the C Portaudio core library with Pulseaudio support only without Jack and other subsystems.

0
Dec 27 '16 at 2:33
source share

Small extra points:

  1. Make sure you copy alsa.conf to another backup location.
  2. Make sure you edit the sudo file when editing alsa.conf (for example, sudo vi alsa.conf) so that you do not need to change the permissions of the alsa.conf file.

In my case, it still threw the following ALSA errors:

  • ALSA lib pcm_route.c: 867: (find_matching_chmap) No matching channel map found
  • ALSA lib pcm_route.c: 867: (find_matching_chmap) No matching channel map found
  • ALSA lib pcm_route.c: 867: (find_matching_chmap) No matching channel map found
  • ALSA lib pcm_route.c: 867: (find_matching_chmap) No matching channel map found
0
May 17 '19 at 12:45
source share



All Articles