提交 1623e5d2 authored 作者: Brian West's avatar Brian West

Merge branch 'openmethods-merged-dtmf-20110126' of git://scm.dashjr.org/var/scmroot/git/freeswitch

...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
* Contributor(s): * Contributor(s):
* *
* Anthony Minessale II <anthm@freeswitch.org> * Anthony Minessale II <anthm@freeswitch.org>
* Luke Dashjr <luke@openmethods.com> (OpenMethods, LLC)
* *
* *
* switch_core.h -- Core Library * switch_core.h -- Core Library
...@@ -1734,6 +1735,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_asr_close(switch_asr_handle_t *ah, s ...@@ -1734,6 +1735,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_asr_close(switch_asr_handle_t *ah, s
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags); SWITCH_DECLARE(switch_status_t) switch_core_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags);
/*!
\brief Feed DTMF to an asr handle
\param ah the handle to feed data to
\param dtmf a string of DTMF digits
\param flags flags to influence behaviour
\return SWITCH_STATUS_SUCCESS
*/
SWITCH_DECLARE(switch_status_t) switch_core_asr_feed_dtmf(switch_asr_handle_t *ah, const switch_dtmf_t *dtmf, switch_asr_flag_t *flags);
/*! /*!
\brief Check an asr handle for results \brief Check an asr handle for results
\param ah the handle to check \param ah the handle to check
...@@ -1768,6 +1778,29 @@ SWITCH_DECLARE(switch_status_t) switch_core_asr_load_grammar(switch_asr_handle_t ...@@ -1768,6 +1778,29 @@ SWITCH_DECLARE(switch_status_t) switch_core_asr_load_grammar(switch_asr_handle_t
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_asr_unload_grammar(switch_asr_handle_t *ah, const char *name); SWITCH_DECLARE(switch_status_t) switch_core_asr_unload_grammar(switch_asr_handle_t *ah, const char *name);
/*!
\brief Enable a grammar from an asr handle
\param ah the handle to enable the grammar from
\param name the name of the grammar to enable
\return SWITCH_STATUS_SUCCESS
*/
SWITCH_DECLARE(switch_status_t) switch_core_asr_enable_grammar(switch_asr_handle_t *ah, const char *name);
/*!
\brief Disable a grammar from an asr handle
\param ah the handle to disable the grammar from
\param name the name of the grammar to disable
\return SWITCH_STATUS_SUCCESS
*/
SWITCH_DECLARE(switch_status_t) switch_core_asr_disable_grammar(switch_asr_handle_t *ah, const char *name);
/*!
\brief Disable all grammars from an asr handle
\param ah the handle to disable the grammars from
\return SWITCH_STATUS_SUCCESS
*/
SWITCH_DECLARE(switch_status_t) switch_core_asr_disable_all_grammars(switch_asr_handle_t *ah);
/*! /*!
\brief Pause detection on an asr handle \brief Pause detection on an asr handle
\param ah the handle to pause \param ah the handle to pause
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
* Anthony Minessale II <anthm@freeswitch.org> * Anthony Minessale II <anthm@freeswitch.org>
* Neal Horman <neal at wanlink dot com> * Neal Horman <neal at wanlink dot com>
* Bret McDanel <trixter AT 0xdecafbad dot com> * Bret McDanel <trixter AT 0xdecafbad dot com>
* Luke Dashjr <luke@openmethods.com> (OpenMethods, LLC)
* *
* switch_ivr.h -- IVR Library * switch_ivr.h -- IVR Library
* *
...@@ -198,8 +199,38 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_load_grammar(switch_cor ...@@ -198,8 +199,38 @@ 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); 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); SWITCH_DECLARE(switch_status_t) switch_ivr_set_param_detect_speech(switch_core_session_t *session, const char *name, const char *val);
/*!
\brief Start input timers on a background speech detection handle
\param session The session to start the timers on
\return SWITCH_STATUS_SUCCESS if all is well
*/
SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_start_input_timers(switch_core_session_t *session);
/*! /*!
\brief Record a session to disk \brief Record a session to disk
\param session the session to record \param session the session to record
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
* Contributor(s): * Contributor(s):
* *
* Anthony Minessale II <anthm@freeswitch.org> * Anthony Minessale II <anthm@freeswitch.org>
* Luke Dashjr <luke@openmethods.com> (OpenMethods, LLC)
* *
* *
* switch_module_interfaces.h -- Module Interface Definitions * switch_module_interfaces.h -- Module Interface Definitions
...@@ -396,6 +397,14 @@ struct switch_asr_interface { ...@@ -396,6 +397,14 @@ struct switch_asr_interface {
switch_mutex_t *reflock; switch_mutex_t *reflock;
switch_loadable_module_interface_t *parent; switch_loadable_module_interface_t *parent;
struct switch_asr_interface *next; struct switch_asr_interface *next;
/*! function to enable a grammar to the asr interface */
switch_status_t (*asr_enable_grammar) (switch_asr_handle_t *ah, const char *name);
/*! function to disable a grammar to the asr interface */
switch_status_t (*asr_disable_grammar) (switch_asr_handle_t *ah, const char *name);
/*! function to disable all grammars to the asr interface */
switch_status_t (*asr_disable_all_grammars) (switch_asr_handle_t *ah);
/*! function to feed DTMF to the ASR */
switch_status_t (*asr_feed_dtmf) (switch_asr_handle_t *ah, const switch_dtmf_t *dtmf, switch_asr_flag_t *flags);
}; };
/*! an abstract representation of an asr speech interface. */ /*! an abstract representation of an asr speech interface. */
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
* Michael Murdock <mike at mmurdock dot org> * Michael Murdock <mike at mmurdock dot org>
* Neal Horman <neal at wanlink dot com> * Neal Horman <neal at wanlink dot com>
* Bret McDanel <trixter AT 0xdecafbad dot com> * Bret McDanel <trixter AT 0xdecafbad dot com>
* Luke Dashjr <luke@openmethods.com> (OpenMethods, LLC)
* *
* mod_dptools.c -- Raw Audio File Streaming Application Module * mod_dptools.c -- Raw Audio File Streaming Application Module
* *
...@@ -269,7 +270,7 @@ SWITCH_STANDARD_APP(bind_digit_action_function) ...@@ -269,7 +270,7 @@ SWITCH_STANDARD_APP(bind_digit_action_function)
} }
#define DETECT_SPEECH_SYNTAX "<mod_name> <gram_name> <gram_path> [<addr>] OR grammar <gram_name> [<path>] OR nogrammar <gram_name> OR pause OR resume OR stop OR param <name> <value>" #define DETECT_SPEECH_SYNTAX "<mod_name> <gram_name> <gram_path> [<addr>] OR grammar <gram_name> [<path>] OR nogrammar <gram_name> OR grammaron/grammaroff <gram_name> OR grammarsalloff OR pause OR resume OR start_input_timers OR stop OR param <name> <value>"
SWITCH_STANDARD_APP(detect_speech_function) SWITCH_STANDARD_APP(detect_speech_function)
{ {
char *argv[4]; char *argv[4];
...@@ -282,6 +283,12 @@ SWITCH_STANDARD_APP(detect_speech_function) ...@@ -282,6 +283,12 @@ SWITCH_STANDARD_APP(detect_speech_function)
switch_ivr_detect_speech_load_grammar(session, argv[1], argv[2]); switch_ivr_detect_speech_load_grammar(session, argv[1], argv[2]);
} else if (!strcasecmp(argv[0], "nogrammar")) { } else if (!strcasecmp(argv[0], "nogrammar")) {
switch_ivr_detect_speech_unload_grammar(session, argv[1]); switch_ivr_detect_speech_unload_grammar(session, argv[1]);
} else if (!strcasecmp(argv[0], "grammaron")) {
switch_ivr_detect_speech_enable_grammar(session, argv[1]);
} else if (!strcasecmp(argv[0], "grammaroff")) {
switch_ivr_detect_speech_disable_grammar(session, argv[1]);
} else if (!strcasecmp(argv[0], "grammarsalloff")) {
switch_ivr_detect_speech_disable_all_grammars(session);
} else if (!strcasecmp(argv[0], "pause")) { } else if (!strcasecmp(argv[0], "pause")) {
switch_ivr_pause_detect_speech(session); switch_ivr_pause_detect_speech(session);
} else if (!strcasecmp(argv[0], "resume")) { } else if (!strcasecmp(argv[0], "resume")) {
...@@ -290,6 +297,8 @@ SWITCH_STANDARD_APP(detect_speech_function) ...@@ -290,6 +297,8 @@ SWITCH_STANDARD_APP(detect_speech_function)
switch_ivr_stop_detect_speech(session); switch_ivr_stop_detect_speech(session);
} else if (!strcasecmp(argv[0], "param")) { } else if (!strcasecmp(argv[0], "param")) {
switch_ivr_set_param_detect_speech(session, argv[1], argv[2]); switch_ivr_set_param_detect_speech(session, argv[1], argv[2]);
} else if (!strcasecmp(argv[0], "start_input_timers")) {
switch_ivr_detect_speech_start_input_timers(session);
} else if (argc >= 3) { } else if (argc >= 3) {
switch_ivr_detect_speech(session, argv[0], argv[1], argv[2], argv[3], NULL); switch_ivr_detect_speech(session, argv[0], argv[1], argv[2], argv[3], NULL);
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
* Michael Jerris <mike@jerris.com> * Michael Jerris <mike@jerris.com>
* Paul D. Tinsley <pdt at jackhammer.org> * Paul D. Tinsley <pdt at jackhammer.org>
* Christopher M. Rienzo <chris@rienzo.net> * Christopher M. Rienzo <chris@rienzo.net>
* Luke Dashjr <luke@openmethods.com> (OpenMethods, LLC)
* *
* *
* switch_core_asr.c -- Main Core Library (Speech Detection Interface) * switch_core_asr.c -- Main Core Library (Speech Detection Interface)
...@@ -160,6 +161,45 @@ SWITCH_DECLARE(switch_status_t) switch_core_asr_unload_grammar(switch_asr_handle ...@@ -160,6 +161,45 @@ SWITCH_DECLARE(switch_status_t) switch_core_asr_unload_grammar(switch_asr_handle
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_core_asr_enable_grammar(switch_asr_handle_t *ah, const char *name)
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_assert(ah != NULL);
if (ah->asr_interface->asr_enable_grammar) {
status = ah->asr_interface->asr_enable_grammar(ah, name);
}
return status;
}
SWITCH_DECLARE(switch_status_t) switch_core_asr_disable_grammar(switch_asr_handle_t *ah, const char *name)
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_assert(ah != NULL);
if (ah->asr_interface->asr_disable_grammar) {
status = ah->asr_interface->asr_disable_grammar(ah, name);
}
return status;
}
SWITCH_DECLARE(switch_status_t) switch_core_asr_disable_all_grammars(switch_asr_handle_t *ah)
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_assert(ah != NULL);
if (ah->asr_interface->asr_disable_all_grammars) {
status = ah->asr_interface->asr_disable_all_grammars(ah);
}
return status;
}
SWITCH_DECLARE(switch_status_t) switch_core_asr_pause(switch_asr_handle_t *ah) SWITCH_DECLARE(switch_status_t) switch_core_asr_pause(switch_asr_handle_t *ah)
{ {
switch_assert(ah != NULL); switch_assert(ah != NULL);
...@@ -199,6 +239,19 @@ SWITCH_DECLARE(switch_status_t) switch_core_asr_feed(switch_asr_handle_t *ah, vo ...@@ -199,6 +239,19 @@ SWITCH_DECLARE(switch_status_t) switch_core_asr_feed(switch_asr_handle_t *ah, vo
return ah->asr_interface->asr_feed(ah, data, len, flags); return ah->asr_interface->asr_feed(ah, data, len, flags);
} }
SWITCH_DECLARE(switch_status_t) switch_core_asr_feed_dtmf(switch_asr_handle_t *ah, const switch_dtmf_t *dtmf, switch_asr_flag_t *flags)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_assert(ah != NULL);
if (ah->asr_interface->asr_feed_dtmf) {
status = ah->asr_interface->asr_feed_dtmf(ah, dtmf, flags);
}
return status;
}
SWITCH_DECLARE(switch_status_t) switch_core_asr_check_results(switch_asr_handle_t *ah, switch_asr_flag_t *flags) SWITCH_DECLARE(switch_status_t) switch_core_asr_check_results(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
{ {
switch_assert(ah != NULL); switch_assert(ah != NULL);
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
* Anthony Minessale II <anthm@freeswitch.org> * Anthony Minessale II <anthm@freeswitch.org>
* Michael Jerris <mike@jerris.com> * Michael Jerris <mike@jerris.com>
* Bret McDanel <bret AT 0xdecafbad dot com> * Bret McDanel <bret AT 0xdecafbad dot com>
* Luke Dashjr <luke@openmethods.com> (OpenMethods, LLC)
* *
* switch_ivr_async.c -- IVR Library (async operations) * switch_ivr_async.c -- IVR Library (async operations)
* *
...@@ -3208,6 +3209,20 @@ static switch_bool_t speech_callback(switch_media_bug_t *bug, void *user_data, s ...@@ -3208,6 +3209,20 @@ static switch_bool_t speech_callback(switch_media_bug_t *bug, void *user_data, s
return SWITCH_TRUE; return SWITCH_TRUE;
} }
static switch_status_t speech_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf, switch_dtmf_direction_t direction)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
struct speech_thread_handle *sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY);
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
if (switch_core_asr_feed_dtmf(sth->ah, dtmf, &flags) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error Feeding DTMF\n");
}
return status;
}
SWITCH_DECLARE(switch_status_t) switch_ivr_stop_detect_speech(switch_core_session_t *session) SWITCH_DECLARE(switch_status_t) switch_ivr_stop_detect_speech(switch_core_session_t *session)
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
...@@ -3277,6 +3292,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_set_param_detect_speech(switch_core_s ...@@ -3277,6 +3292,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_set_param_detect_speech(switch_core_s
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_start_input_timers(switch_core_session_t *session)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
struct speech_thread_handle *sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY);
if (sth) {
switch_core_asr_start_input_timers(sth->ah);
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_unload_grammar(switch_core_session_t *session, const char *name) SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_unload_grammar(switch_core_session_t *session, const char *name)
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
...@@ -3294,6 +3321,57 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_unload_grammar(switch_c ...@@ -3294,6 +3321,57 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_unload_grammar(switch_c
return SWITCH_STATUS_FALSE; 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, SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *session,
const char *mod_name, const char *mod_name,
const char *grammar, const char *name, const char *dest, switch_asr_handle_t *ah) const char *grammar, const char *name, const char *dest, switch_asr_handle_t *ah)
...@@ -3360,6 +3438,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t * ...@@ -3360,6 +3438,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *
return status; return status;
} }
if ((status = switch_core_event_hook_add_recv_dtmf(session, speech_on_dtmf)) != SWITCH_STATUS_SUCCESS) {
switch_ivr_stop_detect_speech(session);
return status;
}
switch_channel_set_private(channel, SWITCH_SPEECH_KEY, sth); switch_channel_set_private(channel, SWITCH_SPEECH_KEY, sth);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论