[Freeswitch-dev] fax tone detection inside app
Hi, Could anyone help me how to setup the event handler within lua script? My dialplan is simply configured to execute an application for the DID range. All code processing is being happened within lua code. Now, consider the following scenario. - The call comes in - My script starts - The prompt(greeting) is being played "No one is available at a moment, please leave a message or start sending your fax now" Are there any ways, to find out at this point, whether fax negotiation has started? The following pseudo code would explain my concern: if ( getEvent("Detected-Tone") == "fax" ) doReceiveFax() else doReceiveVoice() Thanks, Peter
On Wed, Oct 14, 2009 at 11:11 AM, Peter Volchek <pvolchek@voicemobility.com>wrote:
Hi, Could anyone help me how to setup the event handler within lua script? My dialplan is simply configured to execute an application for the DID range. All code processing is being happened within lua code. Now, consider the following scenario.
- The call comes in - My script starts - The prompt(greeting) is being played "No one is available at a moment, please leave a message or start sending your fax now"
Are there any ways, to find out at this point, whether fax negotiation has started? The following pseudo code would explain my concern:
if ( getEvent("Detected-Tone") == "fax" ) doReceiveFax() else doReceiveVoice()
Thanks, Peter
You can use the tone_detect app per the wiki ( http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_tone_detect) to detect the tone and act accordingly. You just need to decide what to do while waiting to detect the tone. Personally, I don't like doing too much call control inside a script, but YMMV.
Not having tried it myself I would suggest trying something simple, like using the tone_detect app to set a chan var and then have your script keep checking that chan var until your timeout has expired or it sees the fax tone. -MC
On Wed, Oct 14, 2009 at 12:44 PM, Peter Volchek <pvolchek@voicemobility.com>wrote:
Well, the problem with the dialplan is that you could have a single entry per application. However, if your mailbox is capable of receiving both the voice and fax messages, then the decision which one to take should be taken inside your application.
In other words, I do have the following in my dialplan:
<extension name="main_entry"> <condition field="destination_number" expression="^(7[0-9][0-9][0-9][0-9])$"> <action application="lua" data="/home/freeswitch/scripts/app/main.lua"/> </condition> </extension>
All calls to the #s 70000-7999 are directed to main.lua scrtipt. The call is answered prompt then, is being played, "Please leave a voice message or fax". Now, I need a way to catch a fax tone, if exists, and route my code flow to the appropriate function. Note, that the sender may hit 'Send' upon listening the prompt, in other words, the fax negotiation will not start immediately. Does it all make sense?
Yep. In either case you need to turn on tone_detect at some point, so you can do it in your script or in your dialplan. -MC
On Wed, Oct 14, 2009 at 1:09 PM, Peter Volchek <pvolchek@voicemobility.com>wrote:
Could you provide with some examples how to do it within lua script, please? I was not able to find any examples myself,
session:execute("tone_detect", "fax 1100 r +5000 set 'fax_tone_detected=true' 1") Then check for the value of the channel variable fax_tone_detected and act accordingly. -MC
Try using transfer instead of set? http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_fax_detect On October 15, 2009 05:35:56 pm Peter Volchek wrote:
I have just realized, that even though you turned on the fax tone detection, the only way to figure it out (whether the tone has been detected) is to poll the system variable (fax_tone_detected). In other words, if the prompt being played or any other lengthy operation is executing, I will not be able to check the variable, till that operation finishes.
More elegant solution to that problem would be the use use of callbacks or hooks.
The following example would demonstrate the idea:
function fax_session_hook(status) -- fax tone detected, go and save the fax doProcessFax(); end
session:setFaxToneDetectHook("fax_session_hook"); playPrompt('greeting');
-- at this point we are receiving a voice mail session:unsetFaxToneDetectHook(); doProcessVoice()
Would it be difficult to implement? PV
Michael Collins wrote:
On Wed, Oct 14, 2009 at 1:09 PM, Peter Volchek <pvolchek@voicemobility.com> wrote:
Could you provide with some examples how to do it within lua script, please? I was not able to find any examples myself,
session:execute("tone_detect", "fax 1100 r +5000 set 'fax_tone_detected=true' 1")
Then check for the value of the channel variable fax_tone_detected and act accordingly. -MC
participants (3)
-
Chris Burns
-
Michael Collins
-
Peter Volchek