login | register
Tue 09 of Feb, 2010 [21:15 UTC]

voip-info.org

History

Asterisk cmd Record

Created by: oej,Last modification on Fri 15 of Jan, 2010 [00:00 UTC] by jdaskew

Synopsis

Record user voice or video input to a file

Description

 Prior to ca. 2004-11-01
   Record(filename:format[|silence][|maxduration][|option])

 After 2004-11-01 (cvs) and in Asterisk v1.2
   Record(filename.format[|silence][|maxduration][|option])

Records from the current channel to a sound file saved with the given filename. The format parameter specifies the sound format and the extension of the file. If you don't specify a full path, the file will be stored in the /var/lib/asterisk/sounds directory. If a file with the same name and extension already exists, it will be overwritten.
In the case of combined audio & video recording the 'format' refers only to the audio portion, while the video portion of the recording is automatically set to the active video codec (Asterisk 1.2/1.4/1.6 cannot transcode video, at least not without out-of-tree patches). You will, for example, end up with two files: sample.wav (audio) and sample.h263 (video).

If filename contains %d, these characters will be replaced with a number incremented by one each time the file is recorded, and the resulting filename will be returned in the channel variable ${RECORDED_FILE}.

The supported sound formats are: sln, g723, g729, gsm, h263, ulaw, alaw, vox, wav, WAV (WAV is the GSM format of wav files). Note that sox may not necessarily understand the chosen sound format (e.g. alaw). This impacts 'cmd Monitor' more than 'cmd Record', but as the page for the former refers to this page, it's probably worth mentioning here too.

The optional parameters are:
  • silence: seconds of silence allowed before the recording is stopped. If missing or 0, silence detection is disabled.
  • maxduration: maximum recording duration in seconds. If missing or 0, there is no maximum.
  • option: may be 'skip' to return immediately if the line is not up, or 'noanswer' to record even if the line is not up.

The Record command will play a beep sound on the channel when it starts recording. Recording stops when the specified silence or maxduration is reached, when the '#' key is pressed, or when the channel is hung up.

(:exclaim:) Make sure that the media path travels through Asterisk, i.e. you need to have a canreinvite=no in your sip.conf if it is a SIP channel, or a t or T in your Dial command, or you need to be transcoding (the conversation partners use different codecs).

Return codes

Returns -1 when the user hangs up.

Example 1

 ; used to record prompts
 exten => 205,1,Answer
 exten => 205,2,Wait(2)
 exten => 205,3,Record(asterisk-recording%d:ulaw)
 exten => 205,4,Wait(2)
 exten => 205,5,Playback(${RECORDED_FILE})
 exten => 205,6,Wait(2)
 exten => 205,7,Hangup

The sound file will be saved in /var/lib/asterisk/sounds with the name asterisk-recording0, asterisk-recording1, etc.

Example 2

This example offers the ability to rerecord if you need to, and to make several recordings without needing to rename the sound file after each recording. This example assumes you have the Festival text to speech engine installed.
If you do not, then edit the script accordingly.

[recordings]
exten => 500,1,Festival('Please record your message')
exten => 500,2,Record(mymessage:gsm)
exten => 500,3,Festival('You said')
exten => 500,4,Playback(mymessage)
exten => 500,5,Festival('Press 1 to continue or 2 to change your message')
exten => 500,6,ResponseTimeout(3)

exten => t,1,Festival('Sorry, I did not get that')
exten => t,2,Goto(500,5)

exten => i,1,Festival('Sorry, that is an invalid choice')
exten => i,2,Goto(500,5)

exten => 1,1,System(/bin/mv /var/lib/asterisk/sounds/mymessage.gsm /var/lib/asterisk/sounds/local/${TIMESTAMP}.gsm)
exten => 1,2,Festival('Thank you, your recording has been saved.')
exten => 1,3,Festival('Press 3 to record another file or 4 to hang up')

exten => 2,1,Goto(500,1)


In asterisk 1.4 the timestamp variable is not available. Change extension 1, priority 1 to read:

exten => 1,1,System(/bin/mv /var/lib/asterisk/sounds/mymessage.gsm /var/lib/asterisk/sounds/local/${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}.gsm)


