Text to speech (TTS) is the conversion of written text into spoken voice.You can create TTS programs in python. The quality of the spoken voice depends on your speech engine.
In this article you’ll learn how to create your own TTS program.
Related course: Complete Python Programming Course & Exercises
Text to speech in python
Example with espeak
The program ‘espeak’ is a simple speech synthesizer which converst written text into spoken voice. The espeak program does sound a bit robotic, but its simple enough to build a basic program.
1 | import subprocess |
TTS with Google
Google has a very natural sounding voices. You can use their TTS engine with the code below.
For this program you need the module gTTS installed as well as the program mpg123.
1 | # need gTTS and mpg123 |
This will output spoken voice / an mp3 file.
Related course: Complete Python Programming Course & Exercises