我开发了一个新程序来与我的聊天机器人对话。它工作得很好,但有一个奇怪的问题我似乎无法弄清楚。每次重复该过程(控制台输出监听并进行语音识别)时,速度都会减慢。第一次很快,第二次慢一点,第三次慢,然后就变得太慢而无法响应。请帮我找出是什么语法可能导致此问题。
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
while True:
print("say something")
audio = r.listen(source)
try:
print("Text:"+r.recognize_google(audio, language = 'en-us', show_all=False));
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
最佳答案
这是循环顺序的问题。我刚刚将 r = sr.Recognizer()
和 with sr.Microphone() 作为源:
包含在 while
中,它工作正常,没有响应延迟。
谢谢
关于Python 语音识别速度变慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52260341/