Asterisk cmd Monitor


Record a telephone conversation to a sound file


  • Monitor(ext,basename)
  • Monitor(ext,basename,flags) — New feature added to CVS 2004-06-03

The Monitor command starts recording a channel. The channel's input and output voice packets are saved to separate sound files. You may change filenames during a recording by using the ChangeMonitor command. Recording continues until either the StopMonitor command is executed or the channel hangs up.
If you don't specify a full path, the file will be stored in the "monitor" subdir of the path specified with astspooldir in asterisk.conf (so default will be /var/spool/asterisk/monitor).

A more detailed description on recording with Asterisk can be found at Asterisk cmd Record.

Command Parameters

  • ext: The sound file format to save in, which will be also used as the filename extension. Default: wav

  • basename: The base filename to use when saving the sound files. If not supplied, the default basename is constructed on the channel name plus a number, for example, IAX2[foo@bar]-3. The channel's input voice packets will be saved to basename-in.ext and the output voice packets will be saved to basename-out.ext. The default location for saved files is the /var/spool/asterisk/monitor directory.

  • flags:
    • m - New in Asterisk v1.2.0 - If flags contains the letter m, then when recording finishes, Asterisk will execute a unix program to combine the two sound files into a single sound file. By default, Asterisk will execute soxmix and then delete the original two sound files. Note that sox/soxmix may not necessarily understand the sound format (e.g. alaw) and can't therefore mix the in and out files down to one single file. You may specify a different mixing method by setting the MONITOR_EXEC channel variable to the path of the unix program you wish executed, then call Monitor to begin recording. At the completion of recording, the specified unix program will be executed with three command-line parameters: the two sound files and the filename where the program should save the combined sound file. In this situation, earlier versions of Asterisk will not delete the two original sound files; it's up to your program to do that if you need/wish to. The "m" flag is settable through the manager interface.
    • b - New in Asterisk v1.2.0 - Don't begin recording unless a call is bridged to another channel.
    • i - New in Asterisk v1.6.0 - Skip recording of input stream (disables m option).
    • o - New in Asterisk v1.6.0 - Skip recording of output stream (disables m option).

Example 1

When a call is sent to extension 2060, recording of the call will begin, and the caller is sent to conference number 1 with the MeetMe command.

exten => 2060,1,Answer
exten => 2060,2,Wait(1)
exten => 2060,3,Monitor(wav,myfilename)
exten => 2060,4,Meetme(1,ps)

For an extensive example of using Monitor, see:

Example 2: 512 Simultaneous Calls with Digital Recording

How to use a RAM disk to eliminate the I/O bottleneck associated with digitally recording calls via the Monitor application:

Related user report Sep 2010: I've already ran into major problems using the Monitor() app due to disk io. The disk writing is done in the same thread as audio bridging, so if you have high disk io contention (which I had), audio bridging suffers while you're recording a call. MixMonitor spawns a new thread and avoids this problem. Ideally Monitor() should also be rewritten to spawn a new thread.

Example 3: Play beeping sound during recording

If you want peep every 15s, you should do

exten => _X.,1,Set(LIMIT_WARNING_FILE=beep)
exten => _X.,2,Dial(Local/mixmoncontext/#{EXTEN}||L(36000000:36000000:15000)\n)

Converting Wav Files

Find all files in monitor directory and convert to mp4 (1/10 size) removing original wav- requires ffmpeg and x264
nice -n 19 find /var/spool/asterisk/monitor/ -iname "*wav" -type f -exec sh -c 'ffmpeg -i {} -y -vn -aq 40 -ac 1 `echo {} | sed "s/.wav/.mp4/g"` && rm {}' \;
(file size approx 6MB per hour)

See also

Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ
Created by: oej, Last modification: Thu 30 of Apr, 2015 (20:51 UTC) by sfgeorge
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+