Python Text to Speech with Full Source Code For Beginners

When executed the text from abc.txt will be turned into an mp3, saved and then played on your device.


  • abc.txt with your text
  • the gTTS==2.1.1 module (pip install gTTS to download)
  • the os module (pip install os)

Run the Script:

  • Write your desired text into the abc.txt file then execute the file.
  • This can be done by typing ‘python’ into your Terminal.

Source Code:

from gtts import gTTS 
import os
file = open("abc.txt", "r").read()

speech = gTTS(text=file, lang='en', slow=False)"voice.mp3")

#print(file)Code language: PHP (php)


Thanks to Gail Cleaver, Beth Barrack, Bingo Nightly, Emily Webber and Sharon Counts. Finally, special thanks to Casey Cromwell. Radio Lab is produced by WNYC New York public radio, and distributed by NPR, National Public Radio.
Code language: PHP (php)

Leave a Comment