Waitforsilence never finds silence

First, I am completely new to asterisk, so please bear with me. I managed to install it (version Asterisk 13.1.0~dfsg-1.1ubuntu4) and my interest is at this time in running and eventually modifying ‘Hello it’s Lenny’

I found all files needed including the dialplan and am running it in on my internal network. It starts and does the first voice prompt (‘Hello it’s Lenny’) but it stops at the ‘waitforsilence call’. The relevant section of extensions.conf looks like this:

exten => 53669,n,Background(lenny/${lennyclip})
exten => 53669,n,AMD(2500,1500,800,5000,100,50,3,256)
exten => 53669,n,NoOp(${AMDCAUSE})
exten => 53669,n,GotoIf($["${AMDCAUSE:0:17}"=“INITIALSILENCE-25”]?reststop)
exten => 53669,n(mach),WaitForSilence(700,3)

This is where it stops. The only way I can make it continue by adding a timeout, as in

exten => 53669,n(mach),WaitForSilence(700,3,3)

but of course the defeats the purpose. I tried switching off the microphone to make sure it is really silent, it makes no difference, it still does not recognize the silence.

I even found the source code at http://download.vicidial.com/asterisk-patches/app_waitforsilence.c and found that the function can have a forth argument which I did not see discussed in the asterisk literature. This determines the silence threshold and it is suggested to increase the value from the default of 128 for noisy systems. So I set

exten => 53669,n(mach),WaitForSilence(700,3,256)

but the program still stops at this point, Even if I put in ridiculously high numbers like 10000 for the fourth argument, it always stops at this function.

Here is an example from the CLI (for some ridiculous value for the threshold):

-- Executing [53669@from-internal:37] BackGround("SIP/dellzoiper-00000009", "lenny/Lenny1") in new stack
-- <SIP/dellzoiper-00000009> Playing 'lenny/Lenny1.ulaw' (language 'en')
-- Executing [53669@from-internal:38] AMD("SIP/dellzoiper-00000009", "2500,1500,800,5000,100,50,3,256") in new stack
-- AMD: SIP/dellzoiper-00000009 dellzoiper (N/A) (Fmt: ulaw)
-- AMD: initialSilence [2500] greeting [1500] afterGreetingSilence [800] totalAnalysisTime [5000] minimumWordLength [100] betweenWordsSilence [50] maximumNumberOfWords [3] silenceThreshold [256] maximumWordLength [5000] 
-- AMD: Channel [SIP/dellzoiper-00000009]. ANSWERING MACHINE: voiceDuration:1500 greeting:1500
-- Executing [53669@from-internal:39] NoOp("SIP/dellzoiper-00000009", "LONGGREETING-1500-1500") in new stack
-- Executing [53669@from-internal:40] NoOp("SIP/dellzoiper-00000009", "AMD status is MACHINE") in new stack
-- Executing [53669@from-internal:41] GotoIf("SIP/dellzoiper-00000009", "0?reststop") in new stack
-- Executing [53669@from-internal:42] NoOp("SIP/dellzoiper-00000009", "Original WAITSTATUS is ") in new stack
-- Executing [53669@from-internal:43] WaitForSilence("SIP/dellzoiper-00000009", "700,1,,100000000") in new stack
-- Waiting 1 time(s) for 700 ms silence with 0 timeout

It freezes here.

Probably I am doing something stupid. Can anyone help me?

Thank you !

Have you tried using Backgroundetect instead?

I have a different version of Lenny that looks like this:
exten => s,1,NoOP()
exten => s,n,Set(TIMEOUT(response)=20)
exten => s,n,Answer()
exten => s,n,Goto(talk,1)
exten => talk,1,Set(i=${IF($[“0${i}”=“016”]?7:$[0${i}+1])})
exten => talk,n,Playback(lenny/Lenny${i})
exten => talk,n,BackgroundDetect(lenny/backgroundnoise,1500)

exten => t,1,Hangup()

Thank you for coming back to me!

I have not tried BackgroundDetect, for two reasons.

One is that I would have to essentially have to rewrite everything in the dialplan. Perhaps that would be a good exercise for me but it is more than I want to do at this time, if I can avoid it.

The other is that I read an explicit warning against doing that. In http://pbxinaflash.com/community/threads/lenny-is-back.13220/page-5
wardmundy says

“Just a heads up. Don’t use BackgroundDetect! It’s dangerous because it also accepts DTMF digits which are passed to your dialplan for processing. It’s also pretty lousy at voice detection, especially with soft-spoken callers. That’s why we moved to the AMD + WaitForSilence approach.”

This makes sense to me so I would like to stick with what he recommends.

Am I doing something wrong?

Hah! I suppose it is bad form to reply to one own’s posting but I just made a discovery:

As I said, turning off the microphone does not make a difference. But I just found while playing with the softphone (zoiper) that lenny continues when I mute the microphone! Each time I mute it, the dialplan continues, until I unmute it (whether the microphone is turned on or off makes no difference).

When I look at the audio signal (in pavucontrol) it is essentially at what the system considers the Silence Base. This is the case with me sitting quiet in front of the microphone or with the microphone turned off. But it appears that this level is still considered as ABOVE the silence level, therefore WaitforSilence() never finds silence.

Is the fourth argument in the function call the right way to set the sensitivity of the function? That does not seem to work. Is there another one?


The WaitForSilence application uses the configuration values in dsp.conf to base how it looks for silence in the audio stream. That config file exposes an option, silencethreshold, that you can modify to determine how long a ‘silence period’ should be before the application decides that silence has been detected.

That being said, if the line is ‘noisy’, you may find that tweaking this setting won’t really help. To denoise the line, try using the DENOISE dialplan function on the channel prior to calling WaitForSilence. That should help the silence detection if there is just some background blips keeping it from picking up the silence.