#!/usr/bin/perl -w # audiotest.agi use DBI; use Asterisk::AGI; my $AGI = new Asterisk::AGI; my @lines; my %input = $AGI->ReadParse(); $dbname = "agi"; ($query)=@ARGV; # Make a connection to your database $dbh = DBI->connect("dbi:mysql:database=$dbname","root","passw0rd") || die "Cannot open db"; $sql = "SELECT file FROM audio WHERE name = \'$query\'"; $sth = $dbh->prepare($sql); $numrows = $sth->execute; srand(time()); $random = rand(); open OUTPUT, ">/tmp/$random.gsm"; $row = $sth->fetchrow_hashref; $audio = $$row{'file'}; print OUTPUT $audio; close OUTPUT; $sth->finish; $dbh->disconnect; # Playback $AGI->stream_file("/tmp/$random"); unlink("/tmp/$random.gsm"); exit;