Asterisk cmd BackGround
Created by: oej,Last modification on Mon 29 of Dec, 2008 [13:43 UTC] by mindaugas_kezys
Synopsis
Play a sound file while awaiting extensionDescription
Background(filename1[&filename2...][|options[|langoverride][|context]])This application will play the given list of files while waiting for an extension to be dialed by the calling channel. To continue waiting for digits after this application has finished playing files, the WaitExten application should be used. The 'langoverride' option explicity specifies which language to attempt to use for the requested sound files. If a 'context' is specified, this is the dialplan context that this application will use when exiting to a dialed extension. If one of the requested sound files does not exist, call processing will be terminated.
Background() inside a macro
If you use Background() inside a macro, the context utilized for the extension is the one where the macro is called, not the context in which the macro is running macro-xxxxx . So if you want to use background with an extension inside your macro, you can use the context parameter, and make it match the one of the macro you are in. Tested successfully on Asterisk 1.4.17.
Options
- s - causes the playback of the message to be skipped if the channel is not in the 'up' state (i.e. it hasn't been answered yet.) If this happens, the application will return immediately.
- n - don't answer the channel before playing the files
- m - only break if a digit hit matches a one digit extension in the destination context
Returns
See http://bugs.digium.com/view.php?id=7835 for details of a crude patch to implement the return of ${BACKGROUNDSTATUS} ("FAILED" or "SUCCESS" in the same way Playback() does).Wait for DTMF Input
If you want Asterisk to just wait for input without playing a sound file, see the WaitExten application.Example
; Sample 'main menu' context with submenuexten => s,1,Answer
exten => s,2,Background(thanks) ; "Thanks for calling. Press 1 for sales, 2 for support, ..."
exten => 1,1,Goto(submenu,s,1)
exten => 2,1,Hangup
See also
- Read: Play a sound file and read digits into a variable
- Playback: Play a sound file
- ControlPlayback: Play a sound file with fast forward, rewind and exit keys
- WaitExten
- Asterisk cmd Progress: Play early audio to caller without answering the channel
- TIMEOUT: Get or set timeouts
- Asterisk sound files
- Asterisk tips answer-before-playback
- Asterisk tips ivr menu: Example Interactive Voice Response IVR menu in Asterisk
- Asterisk Configuration
- The Dialplan: extensions.conf
- Background Stress Test
Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ

Comments
333Using Background with FastAGI to assist interactive voice menus
I had been using :
"EXEC PLAYBACK voicemenu"
"WAIT FOR DIGIT 5000"
but this doesn't allow for the user to interrupt the menu.
The undocumented fact about Background() is that when it is used with AGI, it will return the ASCII digit the user has pressed while the sound file is being played back, or 0 if nothing is pressed, in exactly the same way as WAIT FOR DIGIT does.
So if you don't want the user to be able to interrupt the playing back of a sound file, use "EXEC Playback soundfile".
If you want the user to be able to interrupt and enter a digit, use "EXEC Background soundfile" and process the "200 result = X" response to discover if a digit has been pressed.
333Re: Just upgraded --- Help
exten => s,2,wait(5) ; Listen to ringing for 5 seconds
exten => s,3,Set(TIMEOUT(digit)=8); Increased timeout digit
exten => s,4,Set(TIMEOUT(response)=15)
exten => s,5,Answer()
exten => s,6,Background(messages/psc)
exten => s,7,WaitExten(10)
exten => h,1,Hangup()
exten => i,1,Playback(invalid) ; "That's not valid, try again"
exten => t,1,Hangup()
333Just upgraded --- Help
exten => s,1,Ringing() ; Let's play some ringing sound for inbound callers
exten => s,2,wait(5) ; Listen to ringing for 5 seconds
exten => s,3,Set(TIMEOUT(digit)=8); Increased timeout digit
exten => s,4,Set(TIMEOUT(response)=15)
exten => s,5,Answer()
exten => s,6,Background(messages/psc)
exten => h,1,Hangup()
exten => i,1,Playback(invalid) ; "That's not valid, try again"
exten => t,1,Hangup()
Here is the output from the cli:
— Executing s@inboundpsc:1 Ringing("IAX2/voicepulse-7", "") in new stack
— Executing s@inboundpsc:2 Wait("IAX2/voicepulse-7", "5") in new stack
— Executing s@inboundpsc:3 Set("IAX2/voicepulse-7", "TIMEOUT(digit)=8") in new stack
— Digit timeout set to 8
— Executing s@inboundpsc:4 Set("IAX2/voicepulse-7", "TIMEOUT(response)=15") in new stack
— Response timeout set to 15
— Executing s@inboundpsc:5 Answer("IAX2/voicepulse-7", "") in new stack
— Executing s@inboundpsc:6 BackGround("IAX2/voicepulse-7", "messages/psc") in new stack
— <IAX2/voicepulse-7> Playing 'messages/psc' (language 'en')
== Auto fallthrough, channel 'IAX2/voicepulse-7' status is 'UNKNOWN'
— Executing h@inboundpsc:1 Hangup("IAX2/voicepulse-7", "") in new stack
When the call comes in, it goes to background and then falls out the the h extension to hang up. Any ideas?
333m option in 1.4
exten => s,1,Background(${RECORDING}|m)
exten => s,n,Voicemail(${DID_NO})
exten => 0,1,Voicemail(${DID_NO})
exten => a,1,VoiceMailMain(${DID_NO})
exten => h,1,Hangup
In version 1.2, when I hit "0" during the playback, I will be directed to voicemail. But in verison 1.4, the call hangs up.
Jan 24 16:05:37 DTMF5754: channel.c:2148 __ast_read: DTMF begin '0' received on SIP/5060-08c53e68
Jan 24 16:05:37 DTMF5754: channel.c:2128 __ast_read: DTMF end '0' received on SIP/5060-08c53e68
== Spawn extension (play_recording, s, 1) exited non-zero on 'SIP/5060-08c53e68'
-- Executing h@play_recording:1 Hangup("SIP/5060-08c53e68", "") in new stack
== Spawn extension (play_recording, h, 1) exited non-zero on 'SIP/5060-08c53e68'
Does anyone tell me why this is happening?
333Sound formats
Edit:
Nevermind. Just had a look at http://www.voip-info.org/tiki-index.php?page=Convert+WAV+audio+files+for+use+in+Asterisk
333String Multiple Files Together
Ex: prompt,1,Background(press-1&for-sales&press-2&for-billing)