简体   繁体   English

尝试在 python 中创建虚拟助手时出错

[英]error while trying to make a virtual assistant in python

can someone tell me how i can fix this error I get everytime I try to run this code below有人可以告诉我如何解决我每次尝试在下面运行此代码时遇到的此错误

import pyttsx3
import speech_recognition as sr
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voices', voices[0].id)

# text to speech
def speak(audio):
    engine.say(audio)
    print(audio)
    engine.runAndWait()


def takecommand():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        r.pause_threshold = 1
        audio = r.listen(source, timeout=1, phrase_time_limit=5)

    try:
        print("Recognizing...")
        query = r.recognize_google(audio, language='en-in')
        print(f"user said: {query}")


    except Exception as e:
        speak("say that again please...")
        return "none"
    return query

if __name__ == "__main__":
    takecommand()

and I'm getting this error while running it我在运行它时遇到了这个错误

Traceback (most recent call last):
  File "C:/Users/gouri/PycharmProjects/Jarvis/Jarvis.py", line 33, in <module>
    takecommand()
  File "C:/Users/gouri/PycharmProjects/Jarvis/Jarvis.py", line 19, in takecommand
    audio = r.listen(source, timeout=1, phrase_time_limit=5)
  File "C:\Users\gouri\PycharmProjects\Jarvis\venv\lib\site-packages\speech_recognition\__init__.py", line 618, in listen
    raise WaitTimeoutError("listening timed out while waiting for phrase to start")
speech_recognition.WaitTimeoutError: listening timed out while waiting for phrase to start

audio = r.listen(source,timeout=1,phrase_time_limit=5)音频 = r.listen(源,超时=1,phrase_time_limit=5)

#try without timeout or set at it to atleast 5 #try 不超时或将其设置为至少 5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM