Thanks for your scripting - it works quite well, even with the time delay to collect the file from the web. I have modified your script to acomplish a few little extras.
a) their website now uses session ID's, and if you don't pass a valid SID, you just get back a "session expired" message.
b) I have changed the output filetype to .sln - aparrently this is asterisk's preferred format these days (not sure)
c) It now reads the text from a file, which allows me to dynamically create messages without rewriting the extensions.conf file each time
d) added -r to wget so it just overwrites any old .wav files that have been downloaded with the same name.
I will be using this to call me when an alarm goes off in the server room... We are using IPmonitor and MOM to email when there is a problem with a server. My next task is to monitor a spool folder and mangle sendmail or procmail so it only passes (and therefore speaks) the important parts of the emails.
usage for this script is:
php speakfile.php sometextfile.txt outputmessage
so in extensions.conf you can use something like:
exten => _X.,2,System(php -q /etc/asterisk/php/speakfile /var/spool/asterisk/sendmailconnector/test.txt outputmessage)
exten => _x.,2,Background(outputmessage);
$args = $_SERVER["argv"];
// read the filename base as the second argument to the script
// read the textfile contents as the first arguement to the script
// print to screen during debug
//remove newlines - I'm not sure how cepstral will deal with these.
$remove_nl = array("%0A" => "");
// remove the old .sln file, so if it doesn't work at least asterisk can't present incorrect speech
// get the session ID
$sid=system('/usr/bin/lynx -source http://qs913.pair.com/cepstral/demos/demo.cgi/cepstral.wav |grep sid |cut -b 43-106');
system('/usr/bin/wget -r -O /tmp/'.$filebase.'.wav "http://qs913.pair.com/cepstral/demos/demo.cgi/cepstral.wav?content='.$speechstring.'&voice=Diane&rate=160&pitch=1&effect=none&submit=Synthesize+the+Text&sid='.$sid.'"');
system('/usr/bin/sox /tmp/'.$filebase.'.wav -t raw -r 8000 -c 1 -s -w /var/lib/asterisk/sounds/p2voice/'.$filebase.'.sln');
My ToDo list is also to incorporate a lockfile, so if one process is currently generating files, another cannot start the same process.
Thanks for your work