How to Implement Text to Speech in PHP
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.
Popular Articles:
- OOPS in PHP 5 Tutorial – Defining Class Constants
- PHP5 Tutorial – __toString() Magic Method
- Singleton Class in PHP 5
- PHP5 Tutorial – Not Pure Object Oriented Programming Approach
- Increase Upload FileSize Limit in PHP
- Exploring Magic Methods in PHP 5
- OOPS in PHP 5 – __destruct() Method
- PHP5 Tutorial – __autoload Magic Method
- PHP 5 Tutorial – __set() Magic Method
- PHP5 Tutorial – __clone Magic Method



































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