© 2018 - Analytics Link

Text-To-Speech in 3 lines of Python code

October 25, 2018

gTTS (Google Text-to-Speech), is a Python library and CLI tool to interface with Google Translate’s text-to-speech API.

 

Have a read of the docs to get right into the details!

To get you started however, here are 3 lines of code that will take a text string, convert it to speech, and save an mp3 file for you to listen to.  (use pip install gTTS to install the package)

 

from gtts import gTTS

tts = gTTS(text='Hello from analytics-link!', lang='en')

tts.save("tts_file.mp3")

 

 

Enjoy!

 

 

Share on Facebook
Please reload

Please reload

Recent Posts