Share on social networks!

Text to speech with Python

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

IaTRq36s2sjEVDpH2gH6JD5Or gHYabzyQFZnDrDzUP4g75jNR1

We create a variable with the text and choose the language, in our case Spanish.

VHG BoLdIGxUpg1LMha1ukjjB ZXY4g8FgCc9TCQCQvvTZcHu7dRHO8wUgGZbXRsZJxJHqkMBSNrrlFFbiy8uVVmnZO9XXdHwh4Po1nzYeaqzd8PGziHr NEu5 42DQYrhP8Ahwn1aLl6bXEXw=s0

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.

YaVVvwDGxmQuJi2 nFO3NomNWq8WiFQAdN79SQ4ZOTxtVcjUfEoINZH2NAKPnloswXxVavgfNMb8GHh4l8MRrSd 0V

And finally we call our system predefined player to play it.

I leave you the complete code.

DupEOak ahkWPibLuEsv1ElDV55trbA dyqPk1B6 a3kDPG ut3Y5BzSUBDK41tc1GTolzrj VVtlLEY7Jslymvyikq2Dbio3PJrGLwAWk0DyWU2gnEVuaVSCuZ67Fw181w1r tuev9TyjwoXA=s0

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.

Subscribe to our newsletter to stay up to date with all the news

EIP International Business School informs you that the data in this form will be processed by Mainjobs Internacional Educativa y Tecnológica, SA as the person responsible for this website. The purpose of collecting and processing personal data is to respond to the query made as well as to send information about the services of the data controller. Legitimation is the consent of the interested party.
You can exercise your rights of access, rectification, limitation and deletion of data in compliance@grupomainjobs.com as well as the right to file a claim with the supervisory authority. You can consult additional and detailed information on Data Protection in the Privacy Policy that you will find in our Web page

Leave a comment