Asterisk cmd Record

Business PBX Solutions
Provider Solution Details
Bicom VoIP Become an ITSP Now!
  • Become a serious competitor in VoIP Immediately
  • FULL Consultancy, Installation, Training & Support
  • Sell Hosted IP PBXs, Biz Lines, Call Centre
  • Turnkey Provisioning at your data center
Details
3CX Software PBX for Windows
  • Windows Software Solution
  • Easy to Install and Manage
  • Auto Configures Phones & Trunks
  • Android, iOS, Windows & Mac clients
Details

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.


Option parameters in 1.4:
  • a: Append to existing recording rather than replacing.
  • n: Do not answer, but record anyway if line not yet answered.
  • q: quiet (do not play a beep tone).
  • s: skip recording if the line is not yet answered.
  • t: use alternate '*' terminator key (DTMF) instead of default '#'
  • x: Ignore all terminator keys (DTMF) and keep recording until hangup.

In asterisk 1.4 if the user should hangup during a recording, all data will be lost and the application will teminate.

Option parameters in 1.8:
  • a: Append to existing recording rather than replacing.
  • n: Do not answer, but record anyway if line not yet answered.
  • q: quiet (do not play a beep tone).
  • s: skip recording if the line is not yet answered.
  • t: use alternate '*' terminator key (DTMF) instead of default '#'
  • x: Ignore all terminator keys (DTMF) and keep recording until hangup.
  • k: Keep recorded file upon hangup.
  • y: Terminate recording if *any* DTMF digit is received.

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.

In asterisk 1.6 the '#' key must be pressed to stop recording. If you simply hung up the recording is lost unless k option is used to keep the recording if channel hangs 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%m%d-%H%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!

Example 4 (by Leif Madsen using Asterisk 1.6 Syntax)


 [globals]
 CUSTOM_RECORDINGS=/var/lib/asterisk/sounds/en/custom

 [subRecordPrompt]
 exten => _[A-Za-z0-9].,1,NoOp()

 ; Safely handle extension name -- this will be our filename
 same => n,Set(RecordedFilename=${FILTER(A-Za-z0-9,${EXTEN})})
 same => n,Set(RandomNumber=${RAND()})
 same => n,Answer()

 ; Record the prompt
 same => n(record),Playback(please-enter-your&vm-message&after-the-tone)
 same => n,Wait(1)
 same => n,Record(${GLOBAL(CUSTOM_RECORDINGS)}/temporaryRecording-${RandomNumber}.wav)

 ; Ask how we want to handle the recording
 same => n(handle_recording),Read(ActionItem,vm-review,1)

 ; Verify we got values we expect
 same => n,GotoIf($['${ActionItem}' = '1' | '${ActionItem}' = '2' |  '${ActionItem}' = '3']?valid_action)
 same => n,Playback(wrong-try-again-smarty)
 same => n,Goto(handle_recording)
 same => n(valid_action),NoOp()

 ; Handle the recording
 ; 1 accept
 ; 2 review
 ; 3 re-record
 same => n,GotoIf($['${ActionItem}' = '1']?accept,1) ; keep this recording
 same => n,GotoIf($['${ActionItem}' = '3']?record)   ; re-record it

 ; If we get here they pressed 2
 same => n,Playback(${GLOBAL(CUSTOM_RECORDINGS)}/temporaryRecording-${RandomNumber})
 same => n,Goto(handle_recording)

 exten => accept,1,Verbose(2,Recording accepted!)
 same => n,System(mv ${GLOBAL(CUSTOM_RECORDINGS)}/temporaryRecording-${RandomNumber}.wav ${GLOBAL(CUSTOM_RECORDINGS)}/${RecordedFilename}.wav)

 exten => h,1,Verbose(2,Cleanup the file)
 same => n,System(rm -f ${GLOBAL(CUSTOM_RECORDINGS)}/temporaryRecording-${RandomNumber}.wav)


See also



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

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.


Option parameters in 1.4:
  • a: Append to existing recording rather than replacing.
  • n: Do not answer, but record anyway if line not yet answered.
  • q: quiet (do not play a beep tone).
  • s: skip recording if the line is not yet answered.
  • t: use alternate '*' terminator key (DTMF) instead of default '#'
  • x: Ignore all terminator keys (DTMF) and keep recording until hangup.

In asterisk 1.4 if the user should hangup during a recording, all data will be lost and the application will teminate.

Option parameters in 1.8:
  • a: Append to existing recording rather than replacing.
  • n: Do not answer, but record anyway if line not yet answered.
  • q: quiet (do not play a beep tone).
  • s: skip recording if the line is not yet answered.
  • t: use alternate '*' terminator key (DTMF) instead of default '#'
  • x: Ignore all terminator keys (DTMF) and keep recording until hangup.
  • k: Keep recorded file upon hangup.
  • y: Terminate recording if *any* DTMF digit is received.

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.

In asterisk 1.6 the '#' key must be pressed to stop recording. If you simply hung up the recording is lost unless k option is used to keep the recording if channel hangs 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%m%d-%H%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!

Example 4 (by Leif Madsen using Asterisk 1.6 Syntax)


 [globals]
 CUSTOM_RECORDINGS=/var/lib/asterisk/sounds/en/custom

 [subRecordPrompt]
 exten => _[A-Za-z0-9].,1,NoOp()

 ; Safely handle extension name -- this will be our filename
 same => n,Set(RecordedFilename=${FILTER(A-Za-z0-9,${EXTEN})})
 same => n,Set(RandomNumber=${RAND()})
 same => n,Answer()

 ; Record the prompt
 same => n(record),Playback(please-enter-your&vm-message&after-the-tone)
 same => n,Wait(1)
 same => n,Record(${GLOBAL(CUSTOM_RECORDINGS)}/temporaryRecording-${RandomNumber}.wav)

 ; Ask how we want to handle the recording
 same => n(handle_recording),Read(ActionItem,vm-review,1)

 ; Verify we got values we expect
 same => n,GotoIf($['${ActionItem}' = '1' | '${ActionItem}' = '2' |  '${ActionItem}' = '3']?valid_action)
 same => n,Playback(wrong-try-again-smarty)
 same => n,Goto(handle_recording)
 same => n(valid_action),NoOp()

 ; Handle the recording
 ; 1 accept
 ; 2 review
 ; 3 re-record
 same => n,GotoIf($['${ActionItem}' = '1']?accept,1) ; keep this recording
 same => n,GotoIf($['${ActionItem}' = '3']?record)   ; re-record it

 ; If we get here they pressed 2
 same => n,Playback(${GLOBAL(CUSTOM_RECORDINGS)}/temporaryRecording-${RandomNumber})
 same => n,Goto(handle_recording)

 exten => accept,1,Verbose(2,Recording accepted!)
 same => n,System(mv ${GLOBAL(CUSTOM_RECORDINGS)}/temporaryRecording-${RandomNumber}.wav ${GLOBAL(CUSTOM_RECORDINGS)}/${RecordedFilename}.wav)

 exten => h,1,Verbose(2,Cleanup the file)
 same => n,System(rm -f ${GLOBAL(CUSTOM_RECORDINGS)}/temporaryRecording-${RandomNumber}.wav)


See also



Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ
Created by: oej, Last modification: Sun 28 of Jul, 2013 (22:18 UTC) by weinerk
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+