{"id":46036,"date":"2021-10-11T13:16:31","date_gmt":"2021-10-11T11:16:31","guid":{"rendered":"https:\/\/eiposgrados.com\/?p=46036"},"modified":"2021-10-11T13:16:31","modified_gmt":"2021-10-11T11:16:31","slug":"text-to-speech-with-python","status":"publish","type":"post","link":"https:\/\/eiposgrados.com\/eng\/python-blog\/text-to-speech-with-python\/","title":{"rendered":"Text to speech with Python"},"content":{"rendered":"<p>Today we are going to see how with a few simple lines of code we can <strong>convert text to mp3 file<\/strong> and our system automatically reproduces it for us.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to convert text to an mp3 file<\/h2>\n\n\n\n<p>We start by installing the module <strong><em>gtts<\/em><\/strong><\/p>\n\n\n\n<p><img decoding=\"async\" width=\"167\" height=\"37\" src=\"https:\/\/lh5.googleusercontent.com\/_IaTRq36s2sjEVDpH2gH6JD5Or_gHYabzyQFZnDrDzUP4g75jNR1-YFTzqU4FFdfANCDgaA3shS7vvJ3seeX3klSWH9741Jc_saC9WxNPmJF_PToOXVEjAJEfmvOqq83rvyJD4nmHSxGnvS2pw=s0\" alt=\"\" title=\"\"><\/p>\n\n\n\n<p>We create a variable with the text and choose the language, in our case Spanish.<\/p>\n\n\n\n<p><img decoding=\"async\" width=\"100%\" src=\"https:\/\/lh6.googleusercontent.com\/VHG-BoLdIGxUpg1LMha1ukjjB-ZXY4g8FgCc9TCQCQvvTZcHu7dRHO8wUgGZbXRsZJxJHqkMBSNrrlFFbiy8uVVmnZO9XXdHwh4Po1nzYeaqzd8PGziHr-NEu5-42DQYrhP8Ahwn1aLl6bXEXw=s0\" alt=\"\" title=\"\"><\/p>\n\n\n\n<p>We create the gTTS object with the text and the language and save it as <strong>\u201cWelcome.mp3\u201d. <\/strong>It will be saved in the same project folder.<\/p>\n\n\n\n<p><img decoding=\"async\" width=\"100%\" src=\"https:\/\/lh4.googleusercontent.com\/YaVVvwDGxmQuJi2-nFO3NomNWq8WiFQAdN79SQ4ZOTxtVcjUfEoINZH2NAKPnloswXxVavgfNMb8GHh4l8MRrSd-0V-BLk2oCUHq5G2swa4e4x2T9fzyEmFloW826WkgUqbepPxXbGUSVTyrpQ=s0\" alt=\"\" title=\"\"><\/p>\n\n\n\n<p>And finally we call our system predefined player to play it.<\/p>\n\n\n\n<p><img decoding=\"async\" width=\"275\" height=\"41\" src=\"https:\/\/lh6.googleusercontent.com\/iiYs1tDGp1mjyrSBm4pBZF3pJCOKJWUmTwmk9gjwopJekEauTCop61G_8A04e3YQZ0uCOcaLy0EeBOBmtcwwraSATPVIFxrQhgcd6BMJJf7BcsC2FbP7fb53icBYn9EWYyP64N5iMvanYr5Cng=s0\" alt=\"\" title=\"\"><\/p>\n\n\n\n<p>I leave you the complete code.<\/p>\n\n\n\n<p><img decoding=\"async\" width=\"100%\" src=\"https:\/\/lh6.googleusercontent.com\/DupEOak_ahkWPibLuEsv1ElDV55trbA_dyqPk1B6_a3kDPG-ut3Y5BzSUBDK41tc1GTolzrj_VVtlLEY7Jslymvyikq2Dbio3PJrGLwAWk0DyWU2gnEVuaVSCuZ67Fw181w1r-tuev9TyjwoXA=s0\" alt=\"\" title=\"\"><\/p>\n\n\n\n<p>As we have already told you many times, <strong>Python<\/strong> 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 <a href=\"https:\/\/eiposgrados.com\/eng\/master-in-python\/\">Master in Advanced Programming in Python for Big Data, Hacking and Machine Learning<\/a><strong>, where in just 12 months you will become a qualified expert with extensive knowledge in Big Data, Hacking and Machine Learning.<\/strong><\/p>","protected":false},"excerpt":{"rendered":"<p>Today we are going to see how with a few simple lines of code we can convert text to an mp3 file and have it automatically played by our system.<\/p>","protected":false},"author":1,"featured_media":46043,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[407],"tags":[],"class_list":["post-46036","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-python"],"acf":[],"_links":{"self":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts\/46036","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/comments?post=46036"}],"version-history":[{"count":0,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts\/46036\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/media\/46043"}],"wp:attachment":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/media?parent=46036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/categories?post=46036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/tags?post=46036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}