A simple text-to-speech program using:
Install Google Text-to-Speech lib
user@linux:~$ pip install gTTS
Google Text-to-Speech
from gtts import gTTS
To use operating system funcionalities, import Python OS module
import os
Tkinter Python GUI
from tkinter import *
To show errors, attention and other alert messages
from tkinter import messagebox
For Mac OS users, some buttons and icons does not work properly. Please, use ttk submodule.
from tkinter import ttk
Before running the program, you need to choose the correct player based on your operating system.
(afplay is a Mac OS command.)
- For Arch Linux based (Manjaro...)
user@linux:~$ sudo pacman -S mpg123
- For Debian Linux based (Ubuntu...)
user@linux:~$ sudo apt-get update
user@linux:~$ sudo apt-get install mpg123
- For Redhat Linux based (Fedora, SUSE...)
user@linux:~$ yum install mpg123
- For Windows mpg123 for Windows
After successful installation, you can test it.
user@linux:~$ mpg123 <some_audio_file>.mp3
It's necessary to change afplay to correct mp3 player at /source/TextToSpeech.py
#The argument & indicates afplay to run in the background as a job.
os.system("afplay sound/output.mp3 &")
This project is licensed under the MIT License.