Change language

Converting text to speech in Python


GTTS API supports multiple languages ​​including English, Hindi, Tamil, French, German and many more. Speech can be delivered at any of two available audio speeds, fast or slow. However, since the last update, it is not possible to change the voice of the generated sound.


To install the gTTS API, open a terminal and write

 pip install gTTS 

This works for any platform. 
We are now ready to write a sample program that converts text to speech.

# Import the required module for text
# to speech conversion

from gtts import gTTS

# This module is imported so we can
# play the converted audio

import os

# Text you want to convert to audio

mytext = ’Welcome to pythonengineering!’

# The language you want to convert in

language = ’en’

# Transfer of text and language to the engine,
# here we marked slow = False. Which says
# the module that needs the converted audio
# has a high speed

myobj = gTTS (text = mytext, lang = language, slow = False )

# Save converted audio to mp3 file with name
# welcome ( "welcome.mp3" )

# Play the converted file

os.system ( " mpg321 welcome.mp3 " )


 The output of the above program should be a voice saying, ’Welcome to pythonengineering!’ 

This article contributed by Achil Goel . If you are as Python.Engineering and would like to contribute, you can also write an article using or by posting the article [email protected] ... See my article appearing on the Python.Engineering homepage and help other geeks.

Please post comments if you find anything wrong or if you would like to share more information on the topic discussed above.


Learn programming in R: courses


Best Python online courses for 2022


Best laptop for Fortnite


Best laptop for Excel


Best laptop for Solidworks


Best laptop for Roblox


Best computer for crypto mining


Best laptop for Sims 4


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers



Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method