swift.agi
Created by: shaneyoung,Last modification on Wed 20 of Jun, 2007 [14:43 UTC] by falz
Example AGI for Swift.
exten=> s,1,agi(swift.agi|This is some text\, which needs to be converted to speech.)
- !/bin/sh
text=`echo $*`
# Set $stdin to something
stdin="0"
while [ "$stdin" != "" ]
do
read stdin
if [ "$stdin" != "" ]
then
stdin2=`echo $stdin | sed -e 's/: /=/' -e 's/"//g' -e 's/$/"/' -e 's/=/="/'`
eval `echo $stdin2`
fi
done
calleridnum=`echo $agi_callerid | cut -f2 -d\< | cut -f1 -d\>`
calleridname=`echo $agi_callerid | cut -f1 -d\< `
/usr/local/bin/swift -o /tmp/$agi_uniqueid.wav -p audio/channels=1,audio/sampling-rate=8000 " $text "
# Now, tell asterisk to play that file
echo "stream file /tmp/$agi_uniqueid #"
# Read the reply from asterisk to our command
read stream
# Clean up our mess and delete that file
rm /tmp/$agi_uniqueid.wav
exit 0
Comments
333Small Correction to Simple Way To Get Started With Swift-
!/usr/bin/perl
to instead read:
#!/usr/bin/perl
If your a newbie and the script did not work for you this will fix it.
Additionally if you think the speech sounds funny (slow, slurred) and you would like for the Cepstral swift engine to speak normally for you then modify the line which reads:
my $execf=$t2wp."swift -f $sounddir/say-text-$hash.txt -p audio/channels=1,cst/f0_shift=.8,speech/rate=120,audio/sampling-rate=8000,audio/deadair=2 -o $wavefile";
to instead read as such:
my $execf=$t2wp."swift -f $sounddir/say-text-$hash.txt -p audio/channels=1,audio/volume=70,audio/sampling-rate=8000,audio/deadair=2 -o $wavefile";
If you need details of the parameters such as "speech/rate" or "audio/deadair" then launch the Cepstral swift engine with the following command line options:
swift --params
333Simple way to get started with swift..
create a file called cepstral.agi containing the following (which is just a modified version of festival-script) and you can modify the voice parameters ( I had to increase my gain ) by creating a default.sfx in the /swift/voices/VOICENAME below is the exten.conf calling it as well. :
= CEPSTRAL.AGI ==
use Asterisk::AGI;
use File::Basename;
require Data::UUID;
$AGI = new Asterisk::AGI;
my $ug = new Data::UUID;
my $timestamp = gmtime;
my %input = $AGI->ReadParse();
my ($text)=@ARGV;
my $hash = $ug->create_str;
my $sounddir = "/var/lib/asterisk/sounds/tts";
my $wavefile = "$sounddir/"."tts-$hash.wav";
my $t2wp= "/opt/swift/bin/";
unless (-f $wavefile) {
open(fileOUT, ">$sounddir"."/say-text-$hash.txt");
print fileOUT "$text";
close(fileOUT);
my $execf=$t2wp."swift -f $sounddir/say-text-$hash.txt -p audio/channels=1,cst/f0_shift=.8,speech/rate=120,audio/sampling-rate=8000,audio/deadair=2 -o $wavefile";
system($execf);
unlink($sounddir."/say-text-$hash.txt");
}
$AGI->stream_file('tts/'.basename($wavefile,".wav"));
===
DEFAULT.SFX
- Volume
GAIN 1- Chorus
- CHO 0.5 1.0 0.3 1 1 4
==Extenstions.conf
exten => *23,1,Wait(2) ; So the text does read off before they put the phone to their ear.
exten => *23,2,AGI(cepstral.pl|PUT THE TEXT TO READ HERE)
==
Hope this helps
333he is my asterisk output.
— Hungup 'Zap/3-1'
— Starting simple switch on 'Zap/3-1'
— Executing Answer("Zap/3-1", "") in new stack
— Executing DateTime("Zap/3-1", "") in new stack
— Playing 'digits/day-4' (language 'en')
— Playing 'digits/mon-2' (language 'en')
— Playing 'digits/h-17' (language 'en')
— Playing 'digits/2' (language 'en')
— Playing 'digits/thousand' (language 'en')
— Playing 'digits/5' (language 'en')
— Playing 'digits/at' (language 'en')
— Playing 'digits/4' (language 'en')
— Playing 'digits/40' (language 'en')
— Playing 'digits/8' (language 'en')
— Playing 'digits/p-m' (language 'en')
— Executing AGI("Zap/3-1", "swift.agi|Hello World") in new stack
— Launched AGI Script /var/lib/asterisk/agi-bin/swift.agi
— AGI Script swift.agi completed, returning 0
— Executing Hangup("Zap/3-1", "") in new stack
== Spawn extension (from-internal, 1234, 4) exited non-zero on 'Zap/3-1'
— Executing Macro("Zap/3-1", "hangupcall") in new stack
— Executing ResetCDR("Zap/3-1", "w") in new stack
— Executing NoCDR("Zap/3-1", "") in new stack
— Executing Wait("Zap/3-1", "5") in new stack
— Executing Hangup("Zap/3-1", "") in new stack
== Spawn extension (macro-hangupcall, s, 4) exited non-zero on 'Zap/3-1' in macro 'hangupcall'
== Spawn extension (from-internal, h, 1) exited non-zero on 'Zap/3-1'
— Hungup 'Zap/3-1'
333Swift.agi fails to work.
it works from the command line just fine.
I also have festival installed and it works both from the command line and through asterisk.
swift.agi has been cut and pasted as in into /va/lib/asterisk/agi-bin
My extension.conf file has the following context:
exten => 1234,1,Answer
exten => 1234,2,DateTime()
exten => 1234,3,AGI(swift.agi|Hello World)
exten => 1234,4,Hangup
The date and time works but swift.agi doesn't make a sound.
What am I doing wrong. I changed the line in swift.agi to point correctly to my swift install directory but it still doesn't work.
Also I copied your example after I went into edit mode so I got the correct comments and everything.