提交 160edc55 authored 作者: Anthony Minessale's avatar Anthony Minessale

clean up speak code

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5670 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 352cc958
...@@ -317,13 +317,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session ...@@ -317,13 +317,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session
\param session the session to speak on \param session the session to speak on
\param tts_name the desired tts module \param tts_name the desired tts module
\param voice_name the desired voice \param voice_name the desired voice
\param rate the sample rate
\param text the text to speak \param text the text to speak
\param args arguements to pass for callbacks etc \param args arguements to pass for callbacks etc
\return SWITCH_STATUS_SUCCESS if all is well \return SWITCH_STATUS_SUCCESS if all is well
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *session,
char *tts_name, char *voice_name, uint32_t rate, char *text, switch_input_args_t *args); char *tts_name, char *voice_name, char *text, switch_input_args_t *args);
/*! /*!
\brief Make an outgoing call \brief Make an outgoing call
......
...@@ -3877,7 +3877,7 @@ static switch_status_t conference_local_play_file(conference_obj_t * conference, ...@@ -3877,7 +3877,7 @@ static switch_status_t conference_local_play_file(conference_obj_t * conference,
if (!(conference->tts_engine && conference->tts_voice)) { if (!(conference->tts_engine && conference->tts_voice)) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
} else { } else {
status = switch_ivr_speak_text(session, conference->tts_engine, conference->tts_voice, 0, path + 4, NULL); status = switch_ivr_speak_text(session, conference->tts_engine, conference->tts_voice, path + 4, NULL);
} }
goto done; goto done;
} }
......
...@@ -942,7 +942,7 @@ SWITCH_STANDARD_APP(speak_function) ...@@ -942,7 +942,7 @@ SWITCH_STANDARD_APP(speak_function)
args.input_callback = on_dtmf; args.input_callback = on_dtmf;
args.buf = buf; args.buf = buf;
args.buflen = sizeof(buf); args.buflen = sizeof(buf);
switch_ivr_speak_text(session, engine, voice, codec->implementation->samples_per_second, text, &args); switch_ivr_speak_text(session, engine, voice, text, &args);
} }
......
...@@ -207,7 +207,7 @@ static void tts_function(switch_core_session_t *session, char *data) ...@@ -207,7 +207,7 @@ static void tts_function(switch_core_session_t *session, char *data)
args.input_callback = show_dtmf; args.input_callback = show_dtmf;
args.buf = buf; args.buf = buf;
args.buflen = sizeof(buf); args.buflen = sizeof(buf);
switch_ivr_speak_text(session, tts_name, voice_name, codec->implementation->samples_per_second, text, &args); switch_ivr_speak_text(session, tts_name, voice_name, text, &args);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Done\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Done\n");
} }
...@@ -405,7 +405,7 @@ static void ivrtest_function(switch_core_session_t *session, char *data) ...@@ -405,7 +405,7 @@ static void ivrtest_function(switch_core_session_t *session, char *data)
} }
snprintf(say, sizeof(say), "You Dialed [%s]\n", buf); snprintf(say, sizeof(say), "You Dialed [%s]\n", buf);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, say); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, say);
switch_ivr_speak_text(session, "cepstral", "david", codec->implementation->samples_per_second, say, NULL); switch_ivr_speak_text(session, "cepstral", "david", say, NULL);
} }
} }
......
...@@ -123,7 +123,6 @@ void CoreSession::setDTMFCallback(void *cbfunc, char *funcargs) { ...@@ -123,7 +123,6 @@ void CoreSession::setDTMFCallback(void *cbfunc, char *funcargs) {
int CoreSession::speak(char *text) int CoreSession::speak(char *text)
{ {
switch_status_t status; switch_status_t status;
switch_codec_t *codec;
sanity_check(-1); sanity_check(-1);
...@@ -142,9 +141,9 @@ int CoreSession::speak(char *text) ...@@ -142,9 +141,9 @@ int CoreSession::speak(char *text)
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
codec = switch_core_session_get_read_codec(session);
begin_allow_threads(); begin_allow_threads();
status = switch_ivr_speak_text(session, tts_name, voice_name, codec->implementation->samples_per_second, text, ap); status = switch_ivr_speak_text(session, tts_name, voice_name, text, ap);
end_allow_threads(); end_allow_threads();
return status == SWITCH_STATUS_SUCCESS ? 1 : 0; return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
} }
......
...@@ -263,7 +263,7 @@ static switch_status_t play_or_say(switch_core_session_t *session, switch_ivr_me ...@@ -263,7 +263,7 @@ static switch_status_t play_or_say(switch_core_session_t *session, switch_ivr_me
} else { } else {
if (strlen(sound) > 4 && strncmp(sound, "say:", 4) == 0) { if (strlen(sound) > 4 && strncmp(sound, "say:", 4) == 0) {
if (menu->tts_engine && menu->tts_voice) { if (menu->tts_engine && menu->tts_voice) {
status = switch_ivr_speak_text(session, menu->tts_engine, menu->tts_voice, 0, sound + 4, &args); status = switch_ivr_speak_text(session, menu->tts_engine, menu->tts_voice, sound + 4, &args);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No TTS engine to play sound\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No TTS engine to play sound\n");
} }
...@@ -369,7 +369,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *s ...@@ -369,7 +369,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *s
status = switch_ivr_play_file(session, NULL, aptr, NULL); status = switch_ivr_play_file(session, NULL, aptr, NULL);
break; break;
case SWITCH_IVR_ACTION_SAYTEXT: case SWITCH_IVR_ACTION_SAYTEXT:
status = switch_ivr_speak_text(session, menu->tts_engine, menu->tts_voice, 0, aptr, NULL); status = switch_ivr_speak_text(session, menu->tts_engine, menu->tts_voice, aptr, NULL);
break; break;
case SWITCH_IVR_ACTION_SAYPHRASE: case SWITCH_IVR_ACTION_SAYPHRASE:
status = switch_ivr_phrase_macro(session, aptr, "", menu->phrase_lang, NULL); status = switch_ivr_phrase_macro(session, aptr, "", menu->phrase_lang, NULL);
......
...@@ -250,11 +250,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s ...@@ -250,11 +250,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid SAY Interface [%s]!\n", chan_lang); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid SAY Interface [%s]!\n", chan_lang);
} }
} else if (!strcasecmp(func, "speak-text")) { } else if (!strcasecmp(func, "speak-text")) {
switch_codec_t *read_codec; status = switch_ivr_speak_text(session, tts_engine, tts_voice, odata, args);
if ((read_codec = switch_core_session_get_read_codec(session))) {
status = switch_ivr_speak_text(session, tts_engine, tts_voice, read_codec->implementation->samples_per_second, odata, args);
}
} }
} }
} }
...@@ -1340,9 +1336,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session ...@@ -1340,9 +1336,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session
SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *session,
char *tts_name, char *voice_name, uint32_t rate, char *text, switch_input_args_t *args) char *tts_name, char *voice_name, char *text, switch_input_args_t *args)
{ {
switch_channel_t *channel; switch_channel_t *channel;
uint32_t rate = 0;
int interval = 0; int interval = 0;
switch_frame_t write_frame = { 0 }; switch_frame_t write_frame = { 0 };
switch_timer_t timer; switch_timer_t timer;
...@@ -1365,9 +1362,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses ...@@ -1365,9 +1362,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses
switch_core_session_reset(session); switch_core_session_reset(session);
read_codec = switch_core_session_get_read_codec(session); read_codec = switch_core_session_get_read_codec(session);
if (rate == 0) { rate = read_codec->implementation->samples_per_second;
rate = read_codec->implementation->samples_per_second; interval = read_codec->implementation->microseconds_per_frame / 1000;
}
memset(&sh, 0, sizeof(sh)); memset(&sh, 0, sizeof(sh));
if (switch_core_speech_open(&sh, tts_name, voice_name, (uint32_t) rate, interval, if (switch_core_speech_open(&sh, tts_name, voice_name, (uint32_t) rate, interval,
...@@ -1380,7 +1376,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses ...@@ -1380,7 +1376,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses
switch_channel_answer(channel); switch_channel_answer(channel);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "OPEN TTS %s\n", tts_name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "OPEN TTS %s\n", tts_name);
interval = read_codec->implementation->microseconds_per_frame / 1000;
codec_name = "L16"; codec_name = "L16";
if (switch_core_codec_init(&codec, if (switch_core_codec_init(&codec,
......
...@@ -260,11 +260,11 @@ int fs_switch_ivr_session_transfer(switch_core_session_t *session, char *extensi ...@@ -260,11 +260,11 @@ int fs_switch_ivr_session_transfer(switch_core_session_t *session, char *extensi
return status == SWITCH_STATUS_SUCCESS ? 1 : 0; return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
} }
int fs_switch_ivr_speak_text(switch_core_session_t *session, char *tts_name, char *voice_name, uint32_t rate, char *text) int fs_switch_ivr_speak_text(switch_core_session_t *session, char *tts_name, char *voice_name, char *text)
{ {
switch_status_t status; switch_status_t status;
status = switch_ivr_speak_text(session, tts_name, voice_name, rate, text, NULL); status = switch_ivr_speak_text(session, tts_name, voice_name, text, NULL);
return status == SWITCH_STATUS_SUCCESS ? 1 : 0; return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论