Fax Detection for IAX/SIP/ZAP

Including non-silence and digit detection.


You can find the code and more instructions on the web, or see the patched version below.


Detects fax sounds on all channel types (on IAX and SIP too)



This application listens for fax tones (on IAX and SIP channels too) for waitdur seconds of time. In addition, it can be interrupted by digits, or non-silence. Audio is only 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 greater than 'mindur' ms, yet less than 'maxdur' ms is followed by silence at least 'sildur' ms then the app is aborted and jumps to the 'talk' extension. If all undetected, control will continue at the next priority.


waitdur: Maximum number of seconds to wait (default=4)
'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.


This code is NOT included with Asterisk at this point, however it is free. To get it, please search for it on the web or download it below.

This should only work on channels that are using ULAW/ALAW.

Asterisk 1.8 comes with fax detection, which should make NVFaxDetect unnecessary (it anyways does not appear to be available for Asterisk version > 1.4).


  • Asterisk development or stable

Sample Usage (extensions.conf)

; Answer and do some detection work
exten => s,1,Answer
exten => s,2,NVFaxDetect()
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

Another Example (extensions.conf)

; ring extensions with fax detect
exten => s,1,Dial(${ARG1},17) ; wait 3 rings
exten => s,2,Answer
exten => s,3,Playtones(ring) ; play fake ring so caller doesn't wonder whats going on
exten => s,4,NVFaxDetect(4|dt) ; while playing ring sound, detect faxes for 4 seconds (goes to "fax" extension if detected)
exten => s,5,Goto(s-${DIALSTATUS},1) ; if no fax, branch on dialstatus
exten => s-NOANSWER,1,Voicemail(u${MACRO_EXTEN})
exten => s-NOANSWER,2,Hangup()
exten => s-BUSY,1,Voicemail(b${MACRO_EXTEN})
exten => s-BUSY,2,Hangup()
exten => _s-.,1,Goto(s-NOANSWER,1) ; everything else is treated as no answer

; If this is a fax, get it
exten => fax,1,StopPlaytones ; you must do this or it will play ring sounds over your fax
exten => fax,2,SetVar(FAXFILE=/var/spool/asterisk/fax/${DNID}_${UNIQUEID})
exten => fax,3,Goto(fax,s,1)

exten => s,1,rxfax(${FAXFILE}.tif)
exten => h,1,DEADAGI(faxtoemail.agi|${FAXFILE}.tif) ; you need to download the faxtoemail script or something similar here.


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:

(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:

  1. define CALLERID_FIELD cid.cid_num

Comment out the other, existing definition.

(4) Start or restart Asterisk

(5) Type "show application nvfaxdetect" from the CLI and you should see it

There may be a better way to do this; however, this is what I used to get it working under FreeBSD.

Now cd /usr/ports/distfiles

go ahead and extract the asterisk- file with

tar -zxvf asterisk-

cd asterisk-

vi Makefile

add the following to the list of modules to compile app_nv_backgrounddetect.so app_nv_faxdetectc.so

write the file

Then add the following before file.h in in both app_nv_backgrounddetect.c and app_nv_faxdetect.c

  1. include <stdio.h>

cd ../../..

(You should now be in /usr/ports/distfiles/ )

tar cf asterisk- asterisk-

and then compress with

gzip asterisk- (if it exists, you will need to write over it)

Now cd /usr/ports/net/asterisk

rename the distinfo file to distinfo.old so it wont get used when you begin compiling.

make clean ; make deinstall ; make ; make install

asterisk -vvvgc

asterisk> show modules

You should see the two modules now.



Working version for Asterisk 1.4.24+


Tested with 1.4.26,, 1.4.31.

Also includes NVBackgroundDetect but was untested. Module compiles and loads into Asterisk properly so presumptions would be that it works as well.

NVBackgroundDetect works well on Asterisk 1.4.26 (Doesn't works for me with version above to 1.4.26)

Files included in tarball:

//Drew Thomson

Future Improvements

We are finishing up outgoing fax detect. Look for the patch or new file there.

See also

Created by: justin_newman, Last modification: Sun 15 of Aug, 2010 (02:50 UTC) by mtdrox
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+