I’ve modified the festival-weather-script.pl (included with TrixBox/Asterisk?) so that it will work with Cepstral but I’m having a very strange problem… The problem is that my first call to $AGI->stream_file seems to be ignored.
Here is my AGI script:
#!/usr/bin/perl
#make a tts dir inside your sounds dir (as specified below)
#adjust the t2wp variable to point to your Cepstral bin directory
use Asterisk::AGI;
use File::Basename;
use Digest::MD5 qw(md5_hex);
$AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
my ($text)=@ARGV;
my $hash = md5_hex($text);
my $sounddir = "/var/lib/asterisk/sounds/tts";
my $wavefile = "$sounddir/"."tts-$hash.wav";
my $t2wp= "/opt/swift/bin/";
$AGI->verbose("Text is: " . $text . "\n", 1);
unless (-f $wavefile) {
open(fileOUT, ">$sounddir"."/say-text-$hash.txt");
print fileOUT "$text";
close(fileOUT);
# The next line creates a new wave file...
my $execf=$t2wp."swift -n William -p audio/sampling-rate=8000 -f $sounddir/say-text-$hash.txt -o $wavefile";
$AGI->verbose("File: " . $wavefile . "\n", 1);
system($execf);
unlink($sounddir."/say-text-$hash.txt");
}
# The following line plays the wav file on the audio channel...
my $result2 = $AGI->stream_file('connecting');
my $result = $AGI->stream_file('tts/'.basename($wavefile,".wav"), 1);
$AGI->verbose("Trying to stream: " . 'tts/'.basename($wavefile,".wav") . "\n", 1);
$AGI->verbose("Stream_file returned " . $result2 . "\n", 1);
$AGI->verbose("Stream_file returned " . $result . "\n", 1);
In the Asterisk console (asterisk -r) here is what I see:
-- Executing AGI("SIP/1000-90df", "cepstral2.pl|Testing here") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/cepstral2.pl
cepstral2.pl|Testing here: Text is: Testing here
cepstral2.pl|Testing here: Trying to stream: tts/tts-360c161e24a8fb92b0f8c7dead20694e
cepstral2.pl|Testing here: Stream_file returned
cepstral2.pl|Testing here: Stream_file returned 0
-- AGI Script cepstral2.pl completed, returning 0
When this AGI script is executed, the first $AGI->stream_file is ignored (and returns blank [??]) but the second $AGI->stream_file works perfect (and correctly returns a 0).
What is going on here? Can anybody help me?