Search code examples
pythontext-to-speechpyttsx3

Why is my ttsx3 in Python not playing any audio


I am using pycharm and have pyaudio and pyttsx3 installed. my issue is the audio from my text to speech is not playing. I can see the text being put down in the console so I know that everything else works. Here's the code relating to the tts.

    import pyttsx3 as tts

    import speech_recognition
    import wikipedia
    from neuralintents import GenericAssistant
    import requests
    import pyaudio
    
    recognizer = speech_recognition.Recognizer()
    
    speaker = tts.init()
    speaker.setProperty("rate", 150)
    speaker.setProperty("volume", 1)

Solution

  • Try This It's Works For Me

    Fist Install This If You Have WINDOWS OS:- pip install pyttsx3 OR If You Have MAC OS:- pip3 install pyttsx3

    import pyttsx3
    
    def voicePlay(string):
    
        engine = pyttsx3.init()
        engine.say(f"{string}") 
        try:
            engine.runAndWait()
        except Exception as e:
            pass
        engine.runAndWait()