Search code examples
pythontext-to-speechpython-3.10pyttsx3

No Audio with pyttsx3 Library in Python 3 (No errors)


Using pyttsx3 (tried versions 2.5 to current) on Visual Studios Code on Windows 10 With Python 3.10.0. My Problem that I am currently having is that the code will run through, but no audio is being outputted. while debugging there is no pause stepping into or over the code (for parts including pyttsx3). I made sure my audio is on, and that it is working. I used a different tts library gtts and the audio worked, but I am trying to write offline. I also tried this exact code from VS code in PyCharm and I still had the same problem. Again with no errors or warnings.

import speech_recognition as sr
import pyttsx3


listener = sr.Recognizer()
engine = pyttsx3.init(driverName='sapi5')
#voices = engine.getProperty('voices')
#engine.setProperty('voice', voices[0].id)
engine.say("Testing, audio")
engine.runAndWait

try:
    with sr.Microphone() as source:
        print('Listening...')
        voice = listener.listen(source)
        command = listener.recognize_google(voice)
        print(command)
        engine.say(command)
        engine.runAndWait
except:
    pass

print('Hello')

I also tried this block of code with no driver name and the same problem above persists

import speech_recognition as sr
import pyttsx3


listener = sr.Recognizer()
engine = pyttsx3.init()
#voices = engine.getProperty('voices')
#engine.setProperty('voice', voices[0].id)
engine.say("Testing, audio")
engine.runAndWait

try:
    with sr.Microphone() as source:
        print('Listening...')
        voice = listener.listen(source)
        command = listener.recognize_google(voice)
        print(command)
        engine.say(command)
        engine.runAndWait
except:
    pass

print('Hello')

The two commented lines on both programs didn't change anything for me either. I also tested the program with just pyttsx3.

import pyttsx3

engine = pyttsx3.init(driverName='sapi5')
engine.say("Testing, audio")
engine.runAndWait

and tested using 'Testing, audio' instead of "Testing, audio" and I tried single words as well.

Any help would be amazing! Thank you! In the mean time I will try to test this(translated to work with Linux) program in Linux to see if my OS is the issue. I will also try an older version of python to see if that is the issue. Along with python 2. My biggest assumption is that pyttsx3 needs a earlier version of python to work, but I could also be 100% wrong about that.


Solution

  • You forgot to put the parentheses on engine.runAndWait. Do this: engine.runAndWait()