Hack51.Record Calls


Hack 51. Record Calls

Pitch the microcassette and stick-on microphone. With Asterisk, all you need to record a phone call is Monitor( ).

There are two ways to record calls with Asterisk. One way is to use a softphone that supports call recording or some other client-side desktop solution (in fact, "Secretly Record VoIP Calls" [Hack #85] describes precisely this scenario). The other way is to have Asterisk do all the recording and have SoX do all the mixing. SoX, short for SOund EXchange, is the Swiss army knife of sound-conversion tools. It allows all kinds of format conversion, resampling, and mixing, topics covered in more detail in "Create Telephony Sounds with SoX" [Hack #24].

To record a call with Asterisk, you can use the built-in Monitor dial-plan command. In extensions.conf, any extension can be monitored as follows:

 exten => s,1,Answer exten => s,2,Monitor(wav,most-recent-call,M) 

This example creates a WAV file called most-recent-call-ext in /var/spool/asterisk/monitor. The M argument causes the call to be mixed automatically so that caller and receiver can both be heard in the same file. Without the M, Monitor would just create two different files, most-recent-call-in-ext and most-recent-call-out-ext. ext represents the extension that the caller dialed to trigger this Monitor to begin with.

SoX must be installed for the M option to work. Without SoX, Asterisk cannot output automatically mixed call recordings. Most of the major Linux distributions provide a SoX package as an installation option.


4.12.1. Hacking the Hack

If you want to keep every call you record without overwriting already-recorded WAV files, you'll need to come up with an automatic way of uniquely naming every file that Monitor creates. The best way to do this is probably to base the filename off of the current system date and time. Not only does this make them unique, but it also affords you an easy way to find files by date and time later on when you need them. This example uses the ${DATETIME} variable to produce a file whose name is something like 112205-09:45:42-40:

 exten => 40,1,Answer exten => 40,2,Monitor(wav,${DATETIME},M) 

Once the files are recorded, you can use cron to automatically archive them with gzip, or even use the mail command to send them to an email address, much as you did with faxes in "Build an Inbound Fax-to-Email Gateway" [Hack #91].




VoIP Hacks
VoIP Hacks: Tips & Tools for Internet Telephony
ISBN: 0596101333
EAN: 2147483647
Year: 2005
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net