Upgrade 3CX to v18 and get it hosted free!

Asterisk cmd BackGroundDetect

Author image

Synopsis

Plays a background sound, jumping to an extension on receipt of DTMF tones or to the “talk” extension if it detects talking.

Description

BackgroundDetect(filename[|silence[|min[|max]]])

BackgroundDetect is similar to Background. It plays back a given filename, waiting for interruption from a given digit (the digit must
start the beginning of a valid extension, or it will be ignored).

silence – this is for the silence after you say something. It is a time in ms
min – this is the starting point from which to start to talk. The time is in ms
max – this is the end point. This point is followed by a period of time for silence. Set by the sil parameter. The time is in ms

During the playback of the file, audio is monitored in the receive direction, and if a period of non-silence which is greater than ‘min’ ms yet less than ‘max’ ms is followed by silence for at least ‘silence’ ms then the audio playback is aborted and processing jumps to the ‘talk’ extension if available. If unspecified, by default the parameters are set to: 1000ms for the ‘silence’, 100ms for the ‘min’ and infinity for the ‘max’ parameter. Returns -1 on hangup, and 0 on successful playback completion with no exit conditions.

Example

[incoming]
exten => s,1,Answer
exten => s,2,ResponseTimeout(5)
exten => s,3,BackgroundDetect(mymenu)
exten => s,3,BackgroundDetect(chooseSomething)

exten => t,1,Goto(s,2)

exten => i,1,Playback(pbx-invalid)
exten => i,2,Goto(s,2)

exten => 1,1,DoSomething

exten => 2,1,DoSomethingElse

exten => 3,1,Dial(...)

exten => talk,1,Dial(...)

Basic answering machine detection

I’m using this to make outgoing calls to deliver alarm messages. It acts differently if it delivers a message to a machine vs human, so there’s two different contexts.

[detect]
exten => s,1,Set(MACHINE=0)
exten => s,2,Answer
exten => s,3,BackgroundDetect(silence/5, 1000, 50)
exten => s,4,Noop(answering machine detected)
exten => s,5,Set(MACHINE=1)
exten => s,6,BackgroundDetect(silence/30, 1000, 50, 30050)
exten => s,7,Noop(too long of a message)
exten => s,8,Hangup

exten => talk,1,GotoIf($[${MACHINE}=1]?2:3)
exten => talk,2,Goto(detect-machine,s,1) ; this is a machine
exten => talk,3,Goto(detect-human,s,1) ; this is a human

Basic theory: if there’s noise followed by silence within 5 seconds, assume it’s a human (“hello?”), otherwise, wait until the noise stops, and then start leaving a message for a machine. You need to have a couple files called silence/5.gsm and silence/30.gsm (see Asterisk cmd Record) in your sounds folder that are just silence.

It needs some tweaking with the timing on BackgroundDetect. One big problem (at least with my system) is that you have to be fairly loud, or it won’t detect the noise.

NOTE (from Scott Stingel www.evtmedia.com): The above example is excellent, and should work fine. Assuming reliable answer supervision, for example when using an outbound PRI/BRI line, we’ve also had good luck using a bit shorter detection times for humans (3 seconds for example). We found in testing that some of our more cryptic users record a very short answering machine greeting, example: “This is Bob. You know the drill (beep!)” = 4 seconds 🙂 Also, if proper answer machine detection is critical to your application, you might do what we did and modify app_talkdetect, adding a call to pbx_builtin_setvar_helper to set a channel variable containing the actual length of the detected voice, which can then be tested in your dialplan. You can then use a single call to BackgroundDetect (with a longer period of silence), and there’s no need to define “talk” extensions. UPDATE: It looks like someone kindly added the aforementioned variable, named TALK_DETECTED, to this application. Therefore, you should be able to use it to determine the length (in msec) of the detected voice.

See also


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


Article Reviews

Write a Review

Your email address will not be published. Required fields are marked *

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.