Home > PHP > How to Implement Text to Speech in PHP

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 festival

This 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>

Your email:

 


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>

Your email:

 


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.


Custom Search

Popular Articles:

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • IndianPad
  • LinkedIn
  • Live
  • MySpace
  • Netvibes
  • RSS
  • Technorati
  • Yahoo! Bookmarks
  • Yahoo! Buzz
  • Reddit
  • Add to favorites
  • PDF
  • Twitter
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

  1. June 13th, 2009 at 23:27 | #1
  2. October 28th, 2009 at 22:34 | #2
  3. November 2nd, 2009 at 14:17 | #3