Programming, Python, Tutorials

Instant Free Text to Speech in Python

Text to Speech is converting any given text to a audible speech format.

Adding Speech as a feature in your application can make it more interactive as easier for the user to get response from the machine.

There are many free and paid websites available on the web which can help you convert any text into speech.

With the advancement in machine learning and deep learning algorithms text to speech has become more and more sophisticated in producing human like voice.

Also, There are many Text to speech engine APIs which can be by a developer in there application to enable Text to speech (TTS).

Lets start with a basic off the shelf TTS implementation on Python and later dive into alternate methods.

To start with TTS we need to install the gTTS library.

gTTS is Google Text to Speech is free python library to interface with the Google Translate Engine.

  1. Install gTTS by using command “pip install gTTS“.
  2. Now we can import the library using “from gtts import gTTS” and use it to convert text into speech and save it as a mp3 file or even play it back to back.
  3. Below is a sample program which takes input text from user and plays the output in speech.

Futher you can play the saved mp3 file by using the playsound library

To install the playsound library use command “pip install playsound“.

Use the function playsound with parameter as your mp3 file name, playsound will play the mp3 file.

gTTS library github

Extract Text from Image using optical character reader in python

Thank you for reading, Happy Learning, drop your suggestion in the comments.

Feel free to follow us on Youtube , Linked In , Instagram