Example Audio Discriminator

 

This example is of source code for a VTS page that implements a simple voice response system.

[

    Title = "Voice"; 

    Color = -17; 

    Bitmap; 

    SecBit; 

    WinFlag = 0; 

    AudioDiscriminator Module { Module to receive incoming calls }; 

    { TAPI Media modes used to select the compatibility of a modem } 

    Constant TAPIMEDIATYPE_AUDIO = 0x08; 

    Constant TAPIMEDIATYPE_DATAMODEM = 0x10; 

    Constant NEED_DTMF = 0x1000 { Enable DTMF when handling call }; 

    Constant DTMF_STOPS_SPEECH = 0x2000 { Rec'd DTMF stops any speech }; 

    spVoice = "bf5ead45-9f65-11cf-8fc8-0020af14f271" { Voice for telephone modem}; 

    Constant SMALLPAUSE = "\Pau=250\"; 

    Constant LONGPAUSE = "\Pau=500\"; 

    Trig; 

    Number; 

    Name = "(Phone)"; 

    DataPort; 

    KeyPress; 

    BookMark; 

    Phase; 

    Phrase; 

    Incoming = 0; 

]

Init [

    If \ModemManager\Started Main; 

    [ 

          Return(Self); 

          AddVariable(\Code, Name, 0, 256, 0, 0, 0, 0, 0, 0); 

          Scope(\Code, Name) = Self(); 

          Phase = 0; 

          \ModemManager\Register(Self(), 1, 1, 

          TAPIMEDIATYPE_AUDIO + NEED_DTMF + DTMF_STOPS_SPEECH, 

          SpVoice, 30 { Discriminator Timeout }, Name); 

    ] 

]

Main [

    Return(Self); 

    \System\Edit(40, 60, 180, 90, "Number to Call", Number, !Valid(DataPort), Trig, Invalid, 4, 1); 

    If Trig; 

    [ 

          Trig = Invalid; 

          Phase = BookMark = 1; 

          CloseStream(DataPort); 

          \Code\ModemManager\MakeCall(Number, 110, 8, 1, 0, 5, Name, Invalid, 

          TAPIMEDIATYPE_AUDIO + NEED_DTMF + DTMF_STOPS_SPEECH, spVoice); 

    ] 

    If TimeOut((ValueType(DataPort) == 8) && !Incoming, 6) && Phase == BookMark; 

    [ 

          BookMark = -1; 

          IfThen(!Valid(Case(Phase - 1, 

          {0} Phrase = "Hello and welcome. Please press a key to continue.", 

          {1} Phrase = "This is message number 1", 

          {2} Phrase = "This is message number 2", 

          {3} Phrase = "This is message number 3", 

          {4} Phrase = "Goodbye!" 

          )), 

          CloseStream(DataPort) 

          ); 

          SWrite(DataPort, "%s%s\\Mrk=%d\\\r", SmallPause, Phrase, Phase); 

    ] 

    If SerWait(DataPort, 1); 

    [ 

          KeyPress = SerRcv(DataPort, 1); 

          IfElse( PickValid(KeyPress >= 0 && KeyPress <= 9, 0) || KeyPress == "image\Number_Hatch.gif" || KeyPress == "*", Execute(

          { DTMF from phone - cancels any pending speech } 

          Phase++; 

          IfThen(KeyPress == "*", 

          Phase = 1; 

          ); 

          IfThen(KeyPress == "image\Number_Hatch.gif",

          Phase = 5; 

          ); 

          BookMark = Phase; 

          ); 

          { Else } 

          { Must be a bookmark } 

          IfThen(KeyPress == MakeBuff(1, 0x41 + Phase), 

          IfThen(Phase > 4, 

          Phase++; 

          ); 

          BookMark = Phase; 

          ); 

          ); 

    ] 

]

{==================== Voice\AudioDiscriminator =================== }

{ This module, runs the receive call handling. If a call is not successfully authenticated then the caller (ModemManager) will time out and will then attempt to hand the call off. }

{====================================================================}

AudioDiscriminator

(

Mode; 

)

Check [

    Incoming = 1; 

    If TimeOut(1, 7); 

    [ 

          Phase = 1; 

          Phrase = "Hello, you have reached the VTS modem tester."; 

          SWrite(DataPort, "%s%s\\Mrk=%d\\\r", SmallPause, Phrase, Phase); 

    ] 

    If KeyPress == "9" Idle; 

    [ 

          Phase = BookMark = 1; 

          Incoming = 0; 

          Return(1); 

    ] 

]

Idle [

]

{ End of Voice\AudioDiscriminator }