mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-02-08 08:51:50 +00:00
FS-5573 --resolve
This commit is contained in:
parent
453cfaaf7f
commit
4e74ef3914
@ -184,6 +184,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_and_detect_speech(switch_core_se
|
|||||||
switch_input_args_t *args);
|
switch_input_args_t *args);
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Initialize background Speech detection on a session, so that parameters can be set, and grammars loaded.
|
||||||
|
After calling this function, it is possible to call switch_ivr_set_param_detect_speech() to set recognition parameters.
|
||||||
|
Calling switch_ivr_detect_speech_load_grammar() starts the speech recognition.
|
||||||
|
\param session the session to attach
|
||||||
|
\param mod_name the module name of the ASR library
|
||||||
|
\param dest the destination address
|
||||||
|
\param ah an ASR handle to use (NULL to create one)
|
||||||
|
\return SWITCH_STATUS_SUCCESS if all is well
|
||||||
|
*/
|
||||||
|
SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_init(switch_core_session_t *session, const char *mod_name,
|
||||||
|
const char *dest, switch_asr_handle_t *ah);
|
||||||
/*!
|
/*!
|
||||||
\brief Engage background Speech detection on a session
|
\brief Engage background Speech detection on a session
|
||||||
\param session the session to attach
|
\param session the session to attach
|
||||||
|
@ -445,6 +445,8 @@ SWITCH_STANDARD_APP(detect_speech_function)
|
|||||||
switch_ivr_detect_speech_disable_grammar(session, argv[1]);
|
switch_ivr_detect_speech_disable_grammar(session, argv[1]);
|
||||||
} else if (!strcasecmp(argv[0], "grammarsalloff")) {
|
} else if (!strcasecmp(argv[0], "grammarsalloff")) {
|
||||||
switch_ivr_detect_speech_disable_all_grammars(session);
|
switch_ivr_detect_speech_disable_all_grammars(session);
|
||||||
|
} else if (!strcasecmp(argv[0], "init")) {
|
||||||
|
switch_ivr_detect_speech_init(session, argv[1], argv[2], NULL);
|
||||||
} 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")) {
|
||||||
|
@ -4198,9 +4198,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_disable_all_grammars(sw
|
|||||||
return SWITCH_STATUS_FALSE;
|
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_init(switch_core_session_t *session, const char *mod_name,
|
||||||
const char *mod_name,
|
const char *dest, switch_asr_handle_t *ah)
|
||||||
const char *grammar, const char *name, const char *dest, switch_asr_handle_t *ah)
|
|
||||||
{
|
{
|
||||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||||
switch_status_t status;
|
switch_status_t status;
|
||||||
@ -4210,9 +4209,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *
|
|||||||
const char *p;
|
const char *p;
|
||||||
char key[512] = "";
|
char key[512] = "";
|
||||||
|
|
||||||
switch_core_session_get_read_impl(session, &read_impl);
|
if (sth) {
|
||||||
|
/* Already initialized */
|
||||||
switch_snprintf(key, sizeof(key), "%s/%s/%s/%s", mod_name, grammar, name, dest);
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ah) {
|
if (!ah) {
|
||||||
if (!(ah = switch_core_session_alloc(session, sizeof(*ah)))) {
|
if (!(ah = switch_core_session_alloc(session, sizeof(*ah)))) {
|
||||||
@ -4220,32 +4220,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sth) {
|
switch_core_session_get_read_impl(session, &read_impl);
|
||||||
if (switch_core_asr_load_grammar(sth->ah, grammar, name) != SWITCH_STATUS_SUCCESS) {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Error loading Grammar\n");
|
|
||||||
switch_ivr_stop_detect_speech(session);
|
|
||||||
return SWITCH_STATUS_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((p = switch_channel_get_variable(channel, "fire_asr_events")) && switch_true(p)) {
|
|
||||||
switch_set_flag(sth->ah, SWITCH_ASR_FLAG_FIRE_EVENTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((status = switch_core_asr_open(ah,
|
if ((status = switch_core_asr_open(ah,
|
||||||
mod_name,
|
mod_name,
|
||||||
"L16",
|
"L16",
|
||||||
read_impl.actual_samples_per_second, dest, &flags,
|
read_impl.actual_samples_per_second, dest, &flags,
|
||||||
switch_core_session_get_pool(session))) == SWITCH_STATUS_SUCCESS) {
|
switch_core_session_get_pool(session))) != SWITCH_STATUS_SUCCESS) {
|
||||||
|
|
||||||
if (switch_core_asr_load_grammar(ah, grammar, name) != SWITCH_STATUS_SUCCESS) {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Error loading Grammar\n");
|
|
||||||
switch_core_asr_close(ah, &flags);
|
|
||||||
return SWITCH_STATUS_FALSE;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4258,6 +4239,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *
|
|||||||
switch_set_flag(ah, SWITCH_ASR_FLAG_FIRE_EVENTS);
|
switch_set_flag(ah, SWITCH_ASR_FLAG_FIRE_EVENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch_snprintf(key, sizeof(key), "%s/%s/%s/%s", mod_name, NULL, NULL, dest);
|
||||||
|
|
||||||
if ((status = switch_core_media_bug_add(session, "detect_speech", key,
|
if ((status = switch_core_media_bug_add(session, "detect_speech", key,
|
||||||
speech_callback, sth, 0, SMBF_READ_STREAM | SMBF_NO_PAUSE, &sth->bug)) != SWITCH_STATUS_SUCCESS) {
|
speech_callback, sth, 0, SMBF_READ_STREAM | SMBF_NO_PAUSE, &sth->bug)) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_core_asr_close(ah, &flags);
|
switch_core_asr_close(ah, &flags);
|
||||||
@ -4274,6 +4257,40 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *
|
|||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||||
|
switch_status_t status;
|
||||||
|
struct speech_thread_handle *sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY);
|
||||||
|
const char *p;
|
||||||
|
|
||||||
|
if (!sth) {
|
||||||
|
/* No speech thread handle available yet, init speech detection first. */
|
||||||
|
if ((status = switch_ivr_detect_speech_init(session, mod_name, dest, ah)) != SWITCH_STATUS_SUCCESS) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fetch the new speech thread handle */
|
||||||
|
if (!(sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY))) {
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (switch_core_asr_load_grammar(sth->ah, grammar, name) != SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Error loading Grammar\n");
|
||||||
|
switch_ivr_stop_detect_speech(session);
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((p = switch_channel_get_variable(channel, "fire_asr_events")) && switch_true(p)) {
|
||||||
|
switch_set_flag(sth->ah, SWITCH_ASR_FLAG_FIRE_EVENTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
struct hangup_helper {
|
struct hangup_helper {
|
||||||
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
|
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
|
||||||
switch_bool_t bleg;
|
switch_bool_t bleg;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user