From e0b5df10d6b4fbd36446901b7fd9ce9b37da0115 Mon Sep 17 00:00:00 2001 From: Chris Rienzo Date: Fri, 12 Oct 2018 00:45:03 +0000 Subject: [PATCH] FS-11453 [mod_rayo] allow text/plain grammar for non-mrcp speech recognizers. Added direction to output component to assist with testing. Fix confidence conversion to NLSML. --- src/mod/event_handlers/mod_rayo/rayo_elements.c | 4 ++-- src/mod/event_handlers/mod_rayo/rayo_input_component.c | 6 +++--- src/mod/event_handlers/mod_rayo/rayo_output_component.c | 7 +++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/mod/event_handlers/mod_rayo/rayo_elements.c b/src/mod/event_handlers/mod_rayo/rayo_elements.c index d0892dca80..14e9c61c55 100644 --- a/src/mod/event_handlers/mod_rayo/rayo_elements.c +++ b/src/mod/event_handlers/mod_rayo/rayo_elements.c @@ -1,6 +1,6 @@ /* * mod_rayo for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2013, Grasshopper + * Copyright (C) 2013-2018, Grasshopper * * Version: MPL 1.1 * @@ -42,7 +42,6 @@ ELEMENT(RAYO_INPUT) ATTRIB(sensitivity, 0.5, decimal_between_zero_and_one) ATTRIB(min-confidence, 0, decimal_between_zero_and_one) ATTRIB(max-silence, -1, positive_or_neg_one) - /* for now, only NLSML */ STRING_ATTRIB(match-content-type, application/nlsml+xml, "application/nlsml+xml") /* internal attribs for prompt support */ ATTRIB(barge-event, false, bool) @@ -72,6 +71,7 @@ ELEMENT(RAYO_OUTPUT) ATTRIB(max-time, -1, positive_or_neg_one) ATTRIB(renderer,, any) ATTRIB(voice,, any) + STRING_ATTRIB(direction, out, "out,in") ELEMENT_END /** diff --git a/src/mod/event_handlers/mod_rayo/rayo_input_component.c b/src/mod/event_handlers/mod_rayo/rayo_input_component.c index 13311d5444..84a8e745cc 100644 --- a/src/mod/event_handlers/mod_rayo/rayo_input_component.c +++ b/src/mod/event_handlers/mod_rayo/rayo_input_component.c @@ -415,7 +415,7 @@ static int validate_call_input(iks *input, const char **error) if (!zstr(iks_find_attrib(grammar, "url"))) { *error = "url not allowed with content-type"; return 0; - } else if (strcmp("application/srgs+xml", content_type)) { + } else if (strcmp("application/srgs+xml", content_type) && strcmp("text/plain", content_type)) { *error = "Unsupported content type"; return 0; } @@ -891,7 +891,7 @@ static const char *get_detected_speech_result_text(cJSON *result_json, double *c if (json_confidence && json_confidence->valuedouble > 0.0) { *confidence = json_confidence->valuedouble; } else { - *confidence = 100.0; + *confidence = 0.99; } result_text = text; } else if (error_text) { @@ -940,7 +940,7 @@ static void on_detected_speech_event(switch_event_t *event) result_text = get_detected_speech_result_text(json_result, &confidence, &error_text); if (!zstr(result_text)) { // got result... send as NLSML - iks *result = nlsml_create_match(result_text, NULL, "speech", (int)confidence); + iks *result = nlsml_create_match(result_text, NULL, "speech", (int)(confidence * 100.0)); /* notify of match */ switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "MATCH = %s\n", result_text); send_match_event(RAYO_COMPONENT(component), result); diff --git a/src/mod/event_handlers/mod_rayo/rayo_output_component.c b/src/mod/event_handlers/mod_rayo/rayo_output_component.c index f94921fd91..6ea607e33b 100644 --- a/src/mod/event_handlers/mod_rayo/rayo_output_component.c +++ b/src/mod/event_handlers/mod_rayo/rayo_output_component.c @@ -1,6 +1,6 @@ /* * mod_rayo for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2013-2016, Grasshopper + * Copyright (C) 2013-2018, Grasshopper * * Version: MPL 1.1 * @@ -53,6 +53,8 @@ struct output_component { const char *renderer; /** optional headers to pass to renderer */ const char *headers; + /** audio direction */ + const char *direction; }; #define OUTPUT_FINISH "finish", RAYO_OUTPUT_COMPLETE_NS @@ -79,6 +81,7 @@ static struct rayo_component *create_output_component(struct rayo_actor *actor, output_component->max_time_ms = iks_find_int_attrib(output, "max-time"); output_component->start_paused = iks_find_bool_attrib(output, "start-paused"); output_component->renderer = switch_core_strdup(RAYO_POOL(output_component), iks_find_attrib_soft(output, "renderer")); + output_component->direction = strcmp(iks_find_attrib_soft(output, "direction"), "in") ? "m" : "mr"; output_component->headers = NULL; /* get custom headers */ { @@ -136,7 +139,7 @@ static iks *start_call_output(struct rayo_component *component, switch_core_sess } stream.write_function(&stream, "}fileman://rayo://%s", RAYO_JID(component)); - if (switch_ivr_displace_session(session, stream.data, 0, "m") == SWITCH_STATUS_SUCCESS) { + if (switch_ivr_displace_session(session, stream.data, 0, OUTPUT_COMPONENT(component)->direction) == SWITCH_STATUS_SUCCESS) { RAYO_RELEASE(component); } else { if (component->complete) {