Recording Custom Prompts
Recording Custom Prompts
Provide a dial-in extension where administrators or users can record custom greetings and IVR prompts by speaking into the phone. The recording is saved as a sound file and played back immediately for review.
Dialplan
[features]
exten => *99,1,NoOp(Record a custom prompt)
same => n,Answer()
same => n,Wait(1)
same => n,Playback(beep)
same => n,Record(custom-greeting%d:ulaw)
same => n,Wait(1)
same => n,Playback(${RECORDED_FILE})
same => n,Hangup()
Record with a Specific Filename
[features]
; Record a greeting for a specific mailbox or context
exten => *98,1,NoOp(Record named prompt)
same => n,Answer()
same => n,Wait(1)
same => n,Read(PROMPT_NAME,vm-enter-num-to-call,10)
same => n,GotoIf($["${PROMPT_NAME}" = ""]?invalid)
same => n,Playback(beep)
same => n,Record(custom/${PROMPT_NAME}:wav,,5)
same => n,Wait(1)
same => n,Playback(custom/${PROMPT_NAME})
same => n,Hangup()
same => n(invalid),Playback(an-error-has-occurred)
same => n,Hangup()
How it works
- Record(filename:format,silence,maxduration,options): Records audio from the caller to a file. Recording stops when the caller presses
#, hangs up, or whenmaxdurationseconds elapse. Asilencevalue (in seconds) causes recording to stop after that many seconds of silence. %dauto-numbering: The%din the filename is replaced by an auto-incrementing number, so repeated recordings don't overwrite each other:custom-greeting0.ulaw,custom-greeting1.ulaw, etc.${RECORDED_FILE}: AfterRecord()completes, this channel variable contains the full path of the recorded file (without extension). Pass it directly toPlayback()for immediate review.- Format:
:ulawrecords in 8kHz G.711 mu-law, native to North American telephony. Use:wavfor wideband or:gsmfor compressed storage. The format determines the file extension. - Wait(1) before Record: A short delay after Answer() prevents the first fraction of a second of audio from being clipped, and gives the caller time to prepare.
Tips
- Recorded files land in
/var/lib/asterisk/sounds/by default. Use a subdirectory likecustom/to keep them organized. - Add a re-record loop: after playback, ask "Press 1 to accept, 2 to re-record" using
Read()andGotoIf(). - For voicemail greetings, use
VoiceMailMain()instead: it has a built-in greeting recording flow. - Maximum recording length can be set with the third argument:
Record(file:ulaw,,120)limits to 120 seconds. - Use the
koption (Record(file:ulaw,,,k)) to keep the recording if the caller hangs up during recording, rather than discarding it. - Reference the recorded file in other contexts:
Playback(custom-greeting0)(no extension, no path prefix if it's in the sounds directory).
User Notes
No notes yet. Be the first to contribute a tip or example.
Contribute a note
Share a tip, gotcha, or practical example. Keep it under 2000 characters. No questions (use the Asterisk community forums for support). Wrap code in backticks.