NVBackgroundDetect
Created by: justin_newman,Last modification on Tue 03 of Mar, 2009 [02:10 UTC] by jq53333
Background with Fax Detection for IAX/SIP/ZAP
Including non-silence and digit detection. Search the web for the code.Synopsis
Background a file with talk and fax detect (on IAX and SIP too)Description
NVBackgroundDetect(filename[|options[|sildur[|mindur[|maxdur]]]])Plays filename, waiting for interruption from fax tones (on IAX/SIP too), a digit, or non-silence. Audio is monitored in the receive direction. If digits interrupt, they must be the start of a valid extension unless the option is included to ignore. If fax is detected, it will jump to the 'fax' extension. If a period of non-silence is greater than 'mindur' ms, yet less than 'maxdur' ms is followed by silence at least 'sildur' ms then the app is aborted and processing jumps to the 'talk' extension. If all undetected, control will continue at the next priority.
Parameters
options:'n': Attempt on-hook if unanswered (default=no)
'x': DTMF digits terminate without extension (default=no)
'd': Ignore DTMF digit detection (default=no)
'f': Ignore fax detection (default=no)
't': Ignore talk detection (default=no)
sildur: Silence ms after mindur/maxdur before aborting (default=1000)
mindur: Minimum non-silence ms needed (default=100)
maxdur: Maximum non-silence ms allowed (default=0/forever)
Return codes
Returns -1 on hangup, and 0 on successful completion with no exit conditions.Notes
This code is NOT included with Asterisk at this point, however it is free. To get it, search the web.This should only work on channels that are using ULAW/ALAW.
Requirements
- Asterisk development or stable
Sample Usage (extensions.conf)
[context-incoming]
; Answer and do some detection work
exten => s,1,Answer
exten => s,2,NVBackgroundDetect(welcome)
exten => s,3,Hangup
; If user presses "1", dial main line
exten => 1,1,Dial(SIP/5500)
exten => 1,2,Hangup
; If this is a fax, dial fax line
exten => fax,1,Dial(SIP/5501)
exten => fax,2,Hangup
; If user is talking, send him to Debra
exten => talk,1,Dial(SIP/5502)
exten => talk,2,Hangup
; Answer and do some detection work
exten => s,1,Answer
exten => s,2,NVBackgroundDetect(welcome)
exten => s,3,Hangup
; If user presses "1", dial main line
exten => 1,1,Dial(SIP/5500)
exten => 1,2,Hangup
; If this is a fax, dial fax line
exten => fax,1,Dial(SIP/5501)
exten => fax,2,Hangup
; If user is talking, send him to Debra
exten => talk,1,Dial(SIP/5502)
exten => talk,2,Hangup
Installation
Easiest way to get up and running:
(1) Drop the code in your /usr/src/asterisk/apps directory
(2) Edit the Makefile in the apps directory. Add the following line:
APPS+=app_nv_backgrounddetect.so
(3) Go to /usr/src/asterisk and run "make", then run "make install"
If you encounter compiler errors like:
error: struct ast_channel has no member cid
Edit app_nv_faxdetect.c and enable the CALLERID_FIELD #define statement:
#define CALLERID_FIELD cid.cid_num
Comment out the other, existing definition.
(4) Start or restart Asterisk
(5) Type "show application nvbackgrounddetect" from the CLI and you should see it
(1) Drop the code in your /usr/src/asterisk/apps directory
(2) Edit the Makefile in the apps directory. Add the following line:
APPS+=app_nv_backgrounddetect.so
(3) Go to /usr/src/asterisk and run "make", then run "make install"
If you encounter compiler errors like:
error: struct ast_channel has no member cid
Edit app_nv_faxdetect.c and enable the CALLERID_FIELD #define statement:
#define CALLERID_FIELD cid.cid_num
Comment out the other, existing definition.
(4) Start or restart Asterisk
(5) Type "show application nvbackgrounddetect" from the CLI and you should see it
Future Improvements
We are working on answering machine detection for this module.See also
- NewmanTelOnAsterisk14 - Instructions to modify Newman Telecom modules for use on Asterisk 1.4.0
- NVFaxDetect - Detects fax, talk, DMTF, and other tones on IAX, SIP, ZAP, and other channels
- NVLineDetect - Detects answer, busy, congestion, dialtone, dead, and others on IAX, SIP, ZAP, and other channels
- NVFaxEmail - Integration of SpanDSP, RxFax, and e-mail; quick and simple to use without scripts
- NVMachineDetect - Answering machine, PBX, and talk detection
- Asterisk fax
- Asterisk Fax to email
- Asterisk spandsp - Sending and receiving fax directly with Asterisk
- Hylafax - Another fax solution
- T.38 - The present future for fax over IP (FoIP)
- Answering Machine Detect
- Receiving and sending faxes with asterisk 1.4, NVFaxDetect, iaxmodem and hylafax
- See this link for problems compiling with Asterisk 1.4.23.1

Comments
333NV*Detect on FreeBSD
#include <stdio.h>
right above file.h line in both the faxdetect and backgrounddetect .c files
333
333More code mods for 1.2.4?
With 1.2.4, I needed to add the following to includes to get the code to compile successfully on FC4:
The unistd.h include, defines various UNIX defs such that some pthread defines are enabled. I also added the above includes to app_nv_faxdetect.c as well.
333NVBackgroundDetect on Debian Sarge
So far it worked like a charm.
This is how I got this done for NVBackgroundDetect:
Marcel Prisi on Monday 21 of November, 2005 21:12:27
I successfully installed this app on Debian Sarge using the following method, keeping the official packages :
Install the official sarge asterisk packages : apt-get install asterisk asterisk-dev
Download app_nv_faxdetect.c, edit and replace "#define CALLERID_FIELD cid.cid_num" by "#define CALLERID_FIELD callerid"
Compile it using "gcc -D_GNU_SOURCE -shared -o app_nv_faxdetect.so app_nv_faxdetect.c"
Copy the resulting app_nv_faxdetect.so to /usr/lib/asterisk/modules/
Restart asterisk and enjoy :-)
333NVBackgroundDetect on Asterisk 1.2 (and/or AMP or @home Beta)
1.2 (and/or AMP or @home Beta), make the following changes:
1) Above the following line near the top, in both files:
#include <asterisk/lock.h>
Add:
#include <stdio.h>
2) In NVBackgroundDetect, to get rid of the trigraph warning, search for
"??)" and replace it with "?)".
3) Rebuild Asterisk from /usr/src/asterisk with "make && make install".
4) Restart Asterisk with "restart now" from the CLI.
The new release will have this modification.
Justin