How could I make Python to speak some text ?
I have heard that there is a Python TTS library. How to include that in the program ? and which function should I call with a given text to speak though CPU speakers.
How could I make Python to speak some text ?
I have heard that there is a Python TTS library. How to include that in the program ? and which function should I call with a given text to speak though CPU speakers.
You will need the module : gTTS (Google Text-to-Speech)
First of all, install the module gTTS
pip install gTTS
Then create a python file :
from gtts import gTTS
#Write your text
text_to_speech = "So that's how you convert text to speech using Python"
#Choose your language (en : english, fr: french, ...)
language = "en"
#Passing the text, language and the speed to the module
myobj = gTTS(text=text_to_speech, lang=language, slow=False)
#Saving the audio in mp3
myobj.save("text_to_speech.mp3")