Search code examples
pythonspeech-recognitionpyttsx3

Pyttsx3 not working, process finished with exit code 0


I am making an Artificial Intelligence (AI) assistant and I wrote this to make it speak:

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


def speak(audio):
    engine.say(audio)
    print(audio)
    engine.runAndWait()

it does not speak and shows:

Process finished with exit code 0

how to fix it??


Solution

  • You forgot to use the function. Use this code:

    engine = pyttsx3.init('sapi5')
    voices = engine.getProperty('voices')
    engine.setProperty('voices', voices[0].id)
    
    
    def speak(audio):
        engine.say(audio)
        print(audio)
        engine.runAndWait()
    
    
    # what you are missing
    # use your function to say something
    speak('Hello')
    

    Hopefully, it works!