python logo

Speech engines with python tutorial

Python hosting: Host, run, and code Python in the cloud!
Text To Speech (TTS) Text To Speech (TTS)

A computer system used to create artificial speech is called a speech synthesizer, and can be implemented in software or hardware products.

A text-to-speech (TTS) system converts normal language text into speech. How can we use speech synthesis in Python?

Related courses:


Pyttsx is a cross-platform speech (Mac OSX, Windows, and Linux) library. You can set voice metadata such as age, gender, id, language and name. Thee speech engine comes with a large amount of voices.

Text to speech sample:

Install with:

sudo pip install pyttsx

Create the code

import pyttsx
engine = pyttsx.init()
engine.say('The quick brown fox jumped over the lazy dog.')

And execute it with python.


eSpeak is a compact open source software speech synthesizer for English and other languages, for Linux and Windows.

Text to speech sample:

We can install using:

sudo apt-get install espeak

Create the code

import os
os.system("espeak 'The quick brown fox'")

It is very easy to use, but like pyttsx it sounds very robotic.


The gtts module no longer works.

I found a script on Github that uses the Google speech engine. The script comes with many options and does not speak, instead it saves to an mp3. We added a command to play the mp3 automatically:

os.system("mpg321 out.mp3 -quiet")

Run with:

python -s 'Python programming example'

The voice is extremely natural. The only disadvantage is that you need to be connected with the Internet when running this script.


You might like:


Leave a Reply:

Anjan Dudda Wed, 28 Dec 2016

How do i change the language in pyttsx from english to german? It would be great if you can send me some sample code for the same. Thanks in advance.

Frank Sun, 08 Jan 2017

It depends on the driver, see available drivers on:

If you use Espeak you could try the setProperty method and set 'languages'