python中的SpeechRecogniton模块太慢
我试图使用语音识别进行深度学习聊天机器人,从用户那里获取输入。实际上我的语音识别功能代码是这样的:python中的SpeechRecogniton模块太慢,python,speech-recognition,Python,Speech Recognition,我试图使用语音识别进行深度学习聊天机器人,从用户那里获取输入。实际上我的语音识别功能代码是这样的: def get_audio(): r = sr.Recognizer() with sr.Microphone() as source: r.pause_threshold = 1 r.adjust_for_ambient_noise(source, duration=1) audio = r.listen(source)
def get_audio():
r = sr.Recognizer()
with sr.Microphone() as source:
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration=1)
audio = r.listen(source)
said = ""
try:
print("Listening...")
said = r.recognize_google(audio)
print("You said: " + said)
except Exception as e:
print("Exception: " + str(e))
return said.lower()
嗯,没有错误,这是最大的错误!我的互联网连接没有问题,因为我可以在同一时间流高质量的视频,而这甚至不是视频,它是一个字符串,那么可能是什么问题?我要等将近15分钟才能收到短信
嗯,我还尝试了一个离线API:recognize\u sphinix()
方法。
您需要构建pocketsphinix的二进制安装文件(whl)。
哦,我忘了提一下,你还需要在你的机器上建立pyaudio来使用语音识别。我已经做了所有这些事情,甚至这个离线API也存在同样的问题。。。早上recognize.sphinix()
注意:我用任务管理器监控我的电脑,只运行语音识别功能,Python只占用了9MB的内存,CPU使用率为0.3%。因此,有限的计算能力没有问题
谁能解决这个问题?如果你能解决这个头痛问题,我会很高兴的。提前谢谢 duration参数现在不推荐使用。参考文献
而是使用短语\u time\u limit
或timeout
下面是使用短语\u time \u limit
的代码块:
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
这个很好用