[mod_ssml] Add channel-uuid parameter to the tts:// file format and forward it to the core speech handle as a parameter.

This commit is contained in:
Chris Rienzo 2021-03-01 18:47:54 +00:00 committed by Andrey Volk
parent 1adcebb309
commit 97d5854655
6 changed files with 135 additions and 1 deletions

1
.gitignore vendored
View File

@ -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/applications/mod_http_cache/test/test_aws.trs
src/mod/formats/mod_sndfile/test/test_sndfile src/mod/formats/mod_sndfile/test/test_sndfile
src/mod/formats/mod_sndfile/test/test_sndfile_conf 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/*.log
src/mod/*/*/test/*.trs src/mod/*/*/test/*.trs
src/mod/*/*/test/[0-9]*/* src/mod/*/*/test/[0-9]*/*

View File

@ -1,6 +1,6 @@
/* /*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2020, Anthony Minessale II <anthm@freeswitch.org> * Copyright (C) 2005-2021, Anthony Minessale II <anthm@freeswitch.org>
* *
* Version: MPL 1.1 * Version: MPL 1.1
* *
@ -41,6 +41,7 @@ SWITCH_MODULE_DEFINITION(mod_test, mod_test_load, mod_test_shutdown, mod_test_ru
typedef struct { typedef struct {
char *text; char *text;
int samples; int samples;
const char *channel_uuid;
} test_tts_t; } test_tts_t;
typedef enum { 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; 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)) { if (!zstr(text)) {
char *p = strstr(text, "silence://"); 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) 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) static void test_speech_numeric_param_tts(switch_speech_handle_t *sh, char *param, int val)

View File

@ -5,12 +5,25 @@ IKS_DIR=$(switch_srcdir)/libs/iksemel
IKS_BUILDDIR=$(switch_builddir)/libs/iksemel IKS_BUILDDIR=$(switch_builddir)/libs/iksemel
IKS_LA=$(IKS_BUILDDIR)/src/libiksemel.la 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_LTLIBRARIES = mod_ssml.la
mod_ssml_la_SOURCES = mod_ssml.c mod_ssml_la_SOURCES = mod_ssml.c
mod_ssml_la_CFLAGS = $(AM_CFLAGS) -I$(IKS_DIR)/include mod_ssml_la_CFLAGS = $(AM_CFLAGS) -I$(IKS_DIR)/include
mod_ssml_la_LIBADD = $(switch_builddir)/libfreeswitch.la $(IKS_LA) mod_ssml_la_LIBADD = $(switch_builddir)/libfreeswitch.la $(IKS_LA)
mod_ssml_la_LDFLAGS = -avoid-version -module -no-undefined -shared 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) BUILT_SOURCES=$(IKS_LA)
$(IKS_LA): $(IKS_DIR) $(IKS_DIR)/.update $(IKS_LA): $(IKS_DIR) $(IKS_DIR)/.update

View File

@ -941,6 +941,12 @@ static switch_status_t tts_file_open(switch_file_handle_t *handle, const char *p
memset(context, 0, sizeof(*context)); memset(context, 0, sizeof(*context));
context->flags = SWITCH_SPEECH_FLAG_NONE; 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 ((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) { if ((status = switch_core_speech_feed_tts(&context->sh, document, &context->flags)) == SWITCH_STATUS_SUCCESS) {
handle->channels = 1; handle->channels = 1;
handle->samples = 0; handle->samples = 0;

View File

@ -0,0 +1,36 @@
<document type="freeswitch/xml">
<section name="configuration" description="Various Configuration">
<configuration name="modules.conf" description="Modules">
<modules>
<load module="mod_console"/>
<load module="mod_loopback"/>
<load module="mod_tone_stream"/>
<load module="mod_dptools"/>
<load module="mod_sndfile"/>
<load module="mod_test"/>
</modules>
</configuration>
<configuration name="console.conf" description="Console Logger">
<mappings>
<map name="all" value="console,debug,info,notice,warning,err,crit,alert"/>
</mappings>
<settings>
<param name="colorize" value="true"/>
<param name="loglevel" value="debug"/>
<param name="uuid" value="true"/>
</settings>
</configuration>
</section>
<section name="dialplan" description="Regex/XML Dialplan">
<context name="default">
<extension name="sample">
<condition>
<action application="info"/>
</condition>
</extension>
</context>
</section>
</document>

View File

@ -0,0 +1,66 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2021, 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_tts_format.c -- tests for tts:// file format
*
*/
#include <switch.h>
#include <test/switch_test.h>
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()