-
-
Save DuncanWilliamGibbons/121f169584ee8a74e9c8eeac38ca2196 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") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment