5

每次使用 PyAudio 播放声音并且无法抑制它们时,我都会收到错误消息。

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

我已经尝试过PyAudio 工作的解决方案,但每次都会吐出错误消息,但我一直收到一条错误消息说

OSError:libasound.so:无法打开共享对象文件:没有这样的文件或目录

我曾尝试将其更改为,libasound.so.2但在尝试播放声音而不是做任何事情时它会冻结程序。

我包含了我如何使用 PyAudio 的源代码。该alsaMessageSuppress函数在类的初始化中被调用。

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
4

0 回答 0