{"id":268,"date":"2025-11-21T15:29:09","date_gmt":"2025-11-21T15:29:09","guid":{"rendered":"https:\/\/codetypingpro.com\/?p=268"},"modified":"2025-11-21T15:29:09","modified_gmt":"2025-11-21T15:29:09","slug":"46-real-world-python-projects-text-to-speech-and-speech-to-text-app","status":"publish","type":"post","link":"https:\/\/codetypingpro.com\/?p=268","title":{"rendered":"46 &#8211; Real-World Python Projects &#8211; Text-to-Speech and Speech-to-Text App"},"content":{"rendered":"\n<h6 class=\"wp-block-heading\"><\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">This project allows users to:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u2714 Convert <strong>Text \u2192 Speech (TTS)<\/strong><\/h3>\n\n\n\n<h3 class=\"wp-block-heading\">\u2714 Convert <strong>Speech \u2192 Text (STT)<\/strong><\/h3>\n\n\n\n<h3 class=\"wp-block-heading\">\u2714 Save audio files<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\">\u2714 Use microphone input<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\">\u2714 Build a small GUI app (optional)<\/h3>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udee0 Skills You Will Learn<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python audio processing<\/li>\n\n\n\n<li>Using <strong>gTTS<\/strong> (Google Text-to-Speech)<\/li>\n\n\n\n<li>Using <strong>SpeechRecognition<\/strong> library<\/li>\n\n\n\n<li>Handling audio files (MP3\/WAV)<\/li>\n\n\n\n<li>Optional: GUI using Tkinter<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udce6 Install Required Libraries<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install gtts speechrecognition pyaudio playsound\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If <em>pyaudio<\/em> gives error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install pipwin\npipwin install pyaudio\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\udde9 PART 1 \u2014 Text-to-Speech (TTS)<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>from gtts import gTTS\nfrom playsound import playsound\n\ntext = input(\"Enter text to speak: \")\n\ntts = gTTS(text)\ntts.save(\"speech.mp3\")\n\nprint(\"Speaking...\")\nplaysound(\"speech.mp3\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 Converts text \u2192 audio<br>\u2705 Saves MP3 file<br>\u2705 Plays it automatically<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\udde9 PART 2 \u2014 Speech-to-Text (STT)<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>import speech_recognition as sr\n\nr = sr.Recognizer()\n\nwith sr.Microphone() as mic:\n    print(\"Speak now...\")\n    audio = r.listen(mic)\n\ntry:\n    text = r.recognize_google(audio)\n    print(\"You said:\", text)\nexcept:\n    print(\"Sorry, I could not understand.\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2714 Records live microphone audio<br>\u2714 Uses Google Speech Recognition<br>\u2714 Prints recognized text<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\udde9 PART 3 \u2014 Full App (TTS + STT Combined)<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>from gtts import gTTS\nimport speech_recognition as sr\nfrom playsound import playsound\n\ndef text_to_speech():\n    text = input(\"Enter text: \")\n    tts = gTTS(text)\n    tts.save(\"tts_output.mp3\")\n    playsound(\"tts_output.mp3\")\n\ndef speech_to_text():\n    r = sr.Recognizer()\n    with sr.Microphone() as mic:\n        print(\"Speak now...\")\n        audio = r.listen(mic)\n\n    try:\n        print(\"You said:\", r.recognize_google(audio))\n    except:\n        print(\"Could not understand.\")\n\nprint(\"1 - Text to Speech\")\nprint(\"2 - Speech to Text\")\n\nchoice = input(\"Choose option: \")\n\nif choice == \"1\":\n    text_to_speech()\nelse:\n    speech_to_text()\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This project allows users to: \u2714 Convert Text \u2192 Speech (TTS) \u2714 Convert Speech \u2192 Text (STT) \u2714 Save audio files \u2714 Use microphone input \u2714 Build a small GUI app (optional) \ud83d\udee0 Skills You Will Learn \ud83d\udce6 Install Required Libraries Run: If pyaudio gives error: \ud83e\udde9 PART 1 \u2014 Text-to-Speech (TTS) \u2705 Converts text [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-268","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts\/268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=268"}],"version-history":[{"count":1,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts\/268\/revisions"}],"predecessor-version":[{"id":269,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts\/268\/revisions\/269"}],"wp:attachment":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}