Coders Packet

Text To Speech in Python

By Nediff Amala Nixon

A Text-to-Speech GUI application that uses various python libraries to convert text to speech.

Text to Speech GUI using various libraries of Python 3.0

This application can convert an English text to both English and Hindi speech.

The text input format can be either type in the textbox provided or upload a .txt file to convert.

Before running the code, there are certain prerequisites that must be fulfilled.


  1. PySimpleGUI module (using pip install)

    This module will be used to design the GUI of the application.

    The PySimpleGUI cookbook:

  2. Pyttsx3 module (using pip install)

    This module is used for Text-To-Speech (TTS) conversion. This is an offline convertor module that uses three TTS engines:

    • Sapi5 -SAPI5 on windows

    • nsss – NSSpeechSynthesizer on Mac OS X

    • espeak – eSpeak on every other platform

    Reference to working of the module:

  3. Google_trans_new module (using pip install)

    The command to install this module:

    pip install google_trans_new

    This is a python API for google translator, since this application gives you an option to translate a text in one language to speech in another language, we use this API for this purpose.

    Reference to working of this module:

    This application can convert an English text to English speech and Hindi speech. You can select the languages before you begin the conversion.

    To use the Hindi TTS, you will have to install the Microsoft TTS for the Hindi language. Without this the application will throw an error. I will further add an option to convert only to English if Hindi is not installed.

    Once the Hindi TTS is installed, there has to be few changes made in the registry to make the pttsx3 module to identify those languages. The following steps will show you how to do it:

    1. Open the registry of your system.

    2. Navigate to this directory: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens

    3. If you have installed the Hindi TTS then you will see two following sub directories:

      MSTTS_V110_hiIN_HemantM (Male voice)

      MSTTS_V110_hiIN_KalpanaM (Female voice)

    4. Export these two directories by right-clicking and then select export.

    5. Once exported, Open the .reg file using a text-editor application.

    6. Replace all “Speech_OneCore” to “Speech”. (Be careful with the spelling or else it will cause errors).

    7. Save the file and close it.

    8. Run these two .reg files using windows registry editor and click ok to make changes.

    9. Now you are ready to go with the Hindi TTS.

I have added support for only English and Hindi for now.

Once, these are satisfied, run the file

I am working on the part where this application can communicate between two different systems so that if a server tries to say something, the client can hear that text in their desired language. This is very useful to reduce the communication barrier between a host and various client belonging to different language group.

I will also work on adding support for more file extentions like .doc,.pdf etc. since these extensions are causing an increase in time complexity.

To check what languages are installed in the system that is recognised by pyttsx3 module, run the file.

Download Complete Code


No comments yet