Best of Linux

Best Command Line Text to Speech Apps for Linux

This article will cover a list of useful text to speech (TTS) apps available for Linux. These apps can identify a piece of text, convert it to speech, and then speak words and sentences through the speakers of your Linux system. They convert text to speech using artificial intelligence algorithms and pretrained machine learning models. These apps usually provide a range of different voices having predefined tones, accent and way of speaking. Some of these apps allow you to configure voice parameters like tempo and pitch. It is common for text to speech apps to have robotic voices that don’t sound like real life voices. However, the technology is improving and more human sounding voices are coming off these text to speech apps.

Espeak

Espeak is a free and open source text to speech utility that can be used to convert text to speech in many different languages. It comes with a command line utility as well as a library that can be used in your own app. Most of the voices available in Espeak sound robotic but it is one of the most comprehensive and widely used open source text to speech available today. It supports converting text to speech in more than 40 different languages and you can also save speech to audio files in WAV file format. It also comes with built-in support for converting text into phonemes so that you can use them in other apps, including other text to speech engines.

You can install Epseak in Ubuntu by using the command mentioned below:

$ sudo apt install espeak

You can download Espeak in other Linux distributions from the package manager. More download options are available here.

To convert a piece of text to speech using Espeak, use a command in the following format:

$ espeak "Text will be converted to speech."

You can replace the content in quotes with your own desired string. To synthesize entire contents of a file to speech, run a command in the following format:

$ espeak -f filename.txt

To change language and voice style, run a command in the following format:

$ espeak -v en-gb "Text will be converted to speech."

You can replace “en-gb” with your desired voice code. A list of all available voices and their codes can be found by running the following command:

$ espeak --voices

To save synthesized speech to a WAV file, run a command in the following format:

$ espeak -f filename.txt -w output.wav

You can replace “output.wav” with any other name of your choice.

To know more about other command line options available for Espeak, use the following two commands:

$ espeak --help

$ man espeak

Festival

Festival is another free and open source text to speech engine that works similar to Espeak. It provides a command line utility to convert text to speech as well as an API that you can integrate in your own app. Other main features of Festival include support for converting text to speech in multiple languages, built-in interactive interpreter, a client-server API to access it remotely, and its own scripting engine.

You can install Festival in Ubuntu by using the command mentioned below:

$ sudo apt install festival

You can download Festival in other Linux distributions from the package manager. More download options are available here. An online demo showing the capabilities of the Festival is available here.

To convert a string to speech, use a command in the following format:

$ echo "Test" | festival --tts

You can replace “Test” with any other string of your choice. To convert contents of a text file to speech using Festival, run a command in the following format:

$ festival --tts filename.txt

You can change voice language by running the command below:

$ festival --language americanenglish --tts filename.txt

You can replace “americalenglish” with other languages supported by the Festival. To get a list of all supported languages, run the command below:

$ ls /usr/share/festival/languages/

To run Festival in interactive mode, use the following command:

$ festival

You can learn more about interactive mode specific commands from here.

To know more about other command line options available for Festival, run the following two commands:

$ festival --help

$ man festival

Pico Text to Speech Engine

Pico is a free and open source text to speech engine that is included by default in Android Open Source Project (AOSP). The voice styles included in Pico TTS sound less robotic than Espeak and Festival. Currently, Pico TTS supports speech synthesis in English, Italian, German, French, and Spanish languages.

You can install Pico TTS in Ubuntu by using the command mentioned below:

$ sudo apt install libttspico-utils

You can download Pico TTS in other Linux distributions from the package manager. Alternatively, you can compile it from source code available here.

Pico TTS doesn’t have a command to directly speak out synthesized speech from stdout. However, it can read contents of a text file or a string and can save synthesized speech into a WAV file which can then be played in any audio player.

To convert a string to speech and save output to a WAV file, run a command in the following format:

$ pico2wave -l en-EN -w test.wav "Test"

You can replace “Test” with your own desired string. To change language, replace “en-EN” with codes for other supported languages. Pico TTS supports the following language codes: en-US, it-IT, es-ES, en-GB, de-DE, and fr-FR.

To read contents of a file and convert it to speech, run a command in following format:

$ pico2wave -l en-US -w test.wav "$(cat test.txt)"

You can replace “test.txt” with any other file name.

To know more about Pico TTS command line options, run the following two commands:

$ pico2wave --help

$ man pico2wave

gTTS

gTTS is a command line application and library based on Google Translate’s text to speech engine. Based on Python, it can be used to develop other TTS apps or you can use it as a command line utility to synthesize speech from text. It features much more natural sounding voices than other utilities mentioned in this article, as Google Translate’s text to speech engine is updated quite regularly with new algorithms, natural sounding voices and features.

You can install gTTS in Ubuntu by using the command mentioned below:

$ sudo apt install python3-gtts

You can download gTTS in other Linux distributions from the package manager. Alternatively, you can install it from the pip package manager.

To convert a string to speech, run a command in the following format:

$ gtts-cli 'test' --output test.mp3

You can replace ‘test’ with any string. The synthesized speech is saved in the “test.mp3” file. You can use any name for the output file.

To read contents of a file and convert it to speech, run a command in the following format:

$ gtts-cli -f test.txt --output test.mp3

You can replace “test.txt” with any other file name.

To specify a particular language for synthesizing speech, use a command in the following format:

$ gtts-cli 'test' -l en --output test.mp3

You can replace “en” with code for other supported languages. To get a list of all supported language codes, run the following command:

$ gtts-cli --all

To learn more about other command line options available for gTTS, use the following two commands:

$ man gtts-cli

$ gtts-cli --help

Conclusion

These are some of the best text to speech apps available for Linux that come with support for synthesizing speech in multiple languages. These TTS apps can be used in a variety of ways, but they are especially useful for improving accessibility for people suffering from visual impairment issues.

About the author

Nitesh Kumar

I am a freelancer software developer and content writer who loves Linux, open source software and the free software community.