How to Convert Text to Speech in Python
The text to speech conversion has got many applications nowadays. There are many APIs available for this.
In this article, we are using the Google Text to Speech API. It is commonly known as the gTTS API. This is an easy-to-use tool and supports several languages including English, Hindi, Tamil, French, German, etc. With this API the text we entered will be converted to audio and can be saved as mp3 file.
Install gTTS using the following command.
pip install gTTS
from gtts import gTTS import os sample_text = "Hello Friends. Happy Learning." language = "en" obj = gTTS(text = sample_text, lang = language, slow = False) obj.save("Sample.mp3") os.system("mpg321 Sample.mp3")
A new mp3 file named Sample will be created in the same directory where this python file resides. That mp3 file will be text converted to speech.
Subscribe
Login
Please login to comment
0 Discussion