Fax Detection for IAX/SIP/ZAP
Including non-silence and digit detection.
Download
You can find the code and more instructions on the web, or see the patched version below.
Synopsis
Detects fax sounds on all channel types (on IAX and SIP too)
Description
NVFaxDetect([waitdur[|options[|sildur[|mindur[|maxdur]]]]])
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.
Parameters
waitdur: Maximum number of seconds to wait (default=4)
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, 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).
Requirements
- Asterisk development or stable
Sample Usage (extensions.conf)
[context-incoming]
; 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
[macro-faxexten]
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)
[fax]
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.
Installation
The 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_faxdetect.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 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-1.2.7.1.tar.gz file with
tar -zxvf asterisk-1.2.7.1.tar.gz
cd asterisk-1.2.7.1/apps
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
- include <stdio.h>
cd ../../..
(You should now be in /usr/ports/distfiles/ )
tar cf asterisk-1.2.7.1.tar asterisk-1.2.7.1
and then compress with
gzip asterisk-1.2.7.1.tar (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.
-Greg
UPDATE FOR ASTERISK 1.4.24+ USERS
Working version for Asterisk 1.4.24+
http://www.austechpartnerships.com/app_nv_1.4.2x_07052010.tar.gz
Tested with 1.4.26, 1.4.26.1, 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:
app_nv_backgrounddetect.c
app_nv_backgrounddetect.c.1.4.2x.patch
app_nv_faxdetect.c
app_nv_faxdetect.c.1.4.2x.patch
app_nv_Makefile.patch
README
Enjoy!!!
//Drew Thomson
Future Improvements
We are finishing up outgoing fax detect. Look for the patch or new file there.
See also
- NewmanTelOnAsterisk14 – Instructions to modify Newman Telecom modules for use on Asterisk 1.4.0
- NVBackgroundDetect – 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
- VBS Fax Server A web-based fax server that is extremely feature-rich. Resellers welcome.
- T.38 – The present future for fax over IP (FoIP)