diff --git a/README.md b/README.md index 1a30b05..6d7092c 100644 --- a/README.md +++ b/README.md @@ -18,14 +18,16 @@ To build this module, all you need to do is type `make`, but because it relies on `pkg-config` and FreeSWITCH, you need to point `pkg-config` to where FreeSWITCH is installed before building: -``` +```shell host$ export PKG_CONFIG_PATH=/usr/local/freeswitch/lib/pkgconfig/ host$ make ``` Sample Configuration -------------------- + Just put a file like this in your freeswitch installation, in **conf/autoload_configs/amd.conf.xml** + ```xml @@ -41,3 +43,9 @@ Just put a file like this in your freeswitch installation, in **conf/autoload_co ``` + +Events +------ + +The module fires the custom FreeSWITCH event `amd` with the significant fields `AMD-Result` and `AMD-Cause`. +`Unique-ID` to recognize FreeSWITCH instance. diff --git a/mod_amd.c b/mod_amd.c index cccfad6..cb515a5 100644 --- a/mod_amd.c +++ b/mod_amd.c @@ -145,7 +145,7 @@ typedef enum { } amd_vad_state_t; typedef struct { - const switch_core_session_t *session; + switch_core_session_t *session; switch_channel_t *channel; amd_vad_state_t state; uint32_t frame_ms; @@ -158,6 +158,24 @@ typedef struct { uint32_t in_greeting:1; } amd_vad_t; +static void amd_fire_event(const char *result, const char *cause, switch_core_session_t *fs_s) +{ + switch_event_t *event; + switch_event_t *event_copy; + + if ((switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "amd")) != SWITCH_STATUS_SUCCESS) + return; + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "AMD-Result", result); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "AMD-Cause", cause); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(fs_s)); + if ((switch_event_dup(&event_copy, event)) != SWITCH_STATUS_SUCCESS) + return; + switch_core_session_queue_event(fs_s, &event); + switch_event_fire(&event_copy); + + return; +} + static amd_frame_classifier classify_frame(const switch_frame_t *f, const switch_codec_implementation_t *codec) { int16_t *audio = f->data; @@ -207,6 +225,7 @@ static switch_bool_t amd_handle_silence_frame(amd_vad_t *vad, const switch_frame switch_channel_set_variable(vad->channel, "amd_result", "MACHINE"); switch_channel_set_variable(vad->channel, "amd_cause", "INITIALSILENCE"); + amd_fire_event("MACHINE", "INITIALSILENCE", vad->session); return SWITCH_TRUE; } @@ -220,6 +239,7 @@ static switch_bool_t amd_handle_silence_frame(amd_vad_t *vad, const switch_frame switch_channel_set_variable(vad->channel, "amd_result", "HUMAN"); switch_channel_set_variable(vad->channel, "amd_cause", "HUMAN"); + amd_fire_event("HUMAN", "HUMAN", vad->session); return SWITCH_TRUE; } @@ -252,6 +272,7 @@ static switch_bool_t amd_handle_voiced_frame(amd_vad_t *vad, const switch_frame_ switch_channel_set_variable(vad->channel, "amd_result", "MACHINE"); switch_channel_set_variable(vad->channel, "amd_cause", "MAXWORDLENGTH"); + amd_fire_event("MACHINE", "MAXWORDLENGTH", vad->session); return SWITCH_TRUE; } @@ -265,6 +286,7 @@ static switch_bool_t amd_handle_voiced_frame(amd_vad_t *vad, const switch_frame_ switch_channel_set_variable(vad->channel, "amd_result", "MACHINE"); switch_channel_set_variable(vad->channel, "amd_cause", "MAXWORDS"); + amd_fire_event("MACHINE", "MAXWORDS", vad->session); return SWITCH_TRUE; } @@ -278,6 +300,7 @@ static switch_bool_t amd_handle_voiced_frame(amd_vad_t *vad, const switch_frame_ switch_channel_set_variable(vad->channel, "amd_result", "MACHINE"); switch_channel_set_variable(vad->channel, "amd_cause", "LONGGREETING"); + amd_fire_event("MACHINE", "LONGGREETING", vad->session); return SWITCH_TRUE; } @@ -390,6 +413,7 @@ SWITCH_STANDARD_APP(amd_start_function) switch_channel_set_variable(channel, "amd_result", "NOTSURE"); switch_channel_set_variable(channel, "amd_cause", "TOOLONG"); + amd_fire_event("NOTSURE", "TOOLONG", vad.session); break; } }