问题
I have developed a new program to speak to my chatbot. It works very well, but there is one strange issue I can't seem to figure out. Every time the process repeats (the console outputs listening and does speech recognition), it slows down. The 1st go is quick, the 2nd a little slower, the 3rd slow, and then it just gets too slow to respond from there on. Please help me figure out what syntax could be causing this.
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))
回答1:
It's the problem with loop order. I just included r = sr.Recognizer()
and with sr.Microphone() as source:
inside while
and it is working fine and no delay in response.
Thanks
来源:https://stackoverflow.com/questions/52260341/python-speech-recognition-slowing-down