python 中的 SpeechRecogniton 模块太慢了
SpeechRecogniton module is too slow in python
我试图为我的深度学习聊天机器人使用语音识别来获取用户的输入。其实我的语音识别功能代码是这样的:
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_sphinix()
方法。
您需要构建 pocketsphinix 的二进制安装文件 (whl)。
哦,我忘了说,你还需要在你的机器上构建pyaudio才能使用speech_recognition。我已经做了所有这些事情,甚至同样的问题也出现在这个离线 API... 早上 recognize.sphinix()
识别了我所说的 2-3 倍,但现在,它甚至没有回应!
注意: 我用任务管理器监控我的电脑,只有语音识别功能 运行,而 Python 只占用 9MB 内存, 和 0.3% CPU 的使用率。所以算力有限是没有问题的。
谁能解决这个问题?如果你解决了这个令人头疼的问题,你会让我开心。提前致谢!
duration 参数现已弃用。参考 .
而是使用 phrase_time_limit
或 timeout
.
这是使用 phrase_time_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
这很好用。
我试图为我的深度学习聊天机器人使用语音识别来获取用户的输入。其实我的语音识别功能代码是这样的:
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_sphinix()
方法。
您需要构建 pocketsphinix 的二进制安装文件 (whl)。
哦,我忘了说,你还需要在你的机器上构建pyaudio才能使用speech_recognition。我已经做了所有这些事情,甚至同样的问题也出现在这个离线 API... 早上 recognize.sphinix()
识别了我所说的 2-3 倍,但现在,它甚至没有回应!
注意: 我用任务管理器监控我的电脑,只有语音识别功能 运行,而 Python 只占用 9MB 内存, 和 0.3% CPU 的使用率。所以算力有限是没有问题的。
谁能解决这个问题?如果你解决了这个令人头疼的问题,你会让我开心。提前致谢!
duration 参数现已弃用。参考
而是使用 phrase_time_limit
或 timeout
.
这是使用 phrase_time_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
这很好用。