Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add availity to get file into a variable to use after of AGI… #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ To make sure check your /etc/asterisk/asterisk.conf file
-----
Usage
-----
agi(picotts.agi,"text",[language],[intkey],[speed]): This will invoke the Pico TTS
agi(picotts.agi,"text",[language],[intkey],[speed],[return_variable]): This will invoke the Pico TTS
engine, render the text string to speech and play it back to the user.
If 'intkey' is set the script will wait for user input. Any given interrupt keys will
cause the playback to immediately terminate and the dialplan to proceed to the
matching extension (this is mainly for use in IVR, see README for examples).
If 'return_variable' is set the script return into the variable name passed the file.

The script invokes PicoSpeaker in order to get the voice data,
which then stores in a local cache (by default /tmp/) for future use.
Expand Down
34 changes: 31 additions & 3 deletions picotts.agi
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ my $cachedir = "/tmp";
# Leave blank to auto-detect #
my $samplerate = "";

# Output file into variable #
# set 1 if need not play file #
# the audio and the return a #
# Asterisk variable. Usefull if #
# need play with the file after #
# this need $usecache = 1 #
my $returnvarible = 0;

# SoX Version #
# Leave blank to auto-detect #
my $sox_ver = "14";
Expand All @@ -83,7 +91,7 @@ my $maxlen = 4096;
my $timeout = 10;

# Store AGI input #
($AGI{arg_1}, $AGI{arg_2}, $AGI{arg_3}, $AGI{arg_4}) = @ARGV;
($AGI{arg_1}, $AGI{arg_2}, $AGI{arg_3}, $AGI{arg_4}, $AGI{arg_5}) = @ARGV;
while (<STDIN>) {
chomp;
last if (!length);
Expand Down Expand Up @@ -130,6 +138,14 @@ if ($usecache && ((length($cachedir) + 32 + 6) < $maxlen)) {
$usecache = 0;
}

if (length($AGI{arg_5})) {
if ($usecache) {
$returnvarible = $AGI{arg_5};
} else {
warn "return_variable need usercache = 1.\n";
}
}

# Answer channel if not already answered #
print "CHANNEL STATUS\n";
my @result = checkresponse();
Expand Down Expand Up @@ -166,7 +182,10 @@ for (my $i=0; $i < $lines; $i++) {
# Stream file from cache if it exists #
if (-r "$cachedir/$filename.$fexten") {
warn "$name File already in cache.\n" if ($debug);
$res = playback("$cachedir/$filename", $intkey);

if ($returnvarible) {$res = return_variable("$cachedir/$filename");}
else { $res = playback("$cachedir/$filename", $intkey);}

die if ($res < 0);
last if ($res > 0);
next;
Expand Down Expand Up @@ -202,11 +221,12 @@ for (my $i=0; $i < $lines; $i++) {
unlink "$tmpname.wav";

# Playback and save file in cache #
$res = playback($tmpname, $intkey);
if (!$returnvarible) { $res = playback($tmpname, $intkey);}
die if ($res < 0);
if ($usecache) {
warn "$name Saving file $filename to cache\n" if ($debug);
move("$tmpname.$fexten", "$cachedir/$filename.$fexten");
if ($returnvarible) { $res = return_variable("$cachedir/$filename");}
} else {
unlink "$tmpname.$fexten";
}
Expand Down Expand Up @@ -248,6 +268,14 @@ sub playback {
return $response[0];
}

sub return_variable {
my ($file) = @_;
my @response;
print "SET VARIABLE $returnvarible $file\n";
@response = checkresponse();
return $response[0];
}

sub detect_format {
# Detect the sound format used #
my @format;
Expand Down