From 6d7e019b5c0244f53c16361d2667049b430adb55 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 22 Aug 2010 00:26:21 -0500 Subject: [PATCH] switch_ivr interfaces to enable/disable grammar: switch_ivr_detect_speech_enable_grammar, switch_ivr_detect_speech_disable_grammar, and switch_ivr_detect_speech_disable_all_grammars --- src/include/switch_ivr.h | 24 +++++++++++++++++++ src/switch_ivr_async.c | 52 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index 40ba1dc16f..8641766760 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -26,6 +26,7 @@ * Anthony Minessale II * Neal Horman * Bret McDanel + * Luke Dashjr (OpenMethods, LLC) * * switch_ivr.h -- IVR Library * @@ -198,6 +199,29 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_load_grammar(switch_cor */ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_unload_grammar(switch_core_session_t *session, const char *name); +/*! + \brief Enable a grammar on a background speech detection handle + \param session The session to change the grammar on + \param name the grammar name + \return SWITCH_STATUS_SUCCESS if all is well +*/ +SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_enable_grammar(switch_core_session_t *session, const char *name); + +/*! + \brief Disable a grammar on a background speech detection handle + \param session The session to change the grammar on + \param name the grammar name + \return SWITCH_STATUS_SUCCESS if all is well +*/ +SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_disable_grammar(switch_core_session_t *session, const char *name); + +/*! + \brief Disable all grammars on a background speech detection handle + \param session The session to change the grammar on + \return SWITCH_STATUS_SUCCESS if all is well +*/ +SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_disable_all_grammars(switch_core_session_t *session); + SWITCH_DECLARE(switch_status_t) switch_ivr_set_param_detect_speech(switch_core_session_t *session, const char *name, const char *val); /*! diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 4fe5732f82..672750a4c3 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -26,6 +26,7 @@ * Anthony Minessale II * Michael Jerris * Bret McDanel + * Luke Dashjr (OpenMethods, LLC) * * switch_ivr_async.c -- IVR Library (async operations) * @@ -2745,6 +2746,57 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_unload_grammar(switch_c return SWITCH_STATUS_FALSE; } +SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_enable_grammar(switch_core_session_t *session, const char *name) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE; + struct speech_thread_handle *sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY); + switch_status_t status; + + if (sth) { + if ((status = switch_core_asr_enable_grammar(sth->ah, name)) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Error enabling Grammar\n"); + switch_core_asr_close(sth->ah, &flags); + } + return status; + } + return SWITCH_STATUS_FALSE; +} + +SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_disable_grammar(switch_core_session_t *session, const char *name) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE; + struct speech_thread_handle *sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY); + switch_status_t status; + + if (sth) { + if ((status = switch_core_asr_disable_grammar(sth->ah, name)) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Error disabling Grammar\n"); + switch_core_asr_close(sth->ah, &flags); + } + return status; + } + return SWITCH_STATUS_FALSE; +} + +SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_disable_all_grammars(switch_core_session_t *session) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE; + struct speech_thread_handle *sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY); + switch_status_t status; + + if (sth) { + if ((status = switch_core_asr_disable_all_grammars(sth->ah)) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Error disabling all Grammars\n"); + switch_core_asr_close(sth->ah, &flags); + } + return status; + } + return SWITCH_STATUS_FALSE; +} + SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *session, const char *mod_name, const char *grammar, const char *name, const char *dest, switch_asr_handle_t *ah)