How to Convert TXT to WAV, MP3, OGG, AAC or FLAC in Ubuntu

Converting text files to audio is something that can be useful not only for people with vision problems but also for anyone who want to study or those who, being lazy enough to read or lacking the minimum space of comfort to do so, enjoy being "read" to them while they are on the train, in the subway, etc.At last you will be able to save your favorite books, summaries of the facu, etc. in your music player. and you will be able to take them with you wherever you want!

The method that I am going to teach you this time uses the motor espeak. There are basically 2 ways to use it, through a GUI (speaker) or through a terminal.


Previous steps:

Espeak is already installed in the latest versions of Ubuntu, that's why we chose it. So what remains to install and configure is very little.

Using the Gespeaker GUI

1) Install Gespeaker:
Go to the official page of the project, download the .DEB package and install it.

Once installed, find and run Gespeaker, available in Applications> Audio and Video> Gespeaker

When you run it, you will realize that its use is very intuitive. You just have to choose the voice with which we want to reproduce the text; in our case, it could be Spanish or Spanish-Latin-American. Then, write the text in the main text box and, if necessary, configure the "advanced" options that regulate the speed, volume, pitch and the "delay" between words of the voice. Finally, press Play and voila!

To save this text in an audio file, just press "Record" and choose the destination path.

2) Install Mbrola voices

You may have noticed that the original voices sound somewhat 'robotic', in the 'Stephen Hawking' style. To "smooth out" this problem, a possible solution is to use the Mbrola voices.

To do this, we first have to install the Mbrola motor. Open the terminal and write:

sudo apt-get install mbrola

Then, lower the voices of Mbrola «Es1» and «es2» (if you wish you can also download others), unzip and copy only the files of the same name and without extension to the folder «/ usr / share / mbrola», which we must create if it does not exist .

To do all that very quickly from the terminal, copy and paste all this corn:

wget http://www.tcts.fpms.ac.be/synthesis/mbrola/dba/es1/es1-980610.zip && wget http://www.tcts.fpms.ac.be/synthesis/mbrola/dba/ es2 / es2-989825.zip && unzip es1-980610.zip && unzip es2-989825.zip && sudo mkdir / usr / share / mbrola && sudo cp ~ / es1 / es1 / usr / share / mbrola && sudo cp ~ / es2 / es2 / usr / share / mbrola

3) Tuning Gespeaker

Before continuing, I recommend closing Gespeaker if you had it open. Reopen it and go to Edit> Preferences. In Audio player, they can choose between ALSA and PulseAudio. My recommendation is that you choose "PulseAudio". Everything else can stay the same.

It only remains to see if Gespeaker correctly detected Mbrola's engine and voices. To do this, go to the "Mbrola voices" tab. Where it says "Mbrola main application" a message should appear saying "Package mbrola installed". Then scroll to the bottom of the list to see if it detected the voices "spanish-mbrola-1" and "spanish-mbrola-2". If so, we are on the right track.

4) Try everything ...

Finally, select the Mbrola voices in Gespeaker. In the main window of the program, choose from the list «Language» the item «Spanish-mbrola-1» or «Spanish-mbrola-2».

Using the terminal

1) Learning to use Espeak from the terminal

Play the entered text:

espeak --stdout 'Let's use Linux is the most' | aplay

Play the text as you type it in the terminal:

espeak --stdout | play

Play a document

espeak --stdout -t mydocument.txt | aplay

Play a document and generate WAV file

espeak -t mydocument.txt -w myudio.wav

List all available voices

speak --voicestext

Play using a specific "voice"

espeak -v en-uk --stdout 'Let's use Linux is the best blog in the world' | aplay

Set the number of words per minute played

espeak -s 140 -f mydocument.txt | aplay

List the voices available in a particular language

espeak --voice = es

2) Install Mbrola voices

To do so, they must follow the same steps developed in point 2 above.

Use the Mbrola voices from the terminal.

This can be a bit more cumbersome, but it worked better for me than Gespeaker. Although the conversion engine is the same (espeak + mbrola), Gspeaker's voice was heard worse, probably because the delay between words cannot be reduced to a number less than 5. Therefore, I recommend that you save this page in favorites to access it in times of need.

To convert a text file to a .WAV file using the Mbrola voices:

espeak -v mb-es1 -f textfile | mbrola -e / usr / share / mbrola / es1 - output.wav

To simply play a text file using the Mbrola voices:

espeak -v mb-es1 -f textfile | mbrola -e / usr / share / mbrola / es1 - - | aplay -r16000 -fS16

The -e parameter prevents mbrola from stopping if it encounters phonemes that it does not understand or recognize correctly.

Although this is not the case for "es1" and "es2", it is important to note that some mbrola voices use a sample rate of 22050 Hz. In this case, they should put -r22050 instead of -r16000.

How to convert the final result (.WAV) to a .MP3, .OGG, etc.

The easiest method is using Sound Converter, a GUI for libraries gstreamer.

Open a terminal and enter:

sudo apt-get install soundconverter

Then go to Applications> Audio and Video> Sound Converter and run the program. To configure the conversion parameters go to Edit> Preferences. Then select the file (s) to convert and press the «Convert» button


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Let's use Linux said

    Good date! Thanks Facundo!

  2.   Facundo Peiretti said

    Very good !!
    But I would like to clarify a question: To install the other voices of Mbrola I had to place ALL the content of the .zip in the / usr / share / mbrola folder, since otherwise (when pasting only the file without an extension) the program told me q that "language" was not installed.

  3.   Helena said

    Very good, I'm sure I give it a lot of use. Thank you.

  4.   Edwina said

    Excellent contribution, thank you very much.

  5.   Daniel Esteban Buccafusca said

    Good morning, and followed all the steps, including install the gespeaker by terminal but this program does not run, the espeaker, from the terminal you can listen.