Wednesday, 31 May 2017

Convert text files to MP3 under Linux

Convert text files to MP3 under Linux


Even though I am not a fan of audio books and the only thing I use my iPod for is listening music still while exploring Festival(which is basically a General multi-lingual speech synthesis system) I found out that its very easy to convert normal text files into mp3 using festival . Now this could be especially useful for people who either listen to audio books or people who have difficulty in reading.

First we would need to install festival. We can install festival with the following command :

sudo apt-get install festival


Now we need to install voices which would be used to dictate the text (install any one of the following ) :

To install British Accented male voice issue the following command :

sudo apt-get install festvox-rablpc16k

To install American Accented male voice issue the following command:

sudo apt-get install festival festvox-kallpc16k


Now once you have installed festival and voice package we are ready to convert text files .wav files .

Lets say you want computer to read file named kaddu.txt you would need to pipe(send output of one command to other ) the cat command to festival. You can do so by issuing the following command :
cat -A kaddu.txt | festival --tts
Now instead if you want to convert kaddu.txt to kaddu.wav you can do so by piping the output of cat to a tool that comes with festival text2wave. You can do so by issuing the following command in the terminal window :
cat -A kaddu.txt | text2wave -o kaddu.wav
Now however if you want to remove special characters and want festival/text2wav to read only a to z,A to Z, space, �,�,�.�,�!�,�?�. You can do so by piping the output of cat to sed and then piping the output of sed to text2wav/festival.
cat kaddu.txt |sed s/[^a-zA-Z .,!?]//g|festival --tts

or
cat kaddu.txt|sed s/[^a-zA-Z .,!?]//g|text2wave -o kaddu.wav
Now the (.wav) file produced is uncompressed and are huge in size so you might like to convert it to mp3 to reduce its size and to allow the files to be played on iPod or any other mp3 player. You can convert .wav files easily to (.mp3) file format by using lame .

To install lame issue the following command in the terminal window :
sudo apt-get install lame
after istallation is over to convert say kaddu.wav to kaddu.mp3 issue the following command :
lame -f kaddu.wav kaddu.mp3
NOTE : I am using -f switch here which basically encodes mp3 file faster and in lower quality .

Article Written by : Ambuj Varshney (blogambuj@gmail.com)
For Desktop on Linux Blog , http://linuxondesktop.blogspot.com
(C) 2008 , Ambuj Varshney

download
alternative link download

Like the Post? Do share with your Friends.