由于我在旧帖子和其他论坛中都没有找到我的问题的答案,所以我想向 stackoverflow 社区寻求建议。
我使用的是树莓派版本 9(stretch),内核版本为 4.14.71-v7。 它应该是可用的最新图像。
我想使用 pyaudio 来播放和录制音频流。在我的 Windows 家用电脑上一切正常,没有任何问题。但即使在树莓派上创建 pyaudio 对象也会引发一些奇怪的警告。
首先我安装了以下东西来使用 pyaudio:
sudo apt-get install libasound-dev
树莓派自动选择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 库似乎可以工作。我可以播放 并录制音频流,但每次都会出现这些警告。
感谢 stackoverflow 社区。我得到了一个旧主题的链接,它提供了完美的解决方案。
解释了所有这些警告发生的原因以及如何使用 python 处理它们。
非常感谢!!!