How to Implement Text to Speech in PHP
Check out latest Mobile Phones and Books only at Flipkart.com
I am now become a fan of Linux Operating System. It has all the variant of softwares available either Open Source or Commercial version, and the most important is that the software also runs from command console that means we can run the application from our web application. One such application is Festival, it allows us to convert Text to Speech(WAV) format. In this article we will learn on how we can convert text to speech from PHP applications.
What is Festival?
It is an Open Source tool available that performs Text to Speech Synthesis System. You can install Festival directly by directly calling:
yum -y install festivalThis will ensure that all the dependencies associated with the Festival also gets installed.
Starting Festival Speech Synthesis System:
Once the Festival is installed, we can see the folder Festival getting created in /usr/share. Now goto command prompt and type Festival.
Example:
[root@Hitesh ~]# festival
After entering the following command we get to see following output.
[root@Hitesh ~]# festival Festival Speech Synthesis System 1.95:beta July 2004 Copyright (C) University of Edinburgh, 1996-2004. All rights reserved. For details type `(festival_warranty)' festival>
After seeing festival prompt we are sure that now we can use it to generate Text to Speech Conversion.
Using Festival Speech Synthesis System:
To check the list of voices available we need to enter (voice.list) in the festival prompt.
festival> (voice.list) (cmu_us_slt_arctic_hts cmu_us_jmk_arctic_hts cmu_us_bdl_arctic_hts cmu_us_awb_arctic_hts ked_diphone kal_diphone) festival>
We can change the voice whenever we want to by calling (voice_
festival> (voice_kal_diphone) kal_diphone festival>
Text to Speech Conversion:
Now the most important part in Festival is to convert Text content to Speech. We can achieve this by calling.
festival> (SayText "Hello World")
After entering this command you will hear “Hello World” from your speaker.
Using Festival Speech Synthesis System inside PHP Application:
After you have successfully installed Festival, you get an new command called “text2wave” this command allow us to convert the text content to WAV file.
[root@Hitesh hitesh]# text2wave hello.txt -o /home/hitesh/hello.wav
Here if you see i am passing hello.txt contains the text content and the ouput file will get generated at location /home/hitesh/hello.wav . Now we will achieve the same in our PHP application by calling:
exec("text2wave hello.txt -o /home/hitesh/hello.wav")
If we want to change the voice we need to append -eval argument to text2wave command as shown below:
exec("text2wave hello.txt -o /home/hitesh/hello.wav -eval '(voice_ked_diphone)'");
This will ensure that the Speech Synthesizer will use ked_diphone voice while performing text to speech conversion.
Related Articles:
- PHP5 Tutorial – clone Magic Method
- MySql Prepared Statement in PHP
- Installing MySQL PHP and Apache on Windows
- Increase Upload FileSize Limit in PHP
- Exploring Magic Methods in PHP 5
- PHP5 Tutorial – Parsing XML documents in PHP5 using SimpleXML
- OOPS in PHP5 – Declaring Class and Initializing Class Object
- PHP5 Tutorial – Not Pure Object Oriented Programming Approach
- OOPS in PHP5 – construct() Method
- OOPS in PHP 5 Tutorial – Exploring Inheritance
very nice tutorial..
How did you program your Show Hide Tabs at the top without using javascript?
this is wonderful tutorial .. i read it 3 times and get a fantastic results and sure i put a
copy of this lesson on my site here
thanks
i found that good
It’s good
its really nice work
Hi,
Nice one. I had a doubt when using festival, is it possible to switch voices when we run festival in the server mode? In the festival prompt we can but how to do it when festival is run using “festival -i –server”
Hi Badri,
I have not tried Festival in Server mode so wont be able to answer your queries.
Thanks,
Hitesh Agarwal
Hi Hitesh,
Can we implement this on windows system, if yes then how.
Regards,
Ashish Kataria
i would like to create Sinhala Text To Speech System using festival as my finala year project. but i don’t know the way i use that for new voices can you help me.
Hi Hitesh,
We tried your code. But the problem for us is not able to connect to festival . It displays: SIOD error ran out of storage. Do you know how to execute other festival commands using php? Can you help us with this?
I have worked in this technology. Its easy to use and mighty effective. Following link shows my code using festival with php.
http://sourcecodemania.com/2011/08/18/how-to-convert-text-to-speech-with-php/
Falak