

{"id":81979,"date":"2020-09-07T15:23:35","date_gmt":"2020-09-07T09:53:35","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=81979"},"modified":"2026-06-01T14:00:01","modified_gmt":"2026-06-01T08:30:01","slug":"python-text-to-speech","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/","title":{"rendered":"Convert Text to Speech in Python"},"content":{"rendered":"<p><strong>Learn how to convert your Text into Voice with Python and Google APIs<\/strong><\/p>\n<p>Text to speech is a process to convert any text into voice. Text to speech project takes words on digital devices and convert them into audio with a button click or finger touch. Text to speech python project is very helpful for people who are struggling with reading.<\/p>\n<h3>Project Prerequisites<\/h3>\n<p>To implement this project, we will use the basic concepts of Python, Tkinter, gTTS, and playsound libraries.<\/p>\n<ul>\n<li><strong>Tkinter<\/strong> is a standard GUI Python library that is one of the fastest and easiest ways to build GUI applications using Tkinter.<\/li>\n<li><strong>gTTS (Google Text-to-Speech)<\/strong> is a Python library, which is a very easy library that converts the text into audio.<\/li>\n<li>The <strong>playsound<\/strong> module is used to play audio files. With this module, we can play a sound file with a single line of code.<\/li>\n<\/ul>\n<p>To install the required libraries, you can use pip install command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">pip install tkinter\r\npip install gTTS\r\npip install playsound\r\n<\/pre>\n<h3>Download Python Text to Speech Project Code<\/h3>\n<p>Please download the source code of Text to Speech Project: <a href=\"https:\/\/drive.google.com\/file\/d\/1-8IsnLURbYsJtiJC9KMCK4HMb6sW_a1V\/view?usp=drive_link\"><strong>Python Text to Speech<\/strong><\/a><\/p>\n<h3>Text to Speech Python Project<\/h3>\n<p>The objective of this project is to convert the text into voice with the click of a button. This project will be developed using Tkinter, gTTs, and playsound library.<\/p>\n<p>In this project, we add a message which we want to convert into voice and click on play button to play the voice of that text message.<\/p>\n<ul>\n<li>Importing the modules<\/li>\n<li>Create the display window<\/li>\n<li>Define functions<\/li>\n<\/ul>\n<p>So these are the basic steps that we will do in this Python project. Let\u2019s start.<\/p>\n<h4>1. Import Libraries<\/h4>\n<p>Let\u2019s start by importing the libraries: tkinter, gTTS, and playsound<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">from tkinter import *\r\nFrom gtts import gTTS\r\nFrom playsound import playsound\r\n<\/pre>\n<h4>2. Initializing window<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">root = Tk()\r\ngeometry root.(\"350x300\") \r\nroot.configure(bg='ghost white')\r\nroot.title(\"DataFlair - TEXT TO SPEECH\")\r\n<\/pre>\n<ul>\n<li><strong>Tk()<\/strong> to initialized tkinter which will be used for GUI<\/li>\n<li><strong>geometry()<\/strong> used to set the width and height of the window<\/li>\n<li><strong>configure()<\/strong> used to access window attributes<\/li>\n<li><strong>bg<\/strong> will used to set the color of the background<\/li>\n<li><strong>title()<\/strong> set the title of the window<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Label(root, text = \"TEXT_TO_SPEECH\", font = \"arial 20 bold\", bg='white smoke').pack()\r\nLabel(text =\"DataFlair\", font = 'arial 15 bold', bg ='white smoke' , width = '20').pack(side = 'bottom')\r\n\r\nMsg = StringVar()\r\nLabel(root,text =\"Enter Text\", font = 'arial 15 bold', bg ='white smoke').place(x=20,y=60)\r\n\r\nentry_field = Entry(root, textvariable = Msg ,width ='50')\r\nentry_field.place(x=20,y=100)\r\n\r\n<\/pre>\n<p><strong>Label()<\/strong> widget is used to display one or more than one line of text that users can\u2019t able to modify.<\/p>\n<ul>\n<li><strong>root<\/strong> is the name which we refer to our window<\/li>\n<li><strong>text<\/strong> which we display on the label<\/li>\n<li><strong>font<\/strong> in which the text is written<\/li>\n<li><strong>pack<\/strong> organized widget in block<\/li>\n<li><strong>Msg<\/strong> is a string type variable<\/li>\n<li><strong>Entry()<\/strong> used to create an input text field<\/li>\n<li><strong>textvariable<\/strong> used to retrieve the current text to entry widget<\/li>\n<li><strong>place()<\/strong> organizes widgets by placing them in a specific position in the parent widget<\/li>\n<\/ul>\n<h4>3. Function to Convert Text to Speech in Python<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">def Text_to_speech():\r\n    Message = entry_field.get()\r\n    speech = gTTS(text = Message)\r\n    speech.save('DataFlair.mp3')\r\n    playsound('DataFlair.mp3')\r\n<\/pre>\n<ul>\n<li><strong>Message<\/strong> variable will stores the value of entry_field<\/li>\n<li><strong>text<\/strong> is the sentences or text to be read.<\/li>\n<li><strong>lang<\/strong> takes the language to read the text. The default language is English.<\/li>\n<li><strong>slow<\/strong> use to reads text more slowly. The default is False.<\/li>\n<\/ul>\n<p>As we want the default value of lang, so no need to give that to gTTS.<\/p>\n<ul>\n<li><strong>speech<\/strong> stores the converted voice from the text<\/li>\n<li><strong>speech.save(&#8216;DataFlair.mp3&#8217;)<\/strong> will saves the converted file as DataFlair as mp3 file<\/li>\n<li><strong>playsound()<\/strong> used to play the sound<\/li>\n<\/ul>\n<h4>4. Function to Exit<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">def Exit():\r\n    root.destroy()\r\n\r\n<\/pre>\n<p><strong>root.destroy()<\/strong> will quit the program by stopping the mainloop().<\/p>\n<h4>5. Function to Reset<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">def Reset():\r\n    Msg.set(\"\")\r\n<\/pre>\n<p><strong>Reset<\/strong> function set Msg variable to empty strings.<\/p>\n<h4>6. Define Buttons<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Button(root, text = \"PLAY\", font = 'arial 15 bold' , command = Text_to_speech ,width = '4').place(x=25,y=140)\r\n\r\nButton(root, font = 'arial 15 bold',text = 'EXIT', width = '4' , command = Exit, bg = 'OrangeRed1').place(x=100 , y = 140)\r\n\r\nButton(root, font = 'arial 15 bold',text = 'RESET', width = '6' , command = Reset).place(x=175 , y = 140)\r\n<\/pre>\n<p><strong>Button()<\/strong> widget used to display button on the window<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">root.mainloop()\r\n<\/pre>\n<p><strong>root.mainloop()<\/strong> is a method that executes when we want to run our program.<\/p>\n<h3>Python Text to Speech Project Output<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-text-to-speech-project-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81984\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-text-to-speech-project-output.png\" alt=\"python text to speech project output\" width=\"1366\" height=\"728\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-text-to-speech-project-output.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-text-to-speech-project-output-300x160.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-text-to-speech-project-output-1024x546.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-text-to-speech-project-output-150x80.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-text-to-speech-project-output-768x409.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-text-to-speech-project-output-520x277.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>We have successfully developed the text to speech python project. We used the popular tkinter library for rendering graphics on a display window, gTTs (google text to speech) library to convert text to voice, and playsound library to play that converter voice from the text.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:2582,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1-8IsnLURbYsJtiJC9KMCK4HMb6sW_a1V\\\/view?usp=drive_link&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20260601084342\\\/https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1-8IsnLURbYsJtiJC9KMCK4HMb6sW_a1V\\\/view?usp=drive_link&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-06-01 17:05:50&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-05 15:00:38&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-08 18:13:12&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-12 06:54:42&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-12 06:54:42&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to convert your Text into Voice with Python and Google APIs Text to speech is a process to convert any text into voice. Text to speech project takes words on digital devices&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":81985,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[21082,22734,23207,23208],"class_list":["post-81979","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python-project","tag-python-project-for-beginners","tag-python-text-to-speech","tag-text-to-speech-convertor"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Convert Text to Speech in Python - DataFlair<\/title>\n<meta name=\"description\" content=\"Python Text to Speech project - Convert the text into voice using Tkinter, gTTs (google text to speech library), and playsound libraries.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Convert Text to Speech in Python - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Python Text to Speech project - Convert the text into voice using Tkinter, gTTs (google text to speech library), and playsound libraries.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-07T09:53:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-01T08:30:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-text-to-speech-project.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Convert Text to Speech in Python - DataFlair","description":"Python Text to Speech project - Convert the text into voice using Tkinter, gTTs (google text to speech library), and playsound libraries.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/","og_locale":"en_US","og_type":"article","og_title":"Convert Text to Speech in Python - DataFlair","og_description":"Python Text to Speech project - Convert the text into voice using Tkinter, gTTs (google text to speech library), and playsound libraries.","og_url":"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2020-09-07T09:53:35+00:00","article_modified_time":"2026-06-01T08:30:01+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-text-to-speech-project.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Convert Text to Speech in Python","datePublished":"2020-09-07T09:53:35+00:00","dateModified":"2026-06-01T08:30:01+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/"},"wordCount":613,"commentCount":33,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-text-to-speech-project.jpg","keywords":["Python project","python project for beginners","python text to speech","text to speech convertor"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-text-to-speech\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/","url":"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/","name":"Convert Text to Speech in Python - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-text-to-speech-project.jpg","datePublished":"2020-09-07T09:53:35+00:00","dateModified":"2026-06-01T08:30:01+00:00","description":"Python Text to Speech project - Convert the text into voice using Tkinter, gTTs (google text to speech library), and playsound libraries.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-text-to-speech\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-text-to-speech-project.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-text-to-speech-project.jpg","width":1200,"height":628},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-text-to-speech\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Convert Text to Speech in Python"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/81979","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=81979"}],"version-history":[{"count":5,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/81979\/revisions"}],"predecessor-version":[{"id":148665,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/81979\/revisions\/148665"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/81985"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=81979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=81979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=81979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}