0

I try to create a Voice Assistant on python3

This is my function Speak (with pyttsx):

def speak(what):
    print("Gosha: " + what)
    speak_engine.say( what )
    speak_engine.runAndWait()
    speak_engine.stop()

in the main body it works fine, but in function execute_cmd, after Speak function my code stucks. One part of execute_cmd:

def execute_cmd(cmd, voice):
    global finished
    finished = False
    #import debug
    if cmd == 'ctime':
        now = datetime.datetime.now()
        hours = str(now.hour)
        minutes = str(now.minute)
        if (now.minute < 10): minutes = '0' + minutes
        speak("Now " + hours + ":" + minutes)
        finished = True

finished will never True

This happens anywhere in the function

pls help me

(sorry for my eng, I'm from Russia)

UPD: I debugged my code and noticed, my code get stuck on speak_engine.runAndWait()

I know, many people have same problem, but their solutions didn't help me

1 Answers1

0

I'm not sure I understand you problem. What exactly do you mean by your code getting "Stuck"? Since you said that your finished variable will never be False, I assume that the code runs through and doesn't get stuck. My best guess is that your code simply doesn't produce sound.

If that's the case, I could imagine it's due to the previous loop still being active. So maybe try adding the following to your speak() function:

ef speak(what):
    print("Gosha: " + what)
    try:
        speak_engine.endLoop()
    except Exception as e:
        pass
    speak_engine.say( what )
    speak_engine.runAndWait()
    speak_engine.stop()
thomin
  • 81
  • 5