Text to Speech in Python (Learn Python with Akshit Madan)
Hey readers ! In this blog we are going to see how you can implement a text to speech model in python using gtts package that’s is Google Text to Speech package . The model takes a .txt file as input and reads the file line by line .
So, let’s code !!
First we imported gtts and os libraries, then we opened our text file, please mention the full path of the file if your file exists in folder other than the current one.
As you can see we mentioned .replace() function and replaced all the next line tags with the blank spaces so that the gtts package should work efficiently. Well I recommend you to even try without using replace function and notice what happens.
After reading the file , we mentioned the language of the text and stored the audio result in a file output.mp4, here also mention the complete output path.
And yes you are ready with your own audio book !!