*/
SWITCH_DECLARE(void) switch_core_speech_numeric_param_tts(switch_speech_handle_t *sh, char *param, int val);
+/*!
+ \brief Set a float parameter on a TTS handle
+ \param sh the speech handle
+ \param param the parameter
+ \param val the value
+*/
+SWITCH_DECLARE(void) switch_core_speech_float_param_tts(switch_speech_handle_t *sh, char *param, double val);
+
/*!
\brief Read rendered audio from the TTS module
\param sh the speech handle to read
void (*speech_flush_tts)(switch_speech_handle_t *sh);
void (*speech_text_param_tts)(switch_speech_handle_t *sh, char *param, char *val);
void (*speech_numeric_param_tts)(switch_speech_handle_t *sh, char *param, int val);
+ void (*speech_float_param_tts)(switch_speech_handle_t *sh, char *param, double val);
const struct switch_speech_interface *next;
};
char *name;
/*! The Rate*/
uint32_t rate;
+ uint32_t speed;
+ char voice[80];
+ char engine[80];
/*! the handle's memory pool */
switch_memory_pool_t *memory_pool;
/*! private data for the format module to store handle specific info */
SWITCH_SPEECH_FLAG_PEEK = (1 << 3) - Read data but do not erase it.
SWITCH_SPEECH_FLAG_FREE_POOL = (1 << 4) - Free interface's pool on destruction.
SWITCH_SPEECH_FLAG_BLOCKING = (1 << 5) - Indicate that a blocking call is desired
+SWITCH_SPEECH_FLAG_PAUSE = (1 << 6) - Pause toggle for playback
</pre>
*/
typedef enum {
SWITCH_SPEECH_FLAG_PEEK = (1 << 3),
SWITCH_SPEECH_FLAG_FREE_POOL = (1 << 4),
SWITCH_SPEECH_FLAG_BLOCKING = (1 << 5),
+ SWITCH_SPEECH_FLAG_PAUSE = (1 << 6)
} switch_speech_flag_t;
+++ /dev/null
-/*
- * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
- *
- * 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 <anthmct@yahoo.com>
- * Portions created by the Initial Developer are Copyright (C)
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Anthony Minessale II <anthmct@yahoo.com>
- *
- *
- * mod_rss.c -- RSS Browser
- *
- */
-#include <switch.h>
-
-static const char modname[] = "mod_rss";
-
-
-/* helper object */
-struct dtmf_buffer {
- char *data;
- char *front;
- uint32_t len;
- uint32_t size;
- switch_file_handle_t fh;
-};
-
-/*
- dtmf handler function you can hook up to be executed when a digit is dialed during playback
- if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
-*/
-static switch_status_t on_dtmf(switch_core_session_t *session, char *dtmf, void *buf, unsigned int buflen)
-{
-
- struct dtmf_buffer *dtb;
- uint32_t len, slen;
- uint32_t samps = 0, pos = 0;
- dtb = (struct dtmf_buffer *) buf;
-
- if (*dtmf == '#') {
- return SWITCH_STATUS_FALSE;
- }
-
- len = dtb->size - dtb->len;
- slen = (uint32_t)strlen(dtmf);
-
- if (slen > len) {
- slen = len;
- }
-
- switch_copy_string(dtb->front, dtmf, len);
- dtb->front += slen;
- dtb->len += slen;
-
- if (dtb->len == 2) {
- if (*dtb->data == '*') {
- dtb->front = dtb->data;
- dtb->len = 0;
- *dtb->data = '\0';
- switch(*(dtb->data+1)) {
- case '0':
- dtb->fh.speed = 0;
- break;
- case '2':
- dtb->fh.speed++;
- break;
- case '1':
- dtb->fh.speed--;
- break;
- case '5':
- {
- switch_codec_t *codec = switch_core_session_get_read_codec(session);
- samps = 5000 * (codec->implementation->samples_per_second / 1000);
- switch_core_file_seek(&dtb->fh, &pos, samps, SEEK_CUR);
- }
- break;
- case '4':
- {
- int32_t lpos = 0;
- switch_codec_t *codec = switch_core_session_get_read_codec(session);
-
- samps = 5000 * (codec->implementation->samples_per_second / 1000);
- lpos = (int) dtb->fh.pos - samps;
- if (lpos < 0) {
- lpos = 0;
- }
- switch_core_file_seek(&dtb->fh, &pos, lpos, SEEK_SET);
- }
- break;
- case '*':
- if (switch_test_flag(&dtb->fh, SWITCH_FILE_PAUSE)) {
- switch_clear_flag(&dtb->fh, SWITCH_FILE_PAUSE);
- } else {
- switch_set_flag(&dtb->fh, SWITCH_FILE_PAUSE);
- }
- break;
- }
-
- return SWITCH_STATUS_SUCCESS;
- }
- return SWITCH_STATUS_BREAK;
- }
-
- return SWITCH_STATUS_SUCCESS;
-}
-
-
-static void rss_function(switch_core_session_t *session, char *data)
-{
- switch_channel_t *channel;
- uint8_t index = 0;
- char fname[512];
- switch_status_t status;
- char buf[10];
- struct dtmf_buffer dtb;
-
-
- dtb.data = buf;
- dtb.front = buf;
- dtb.len = 0;
- dtb.size = sizeof(buf);
-
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
-
- if (switch_strlen_zero(data)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No Path Specified!\n");
- return;
- }
-
- switch_channel_answer(channel);
-
- while(switch_channel_ready(channel)) {
- snprintf(fname, sizeof(fname), "%s/%.2u.raw", data, index);
- memset(&dtb.fh, 0, sizeof(dtb.fh));
- if ((status = switch_ivr_play_file(session, &dtb.fh, fname, NULL, on_dtmf, &dtb, sizeof(dtb))) == SWITCH_STATUS_FALSE) {
- break;
- }
-
- index = (uint8_t)atoi(buf);
-
- /* reset for next loop */
- *buf = '\0';
- dtb.front = buf;
- dtb.len = 0;
- }
-
-
-
-}
-
-static const switch_application_interface_t rss_application_interface = {
- /*.interface_name */ "rss",
- /*.application_function */ rss_function,
- NULL, NULL, NULL,
- /*.next*/ NULL
-};
-
-
-static switch_loadable_module_interface_t rss_module_interface = {
- /*.module_name */ modname,
- /*.endpoint_interface */ NULL,
- /*.timer_interface */ NULL,
- /*.dialplan_interface */ NULL,
- /*.codec_interface */ NULL,
- /*.application_interface */ &rss_application_interface,
- /*.api_interface */ NULL,
- /*.file_interface */ NULL,
- /*.speech_interface */ NULL,
- /*.directory_interface */ NULL
-};
-
-
-SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
-{
- /* connect my internal structure to the blank pointer passed to me */
- *module_interface = &rss_module_interface;
-
- /* indicate that the module should continue to be loaded */
- return SWITCH_STATUS_SUCCESS;
-}
-
+++ /dev/null
-<?xml version="1.0" encoding="Windows-1252"?>\r
-<VisualStudioProject\r
- ProjectType="Visual C++"\r
- Version="8.00"\r
- Name="mod_rss"\r
- ProjectGUID="{B69247FA-ECD6-40ED-8E44-5CA6C3BAF9A4}"\r
- RootNamespace="mod_rss"\r
- Keyword="Win32Proj"\r
- >\r
- <Platforms>\r
- <Platform\r
- Name="Win32"\r
- />\r
- </Platforms>\r
- <ToolFiles>\r
- </ToolFiles>\r
- <Configurations>\r
- <Configuration\r
- Name="Debug|Win32"\r
- OutputDirectory="Debug"\r
- IntermediateDirectory="Debug"\r
- ConfigurationType="2"\r
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"\r
- CharacterSet="2"\r
- >\r
- <Tool\r
- Name="VCPreBuildEventTool"\r
- />\r
- <Tool\r
- Name="VCCustomBuildTool"\r
- />\r
- <Tool\r
- Name="VCXMLDataGeneratorTool"\r
- />\r
- <Tool\r
- Name="VCWebServiceProxyGeneratorTool"\r
- />\r
- <Tool\r
- Name="VCMIDLTool"\r
- />\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- Optimization="0"\r
- AdditionalIncludeDirectories=""$(InputDir)..\..\..\include";"$(InputDir)include";"$(InputDir)..\..\..\..\libs\include""\r
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_EXPORTS"\r
- MinimalRebuild="true"\r
- BasicRuntimeChecks="3"\r
- RuntimeLibrary="1"\r
- UsePrecompiledHeader="0"\r
- WarningLevel="4"\r
- WarnAsError="true"\r
- Detect64BitPortabilityProblems="true"\r
- DebugInformationFormat="4"\r
- />\r
- <Tool\r
- Name="VCManagedResourceCompilerTool"\r
- />\r
- <Tool\r
- Name="VCResourceCompilerTool"\r
- />\r
- <Tool\r
- Name="VCPreLinkEventTool"\r
- />\r
- <Tool\r
- Name="VCLinkerTool"\r
- OutputFile="..\..\..\..\w32\vsnet\$(OutDir)/mod/mod_rss.dll"\r
- LinkIncremental="2"\r
- AdditionalLibraryDirectories="..\..\..\..\w32\vsnet\$(OutDir)"\r
- GenerateDebugInformation="true"\r
- ProgramDatabaseFile="$(OutDir)/mod_rss.pdb"\r
- SubSystem="2"\r
- ImportLibrary="$(OutDir)/mod_rss.lib"\r
- TargetMachine="1"\r
- />\r
- <Tool\r
- Name="VCALinkTool"\r
- />\r
- <Tool\r
- Name="VCManifestTool"\r
- />\r
- <Tool\r
- Name="VCXDCMakeTool"\r
- />\r
- <Tool\r
- Name="VCBscMakeTool"\r
- />\r
- <Tool\r
- Name="VCFxCopTool"\r
- />\r
- <Tool\r
- Name="VCAppVerifierTool"\r
- />\r
- <Tool\r
- Name="VCWebDeploymentTool"\r
- />\r
- <Tool\r
- Name="VCPostBuildEventTool"\r
- />\r
- </Configuration>\r
- <Configuration\r
- Name="Release|Win32"\r
- OutputDirectory="Release"\r
- IntermediateDirectory="Release"\r
- ConfigurationType="2"\r
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"\r
- CharacterSet="2"\r
- >\r
- <Tool\r
- Name="VCPreBuildEventTool"\r
- />\r
- <Tool\r
- Name="VCCustomBuildTool"\r
- />\r
- <Tool\r
- Name="VCXMLDataGeneratorTool"\r
- />\r
- <Tool\r
- Name="VCWebServiceProxyGeneratorTool"\r
- />\r
- <Tool\r
- Name="VCMIDLTool"\r
- />\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- AdditionalIncludeDirectories=""$(InputDir)..\..\..\include";"$(InputDir)include";"$(InputDir)..\..\..\..\libs\include""\r
- PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MOD_EXPORTS"\r
- RuntimeLibrary="0"\r
- UsePrecompiledHeader="0"\r
- WarningLevel="4"\r
- WarnAsError="true"\r
- Detect64BitPortabilityProblems="true"\r
- DebugInformationFormat="3"\r
- />\r
- <Tool\r
- Name="VCManagedResourceCompilerTool"\r
- />\r
- <Tool\r
- Name="VCResourceCompilerTool"\r
- />\r
- <Tool\r
- Name="VCPreLinkEventTool"\r
- />\r
- <Tool\r
- Name="VCLinkerTool"\r
- OutputFile="..\..\..\..\w32\vsnet\$(OutDir)/mod/mod_rss.dll"\r
- LinkIncremental="1"\r
- AdditionalLibraryDirectories="..\..\..\..\w32\vsnet\$(OutDir)"\r
- GenerateDebugInformation="true"\r
- SubSystem="2"\r
- OptimizeReferences="2"\r
- EnableCOMDATFolding="2"\r
- ImportLibrary="$(OutDir)/mod_rss.lib"\r
- TargetMachine="1"\r
- />\r
- <Tool\r
- Name="VCALinkTool"\r
- />\r
- <Tool\r
- Name="VCManifestTool"\r
- />\r
- <Tool\r
- Name="VCXDCMakeTool"\r
- />\r
- <Tool\r
- Name="VCBscMakeTool"\r
- />\r
- <Tool\r
- Name="VCFxCopTool"\r
- />\r
- <Tool\r
- Name="VCAppVerifierTool"\r
- />\r
- <Tool\r
- Name="VCWebDeploymentTool"\r
- />\r
- <Tool\r
- Name="VCPostBuildEventTool"\r
- />\r
- </Configuration>\r
- </Configurations>\r
- <References>\r
- </References>\r
- <Files>\r
- <Filter\r
- Name="Source Files"\r
- Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
- UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
- >\r
- <File\r
- RelativePath=".\mod_rss.c"\r
- >\r
- </File>\r
- </Filter>\r
- <Filter\r
- Name="Header Files"\r
- Filter="h;hpp;hxx;hm;inl;inc;xsd"\r
- UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
- >\r
- </Filter>\r
- <Filter\r
- Name="Resource Files"\r
- Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"\r
- UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"\r
- >\r
- </Filter>\r
- </Files>\r
- <Globals>\r
- </Globals>\r
-</VisualStudioProject>\r
#include <swift.h>
#include <switch.h>
-#define MY_BUF_LEN 1024 * 512
+#define MY_BUF_LEN 1024 * 256
static const char modname[] = "mod_cepstral";
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to set voice.\n");
goto all_done;
}
+
+ voice_name = (char *) swift_voice_get_attribute(cepstral->voice, "name");
}
+ if (voice_name) {
+ switch_copy_string(sh->voice, voice_name, sizeof(sh->voice));
+ }
+
swift_port_set_callback(cepstral->port, &write_audio, SWIFT_EVENT_AUDIO, cepstral);
sh->private_info = cepstral;
cepstral->done = 1;
cepstral->done_gen = 1;
- printf("CLOSE!!!\n");
swift_port_stop(cepstral->port, SWIFT_ASYNC_ANY, SWIFT_EVENT_NOW);
/* Close the Swift Port and Engine */
if (NULL != cepstral->port) swift_port_close(cepstral->port);
return status;
}
+static void cepstral_text_param_tts(switch_speech_handle_t *sh, char *param, char *val)
+{
+ cepstral_t *cepstral;
+
+ cepstral = sh->private_info;
+ assert(cepstral != NULL);
+
+ if (!strcasecmp(param, "voice")) {
+ char *voice_name = val;
+ if (!strcasecmp(voice_name, "next")) {
+ if ((cepstral->voice = swift_port_find_next_voice(cepstral->port))) {
+ if ( SWIFT_FAILED(swift_port_set_voice(cepstral->port, cepstral->voice)) ) {
+ cepstral->done = cepstral->done_gen = 1;
+ return;
+ }
+ voice_name = (char *) swift_voice_get_attribute(cepstral->voice, "name");
+ } else {
+ voice_name = NULL;
+ }
+ } else {
+ if (voice_name && SWIFT_FAILED(swift_port_set_voice_by_name(cepstral->port, voice_name))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid voice %s!\n", voice_name);
+ voice_name = NULL;
+ }
+ }
+
+ if (!voice_name) {
+ /* Find the first voice on the system */
+ if ((cepstral->voice = swift_port_find_first_voice(cepstral->port, NULL, NULL)) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to find any voices!\n");
+ cepstral->done = cepstral->done_gen = 1;
+ return;
+ }
+
+ /* Set the voice found by find_first_voice() as the port's current voice */
+ if ( SWIFT_FAILED(swift_port_set_voice(cepstral->port, cepstral->voice)) ) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to set voice.\n");
+ cepstral->done = cepstral->done_gen = 1;
+ return;
+ }
+
+ voice_name = (char *) swift_voice_get_attribute(cepstral->voice, "name");
+ }
+
+ if (voice_name) {
+ switch_copy_string(sh->voice, voice_name, sizeof(sh->voice));
+ }
+
+ return;
+ }
+
+ swift_port_set_param_string(cepstral->port, param, val, NULL);
+}
+
+static void cepstral_numeric_param_tts(switch_speech_handle_t *sh, char *param, int val)
+{
+ cepstral_t *cepstral;
+
+ cepstral = sh->private_info;
+ assert(cepstral != NULL);
+
+ swift_port_set_param_int(cepstral->port, param, val, NULL);
+
+}
+
+
+static void cepstral_float_param_tts(switch_speech_handle_t *sh, char *param, double val)
+{
+ cepstral_t *cepstral;
+
+ cepstral = sh->private_info;
+ assert(cepstral != NULL);
+
+ swift_port_set_param_float(cepstral->port, param, val, NULL);
+
+}
+
static const switch_speech_interface_t cepstral_speech_interface = {
/*.interface_name*/ "cepstral",
/*.speech_open*/ cepstral_speech_open,
/*.speech_interpret_asr*/ NULL,
/*.speech_feed_tts*/ cepstral_speech_feed_tts,
/*.speech_read_tts*/ cepstral_speech_read_tts,
- /*.speech_flush_tts*/ cepstral_speech_flush_tts
+ /*.speech_flush_tts*/ cepstral_speech_flush_tts,
+ /*.speech_text_param_tts*/ cepstral_text_param_tts,
+ /*.speech_numeric_param_tts*/ cepstral_numeric_param_tts,
+ /*.speech_numeric_param_tts*/ cepstral_float_param_tts
};
static const switch_loadable_module_interface_t cepstral_module_interface = {
while (bytes > 0) {
unsigned int towrite;
-#if 0
- if (sangoma_socket_waitfor(tech_pvt->socket, -1, POLLOUT | POLLERR | POLLHUP) <= 0) {
+#if 1
+ if (sangoma_socket_waitfor(tech_pvt->socket, 1000, POLLOUT | POLLERR | POLLHUP) <= 0) {
return SWITCH_STATUS_GENERR;
}
#endif
return SWITCH_STATUS_GENERR;
}
+ switch_copy_string(sh->engine, module_name, sizeof(sh->engine));
sh->flags = *flags;
if (pool) {
sh->memory_pool = pool;
}
}
+SWITCH_DECLARE(void) switch_core_speech_float_param_tts(switch_speech_handle_t *sh, char *param, double val)
+{
+ assert(sh != NULL);
+
+ if (sh->speech_interface->speech_float_param_tts) {
+ sh->speech_interface->speech_float_param_tts(sh, param, val);
+ }
+}
+
SWITCH_DECLARE(switch_status_t) switch_core_speech_read_tts(switch_speech_handle_t *sh,
void *data,
switch_size_t *datalen,
while (data->running > 0) {
switch (switch_core_session_read_frame(session, &read_frame, -1, stream_id)) {
case SWITCH_STATUS_SUCCESS:
- break;
case SWITCH_STATUS_TIMEOUT:
+ case SWITCH_STATUS_BREAK:
break;
default:
data->running = -1;
continue;
}
-
- switch_yield(10000);
}
data->running = 0;
ilen = len;
while(switch_channel_ready(channel)) {
+
+ if (dtmf_callback || buf) {
+ /*
+ dtmf handler function you can hook up to be executed when a digit is dialed during playback
+ if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
+ */
+ if (switch_channel_has_dtmf(channel)) {
+ if (buf && !strcasecmp(buf, "_break_")) {
+ status = SWITCH_STATUS_BREAK;
+ } else {
+ switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
+ if (dtmf_callback) {
+ status = dtmf_callback(session, dtmf, buf, buflen);
+ } else {
+ switch_copy_string((char *)buf, dtmf, buflen);
+ status = SWITCH_STATUS_BREAK;
+ }
+ }
+ }
+
+ if (status != SWITCH_STATUS_SUCCESS) {
+ done = 1;
+ break;
+ }
+ }
+
+ if (switch_test_flag(sh, SWITCH_SPEECH_FLAG_PAUSE)) {
+ if (timer) {
+ if ((x = switch_core_timer_next(timer)) < 0) {
+ break;
+ }
+ } else {
+ switch_frame_t *read_frame;
+ switch_status_t status = switch_core_session_read_frame(session, &read_frame, -1, 0);
+
+ while (switch_channel_test_flag(channel, CF_HOLD)) {
+ switch_yield(10000);
+ }
+
+ if (!SWITCH_READ_ACCEPTABLE(status)) {
+ break;
+ }
+ }
+ continue;
+ }
+
flags = SWITCH_SPEECH_FLAG_BLOCKING;
status = switch_core_speech_read_tts(sh,
abuf,
}
}
- if (dtmf_callback || buf) {
- /*
- dtmf handler function you can hook up to be executed when a digit is dialed during playback
- if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
- */
- if (switch_channel_has_dtmf(channel)) {
- switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
- if (dtmf_callback) {
- status = dtmf_callback(session, dtmf, buf, buflen);
- } else {
- switch_copy_string((char *)buf, dtmf, buflen);
- status = SWITCH_STATUS_BREAK;
- }
- }
-
- if (status != SWITCH_STATUS_SUCCESS) {
- done = 1;
- break;
- }
- }
-
if (timer) {
if ((x = switch_core_timer_next(timer)) < 0) {
break;