python-3.xspeech-to-textpyttsx

Voice Assistant using python Showing loop error


HI I am trying to make a voice assistant in python with wake command, but its giving loop error.

I am new to pyttx3 so unable to find where i can fix this.

There is some loop error which i am unable fix, please help to make it working.

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

Solution

  • I think you need to import pyttsx3 and other modules.

    If you are still facing problems, then you can use my source code.