Text to Speech AGI

#!/usr/bin/perl
#————————-
#Text to Speech AGI
#Mod by V
#ver 0.03
#http://www.deepthought.ws
#—————————————————————————
#Standard Usage
# Usage: exten => s,n,AGI(tts.pl,TEXT,VOICEENGINE,BACKGROUND,DELFILE)
#Background Usage
# exten => s,n,AGI(tts.pl,TEXT,VOICEENGINE,1,1)
# exten => s,3,Background(${MY_VOICEFILE})
#-Optional:
# exten => s,n,System(rm /var/lib/asterisk/sounds/tts/${MY_VOICEFILE})
#—————————————————————————

use Asterisk::AGI;
use File::Basename;
use Digest::MD5 qw(md5_hex);

$AGI = new Asterisk::AGI;

my %input = $AGI->ReadParse();
my ($text)=$ARGV[0];
my $vreng=$ARGV[1];
my $isbg=$ARGV[2];
my $dtfile=$ARGV[3];
my $hash = md5_hex($vreng+$text);
my $sounddir = “/var/lib/asterisk/sounds/tts”;
my $wavefilename = “tts-$hash.wav”;
my $wavefile = “$sounddir/”.”$wavefilename”;
my $t2wp= “/usr/bin/”;

unless (-f $wavefile) {
if($vreng == 1){
my $execf=”swift \”$text\” -o $wavefile  > /dev/null”;
system($execf);
} elsif ($vreng == 2) {
my $execf=”swift \”$text\” -o $wavefile -n Allison-8kHz > /dev/null”;
system($execf);
} elsif ($vreng == 3) {
my $execf=”swift \”$text\” -o $wavefile -p audio/channels=1,audio/sampling-rate=8000 > /dev/null”;
system($execf);
} elsif ($vreng == 4) {
my $execf=”echo \”$text\”|/usr/bin/text2wave -scale 1.5 -F 8000 -o $wavefile -eval ‘(voice_nitech_us_slt_arctic_hts)’ > /dev/null”;
system($execf);
} elsif ($vreng == 5) {
my $execf=”swift \”$text\” -o $wavefile -n Allison > /dev/null”;
system($execf);
} else {
my $execf=”swift \”$text\” -o $wavefile  > /dev/null”;
system($execf);
}
}
if($isbg == 1){
$AGI->set_variable(‘MY_VOICEFILE’, $sounddir.’/’.basename($wavefile,”.wav”));
} else {
$AGI->stream_file($sounddir.’/’.basename($wavefile,”.wav”));
}
if($dtfile != 1){
unlink($wavefile);
}

, , , , , , , , ,

No comments yet.

Leave a Reply

*

Powered by recycled bites and bytes.