PyAudio alsa error messages

2019-02-24 00:23发布

问题:

I am receiving error messages every time I play a sound with PyAudio and am having trouble supressing them.

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
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
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 request channel
jack server is not running or cannot be started

I have tried the solution from PyAudio working, but spits out error messages each time but I keep getting an error message saying

OSError: libasound.so: cannot open shared object file: No such file or directory

I have tried changing it to libasound.so.2 but then it freezes the program when trying to play a sound instead of doing anything.

I am including my source code for how I am using PyAudio. The alsaMessageSuppress function is called in the initialization of the class.

def alsaMessageSuppress(self):
    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 'Debug Message Suppressed'
    c_error_handler = ERROR_HANDLER_FUNC(py_error_handler)
    asound = cdll.LoadLibrary('libasound.so.2')
    # Set error handler
    asound.snd_lib_error_set_handler(c_error_handler)

def soundThread(self, sound):

    p = pyaudio.PyAudio()

    duplicated_sound = wave.open(StringIO.StringIO(self.loaded_sounds[sound]), 'rb')

    def callback(in_data, frame_count, time_info, status):
        data = duplicated_sound.readframes(frame_count)
        return (data, pyaudio.paContinue)

    stream = p.open(format=p.get_format_from_width(duplicated_sound.getsampwidth()),
                    channels=duplicated_sound.getnchannels(),
                    rate=duplicated_sound.getframerate(),
                    output=True,
                    stream_callback=callback)

    while stream.is_active():
        sleep(.1)

    stream.stop_stream()
    stream.close()

    #print "%s Finished" % sound

    p.terminate()

    duplicated_sound = None