使用 python 的语音助手显示循环错误
Voice Assistant using python Showing loop error
嗨,我正在尝试使用唤醒命令在 python 中制作语音助手,但它给出了循环错误。
我是 pyttx3 的新手,所以找不到我可以解决这个问题的地方。
有一些我无法修复的循环错误,请帮助使其正常工作。
import pyjokes
client = wolframalpha.Client(app_id)
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
def speak(text):
engine.say(text)
engine.runAndWait()
WAKE = "hello jack"
SERVICE = authenticate_google()
print("Start")
while True:
text = get_audio()
if text.count(WAKE) > 0:
speak("I am ready")
text = get_audio()
CALENDAR_STRS = ["what do i have", "do i have", "am i busy"]
for phrase in CALENDAR_STRS:
if phrase in text:
date = get_date(text)
if date:
get_events(date, SERVICE)
else:
speak("I don't understand")
NOTE_STRS = ["make a note", "write this down", "remember this"]
for phrase in NOTE_STRS:
if phrase in text:
speak("What would you like me to write down?")
note_text = get_audio()
note(note_text)
speak("I've made a note of that.")
RuntimeError: run loop already started
我认为您需要导入 pyttsx3
和其他模块。
如果您仍然遇到问题,那么您可以使用my source code。
嗨,我正在尝试使用唤醒命令在 python 中制作语音助手,但它给出了循环错误。
我是 pyttx3 的新手,所以找不到我可以解决这个问题的地方。
有一些我无法修复的循环错误,请帮助使其正常工作。
import pyjokes
client = wolframalpha.Client(app_id)
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
def speak(text):
engine.say(text)
engine.runAndWait()
WAKE = "hello jack"
SERVICE = authenticate_google()
print("Start")
while True:
text = get_audio()
if text.count(WAKE) > 0:
speak("I am ready")
text = get_audio()
CALENDAR_STRS = ["what do i have", "do i have", "am i busy"]
for phrase in CALENDAR_STRS:
if phrase in text:
date = get_date(text)
if date:
get_events(date, SERVICE)
else:
speak("I don't understand")
NOTE_STRS = ["make a note", "write this down", "remember this"]
for phrase in NOTE_STRS:
if phrase in text:
speak("What would you like me to write down?")
note_text = get_audio()
note(note_text)
speak("I've made a note of that.")
RuntimeError: run loop already started
我认为您需要导入 pyttsx3
和其他模块。
如果您仍然遇到问题,那么您可以使用my source code。