Reputation: 1
I am using Sublime Text 3 and Python 3.7.6.
Here is the code I'm using;
from gtts import gTTS
tts = gTTS(text="Hello crazy programmer", lang='en')
tts.save("audio.mp3")
Upvotes: 0
Views: 411
Reputation: 176
The above code just create a mp3 file, you have to use a mp3 player to play it. I would suggest using playsound library for simplicity but you can find more options here
from playsound import playsound
playsound("audio.mp3")
If this is not the case, you may check if GTTS save the mp3 file correctly by double-clicking in and play with your built-in mp3 player. For more safety, I suggest using something like this instead of your code:
try:
tts = gTTS(text=self.__speech, lang=self.__lang)
except Exception as e:
print("Failed to generate speech from text")
removeSpeech()
exit(e)
else: #if no exception then save the file
tts.save(self.__name_save)
Upvotes: 1