FS-11442 [mod_test] new module, mod_test - mock ASR interface.

This commit is contained in:
Chris Rienzo committed 2018-12-20 10:17:50 -05:00
1 parent a4a0dd81bb
commit 101512ba33
13 files changed
+781 -28

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
include $(top_srcdir)/build/modmake.rulesam
MODNAME=mod_test
mod_LTLIBRARIES = mod_test.la
mod_test_la_SOURCES = mod_test.c
mod_test_la_CFLAGS = $(AM_CFLAGS)
mod_test_la_LIBADD = $(switch_builddir)/libfreeswitch.la
mod_test_la_LDFLAGS = -avoid-version -module -no-undefined -shared
SUBDIRS=. test
+407
View File
@@ -0,0 +1,407 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2018, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthm@freeswitch.org>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Rienzo <chris@signalwire.com>
*
*
* mod_test.c -- mock module interfaces for testing
*
*/
#include <switch.h>
SWITCH_MODULE_LOAD_FUNCTION(mod_test_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_test_shutdown);
SWITCH_MODULE_RUNTIME_FUNCTION(mod_test_runtime);
SWITCH_MODULE_DEFINITION(mod_test, mod_test_load, mod_test_shutdown, mod_test_runtime);
typedef enum {
ASRFLAG_READY = (1 << 0),
ASRFLAG_INPUT_TIMERS = (1 << 1),
ASRFLAG_START_OF_SPEECH = (1 << 2),
ASRFLAG_RETURNED_START_OF_SPEECH = (1 << 3),
ASRFLAG_NOINPUT_TIMEOUT = (1 << 4),
ASRFLAG_RESULT = (1 << 5),
ASRFLAG_RETURNED_RESULT = (1 << 6)
} test_asr_flag_t;
typedef struct {
uint32_t flags;
const char *result_text;
double result_confidence;
uint32_t thresh;
uint32_t silence_ms;
uint32_t voice_ms;
int no_input_timeout;
int speech_timeout;
switch_bool_t start_input_timers;
switch_time_t no_input_time;
switch_time_t speech_time;
char *grammar;
char *channel_uuid;
switch_vad_t *vad;
} test_asr_t;
static void test_asr_reset(test_asr_t *context)
{
if (context->vad) {
switch_vad_reset(context->vad);
}
context->flags = 0;
context->result_text = "agent";
context->result_confidence = 87.3;
switch_set_flag(context, ASRFLAG_READY);
context->no_input_time = switch_micro_time_now();
if (context->start_input_timers) {
switch_set_flag(context, ASRFLAG_INPUT_TIMERS);
}
}
static switch_status_t test_asr_open(switch_asr_handle_t *ah, const char *codec, int rate, const char *dest, switch_asr_flag_t *flags)
{
test_asr_t *context;
if (switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "asr_open attempt on CLOSED asr handle\n");
return SWITCH_STATUS_FALSE;
}
if (!(context = (test_asr_t *) switch_core_alloc(ah->memory_pool, sizeof(*context)))) {
return SWITCH_STATUS_MEMERR;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "codec = %s, rate = %d, dest = %s\n", codec, rate, dest);
ah->private_info = context;
ah->codec = switch_core_strdup(ah->memory_pool, codec);
if (rate > 16000) {
ah->native_rate = 16000;
}
context->thresh = 400;
context->silence_ms = 700;
context->voice_ms = 60;
context->start_input_timers = 1;
context->no_input_timeout = 5000;
context->speech_timeout = 10000;
context->vad = switch_vad_init(ah->native_rate, 1);
switch_vad_set_mode(context->vad, -1);
switch_vad_set_param(context->vad, "thresh", context->thresh);
switch_vad_set_param(context->vad, "silence_ms", context->silence_ms);
switch_vad_set_param(context->vad, "voice_ms", context->voice_ms);
switch_vad_set_param(context->vad, "debug", 0);
test_asr_reset(context);
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t test_asr_load_grammar(switch_asr_handle_t *ah, const char *grammar, const char *name)
{
test_asr_t *context = (test_asr_t *)ah->private_info;
if (switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "asr_open attempt on CLOSED asr handle\n");
return SWITCH_STATUS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_INFO, "load grammar %s\n", grammar);
context->grammar = switch_core_strdup(ah->memory_pool, grammar);
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t test_asr_unload_grammar(switch_asr_handle_t *ah, const char *name)
{
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t test_asr_close(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
{
test_asr_t *context = (test_asr_t *)ah->private_info;
switch_status_t status = SWITCH_STATUS_SUCCESS;
if (switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Double ASR close!\n");
return SWITCH_STATUS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_NOTICE, "ASR closing ...\n");
if (context->vad) {
switch_vad_destroy(&context->vad);
}
switch_set_flag(ah, SWITCH_ASR_FLAG_CLOSED);
return status;
}
static switch_status_t test_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags)
{
test_asr_t *context = (test_asr_t *) ah->private_info;
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_vad_state_t vad_state;
if (switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED)) {
return SWITCH_STATUS_BREAK;
}
if (switch_test_flag(context, ASRFLAG_RETURNED_RESULT) && switch_test_flag(ah, SWITCH_ASR_FLAG_AUTO_RESUME)) {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "Auto Resuming\n");
test_asr_reset(context);
}
if (switch_test_flag(context, ASRFLAG_READY)) {
vad_state = switch_vad_process(context->vad, (int16_t *)data, len / sizeof(uint16_t));
if (vad_state == SWITCH_VAD_STATE_STOP_TALKING) {
switch_set_flag(context, ASRFLAG_RESULT);
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_INFO, "Talking stopped, have result.\n");
switch_vad_reset(context->vad);
switch_clear_flag(context, ASRFLAG_READY);
} else if (vad_state == SWITCH_VAD_STATE_START_TALKING) {
switch_set_flag(context, ASRFLAG_START_OF_SPEECH);
context->speech_time = switch_micro_time_now();
}
}
return status;
}
static switch_status_t test_asr_pause(switch_asr_handle_t *ah)
{
test_asr_t *context = (test_asr_t *) ah->private_info;
if (switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "asr_pause attempt on CLOSED asr handle\n");
return SWITCH_STATUS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "Pausing\n");
context->flags = 0;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t test_asr_resume(switch_asr_handle_t *ah)
{
test_asr_t *context = (test_asr_t *) ah->private_info;
if (switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "asr_resume attempt on CLOSED asr handle\n");
return SWITCH_STATUS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "Resuming\n");
test_asr_reset(context);
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t test_asr_check_results(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
{
test_asr_t *context = (test_asr_t *) ah->private_info;
if (switch_test_flag(context, ASRFLAG_RETURNED_RESULT) || switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED)) {
return SWITCH_STATUS_BREAK;
}
if (!switch_test_flag(context, ASRFLAG_RETURNED_START_OF_SPEECH) && switch_test_flag(context, ASRFLAG_START_OF_SPEECH)) {
return SWITCH_STATUS_SUCCESS;
}
if ((!switch_test_flag(context, ASRFLAG_RESULT)) && (!switch_test_flag(context, ASRFLAG_NOINPUT_TIMEOUT))) {
if (switch_test_flag(context, ASRFLAG_INPUT_TIMERS) && !(switch_test_flag(context, ASRFLAG_START_OF_SPEECH)) &&
context->no_input_timeout >= 0 &&
(switch_micro_time_now() - context->no_input_time) / 1000 >= context->no_input_timeout) {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "NO INPUT TIMEOUT %" SWITCH_TIME_T_FMT "ms\n", (switch_micro_time_now() - context->no_input_time) / 1000);
switch_set_flag(context, ASRFLAG_NOINPUT_TIMEOUT);
} else if (switch_test_flag(context, ASRFLAG_START_OF_SPEECH) && context->speech_timeout > 0 && (switch_micro_time_now() - context->speech_time) / 1000 >= context->speech_timeout) {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "SPEECH TIMEOUT %" SWITCH_TIME_T_FMT "ms\n", (switch_micro_time_now() - context->speech_time) / 1000);
if (switch_test_flag(context, ASRFLAG_START_OF_SPEECH)) {
switch_set_flag(context, ASRFLAG_RESULT);
} else {
switch_set_flag(context, ASRFLAG_NOINPUT_TIMEOUT);
}
}
}
return switch_test_flag(context, ASRFLAG_RESULT) || switch_test_flag(context, ASRFLAG_NOINPUT_TIMEOUT) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_BREAK;
}
static switch_status_t test_asr_get_results(switch_asr_handle_t *ah, char **resultstr, switch_asr_flag_t *flags)
{
test_asr_t *context = (test_asr_t *) ah->private_info;
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_stream_handle_t result = { 0 };
SWITCH_STANDARD_STREAM(result);
if (switch_test_flag(context, ASRFLAG_RETURNED_RESULT) || switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED)) {
return SWITCH_STATUS_FALSE;
}
if (switch_test_flag(context, ASRFLAG_RESULT)) {
*resultstr = switch_mprintf("{\"grammar\": \"%s\", \"text\": \"%s\", \"confidence\": %f}", context->grammar, context->result_text, context->result_confidence);
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_ERROR, "Result: %s\n", *resultstr);
status = SWITCH_STATUS_SUCCESS;
} else if (switch_test_flag(context, ASRFLAG_NOINPUT_TIMEOUT)) {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "Result: NO INPUT\n");
*resultstr = switch_mprintf("{\"grammar\": \"%s\", \"text\": \"\", \"confidence\": 0, \"error\": \"no_input\"}", context->grammar);
status = SWITCH_STATUS_SUCCESS;
} else if (!switch_test_flag(context, ASRFLAG_RETURNED_START_OF_SPEECH) && switch_test_flag(context, ASRFLAG_START_OF_SPEECH)) {
switch_set_flag(context, ASRFLAG_RETURNED_START_OF_SPEECH);
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "Result: START OF SPEECH\n");
status = SWITCH_STATUS_BREAK;
} else {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_ERROR, "Unexpected call to asr_get_results - no results to return!\n");
status = SWITCH_STATUS_FALSE;
}
if (status == SWITCH_STATUS_SUCCESS) {
switch_set_flag(context, ASRFLAG_RETURNED_RESULT);
switch_clear_flag(context, ASRFLAG_READY);
}
return status;
}
static switch_status_t test_asr_start_input_timers(switch_asr_handle_t *ah)
{
test_asr_t *context = (test_asr_t *) ah->private_info;
if (switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "asr_start_input_timers attempt on CLOSED asr handle\n");
return SWITCH_STATUS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "start_input_timers\n");
if (!switch_test_flag(context, ASRFLAG_INPUT_TIMERS)) {
switch_set_flag(context, ASRFLAG_INPUT_TIMERS);
context->no_input_time = switch_micro_time_now();
} else {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_INFO, "Input timers already started\n");
}
return SWITCH_STATUS_SUCCESS;
}
static void test_asr_text_param(switch_asr_handle_t *ah, char *param, const char *val)
{
test_asr_t *context = (test_asr_t *) ah->private_info;
if (!zstr(param) && !zstr(val)) {
int nval = atoi(val);
double fval = atof(val);
if (!strcasecmp("no-input-timeout", param) && switch_is_number(val)) {
context->no_input_timeout = nval;
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "no-input-timeout = %d\n", context->no_input_timeout);
} else if (!strcasecmp("speech-timeout", param) && switch_is_number(val)) {
context->speech_timeout = nval;
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "speech-timeout = %d\n", context->speech_timeout);
} else if (!strcasecmp("start-input-timers", param)) {
context->start_input_timers = switch_true(val);
if (context->start_input_timers) {
switch_set_flag(context, ASRFLAG_INPUT_TIMERS);
} else {
switch_clear_flag(context, ASRFLAG_INPUT_TIMERS);
}
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "start-input-timers = %d\n", context->start_input_timers);
} else if (!strcasecmp("vad-mode", param)) {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "vad-mode = %s\n", val);
if (context->vad) switch_vad_set_mode(context->vad, nval);
} else if (!strcasecmp("vad-voice-ms", param) && nval > 0) {
context->voice_ms = nval;
switch_vad_set_param(context->vad, "voice_ms", nval);
} else if (!strcasecmp("vad-silence-ms", param) && nval > 0) {
context->silence_ms = nval;
switch_vad_set_param(context->vad, "silence_ms", nval);
} else if (!strcasecmp("vad-thresh", param) && nval > 0) {
context->thresh = nval;
switch_vad_set_param(context->vad, "thresh", nval);
} else if (!strcasecmp("channel-uuid", param)) {
context->channel_uuid = switch_core_strdup(ah->memory_pool, val);
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "channel-uuid = %s\n", val);
} else if (!strcasecmp("result", param)) {
context->result_text = switch_core_strdup(ah->memory_pool, val);
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "result = %s\n", val);
} else if (!strcasecmp("confidence", param) && fval >= 0.0) {
context->result_confidence = fval;
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "confidence = %f\n", fval);
}
}
}
SWITCH_MODULE_LOAD_FUNCTION(mod_test_load)
{
switch_asr_interface_t *asr_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
asr_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ASR_INTERFACE);
asr_interface->interface_name = "test";
asr_interface->asr_open = test_asr_open;
asr_interface->asr_load_grammar = test_asr_load_grammar;
asr_interface->asr_unload_grammar = test_asr_unload_grammar;
asr_interface->asr_close = test_asr_close;
asr_interface->asr_feed = test_asr_feed;
asr_interface->asr_resume = test_asr_resume;
asr_interface->asr_pause = test_asr_pause;
asr_interface->asr_check_results = test_asr_check_results;
asr_interface->asr_get_results = test_asr_get_results;
asr_interface->asr_start_input_timers = test_asr_start_input_timers;
asr_interface->asr_text_param = test_asr_text_param;
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_test_shutdown)
{
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_RUNTIME_FUNCTION(mod_test_runtime)
{
return SWITCH_STATUS_TERM;
}
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
@@ -0,0 +1,5 @@
include $(top_srcdir)/build/modmake.rulesam
bin_PROGRAMS = test_asr
test_asr_CFLAGS = $(AM_CFLAGS) -I../
test_asr_LDFLAGS = $(AM_LDFLAGS) -avoid-version -no-undefined $(freeswitch_LDFLAGS) ../mod_test.la $(switch_builddir)/libfreeswitch.la $(CORE_LIBS) $(APR_LIBS)
TESTS = $(bin_PROGRAMS)
@@ -0,0 +1,23 @@
<document type="freeswitch/xml">
<section name="configuration" description="Various Configuration">
<configuration name="modules.conf" description="Modules">
<modules>
<load module="mod_loopback"/>
<load module="mod_tone_stream"/>
<load module="mod_dptools"/>
<load module="mod_sndfile"/>
</modules>
</configuration>
</section>
<section name="dialplan" description="Regex/XML Dialplan">
<context name="default">
<extension name="sample">
<condition>
<action application="info"/>
</condition>
</extension>
</context>
</section>
</document>
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,292 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2018, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthm@freeswitch.org>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Rienzo <chris@signalwire.com>
*
*
* test_asr.c -- tests for mock test asr interface
*
*/
#include <switch.h>
#include <test/switch_test.h>
#include <stdlib.h>
static const char *get_query_result_text(switch_memory_pool_t *pool, const char *result)
{
const char *result_text = NULL;
cJSON *result_json = cJSON_Parse(result);
if (result_json) {
const char *text = cJSON_GetObjectCstr(result_json, "text");
if (!zstr(text)) {
result_text = switch_core_strdup(pool, text);
} else {
text = cJSON_GetObjectCstr(result_json, "error");
if (!zstr(text)) {
result_text = switch_core_strdup(pool, text);
}
}
cJSON_Delete(result_json);
}
return result_text;
}
FST_CORE_BEGIN(".")
FST_MODULE_BEGIN(mod_test, test_asr)
FST_SETUP_BEGIN()
{
fst_requires_module("mod_tone_stream");
fst_requires_module("mod_sndfile");
fst_requires_module("mod_dptools");
}
FST_SETUP_END()
FST_TEARDOWN_BEGIN()
{
}
FST_TEARDOWN_END()
FST_TEST_BEGIN(core_asr)
{
const char* session_id = "123435";
char *grammar = switch_core_sprintf(fst_pool, "{start-input-timers=true,no-input-timeout=5000,speech-timeout=10000,channel-uuid=%s}default", session_id);
fst_test_core_asr_open("test");
fst_test_core_asr(
grammar,
"file_string://silence_stream://3000,0!sounds/agent.wav!silence_stream://3000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "agent");
fst_test_core_asr_resume();
fst_test_core_asr(
grammar,
"silence_stream://30000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "no_input");
fst_test_core_asr_resume();
fst_test_core_asr(
grammar,
"file_string://sounds/agent.wav!silence_stream://3000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "agent");
fst_test_core_asr_resume();
fst_test_core_asr(
grammar,
"silence_stream://30000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "no_input");
fst_test_core_asr_resume();
fst_test_core_asr(
grammar,
"file_string://sounds/agent.wav!silence_stream://3000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "agent");
fst_test_core_asr_pause();
fst_test_core_asr_resume();
fst_test_core_asr(
grammar,
"file_string://sounds/agent.wav!silence_stream://3000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "agent");
fst_test_core_asr_close();
fst_test_core_asr_open("test");
fst_test_core_asr(
grammar,
"file_string://silence_stream://1000,0!sounds/ivr-please_state_your_name_and_reason_for_calling.wav!silence_stream://3000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "agent");
fst_test_core_asr_close();
}
FST_TEST_END()
FST_TEST_BEGIN(core_asr_auto_resume)
{
const char* session_id = "123435";
char *grammar = switch_core_sprintf(fst_pool, "{start-input-timers=true,no-input-timeout=5000,speech-timeout=10000,channel-uuid=%s}default", session_id);
fst_test_core_asr_open("test");
switch_set_flag(&ah, SWITCH_ASR_FLAG_AUTO_RESUME);
fst_test_core_asr(
grammar,
"file_string://silence_stream://3000,0!sounds/agent.wav!silence_stream://3000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "agent");
fst_test_core_asr(
grammar,
"silence_stream://30000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "no_input");
fst_test_core_asr(
grammar,
"file_string://sounds/agent.wav!silence_stream://3000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "agent");
fst_test_core_asr(
grammar,
"silence_stream://30000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "no_input");
fst_test_core_asr_resume();
fst_test_core_asr(
grammar,
"file_string://sounds/agent.wav!silence_stream://3000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "agent");
fst_test_core_asr_resume();
fst_test_core_asr(
grammar,
"file_string://silence_stream://1000,0!sounds/ivr-please_state_your_name_and_reason_for_calling.wav!silence_stream://3000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "agent");
fst_test_core_asr_close();
}
FST_TEST_END()
FST_TEST_BEGIN(core_asr_abuse)
{
const char* session_id = "5351514";
char *grammar = switch_core_sprintf(fst_pool, "{start-input-timers=true,no-input-timeout=5000,speech-timeout=10000,channel-uuid=%s}default", session_id);
fst_test_core_asr_open("test");
fst_test_core_asr(
grammar,
"file_string://silence_stream://3000,0!sounds/agent.wav!silence_stream://3000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "agent");
fst_test_core_asr_resume();
fst_test_core_asr_resume();
fst_test_core_asr_resume();
fst_test_core_asr_pause();
fst_test_core_asr_resume();
fst_test_core_asr(
grammar,
"file_string://sounds/agent.wav!silence_stream://3000,0");
fst_check_string_equals(get_query_result_text(fst_pool, fst_asr_result), "agent");
fst_test_core_asr_resume();
// Tested double-close, but FS core will crash...
fst_test_core_asr_close();
}
FST_TEST_END()
FST_SESSION_BEGIN(play_and_detect_1)
{
const char *result_text = NULL;
char *grammar = switch_core_session_sprintf(fst_session, "{start-input-timers=false,no-input-timeout=5000,speech-timeout=10000,channel-uuid=%s}default", switch_core_session_get_uuid(fst_session));
fst_play_and_detect_speech_test_begin();
/* initial welcome and request */
fst_play_and_detect_speech_app_test("test",
grammar,
"sounds/ivr-please_state_your_name_and_reason_for_calling.wav",
"sounds/agent.wav");
result_text = get_query_result_text(fst_pool, fst_asr_result);
fst_requires(result_text != NULL);
fst_check_string_equals(result_text, "agent");
/* follow up request */
fst_play_and_detect_speech_app_test("test",
grammar,
"sounds/ivr-please_state_your_name_and_reason_for_calling.wav",
"file_string://1000,0!sounds/agent.wav");
result_text = get_query_result_text(fst_pool, fst_asr_result);
fst_requires(result_text != NULL);
fst_check_string_equals(result_text, "agent");
fst_play_and_detect_speech_test_end();
}
FST_SESSION_END()
FST_SESSION_BEGIN(play_and_detect_no_input_follow_up)
{
const char *result_text = NULL;
char *grammar = switch_core_session_sprintf(fst_session, "{start-input-timers=false,no-input-timeout=5000,speech-timeout=10000,channel-uuid=%s}", switch_core_session_get_uuid(fst_session));
switch_ivr_schedule_hangup(switch_epoch_time_now(NULL) + 60, switch_core_session_get_uuid(fst_session), SWITCH_CAUSE_NORMAL_CLEARING, SWITCH_FALSE);
fst_play_and_detect_speech_test_begin();
fst_play_and_detect_speech_app_test("test",
grammar,
"sounds/ivr-please_state_your_name_and_reason_for_calling.wav",
"file_string://silence_stream://4000,0!sounds/agent.wav");
result_text = get_query_result_text(fst_pool, fst_asr_result);
fst_requires(result_text != NULL);
fst_check_string_equals(result_text, "agent");
/* follow up request - no input */
fst_play_and_detect_speech_app_test("test",
grammar,
"sounds/ivr-please_state_your_name_and_reason_for_calling.wav",
"silence_stream://10000,0");
result_text = get_query_result_text(fst_pool, fst_asr_result);
fst_requires(result_text != NULL);
fst_check_string_equals(result_text, "no_input");
fst_play_and_detect_speech_test_end();
}
FST_SESSION_END()
FST_SESSION_BEGIN(play_and_detect_no_input)
{
const char *result_text = NULL;
switch_ivr_schedule_hangup(switch_epoch_time_now(NULL) + 60, switch_core_session_get_uuid(fst_session), SWITCH_CAUSE_NORMAL_CLEARING, SWITCH_FALSE);
fst_play_and_detect_speech_test_begin();
fst_play_and_detect_speech_app_test("test",
switch_core_session_sprintf(fst_session,
"{start-input-timers=false,no-input-timeout=5000,speech-timeout=10000,channel-uuid=%s}default",
switch_core_session_get_uuid(fst_session)),
"sounds/ivr-please_state_your_name_and_reason_for_calling.wav",
"silence_stream://10000,0");
result_text = get_query_result_text(fst_pool, fst_asr_result);
fst_requires(result_text != NULL);
fst_check_string_equals(result_text, "no_input");
fst_play_and_detect_speech_test_end();
}
FST_SESSION_END()
FST_SESSION_BEGIN(play_and_detect_start_input_timers)
{
const char *result_text = NULL;
switch_ivr_schedule_hangup(switch_epoch_time_now(NULL) + 60, switch_core_session_get_uuid(fst_session), SWITCH_CAUSE_NORMAL_CLEARING, SWITCH_FALSE);
fst_play_and_detect_speech_test_begin();
fst_play_and_detect_speech_app_test("test",
switch_core_session_sprintf(fst_session,
"{start-input-timers=true,no-input-timeout=5000,speech-timeout=10000,channel-uuid=%s}default",
switch_core_session_get_uuid(fst_session)),
"sounds/ivr-please_state_your_name_and_reason_for_calling.wav",
"silence_stream://10000,0");
result_text = get_query_result_text(fst_pool, fst_asr_result);
fst_requires(result_text != NULL);
fst_check_string_equals(result_text, "no_input");
fst_play_and_detect_speech_test_end();
fst_check_duration(5000, 500);
}
FST_SESSION_END()
FST_TEST_BEGIN(unload_test)
{
const char *err = NULL;
switch_sleep(1000000);
fst_check(switch_loadable_module_unload_module((char *)"../.libs", (char *)"mod_test", SWITCH_FALSE, &err) == SWITCH_STATUS_SUCCESS);
}
FST_TEST_END()
FST_MODULE_END()
FST_CORE_END()