Text-To-Speech with Python Espeak



NOTE: There is a better text-to-speech package that I would recommend for Python. It supports espeak, but also supports native Windows and Mac speech APIs. Check out my Text-to-speech in Python with pyttsx3 tutorial. It also covers how to use English and Russian voices but works in Windows.

Install espeak and the python-espeak package in Ubuntu with apt-get.

sudo apt-get install espeak python-espeak

Next, download the Russian dictionary pack from http://espeak.sourceforge.net/data/. Download the version that matches your installed version. If you need to check what version you have installed use apt-cache.

apt-cache show espeak

After downloading the zip file, unzip it to get the dictionary file. Move it in to the espeak-data folder and overwrite the existing # and unzip it and replace the existing ru_dict file.

wget http://espeak.sourceforge.net/data/ru_dict-48.zip
unzip ru_dict-48.zip
sudo mv ru_dict-48 /usr/lib/x86_64-linux-gnu/espeak-data/ru_dict

In Python 2, You must specify the encoding in the first or second line to allow Cyrillic Characters.

# -*- coding: utf-8 -*-
from espeak import espeak


espeak.synth("где хакер")

while espeak.is_playing: