Coders Packet

Convert Text to Speech using Python

By Suryansh Mamgain

A Python Script to convert text to speech using Google's text to speech API commonly known as gTTS API.

Requirements:

    1.Install the gTTS API using the command given below in the terminal because this API doesn't come with python:

     pip install gTTS

Methodology:

    1.Import the gTTS API

    2.Import OS (this module is imported so that we can play the converted audio)

    3.Enter the text to be converted

    4.Choose the language in which you want to convert

    5.Create the object of gTTS module and pass the following parameters in it:

            * text=text

            * lang=language

            * slow=False (by doing this it will tell the module that the converted audio will have a high speed)

    6.Now, save the converted audio in a mp3 file named "audio.mp3"

    7.Play the audio

NOTE:

1. The gTTS API supports languages like English, Hindi, French, Tamil, and many more.

2. We can set the speed of converted audio(fast or slow). 

Download Complete Code

Comments

No comments yet