Python 语音识别速度变慢

2023-11-29

我开发了一个新程序来与我的聊天机器人对话。它工作得很好,但有一个奇怪的问题我似乎无法弄清楚。每次重复该过程(控制台输出监听并进行语音识别)时,它都会减慢速度。第一次很快,第二次慢一点,第三次慢,然后就变得太慢而无法响应。请帮我找出是什么语法可能导致此问题。

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() and with sr.Microphone() as source: inside while并且它工作正常并且响应没有延迟。

Thanks

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python 语音识别速度变慢 的相关文章