How to Implement Text to Speech in PHP  

Check out latest Mobile Phones and Books only at Flipkart.com
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 festival

This will ensure that all the dependencies associated with the Festival also gets installed.

Prepared Statement in MySQL

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

OOPS in PHP5

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>


 

HTML Scrapper in PHP

We can change the voice whenever we want to by calling (voice_) from festival prompt. Suppose we want to use kal_diphone for our application we would call

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:

Categories: PHP Tags: ,
  1. yoshi
    April 23rd, 2009 at 17:54 | #1

    very nice tutorial..

  2. sam
    May 5th, 2009 at 14:38 | #2

    How did you program your Show Hide Tabs at the top without using javascript?

  3. June 12th, 2009 at 11:58 | #3

    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

  4. June 22nd, 2009 at 12:54 | #4

    thanks
    i found that good

  5. Shailesh kumar
    July 15th, 2009 at 04:32 | #5

    It’s good :)

  6. harry
    July 30th, 2009 at 22:58 | #6

    its really nice work

  7. Badri Narayan
    November 5th, 2009 at 00:54 | #7

    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”

    • November 5th, 2009 at 22:35 | #8

      Hi Badri,
      I have not tried Festival in Server mode so wont be able to answer your queries.

      Thanks,
      Hitesh Agarwal

  8. Ashish Kataria
    February 21st, 2011 at 23:06 | #9

    Hi Hitesh,

    Can we implement this on windows system, if yes then how.

    Regards,
    Ashish Kataria

  9. shashi
    March 15th, 2011 at 00:09 | #10

    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.

  10. speech
    April 28th, 2011 at 00:33 | #11

    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?

  11. August 24th, 2011 at 09:42 | #12

    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

  1. June 13th, 2009 at 23:27 | #1
  2. October 28th, 2009 at 22:34 | #2
  3. November 2nd, 2009 at 14:17 | #3
  4. February 6th, 2011 at 14:03 | #4
  5. May 1st, 2011 at 14:22 | #5

 

Page optimized by WP Minify WordPress Plugin