AGI - stumped

Well, after years of using *, I finally hit a brick wall on what appears to be ridiculously stupid.

A perl AGI script that simply plays a message. The script runs, returns completed 0, but it really isn’t playing the message.
I recorded this over a phone using the record function in Asterisk. The reccordings play fine with the playback command in the dialplan and also play fine in a media player (wav format). I have tried long and short recordings. It just returns a completed 0 immediately without really playing it back. I have put this on two different production servers both of which are running other AGI scripts using the stream file function without any issues.

I am using Asterisk version 1.4.33.1

My script is this:

#!/usr/bin/perl

use strict;
use Asterisk::AGI;
use DBI;
use Date::Calc qw(:all);
use vars qw ($AGI %config %input);

my %config;
$config{‘prompts’} = ‘/var/lib/asterisk/apps/paybyphone/prompts’;
$config{‘tempdir’} = ‘/tmp’;

my $AGI = new Asterisk::AGI;
$SIG{HUP} = &hangup;
$SIG{TERM} = &hangup;

greeting();

sub greeting {
my ($file);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($hour < 12) {
$file=“goodmorning”;
} elsif ($hour < 17) {
$file=“goodafternoon”;
} else {
$file=“goodevening”;
}
say_file($file);
}

sub say_file {
my ($file) = @_;
$AGI->stream_file(’$config{‘prompts’}/’.$file,’*’,0) if (defined($AGI));
}

The AGI debug is this:

-- Executing [9257@itdept:1] Goto("SIP/101120-0000e2b3", "paybyphone_test|s|1") in new stack
-- Goto (paybyphone_test,s,1)
-- Executing [s@paybyphone_test:1] AGI("SIP/101120-0000e2b3", "/var/lib/asterisk/apps/paybyphone/paybyphone.agi") in new stack
-- Launched AGI Script /var/lib/asterisk/apps/paybyphone/paybyphone.agi

AGI Tx >> agi_request: /var/lib/asterisk/apps/paybyphone/paybyphone.agi
AGI Tx >> agi_channel: SIP/101120-0000e2b3
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1284578777.58084
AGI Tx >> agi_callerid: 101120
AGI Tx >> agi_calleridname: Jason Brown
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: 9257
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: paybyphone_test
AGI Tx >> agi_extension: s
AGI Tx >> agi_priority: 1
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode:
AGI Tx >>
AGI Rx << STREAM FILE /var/lib/asterisk/apps/paybyphone/prompts/welcome * 0
– Playing ‘/var/lib/asterisk/apps/paybyphone/prompts/welcome’ (escape_digits=*) (sample_offset 0)
– AGI Script /var/lib/asterisk/apps/paybyphone/paybyphone.agi completed, returning 0

Anyone have any earthly idea? Thanks in advance for the extra set of eyes.

I am having the same exact problem with STREAM FILE with both PHP and Python. I have been searching for weeks and found no solution at all.

Steve Phillips

Have you tried using EXEC PLAYBACK instead of STREAM FILE? I think I had issues with STREAM FILE but solved it by using EXEC PLAYBACK.

I also wrote a small wrapper to condense the script a bit.

Here:

def write(string):

    sys.stdout.write(string)
    sys.stdout.flush()

def say(string):
write(“EXEC PLAYBACK %s \n” % string)

say(‘MyFile’)

now the command say(‘filename’) will make asterisk play the recorded file. However I can only get this to work with sound files that are stored under:

/var/lib/asterisk/sounds or /var/lib/asterisk/sounds/en

but, since the record function seems to automatically put the recordings under /var/lib/asterisk/sounds that’s not an issue.

NB//*************** ‘MyFile’ is the name of the .wav (or other type) of file. It MUST be in quotes. Also do NOT include the file extension, asterisk does that for you ***********************

Hope that helps
Dave