[Asterisk-Users] help - recording both sides of a conversation
John Baker
johnb at listbrokers.com
Sun Jan 4 13:07:25 MST 2004
Iain -
First off, all of this is heavily borrowed from others. For those who see
their code embedded here, I thank you and give you full credit.
Here's how I do it. It's a bit convoluted, but I didn't want to record
everything. So, if a call comes in and I want to record it, I send it here:
[ext-surrept]
exten => _57XXX,1,Answer
exten => _57XXX,2,Macro(record-enable)
exten => _57XXX,3,BackGround(for-quality-purposes)
exten => _57XXX,4,BackGround(this-call-may-be)
exten => _57XXX,5,BackGround(recorded)
exten => _57XXX,6,Dial(SIP/${EXTEN:1},120,tm)
exten => _57XXX,7,Macro(rg-inbound,10,tr)
exten => _57XXX,8,Goto(aa-nooneavail,s,1)
By transferring a call to 5 + the extension I'm at, I enable the call
recording, let the caller know he might be recorded and then send the call
right back to myself.
Here's the Macro:
[macro-record-enable]
exten => s,1,AGI(set-timestamp.agi)
exten => s,2,SetVar(CALLFILENAME=${timestamp}-${CALLERIDNUM}-${MACRO_EXTEN})
exten => s,3,Monitor(wav,${CALLFILENAME})
It starts the recording and calls set-timestamp.agi
Here's the agi file:
#!/bin/sh
longtime=`date +%Y%m%d-%H%M%S`
echo SET VARIABLE timestamp $longtime
It sets a timestamp, which if you scour the asterisk list, you'll see that
it is necessary for mixing the in and out audio later.
I have one hangup extension set for my internal phones; it looks like this:
exten => h,1,Macro(record-cleanup)
And the record-cleanup macro looks like this:
[macro-record-cleanup]
exten => s,1,SetVar(MONITORDIR=/var/spool/asterisk/monitor)
exten => s,2,GotoIf($[${CALLFILENAME} = ${FOO}]?6:3)
exten => s,3,System(/usr/scripts/mix_monitor_files.pl ${MONITORDIR}
${CALLFILENAME}-in.wav ${CALLFILENAME}-out.wav ${CALLFILENAME}.wav)
exten => s,6,NoOp
Don't forget to make the /var/spool/asterisk/monitor directory!
Finally, mix_monitor_files.pl does the mixing job and combines the in and
out files:
#!/usr/bin/perl
$monitordir = shift;
$infile = shift;
$outfile = shift;
$finishfile = shift;
chdir($monitordir);
$infile_output = `sox $infile -e stat 2>&1`;
$outfile_output = `sox $outfile -e stat 2>&1`;
$infile_output =~ /Samples read:\s+(\d+)/;
$infile_samples = $1;
$outfile_output =~ /Samples read:\s+(\d+)/;
$outfile_samples = $1;
if($outfile_samples > $infile_samples)
{
$diff_samples = $outfile_samples - $infile_samples;
system("sox -v 3 $outfile temp${outfile} trim ${diff_samples}s");
system("wmix $infile temp${outfile} > $finishfile");
system("rm -f $infile temp${outfile} $outfile");
}
elsif($infile_samples > $outfile_samples)
{
$diff_samples = $infile_samples - $outfile_samples;
system("sox -v 3 $infile temp${infile} trim ${diff_samples}s");
system("wmix temp${infile} $outfile > $finishfile");
system("rm -f temp${infile} $outfile $infile");
}
else
{
system("wmix $infile $outfile > $finishfile");
system("rm -f $infile $outfile");
}
You'll need wmix from http://tph.tuwien.ac.at/~oemer/wavetools.html and
sox, which was already on my system and is pretty standard.
The only problem I've found is that my in channel is a bit low, with respect
to volume. It's probably a sox issue, but I haven't had time to mess with
the settings yet. It's only an annoyance; you can definitely hear both
sides of the conversation.
John
P.S. I record my outbound calls by prefixing my outbound calls with a 5,
which similiarly call record-enable. In that case, the other party doesn't
know they're being recorded. IANAL. Check your state laws first! In some
states both parties must know about calls being recorded. In mine, TX, only
the calling party must know, but it must be first person. For this reason,
I do not let asterisk record everything, because my employees must
themselves determine what they're going to record.
----- Original Message -----
From: "Iain Stevenson" <iain at iainstevenson.com>
To: <asterisk-users at lists.digium.com>
Sent: Sunday, January 04, 2004 12:51 PM
Subject: Re: [Asterisk-Users] help - recording both sides of a conversation
>
> * always records both sides of the conversation - but stores them in
> separate files in
> /var/spool/asterisk/monitor/. You need to combine the "in" and "out"
parts
> using soxmix.
>
> Iain
>
>
>
> --On Sunday, January 4, 2004 9:59 am -0800 Paul Mahler
> <pmahler at signate.com> wrote:
>
> > Does some kind Asterisk soul have an example from extensions.conf that
> > shows how to record both sides of a conversation?
> >
> > Thanks!
> >
> >
> > Paul Mahler
> > mail:pmahler at signate.com
> > phone: 650.207.9855
> > fax: 877.408.0105
> >
> > -----Original Message-----
> > From: asterisk-users-admin at lists.digium.com
> > [mailto:asterisk-users-admin at lists.digium.com] On Behalf Of Philipp von
> > Klitzing
> > Sent: Sunday, January 04, 2004 9:23 AM
> > To: asterisk-users at lists.digium.com
> > Subject: Re: [Asterisk-Users] CAPI, transfering thru a 2nd PBX - keep
> > original CallerID
> >
> > Hi!
> >
> >> I want to have Asterisk as my gateway to the outside world and use
> >> another PBX to connect my existing phones.
> >>
> >> exten => ${OUTSIDEMSN},1,Dial,CAPI/${MSN2NDPBX}:${EXTEN}
> >>
> >> How do I transfer the caller Id information initially coming in?
> >
> > I have strong doubts that this can be done at all. One way would be to
> > set your ${MSN2ndPBX} to ${CALLERIDNUM}, but that would require that
> > capi.conf has that CALLERIDNUM listed as one of the valid outgoing MSNs.
> > Since you won't know in advance who'll call that'll be a problem - also
I
> > don't think you can reconfigure capi.conf in the midst of processing a
> > call...
> >
> > Besides: I suppose your ISDN PBX (which brand exactly?) supports CLIP
(or
> > comes with an internal S0 bus) and you have an analog CLIP phone (or
ISDN
> > phone) connected?
> >
> > Workaround: See my last posting and other very recent discussions
> > concerning a simple tool that shows the current caller ID and name on
> > your PC using either Flash, HTML or Java. Or use astman/ gastman.
> > As of now I am storing the caller data through AGI in mySQL and display
> > that on a web page that the user needs to re-load manually when desired.
> >
> > Cheers, Philipp
> >
> >
> > _______________________________________________
> > Asterisk-Users mailing list
> > Asterisk-Users at lists.digium.com
> > http://lists.digium.com/mailman/listinfo/asterisk-users
> >
> > _______________________________________________
> > Asterisk-Users mailing list
> > Asterisk-Users at lists.digium.com
> > http://lists.digium.com/mailman/listinfo/asterisk-users
> >
>
>
>
>
> _______________________________________________
> Asterisk-Users mailing list
> Asterisk-Users at lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-users
>
More information about the asterisk-users
mailing list