语音识别Python模块在6个月后停止工作

2024-04-19 05:39:49 发布

您现在位置:Python中文网/ 问答频道 /正文

6个月前,我使用voice recognition/pyttsx3 python模块制作了一个小型语音助手,它已经工作了6个月,直到最近似乎停止工作。因为当我开始运行脚本时,它似乎无法识别我的声音,只是停留在“倾听”状态,根本没有给出任何响应或错误消息。此外,我尝试卸载/重新安装模块,但这没有改变任何事情,我试着在线查看某人是否有类似问题,但我没能找到任何类似于我所遇到的问题的东西

以下是我为语音助手的语音识别/响应所做的功能:

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def takeCommand(): 
    r = sr.Recognizer()
    with sr.Microphone() as source:
        speak("Listening...")
        print("Listening...")
        audio = r.listen(source)
    try:
        print("Recognizing...")
        query = r.recognize_google(audio, language = 'en-us')
        print(f"user said: {query}\n")
    except Exception as e:
        print(e) 
        print("Say that again please")
        query = None
    return query 

任何帮助都将不胜感激,谢谢-奥本加


Tags: 模块sourceas助手语音queryaudioengine