diff --git a/.gitignore b/.gitignore index 3ad88ef734..7041de0494 100644 --- a/.gitignore +++ b/.gitignore @@ -266,6 +266,7 @@ src/mod/applications/mod_http_cache/test/test_aws.log src/mod/applications/mod_http_cache/test/test_aws.trs src/mod/formats/mod_sndfile/test/test_sndfile src/mod/formats/mod_sndfile/test/test_sndfile_conf +src/mod/formats/mod_ssml/test/test_tts_format src/mod/*/*/test/*.log src/mod/*/*/test/*.trs src/mod/*/*/test/[0-9]*/* diff --git a/src/mod/applications/mod_test/mod_test.c b/src/mod/applications/mod_test/mod_test.c index 02292a7a3b..55729548f7 100644 --- a/src/mod/applications/mod_test/mod_test.c +++ b/src/mod/applications/mod_test/mod_test.c @@ -1,6 +1,6 @@ /* * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2020, Anthony Minessale II + * Copyright (C) 2005-2021, Anthony Minessale II * * Version: MPL 1.1 * @@ -41,6 +41,7 @@ SWITCH_MODULE_DEFINITION(mod_test, mod_test_load, mod_test_shutdown, mod_test_ru typedef struct { char *text; int samples; + const char *channel_uuid; } test_tts_t; typedef enum { @@ -393,6 +394,10 @@ static switch_status_t test_speech_feed_tts(switch_speech_handle_t *sh, char *te { test_tts_t *context = (test_tts_t *)sh->private_info; + if (switch_true(switch_core_get_variable("mod_test_tts_must_have_channel_uuid")) && zstr(context->channel_uuid)) { + return SWITCH_STATUS_FALSE; + } + if (!zstr(text)) { char *p = strstr(text, "silence://"); @@ -431,6 +436,13 @@ static void test_speech_flush_tts(switch_speech_handle_t *sh) static void test_speech_text_param_tts(switch_speech_handle_t *sh, char *param, const char *val) { + test_tts_t *context = (test_tts_t *)sh->private_info; + if (!zstr(param) && !zstr(val)) { + if (!strcasecmp("channel-uuid", param)) { + context->channel_uuid = switch_core_strdup(sh->memory_pool, val); + switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->channel_uuid), SWITCH_LOG_DEBUG, "channel-uuid = %s\n", val); + } + } } static void test_speech_numeric_param_tts(switch_speech_handle_t *sh, char *param, int val) diff --git a/src/mod/formats/mod_ssml/Makefile.am b/src/mod/formats/mod_ssml/Makefile.am index ad91a27f29..9a54b5e710 100644 --- a/src/mod/formats/mod_ssml/Makefile.am +++ b/src/mod/formats/mod_ssml/Makefile.am @@ -5,12 +5,25 @@ IKS_DIR=$(switch_srcdir)/libs/iksemel IKS_BUILDDIR=$(switch_builddir)/libs/iksemel IKS_LA=$(IKS_BUILDDIR)/src/libiksemel.la +noinst_LTLIBRARIES = libssmlmod.la +libssmlmod_la_SOURCES = mod_ssml.c +libssmlmod_la_CFLAGS = $(AM_CFLAGS) -I$(IKS_DIR)/include + mod_LTLIBRARIES = mod_ssml.la mod_ssml_la_SOURCES = mod_ssml.c mod_ssml_la_CFLAGS = $(AM_CFLAGS) -I$(IKS_DIR)/include mod_ssml_la_LIBADD = $(switch_builddir)/libfreeswitch.la $(IKS_LA) mod_ssml_la_LDFLAGS = -avoid-version -module -no-undefined -shared +noinst_PROGRAMS = test/test_tts_format + +test_test_tts_format_SOURCES = test/test_tts_format.c +test_test_tts_format_CFLAGS = $(AM_CFLAGS) -I. -DSWITCH_TEST_BASE_DIR_FOR_CONF=\"${abs_builddir}/test\" -DSWITCH_TEST_BASE_DIR_OVERRIDE=\"${abs_builddir}/test\" +test_test_tts_format_LDFLAGS = $(AM_LDFLAGS) -avoid-version -no-undefined $(freeswitch_LDFLAGS) $(switch_builddir)/libfreeswitch.la $(CORE_LIBS) $(APR_LIBS) +test_test_tts_format_LDADD = libssmlmod.la $(IKS_LA) + +TESTS = $(noinst_PROGRAMS) + BUILT_SOURCES=$(IKS_LA) $(IKS_LA): $(IKS_DIR) $(IKS_DIR)/.update diff --git a/src/mod/formats/mod_ssml/mod_ssml.c b/src/mod/formats/mod_ssml/mod_ssml.c index 85f5ec0556..633b08dd07 100644 --- a/src/mod/formats/mod_ssml/mod_ssml.c +++ b/src/mod/formats/mod_ssml/mod_ssml.c @@ -941,6 +941,12 @@ static switch_status_t tts_file_open(switch_file_handle_t *handle, const char *p memset(context, 0, sizeof(*context)); context->flags = SWITCH_SPEECH_FLAG_NONE; if ((status = switch_core_speech_open(&context->sh, module, voice, handle->samplerate, handle->interval, handle->channels, &context->flags, NULL)) == SWITCH_STATUS_SUCCESS) { + if (handle->params) { + const char *channel_uuid = switch_event_get_header(handle->params, "channel-uuid"); + if (!zstr(channel_uuid)) { + switch_core_speech_text_param_tts(&context->sh, "channel-uuid", channel_uuid); + } + } if ((status = switch_core_speech_feed_tts(&context->sh, document, &context->flags)) == SWITCH_STATUS_SUCCESS) { handle->channels = 1; handle->samples = 0; diff --git a/src/mod/formats/mod_ssml/test/freeswitch.xml b/src/mod/formats/mod_ssml/test/freeswitch.xml new file mode 100644 index 0000000000..eb2f8bda7e --- /dev/null +++ b/src/mod/formats/mod_ssml/test/freeswitch.xml @@ -0,0 +1,36 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + +
+
diff --git a/src/mod/formats/mod_ssml/test/test_tts_format.c b/src/mod/formats/mod_ssml/test/test_tts_format.c new file mode 100644 index 0000000000..d3edaf6300 --- /dev/null +++ b/src/mod/formats/mod_ssml/test/test_tts_format.c @@ -0,0 +1,66 @@ +/* + * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2005-2021, Anthony Minessale II + * + * 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 + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Chris Rienzo + * + * + * test_tts_format.c -- tests for tts:// file format + * + */ +#include +#include + +FST_CORE_BEGIN(".") + +FST_MODULE_BEGIN(mod_ssml, test_tts_format) + +FST_SETUP_BEGIN() +{ + fst_requires_module("mod_test"); +} +FST_SETUP_END() + +FST_TEARDOWN_BEGIN() +{ + switch_core_set_variable("mod_test_tts_must_have_channel_uuid", "false"); +} +FST_TEARDOWN_END() + +FST_SESSION_BEGIN(tts_channel_uuid) +{ + char *tts_without_channel_uuid = "tts://test||This is a test"; + char *tts_with_channel_uuid = switch_core_session_sprintf(fst_session, "{channel-uuid=%s}tts://test||This is a test", switch_core_session_get_uuid(fst_session)); + switch_status_t status; + switch_core_set_variable("mod_test_tts_must_have_channel_uuid", "true"); + status = switch_ivr_play_file(fst_session, NULL, tts_without_channel_uuid, NULL); + fst_xcheck(status != SWITCH_STATUS_SUCCESS, "Expect channel UUID not to be delivered to TTS module"); + + status = switch_ivr_play_file(fst_session, NULL, tts_with_channel_uuid, NULL); + fst_xcheck(status == SWITCH_STATUS_SUCCESS, "Expect channel UUID to be delivered to TTS module"); +} +FST_SESSION_END() + +FST_MODULE_END() + +FST_CORE_END()