Python speech recognition slowing down

[亡魂溺海] 提交于 2021-02-16 21:20:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!