Today we are going to see how with a few simple lines of code we can convert text to mp3 file and our system automatically reproduces it for us.
Steps to convert text to an mp3 file
We start by installing the module gtts
We create a variable with the text and choose the language, in our case Spanish.
We create the gTTS object with the text and the language and save it as “Welcome.mp3”. It will be saved in the same project folder.
And finally we call our system predefined player to play it.
I leave you the complete code.
As we have already told you many times, Python It is a very simple, clean language and full of possibilities with the support of a great community. If you want to learn how to program it, we invite you to learn about our Master in Advanced Programming in Python for Big Data, Hacking and Machine Learning, where in just 12 months you will become a qualified expert with extensive knowledge in Big Data, Hacking and Machine Learning.