我正在开发一个项目,我需要从内置麦克风中获取输入并在Python中处理它。输入将是一个命令,如"右","左","前进"等。
我找到了语音识别库here。
当我运行命令python -m speech_recognition
时,我得到以下输出:
A moment of silence, please...
ALSA lib pcm_dsnoop.c:614:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1024:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2267:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2267:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2267:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_dmix.c:1024:(snd_pcm_dmix_open) unable to open slave
Cannot lock down 82274202 byte memory area (Cannot allocate memory)
Set minimum energy threshold to 48.5477227879
Say something!
ALSA lib pcm_dsnoop.c:614:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1024:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2267:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2267:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2267:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_dmix.c:1024:(snd_pcm_dmix_open) unable to open slave
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/dist-packages/speech_recognition /__main__.py", line 12, in <module>
with m as source: audio = r.listen(source)
File "/usr/local/lib/python2.7/dist-packages/speech_recognition/__init__.py", line 377, in listen
buffer = source.stream.read(source.CHUNK, exception_on_overflow = False)
TypeError: read() got an unexpected keyword argument 'exception_on_overflow'
答案 0 :(得分:0)
此错误表示您的pyaudio太旧了。 speech_recognition模块需要来自PyAudio 0.2.9的最新API,你的版本较旧。升级Pyaudio并且错误将消失。