每次我用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 working, but spits out error messages each time的解决方案,但我不断收到错误消息
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