如何解决Python语音识别,Pyaudio不听,但是给这个
我正在尝试使用python中的语音识别和pyaudio将语音转换为文本。在转换预先录制的音频文件时效果很好,但是当我使用麦克风(外部)录制时,它没有在听,而是显示以下内容:
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 pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
这是我的代码:
import speech_recognition as sr
r = sr.Recognizer()
mic = sr.Microphone()
with mic as source:
print('say somthing')
audio = r.listen(source)
print(r.recognize_google(audio))
解决方法
尝试以下代码块。即使在实时输入中,这在我的系统中也能正常工作。
import speech_recognition as sr
def myCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source,phrase_time_limit = 5)
try:
command = r.recognize_google(audio).lower()
print("you said: " + command)
except sr.UnknownValueError:
print("Sorry,Cant understand,Please say again")
command = myCommand()
return command
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。