Python Text-to-Speech App with gTTS
A Python desktop GUI that converts typed text to speech using Google Text-to-Speech (gTTS), with 15 language and accent options, a modern customtkinter interface, and playback through pygame.
Python projects · Desktop interfaces and audio
Start here
Read the requirements and any configuration below, then follow the usage example. Source paths below are relative to the repository root; run commands from the working directory stated in Usage. This example’s source is in Text2Audio/GUI_Code/. Install any third-party packages in an isolated Python environment.
Overview
Text2Audio provides a clean, dark-themed desktop interface where you type text, select a language variant, and press Play to hear the text read aloud. The audio is generated by gTTS and played back using pygame. The app is built with customtkinter for a modern look.
Features
- Text input area for entering any text to convert
- Language selection dropdown with 15 locale options
- Play button that generates and immediately plays the audio
- Reset button to clear the text input
- Exit button to close the application
- Dark mode with blue color theme
- Fixed window size (500×420), centered on screen
- Warning dialogs for empty text or invalid language selection
Prerequisites and installation
customtkinter
gtts
pygame
Install dependencies:
python -m pip install customtkinter gtts pygame
Usage
From the Text2Audio folder:
python GUI_Code/main.py
- Type your text in the input box.
- Select a language from the dropdown.
- Click Play to generate and hear the audio.
- Click Reset to clear the text.
- Click Exit to close the app.
Supported Languages
| Language | Variant |
|---|---|
| English | Australia, UK, USA, Canada, India, Ireland, South Africa, Nigeria |
| French | Canada, France |
| Portuguese | Brazil, Portugal |
| Spanish | Mexico, Spain, USA |
How It Works
- The text is passed to
gTTS(text, lang=lang, tld=tld, slow=False)which calls the Google TTS API. - The audio is saved to
output.mp3in the working directory. pygame.mixerloads and plays the file.- The app waits for playback to finish before returning control.
Architecture
Text2Audio/
└── GUI_Code/
├── main.py # Entry point — creates and runs TextToAudio instance
└── screen.py # TextToAudio class — UI layout and audio logic
Troubleshooting and limitations
- An active internet connection is required since gTTS sends requests to Google’s TTS API.
- Speech generation and the playback loop run in the GUI callback, so the interface can become unresponsive until playback ends. Network and audio exceptions are not caught in that callback. Text is sent to the external speech service; use text appropriate for that service.
- The generated
output.mp3file is saved in the current working directory and overwritten on each use. - Accents are produced by sending the request to a regional Google domain through gTTS’s
tldparameter (for exampleco.ukfor UK English orcom.brfor Brazilian Portuguese).
Related documentation
- Story Reader — read a PDF aloud with offline TTS
- Setup Wizard — Fruit Wiki GUI
- Back to all Python projects
Documentation links
Read all Python Projects and Code Examples guides online · Project overview · All developer projects