Created
September 10, 2019 20:57
-
-
Save pknowledge/dc4ba582623cc3682a62d7d7a69f7887 to your computer and use it in GitHub Desktop.
TEXT TO SPEECH IN PYTHON | Convert Text to Speech in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") | |
Sir, how can we add some expressions?
where to get output file
in the folder where your script is
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
It is really helpful, thank you.