Skip to content

Instantly share code, notes, and snippets.

@vir
Created June 30, 2015 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vir/b1a868ef1d4aa5239064 to your computer and use it in GitHub Desktop.
Save vir/b1a868ef1d4aa5239064 to your computer and use it in GitHub Desktop.
Yate call recorder script
#!/usr/bin/perl
use strict;
use warnings;
use Yate;
use Data::Dumper;
# Convert results into stereo wav:
# sox -M /tmp/rec_2015-05-20T17\:09\:44_no-billid_6134-[AB].au /tmp/rec_2015-05-20T17:09:44_no-billid_6134.wav
my $yate = new Yate(Debug=>0);
$yate->connect("127.0.0.1:42428");
$yate->install('call.answered', \&call_answered_handler, 70);
$yate->listen();
sub call_answered_handler
{
my $m = shift;
my $billid = $m->param('billid') // 'no-billid';
my $date = mk_date();
my $fn = sprintf("/tmp/rec_%s_%s_%04d", $date, $billid, int(rand(10000)));
my $ext = 'au';
print "Recording call: $fn\n";
$m->message('chan.masquerade', undef, '',
message => "chan.record",
id => $m->param('id'),
peer => "wave/record/$fn-A.$ext",
call => "wave/record/$fn-B.$ext",
);
open F, '>:utf8', "$fn.txt" or warn "Can't open $fn.txt: $!\n";
print F Dumper($m->{params});
close F or warn "Can't write to $fn.txt: $!\n";
$date =~ s/_.*//;
my $script = "/tmp/convert_$date.sh";
my $first = !-e $script;
open F, '>>:utf8', $script or warn "Can't open $script: $!\n";
print F "#!/bin/sh\n" if $first;
print F "sox -M $fn-[AB].au $fn.wav && rm $fn-[AB].au\n";
close F;
return undef;
}
sub mk_date
{
my $time = shift;
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time // time());
return sprintf "%04d-%02d-%02d_%02d%02d%02d", $year + 1900, $mon + 1, $mday,$hour,$min,$sec;
}
@DamDat
Copy link

DamDat commented Jul 31, 2018

tell me please, how can i run .pl file ?

@sfitsp
Copy link

sfitsp commented Jul 29, 2019

As now I tried to use Yate and I need call recording so can you please let me know procedure to implement above script?

Thanks in advance!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment