0

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)
Tim Roberts
  • 48,973
  • 4
  • 21
  • 30

2 Answers2

0

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()
Brijesh Kalkani
  • 789
  • 10
  • 27
-1

You have to install 2 libraries

For Mac or Linux pip3 install gtts pip3 install playsound

For Windos pip install gtts pip install playsound

from gtts import gTTS
from playsound import playsound


def voicePlay(string):

    myobj = gTTS(text=string, lang='en', slow=False)
    myobj.save("tts.mp3")
    playsound('tts.mp3')


voicePlay("string")
Brijesh Kalkani
  • 789
  • 10
  • 27