NO JOY File /tmp/google_audio3986_8k Does not exist, but google_audio3986 Does.

trupsalms

Member
Joined
May 13, 2011
Messages
337
Reaction score
6
Connected to Asterisk 13.22.0 currently running on noreply (pid = 1612)
-- Registered SIP '701' at xxx.xxx.xxx.xxx:37948
[2018-10-27 16:20:57] NOTICE[9242]: chan_sip.c:24653 handle_response_peerpoke: Peer '701' is now Reachable. (123ms / 2000ms)
-- Unregistered SIP '701'
-- Registered SIP '701' at xxx.xxx.xxx.xxx:37948
-- Unregistered SIP '701'
-- Registered SIP '701' at xxx.xxx.xxx.xxx:37948
== Using SIP VIDEO TOS bits 136
== Using SIP VIDEO CoS mark 6
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
> 0x7f3990233c00 -- Strict RTP learning after remote address set to: xxx.xxx.xxx.xxx:49712
> 0x7f39902366a0 -- Strict RTP learning after remote address set to: xxx.xxx.xxx.xxx:61586
-- Executing [[email protected]:1] Answer("SIP/701-0000001e", "") in new stack
> 0x7f3990233c00 -- Strict RTP qualifying stream type: audio
> 0x7f3990233c00 -- Strict RTP switching source address to xxx.xxx.xxx.xxx:59850
-- Executing [[email protected]:2] Playback("SIP/701-0000001e", "./custom/google_hello") in new stack
-- <SIP/701-0000001e> Playing './custom/google_hello.slin' (language 'en')
> 0x7f39902366a0 -- Strict RTP qualifying stream type: video
> 0x7f39902366a0 -- Strict RTP switching source address to xxx.xxx.xxx.xxx:2079
-- Executing [[email protected]:3] Playback("SIP/701-0000001e", "./custom/google_example") in new stack
-- <SIP/701-0000001e> Playing './custom/google_example.slin' (language 'en')
> 0x7f39902366a0 -- Strict RTP learning complete - Locking on source address xxx.xxx.xxx.xxx:2079
> 0x7f3990233c00 -- Strict RTP learning complete - Locking on source address xxx.xxx.xxx.xxx:59850
-- Executing [[email protected]:4] AGI("SIP/701-0000001e", "google.agi,en-us") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/google.agi
-- <SIP/701-0000001e> Playing 'beep.ulaw' (language 'en')
-- <SIP/701-0000001e> Playing '/var/lib/asterisk/sounds/en/auth-thankyou.ulaw' (escape_digits=#) (sample_offset 0) (language 'en')
[2018-10-27 16:21:17] WARNING[3928][C-0000002a]: file.c:774 ast_openstream_full: File /tmp/google_audio3986_8k does not exist in any format
-- <SIP/701-0000001e>AGI Script google.agi completed, returning -1
-- Executing [[email protected]:5] Playback("SIP/701-0000001e", "./custom/google_another") in new stack
-- <SIP/701-0000001e> Playing './custom/google_another.slin' (language 'en')
-- Executing [[email protected]:6] Goto("SIP/701-0000001e", "record") in new stack
-- Goto (from-internal,6666,4)
-- Executing [[email protected]:4] AGI("SIP/701-0000001e", "google.agi,en-us") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/google.agi
-- <SIP/701-0000001e> Playing 'beep.ulaw' (language 'en')
-- <SIP/701-0000001e> Playing '/var/lib/asterisk/sounds/en/auth-thankyou.ulaw' (escape_digits=#) (sample_offset 0) (language 'en')
-- <SIP/701-0000001e>AGI Script google.agi completed, returning 4
== Spawn extension (from-internal, 6666, 4) exited non-zero on 'SIP/701-0000001e'
-- Executing [[email protected]:1] Macro("SIP/701-0000001e", "hangupcall,") in new stack
-- Executing [[email protected]:1] GotoIf("SIP/701-0000001e", "1?theend") in new stack
-- Goto (macro-hangupcall,s,3)
-- Executing [[email protected]:3] ExecIf("SIP/701-0000001e", "0?Set(CDR(recordingfile)=)") in new stack
-- Executing [[email protected]:4] Hangup("SIP/701-0000001e", "") in new stack
== Spawn extension (macro-hangupcall, s, 4) exited non-zero on 'SIP/701-0000001e' in macro 'hangupcall'
== Spawn extension (from-internal, h, 1) exited non-zero on 'SIP/701-0000001e'
noreply*CLI>
Disconnected from Asterisk server
Asterisk cleanly ending (0).
Executing last minute cleanups
WARNING: Always run Incredible PBX behind a secure firewall.
[email protected]:~ $
 

trupsalms

Member
Joined
May 13, 2011
Messages
337
Reaction score
6
#!/usr/bin/env perl
#
# AGI script that interfaces Asterisk PBX to Google Assistant
#
# This program is free software, distributed under the terms of
# the GNU General Public License Version 2.
#
# For Documentation, See
# https://github.com/rgrokett/RaspiAsteriskGoogle
#
# Version 1.1 - 2017-06-16 r.grokett
#
#

use warnings;
use strict;

$| = 1;

# ----------------------------- #
# User defined parameters: #
# ----------------------------- #
# Default language (future) #
my $language = "en-us";

# Default max silence timeout #
my $timeout = 2;

# Absolute Recording timeout #
my $abs_timeout = -1;

# Default interrupt key #
my $intkey = "#";

# Verbose debugging messages #
my $debug = 0;

# ----------------------------- #

my %AGI;
my $ua;
my $fh;
my @result;
my $name;
my $audio;
my $uarequest;
my $uaresponse;
my %response;
my $endian;
my $silence;
my $filetype;
my $json;
my $results = 1;
my $beep = "BEEP";
my $comp_level = -8;
my $ua_timeout = 10;
my $tmpdir = "/tmp";
my $tmpname = "$tmpdir/google_audio$$";
my $sox = "/usr/bin/sox";
my $format = "wav";
my $command = "googlesamples-assistant-pushtotalk";
my $oauth_dir = "/root/.config/google-oauthlib-tool";
my $api_json_file = "$oauth_dir/credentials.json";
my $thank = "/var/lib/asterisk/sounds/en/auth-thankyou";

# Store AGI input #
($AGI{arg_1}, $AGI{arg_2}, $AGI{arg_3}, $AGI{arg_4}) = @ARGV;
while (<STDIN>) {
chomp;
last if (!length);
$AGI{$1} = $2 if (/^agi_(\w+)\:\s+(.*)$/);
}

$name = " -- $AGI{request}:";
console_log ("Starting...") if ($debug);

# Setting language, timeout, interrupt keys and BEEP indication #
if (length($AGI{arg_1})) {
$language = $AGI{arg_1} if ($AGI{arg_1} =~ /^[a-z]{2}(-[a-zA-Z]{2,6})?$/);
}

if (length($AGI{arg_2})) {
if ($AGI{arg_2} == -1) {
$silence = "";
} elsif ($AGI{arg_2} =~ /^\d+$/) {
$silence = "s=$AGI{arg_2}";
} else {
$silence = "s=$timeout";
}
} else {
$silence = "s=$timeout";
}

if (length($AGI{arg_3})) {
$intkey = "0123456789#*" if ($AGI{arg_3} eq "any");
$intkey = $AGI{arg_3} if ($AGI{arg_3} =~ /^[0-9*#]+$/);
}

if (length($AGI{arg_4})) {
$beep = "" if ($AGI{arg_4} eq "NOBEEP");
}

# Answer channel if not already answered #
console_log ("Checking channel status.") if ($debug);
print "CHANNEL STATUS\n";
@result = checkresponse();
if ($result[0] == 4) {
console_log ("Answering channel.") if ($debug);
print "ANSWER\n";
@result = checkresponse();
if ($result[0] != 0) {
die "$name Failed to answer channel.\n";
}
}

# Handle interrupts
$SIG{'INT'} = \&int_handler;
$SIG{'HUP'} = \&int_handler;


####
# START OF REQ/RESP AUDIO HANDLING
####

# RECORD REQUEST AUDIOFILE
console_log ("RECORD FILE $tmpname $format $intkey $abs_timeout $beep $silence") if ($debug);
print "RECORD FILE $tmpname $format \"$intkey\" \"$abs_timeout\" $beep \"$silence\"\n";
@result = checkresponse();
die "$name Failed to record file, aborting...\n" if ($result[0] == -1);

# END RECORDING
console_log ("Playing $thank") if ($debug);
my $res = playback($thank, $intkey);
die if ($res < 0);

# RE-ENCODE REQUEST WAV AUDIO FILE FROM 8000 TO 16000
console_log ("Converting $sox $tmpname.$format.") if ($debug);
my $cmd = "$sox $tmpname.$format -r 16000 ${tmpname}_in.wav";
console_log ("CMD: $cmd") if ($debug);
my $status = qx/$cmd/;

# SEND/RCV GOOGLE API Request/Response
console_log ("Calling gRPC $command") if ($debug);
my $v = "";
$v = "-v" if ($debug);
$cmd = "${command} --credentials ${api_json_file} -i ${tmpname}_in.wav -o ${tmpname}_out.wav ${v}";
console_log ("CMD: $cmd") if ($debug);
$status = qx/$cmd/;
console_log ("Got gRPC API response.") if ($debug);

# CONVERT 16K WAV FILE TO 8KHZ SLN
console_log ("Converting 16K wav to 8K $tmpname.sln") if ($debug);
$cmd = "sox \"${tmpname}_out.wav\" -t raw -r 8k -s -2 -c 1 \"${tmpname}_8k.sln\"\n";
$status = qx/$cmd/;


# PLAY RESPONSE
# NOTE THAT ASTERISK EXPECTS NAME HERE W/O THE EXTENSION.
# Else you get "...file .sln does not exist in any format" -- Dumb
console_log ("Playing ${tmpname}_8k") if ($debug);
$res = playback("${tmpname}_8k", $intkey);
die if ($res < 0);

# CLEAN
if (!$debug)
{
unlink glob "$tmpname*";
}

exit;


#------------------------------------------



sub checkresponse {
my $input = <STDIN>;
my @values;

chomp $input;
if ($input =~ /^200 result=(-?\d+)\s?(.*)$/) {
warn ("Command returned: $input\n") if ($debug);
@values = ("$1", "$2");
} else {
$input .= <STDIN> if ($input =~ /^520-Invalid/);
warn ("Unexpected result: $input\n");
@values = (-1, -1);
}
return @values;
}


sub int_handler {
die "$name Interrupt signal received, terminating...\n";
}

sub playback {
my ($file, $keys) = @_;
my @response;

print "STREAM FILE $file \"$keys\"\n";
@response = checkresponse();
if ($response[0] >= 32 && chr($response[0]) =~ /[\w*#]/) {
console_log("Got digit chr($response[0])") if ($debug);
print "SET EXTENSION ", chr($response[0]), "\n";
checkresponse();
print "SET PRIORITY 1\n";
checkresponse();
} elsif ($response[0] == -1) {
console_log("Failed to play $file.");
}
return $response[0];
}

sub console_log {
foreach my $message (@_) {
warn "$name $message\n";
print "NOOP \"$name $message\"\n";
checkresponse();
}
}


END {
if ($tmpname) {
console_log ("Cleaning temp files.") if ($debug);
#unlink glob "$tmpname.*";
}
}
 

Members online

PIAF 5 - Powered by 3CX

Forum statistics

Threads
22,564
Messages
138,894
Members
14,672
Latest member
evilcocuyo