For some of my telephone apps, stringing together pre-recorded messages is a pain, and it’s not even useful for more dynamic content.
This blog post is a quick write-up of how I got PHP to do sound output via festival, whilst using the asterisk AGI.
First, I made a folder called agi
in my /var/lib/asterisk/sounds/en/
. This is where we will cache sound files.
This shell script makes a sound file with your text, and saves it in that directory:
|
|
For the PHP side, we just use MD5 to name the files based on their contents, and only run the shell script if no file has been created with the text we want.
In this project, $agi
refers to an instance of PHP AGI(highly recommended)
|
|
This makes sound output at least a million times easier. We use it like this:
|
|
That’s all there is to it. I should probably also set up a cron
job to clear the sound files at the end of each week.