[Asterisk-Dev] new version of axra, includes multi-threading and a talking caller id in english and french

Eric Bart btk-adm at byortek.com
Tue Oct 5 15:31:24 MST 2004


axra is a framework for processing an agi while using the *
manager api. it should help in developping outside apps.

the talking caller id app use a tts engine, either festival 
for english, either mbrola/lliaphon for french.

there's also a "Say" app for french tts.

download :
http://byortek.com/asterisk/download/

Regards
Eric

Below is the copy of the REAME file :

axra is an interface program that dialogs with asterisk through
agi calls and through the manager api. it proccesses phone calls
through agis and concurently through the manager api.  it 
provides a framework for managing complex telephony functions.

axra receives agi commands from the dial plan. the agi program
is 'axraagi'. it is copied in /var/lib/asterisk/agi-bin. 
'axraagi' is just forwarding (back and forth) the datas to axra. 
there may be several concurent agis.

axra reads the asterisk state through the manager api messages. it
stores and maintains its own description of the asterisk state.

when needed axra sends commands to asterisk either through agis 
or through the manager api.

axra is multi-threaded. once in a thread, axra apps may register 
events and wait for events to occur. there are manager api events,
agi events and timer events. events can only occur during a
CheckGroup() command. Normally you wait for a single event, if
another event occur, an exception is thrown.

Here's an excerpt from app-test.c :
/*
Test app

This app will create the sound prompt : "please press a key for hangup"
on first run, it will play beeps while computing the audio, next times
the prompt will be played immediatly.

the user will hear the key he pressed and the call will hangup. 

after 20 seconds of inactivity the call will automatically hangup.

To use it, add the following in your dialplan : 
exten => xxx,1,AGI(axraagi|Test)
run axra and dial the xxx extension.
*/

void * test(void * ptr)
{
  // as is the agi instance created in the dialplan
  BKagiSession * as = reinterpret_cast<BKagiSession *>(ptr);  

  // instance creation of the events (with a debugging string)
  BKastRegEv REvAsChanHangup("Manager api hangup event");  // for hangup detection
  BKagiRegEv REvAgi("Agi Event");                          // for waiting for agi commands
  BKtimerRegEv REvTimeout("Timeout");                      // timeout event 
  BKregEv REvNull("Null event");                           // null event, never up

  try {    // exceptions may occur in this block, like "throw (BKregEv *)REvTimeout;"

    // register exceptions events. events can only occur after their registration
    REvAsChanHangup.Register(Hangup, as->agi_channel);   // will detect hangup of as agi channel
    REvTimeout.Register(20);   // Event will be up in 20 seconds

    as->SendStringToAgi("answer");                // answer the channel
    as->SendStringToAgi("exec SetLanguage en");   // choose english language

    // create the custom prompt sound file "please press a key for hangup". the file will be 
    // stored in the axra asterisk sound directory. the asterik and unix filemames are filled in.
    string ttsfilenameAst;
    string ttsfilenameUnix;         
    getTtsAudio("please press a key for hangup", "axra", "en", "", ttsfilenameAst, ttsfilenameUnix);

    // play beep each 2 seconds while the tts is being computed
    // the while condition is always true but exception events may occur during the 2 seconds waiting time
    do 
      if (access(ttsfilenameUnix.c_str(), F_OK) == 0)  // test existence of the audio file
 break;                                         // skips immediatly if the file already exists 
      else
  as->SendStringToAgi("exec playback beep");
    while (BKregEv::CheckGroup(&REvNull, 2) < 1);      // check and wait 2 seconds


    // play the prompt in loop and wait for a pressed key or an exception
    while (BKregEv::CheckGroup(&REvNull) < 1) {    // always true but exception events may occur
      
      as->SendStringToAgi("get data " + ttsfilenameAst + " 1500 1");   // play the tts audio 

      // wait for asterisk response to the "get data" command and store it in resp
      REvAgi.Register(as,"");                    // will wait for all queued agi commands to be responded
      while (BKregEv::CheckGroup(&REvAgi) < 1);  // wait here
      string resp = REvAgi.GetResponse();        // get the response to the last agi command

      // see if the user pressed a key
      if(resp.find("200 result=")==0) {
 if(resp.length()==12) {                           // the user pressed a key
   char key = resp[11];                            // key is the key
   ast_log(LOG_DEBUG,"the user pressed the key %c", key);
   BKregEv::CheckGroup(&REvNull, 0.5);             // wait 0.5 seconds
   string command = "exec SayDigits ";
   command += key;
   as->SendStringToAgi(command);                   // say the key
   break;  // the end
 }
      }
    }
  }    
  catch(BKregEv * up) {   // we jump here either by timeout or by user hangup
    ast_log(LOG_DEBUG,"BKregEv exception catched: %s", up->DebugName.c_str());
  }

  as->AgiExit(1);                    // hangup and close the agi
  as->AuthorizeDeletion();           // allow the cleaner to clean the 'as' instance
}




More information about the asterisk-dev mailing list