# Convert Text to Speech



## Convert Text to Speech in Python

There are several APIs available to convert text to speech in python. One of such APIs is the Google Text to Speech API commonly known as the gTTS API. gTTS is a very easy to use tool which converts the text entered, into audio which can be saved as a mp3 file.

The gTTS API supports several languages including English, Hindi, Tamil, French, German and many more. The speech can be delivered in any one of the two available audio speeds, fast or slow. However, as of the latest update, it is not possible to change the voice of the generated audio.

#### **Installation**

To install the gTTS API, open terminal and write\
\


```
pip install gTTS
```

This works for any platform.\
Now we are all set to write a sample program that converts text to speech

```python
# Import the required module for text  
# to speech conversion 
from gtts import gTTS 
  
# This module is imported so that we can  
# play the converted audio 
import os 
  
# The text that you want to convert to audio 
mytext = 'Welcome to geeksforgeeks!'
  
# Language in which you want to convert 
language = 'en'
  
# Passing the text and language to the engine,  
# here we have marked slow=False. Which tells  
# the module that the converted audio should  
# have a high speed 
myobj = gTTS(text=mytext, lang=language, slow=False) 
  
# Saving the converted audio in a mp3 file named 
# welcome  
myobj.save("welcome.mp3") 
  
# Playing the converted file 
os.system("mpg321 welcome.mp3") 
```

#### **Output**

```
The output of the above program should be a 
voice saying, 'Welcome to geeksforgeeks!'
```

This article is contributed by **Akhil Goel**. If you like GeeksforGeeks and would like to contribute, you can also write an article using [contribute.geeksforgeeks.org](http://contribute.geeksforgeeks.org/) or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

### Recommended Posts:

* [Python: Convert Speech to text and text to Speech](https://www.geeksforgeeks.org/python-convert-speech-to-text-and-text-to-speech/)
* [Python | Convert image to text and then to speech](https://www.geeksforgeeks.org/python-convert-image-to-text-and-then-to-speech/)
* [Convert Text to Speech in Python using win32com.client](https://www.geeksforgeeks.org/convert-text-speech-python-using-win32com-client/)
* [Python | Text to Speech by using pyttsx3](https://www.geeksforgeeks.org/python-text-to-speech-by-using-pyttsx3/)
* [Python Text To Speech | pyttsx module](https://www.geeksforgeeks.org/python-text-to-speech-pyttsx-module/)
* [Text-To-Speech changing voice in Python](https://www.geeksforgeeks.org/text-to-speech-changing-voice-in-python/)
* [Convert Text and Text File to PDF using Python](https://www.geeksforgeeks.org/convert-text-and-text-file-to-pdf-using-python/)
* [Speech Recognition in Python using Google Speech API](https://www.geeksforgeeks.org/speech-recognition-in-python-using-google-speech-api/)
* [Speech To Text using IBM Watson Studio](https://www.geeksforgeeks.org/speech-to-text-using-ibm-watson-studio/)
* [Convert Text file to JSON in Python](https://www.geeksforgeeks.org/convert-text-file-to-json-in-python/)
* [Python | Part of Speech Tagging using TextBlob](https://www.geeksforgeeks.org/python-part-of-speech-tagging-using-textblob/)
* [Python | Speech recognition on large audio files](https://www.geeksforgeeks.org/python-speech-recognition-on-large-audio-files/)
* [Part of Speech Tagging with Stop words using NLTK in python](https://www.geeksforgeeks.org/part-speech-tagging-stop-words-using-nltk-python/)
* [Text Preprocessing in Python | Set 2](https://www.geeksforgeeks.org/text-preprocessing-in-python-set-2/)
* [Python | Text Summarizer](https://www.geeksforgeeks.org/python-text-summarizer/)

Reference : [https://www.geeksforgeeks.org/convert-text-speech-python/](https://www.geeksforgeeks.org/convert-text-speech-python/)
