Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import below module for text to speech conversion.
- from gtts import gTTS
- #import below module to play saved audio files
- import os
- #text to be converted
- mytxt = 'Hello Python..! This is text to speech conversion'
- #specifying the language
- language = 'en'
- #creating an object of gTTS with required parameters
- myobj = gTTS(text=mytxt, lang=language, slow=False)
- # Saving the converted audio in a mp3 file named 'example'
- myobj.save("example.mp3")
- # Playing the converted file
- os.system("mpg321 example.mp3")
Add Comment
Please, Sign In to add comment