B.68. Monitor()

Records the current channel in two separate files.
Monitor([format[,fileprefix[,options]]])
Starts audio recording on the current channel. Incoming and outgoing audio packets are written to separate files until the channel is hung up or monitoring is stopped with StopMonitor().
The parameter format sets the file format. If this is not specified, wav is used.
The parameter fileprefix specifies the filename without extension. If this is not specified, the filename is assembled out of the channel name and a number, for example, IAX2[foo@bar]-3. Incoming audio is written to fileprefix-in.format, outgoing audio in fileprefix-out.format, both in /var/spool/asterisk/monitor/.
Two options may be specified:
m
After recording is complete, mixes the incoming and outgoing audio files into a single file and deletes the originals. Requires that soxmix from the sox package be installed on the server.[64]If the variable ${MONITOR_EXEC} is defined, this application is executed instead of soxmix and the original incoming and outgoing audio files are not deleted.[65]. soxmix (or ${MONITOR_EXEC} if specified) is passed three values: the names of the incoming and outgoing audio files and the name of the mixed file, which is the fileprefix without -in/-out. If ${MONITOR_EXEC_ARGS} is set, the contents are used as arguments to ${MONITOR_EXEC}.

Important

Note that soxmix attempts to determine the file type based on the file extension. Formats such as gsm and wav are normally not a problem, but for other formats such as alaw and ulaw, it expects the file extensions .al and .ul respectively. To resolve this, read the manual pages for sox (/soxmix) and use ${MONITOR_EXEC_ARGS} or write a small wrapper script that reads the format parameter and call it in ${MONITOR_EXEC}.

Note

If you wanted a single mixed sound file, MixMonitor() is usually the better option, as it mixes on-the-fly and thereby avoids a spike in CPU load at the end of the recording.
b
Saves audio to the file only while the channel is bridged, i.e. once a conversation has actually begun, and only until it is hung up.
Returns 0 on success, or -1 on failure (such as a failure to open the audio files for writing, or the channel is already being monitored, etc.)
; record the conversation and mix the audio afterwards:
exten => 123,1,Answer()
exten => 123,n,Monitor(gsm,,mb)
exten => 123,n,SayDigits(123456789)
exten => 123,n,Hangup()

; as above, only with our own wrapper script that calls soxmix:
exten => 123,1,Answer()
exten => 123,n,Set(MONITOR_EXEC=/path/to/my-soxmix-wrapper.sh)
exten => 123,n,Monitor(gsm,,mb)
exten => 123,n,SayDigits(123456789)
exten => 123,n,Hangup()

Important

Before recording conversations, make sure you are complying with the relevant legislation in your jurisdiction. In most cases, both parties must be aware they are being recorded.[66]

Note

Some Asterisk users who routinely need to record many conversations (50-500) report much better performance if call recordings are written to a RAM disk (fewer and shorter seek operations) before being copied to a hard disk when the conversation is over.

Note

Internal help for this application in Asterisk 1.4:
  -= Info about application 'Monitor' =- 

[Synopsis]
Monitor a channel

[Description]
Monitor([file_format[:urlbase]|[fname_base]|[options]]):
Used to start monitoring a channel. The channel's input and output
voice packets are logged to files until the channel hangs up or
monitoring is stopped by the StopMonitor application.
  file_format  optional, if not set, defaults to "wav"
  fname_base   if set, changes the filename used to the one specified.
  options:
    m   - when the recording ends mix the two leg files into one and
          delete the two leg files.  If the variable MONITOR_EXEC is set, the
          application referenced in it will be executed instead of
          soxmix and the raw leg files will NOT be deleted automatically.
          soxmix or MONITOR_EXEC is handed 3 arguments, the two leg files
          and a target mixed file name which is the same as the leg file names
          only without the in/out designator.
          If MONITOR_EXEC_ARGS is set, the contents will be passed on as
          additional arguements to MONITOR_EXEC
          Both MONITOR_EXEC and the Mix flag can be set from the
          administrator interface

    b   - Don't begin recording unless a call is bridged to another channel

Returns -1 if monitor files can't be opened or if the channel is already
monitored, otherwise 0.
diff output to internal help in Asterisk 1.2:
- none - 


http://sox.sourceforge.net/, see also an explanation in, version 12.17.7 or newer. You may check your installed version with soxmix -help

[65] depends on Asterisk version; older versions do not delete automatically. It's best to check with a proper test.