Skip to content

Instantly share code, notes, and snippets.

@pknowledge
Created September 10, 2019 20:57
Show Gist options
  • Save pknowledge/dc4ba582623cc3682a62d7d7a69f7887 to your computer and use it in GitHub Desktop.
Save pknowledge/dc4ba582623cc3682a62d7d7a69f7887 to your computer and use it in GitHub Desktop.
TEXT TO SPEECH IN PYTHON | Convert Text to Speech in Python
# Import the Gtts module for text
# to speech conversion
from gtts import gTTS
# import Os module to start the audio file
import os
fh = open("test.txt", "r")
myText = fh.read().replace("\n", " ")
# Language we want to use
language = 'en'
output = gTTS(text=myText, lang=language, slow=False)
output.save("output.mp3")
fh.close()
# Play the converted file
os.system("start output.mp3")
# Import the Gtts module for text
# to speech conversion
from gtts import gTTS
# import Os module to start the audio file
import os
mytext = 'Convert this Text to Speech in Python'
# Language we want to use
language = 'en'
myobj = gTTS(text=mytext, lang=language, slow=False)
myobj.save("output.mp3")
# Play the converted file
os.system("start output.mp3")
@MainakRepositor
Copy link

Sir, how can we add some expressions?

@pegvin
Copy link

pegvin commented Jan 28, 2021

where to get output file

in the folder where your script is

@manisha6367
Copy link

What is the purpose of deploying this as a image container?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment