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")
@Zeph2020
Copy link

Good lesson. I realy appreciate.
It repeat the sentence several times. How can I stop it?
Can I change the carateristics of the voice?
How can I translate a pdf text file to mp3? I tried but I have an encode error

In French, we can read the following text:"Ce cours a pour objectif d’initier l’apprenant à la programmation en utilisant le langage C" very well. But in a file, there is a problem to read, when the apostroph caracter ( ' ) is met. How can I solve it?

@RiskyTrick
Copy link

helped me a lot

@Daniyal421
Copy link

where to get output file

@DuncanWilliamGibbons
Copy link

Thanks, this was very helpful.

How can I use this with different voices and the WaveNet type?

@surjitsingh790
Copy link

It is really helpful, thank you.

@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