In this tutorial, you will learn how to text to speech using Python. Python is an incredibly strong and flexible language used for multi-purpose programming. There are a lot of things possible using Python one of them is Text to Speech conversion.

We are going to use a Python package called gTTS (Google Text-to-Speech) for this purpose. gTTS is a Python library and CLI tool to interface with Google Translate’s text-to-speech API. Which writes spoken mp3 data to a file, a file-like object (byte string) for further audio manipulation, or stdout.

Google Cloud Text-to-Speech converts text into human-like speech in more than 100 voices across 20+ languages and variants. The gTTS API supports several languages including English, Hindi, Tamil, French, German, and many more. Let’s being with installing the gTTS package first.

After the installation is done you can go ahead run the following Scripts. Note that gTTS works perfectly in python but it needs an internet connection to work since it relies on Google to get the audio data so your machine must have a working internet connection.

Python Program to convert a text into speech

Save the file and run it this should open your default music player app and play the audio. but what if you wanted to convert a large string or document into speech for that you might wanna save the content into a text file then convert it into speech as follows.

Python program to convert a text file into speech

Save and run the file you should get the desired output.

Text To Speech Conversion Using Python

The article was published on November 5, 2020 @ 2:07 PM

Leave a Comment