Here's an alternative method of Example 2, just in case you can't get the example above to work:

[recordings]
exten => 500,1,Festival('Please record your message')
exten => 500,2,Record(mymessage:gsm)
exten => 500,3,Festival('You said')
exten => 500,4,Playback(mymessage)
exten => 500,5,Festival('Press 1 to continue or 2 to change your message')

exten => 500,6,Read(KEEPORTOSS||1)
exten => 500,7,Gotoif($[${KEEPORTOSS}=1]?recordings,501,1)
exten => 500,8,Gotoif($[${KEEPORTOSS}=2]?recordings,502,1)
exten => 500,9,Gotoif($[${KEEPORTOSS}=3]?recordings,503,1)
exten => 500,10,Gotoif($[${KEEPORTOSS}=4]?recordings,504,1)
exten => 500,11,Festival(Goodbye)
exten => 500,12,Hangup()

exten => 501,1,System(/bin/mv /var/lib/asterisk/sounds/mymessage.gsm /var/lib/asterisk/sounds/local/${STRFTIME(${EPOCH},,%Y%mNaVH%M%S)}.gsm)
exten => 501,2,Festival('Thank you, your recording has been saved.')
exten => 501,3,Festival('Press 3 to record another file or 4 to hang up')
exten => 501,4,Goto(recordings,500,6)

exten => 502,1,Goto(recordings,500,1)

exten => 503,1,Goto(recordings,500,1)

exten => 504,1,Goto(recordings,500,11)



Example 3

To record silence:
1. Call your pbx
2. Mute your phone (or take the cord off the handset)
3. Have the dialplan be something like
  • exten => s,1,Record(silence/30.gsm,0,30)
  • exten => s,n,Hangup
4. The call will automatically disconnect after 30 seconds
5. Enjoy your period of silence!

See also



Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ


Comments

Comments Filter
222

333Recording a G.711 mu-law stream to avoid transcoding

by jhl, Thursday 20 of March, 2008 [01:58:37 UTC]
Hi,

If an inbound audio stream is using the G.711 mu-law codec, in what format should I record a message so G.711 mu-law is the codec used in the resultant audio files?

Also, If the above format is not .wav, what kind of performance hit should one expect when recording an incoming G.711 mu-law audio stream as a .wav file?

Thanks,

James

222

333wav format

by clagos, Tuesday 11 of July, 2006 [18:00:53 UTC]
Asterisk records wav files in 16bits, signed. Is there any way of recording in 8bits, unsigned? I hope someone can help me. Thanks
222

333Anotger example

by , Tuesday 13 of April, 2004 [13:12:24 UTC]
I use this for recording samples, it is still a bit clunky, but offers the ability to re-record if you need to, and also to record a bunch of prompts in one hit (instead of needing to go and re-name the file after each recording).

Just paste this to your extensions.conf and include the recordings context for your line. If this breaks, you can keep both parts, if you fix it, please leave a comment here, and/or let me know...

recordings
exten => 500,1,Festival,Please record your message
exten => 500,2,Record,mymessage:gsm
exten => 500,3,Festival,You said
exten => 500,4,Playback,mymessage
exten => 500,5,Festival,Press 1 to continue or 2 to change your message
exten => 500,6,ResponseTimeout,3
                                                                                                  
exten => t,1,Festival,Sorry, I did not get that
exten => t,2,Goto,500|5
                                                                                                  
exten => i,1,Festival,Sorry, that is an invalid choice
exten => i,2,Goto,500|5
                                                                                                  
exten => 1,1,System,/bin/mv /var/lib/asterisk/sounds/mymessage.gsm /var/lib/asterisk/sounds/local/`date +%s`.gsm
exten => 1,2,Festival,Thank you, your recording has been saved.
exten => 1,3,Festival,Press 3 to record another file or 4 to hang up
                                                                                                  
exten => 2,1,Goto,500|1
exten => 3,1,Goto,500|1
exten => 4,1,Hangup


Hmmm, newer versions of asterisk include a variable with current unixtime, I wrote this ages ago.