PyAudio 在 Raspberry Pi 上抛出警告

PyAudio throws warnings on Raspberry Pi

由于我的问题在旧帖子和其他论坛中均未找到答案,因此我想向 Whosebug 社区寻求建议。

我正在使用 raspberry pi,版本 9(扩展)和内核版本 4.14.71-v7。 它应该是可用的最新图像。

我想使用 pyaudio 来播放和录制音频流。在我的 windows 家用电脑上,一切正常,没有任何问题。但即使在 raspberry pi 上创建一个 pyaudio 对象也会引发一些奇怪的警告。

首先我安装了以下东西来使用 pyaudio:

    sudo apt-get install libasound-dev

raspberry pi自动选择libasound2-dev

    sudo apt-get install portaudio19-dev
    sudo apt-get install python3-pyaudio

如果我运行以下python代码:

   import pyaudio
   py=pyaudio.PyAudio()

我收到这些警告:

   '$'ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.front.0:CARD=0'
   '$'ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
   '$'ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM front
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
   '$'ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
   '$'ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
   '$'ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround21
   '$'ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
   '$'ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
   '$'ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround21
   '$'ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround40.0:CARD=0'
   '$'ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
   '$'ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround40
   '$'ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
   '$'ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
   '$'ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround41
   '$'ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
   '$'ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
   '$'ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround50
   '$'ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
   '$'ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
   '$'ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround51
   '$'ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround71.0:CARD=0'
   '$'ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
   '$'ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround71
   '$'ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2                    =0,AES3=2'
   '$'ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
   '$'ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM iec958
   '$'ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2                    =0,AES3=2'
   '$'ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
   '$'ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM spdif
   '$'ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2                    =0,AES3=2'
   '$'ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
   '$'ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM spdif
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
   '$'ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
   '$'ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
   '$'ALSA lib conf.c:4996:(snd_config_expand) Args evaluate error: No such file or directory
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM bluealsa
   '$'ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
   '$'ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
   '$'ALSA lib conf.c:4996:(snd_config_expand) Args evaluate error: No such file or directory
   '$'ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM bluealsa
   '$'connect(2) call to /tmp/jack-1000/default/jack_0 failed (err=No such file or directory)
   '$'attempt to connect to server failed

对我来说,pyaudio 似乎想使用 hdmi(带环绕声), 插孔和蓝牙 (bluealsa)。 pyaudio好像没有用portaudio。 但我不确定。

也许有人知道,为什么仅仅创建一个对象就会抛出这些警告。 在这些警告旁边,pyaudio 库似乎可以工作。我可以播放 并录制音频流,但每次都会出现这些警告。

感谢 Whosebug 社区。我得到了一个 link 旧主题,它给出了完美的解决方案。

  • 主题名称:"PyAudio working, but spits out error messages each time"

解释了所有这些警告出现的原因以及如何使用 python 处理它们。

非常感谢!!!