Fishtrap

php and other stuff I know

Festival Text to Speech PHP Extension

| 1 Comment

A while ago I knocked up a quick PHP extension to link it to the text to speech C++ library festival. I did this mainly to learn a little more about extension writing. I chose festival because it is well documented and testing is kind of fun.

I’ve put the very rough results up on git hub here.

So far the linking doesn’t look for the headers in many places yet and I have only ever built it on Ubuntu. If you are using ubuntu you will need to install the festival packages.

sudo apt-get install festival festival-dev

and to make it more fun some alternative voices

sudo apt-get install festvox-don festvox-italp16k

Then it’s just a matter of changing into the festival_php root

phpize
./configure
make
make install

You will than be able to create a Festival_FestivalClass and send it text

$festObj = new Festival_FestivalClass();
$festObj->sayText('php '.phpversion());

Or make it read out a file

$festObj = new Festival_FestivalClass();
$festObj->sayFile(__FILE__);

To use a slightly less wooden sounding voice than the default

$festObj = new Festival_FestivalClass();
$festObj->evalCommand('voice_don_diphone');
$festObj->sayText('I am a different voice');

There is also a function which will take a string and convert it to a wav

$festObj = new Festival_FestivalClass();
$festObj->textToWave('I am in a wav file');

This will currently create a file named wave.wav in your /tmp directory although this function will in future allow you to specify the filename and possibly return it.

As to uses. At the moment I can only think of one and that is in creating accessable CAPTCHA text. It’s just a bit of fun and the code isn’t the best but let me know if you find this and manage to get it running and certainly if you find any problems.

One Comment

  1. The behaviour alluded to in textToWave is now there
    e.g.
    $filename = $festObj->textToWave(‘I am in a wav file’, ‘my_filename’);

Leave a Reply

Required fields are marked *.

*