Friday, March 26, 2010

TTS (Text-to-Speech) Using Linux

Okey... TTS or Text to Speech is the system converts normal language text into speech. Speech synthesis is the artificial production of human speech. A computer system used for this purpose is called a speech synthesizer, and can be implemented in software or hardware

This Schema of TTS generally :

File:Festival TTS Telugu.jpg
for more information about TTS u can go to http://en.wikipedia.org/wiki/Speech_synthesis
Now at least we know how text can be converted to voice.

Let's Rock n Roll On LINUX
actually, you can use any LINUX Distro and I Use CENTOS 5.2 to implement TTS
here we go...
if you have install linux on your PC, you can go now to try TTS but if you have not install yet. i will wait you :P hehehe......
Okey....Now We install dependencies of TTS using gnome-terminal or shell (run as root)


1. yum install festival (for REDHAT-Based) / apt-get install festival (for Debian-Based)
festival is the speech synthesizer that developed by The University of Edinburgh


2. yum install text2wave (for REDHAT-Based) / apt-get install text2wave (for Debian-Based)
taxe2wave is text to wav converter based-on festival voice

3. Install lame :
- wget http://nchc.dl.sourceforge.net/project/lame/lame/3.98.4/lame-3.98.4.tar.gz
- tar xvfz lame-3.98.4.tar.gz
- cd lame-3.98.4
- ./configure --prefix=/usr
- make
- make install
lame is wav to mp3 converter :D
4. Install PHP and Web Server (Optional: Just if you want to make a TTS Web-Based)
- yum install php5 httpd (for REDHAT-Based) / apt-get install php5 httpd (for Debian-Based)
PHP and Web Server for create web-based TTS



Now test festival running or not

$ echo hello world festival --tts (you will hear "Hello World")

$ nano myspeech.txt (write everything you wanna say)

$ festival --tts myspeech.txt (you will hear everything you wanna say)



Test text2wav

$text2wave myspeech.txt -o myspeech.wav (Now you will get wav file from text2wave )



Test lame

$lame myspeech.wav myspeech.mp3 (and you get mp3 file from lame you can play using totem in linux)



Okey....actually it's over if we just talking how can we convert text to audio file but if we want to try explore.

I will give u a simple source code for PHP front-end below


< html >
< body >
< form method="POST" >
< textarea name="text" cols="70" > < /textarea > < br / >
< input type="submit" >
< /form >
< ?php
error_reporting ( E_ALL );
ini_set ( 'display_errors', True );
if ( isset ( $_REQUEST['text'] ) ) {

//Directory OF WAV FILE
$wavfile = "wav/".time().".wav";

//Directory Of WWW file default is /var/www
$wwwDir = '/var/www/voice/';
2
//Directory of mp3 file
$mp3file = "mp3/".time().".wav";

// convert text 2 wav
exec ( 'echo "'. escapeshellarg ( utf8_decode ( $_REQUEST['text'] ) ) . '" | text2wave -o ' . $wwwDir . $wavfile );

// convert wav to mp3
exec ( "lame '".$wavfile."' '".$mp3file."'" );
? >
< p > The File is < a href="
< ?php
echo $speechfile;
? > " > Here< a > < /p >
< ?php
}
? >
< /body >
< /html >

Oke See ya..... I hope can help you