For various reasons; disability, desire to take advantage of the time traveling or waiting or, simply by personal preference, the possibility that computers give us to Converting text to audio, either by reading it or converting it to a file to listen to later, is a widely used feature.
Windows and Android natively have the ability to read with voices that, although they retain some characteristics that continue to identify their artificial origin, are nevertheless pleasant to the ear.
Added to this is a series of free and paid programs that make the most of these features.
After remembering that Windows is paid and Android collects data for Google, we must say whate Linux is still not up to the mark though, we can manage to achieve passable results. On the other hand, although there are options for commercial-grade Linux (and, of course, you have to pay) in this article we are going to concentrate on free and open source options.
Table of Contents
Tools to convert text to speech
Speech Dispatcher
If you use the Caliber e-book viewer, you will see that on Linux it asks you to install a package called Speech-Dispatcher. This system daemon acts as a link between the programs that want to convert text to speech and the programs that handle speech synthesis.
Of the programs discussed in this article works with Espeak and Festival.
It is an application that is in the repositories so you can search for it by name to install it from the package manager.
Espeak / Espeak NG
To test the following commands, you will need to create a text file, write something and save it as test.txt
Espeak is a text-to-speech utility used by the screen reading tools of many Linux distributions so you can install it from its repositories. It is used both from the command line and through programs with a graphical interface such as Gespeaker or Kmouth (both in repositories).
Most of the voices available in Espeak sound robotic, but, they are quite well understood and, there is no restriction for their use.
Espeak NG is a more compact version of the previous one.
To convert a file from text to speech
Spanish from Spain
espeak -f prueba.txt -v es -w prueba.wav
Latin American Spanish
espeak -f prueba.txt -v es-419 -w prueba.wav
Help and more information
man espeak
Festival
Another tool available in the repositories is Festival. It includes the same characteristics of the two previous ones, in addition to the possibility of reading what we are writing.
We can see the list of languages installed with:
ls /usr/share/festival/languages/
Read a file
festival --language castillian_spanish --tts prueba.txt
More information
man festival
The default voice in Spanish is clear, albeit robotic, but has problems with diphthongs. Festival does not generate audio files.
Peak Text-to-Speech Engine
It is the speech synthesizer of the open source version of Android. The voice is much more natural, although it places restrictions on the length of the text. You can find it in the repositories under the name ibttspico-utils.
To convert from text to voice file we use the command:
pico2wave -l es-ES -w prueba.wav "$(cat prueba.txt)"
We can find more information by writing:
pico2wave --help
gTTS
This application uses the same library that Google Translate uses to demonstrate the pronunciation of a word. Although it is in the repositories, it may be that because it is an old version, it cannot communicate with the Google servers so it is better to install it from the PyPy.org repositories
For this we have to make sure that we have the python3-pip package installed and then write:
sudo pip3 install gTTS
Then we do the following:
sudo nano ~/.profile
And we add this line
export PATH="$HOME/.local/bin:$PATH"
We save with CTRL OR and we keep with CTRLX
We can see the available languages by typing
gtts-cli --all
To convert (in this case to mp3) a text file, we do:
gtts-cli -f prueba.txt --l es --output test.mp3
Google puts limits on the use we can make of the program, but I was able to generate files up to an hour long.
Be the first to comment