mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-13 12:40:17 +00:00
FS-7720 improve play_and_detect_speech to set current_application_response channel variable as follows:
"USAGE ERROR": bad application arguments "GRAMMAR ERROR": speech recognizer failed to load grammar "ASR INIT ERROR": speech recognizer failed to allocate a session "ERROR": any other errors This is useful for determining that play_and_detect_speech failed because the recognizer is out of licenses giving the developer a chance to fall back to traditional DTMF menu navigation.
This commit is contained in:
parent
e401b1469f
commit
06f7040e21
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
* Copyright (C) 2005-2015, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
* Version: MPL 1.1
|
||||
*
|
||||
@ -514,9 +514,17 @@ SWITCH_STANDARD_APP(play_and_detect_speech_function)
|
||||
char *engine = argv[0];
|
||||
char *grammar = argv[1];
|
||||
char *result = NULL;
|
||||
switch_ivr_play_and_detect_speech(session, file, engine, grammar, &result, 0, NULL);
|
||||
if (!zstr(result)) {
|
||||
switch_channel_set_variable(channel, "detect_speech_result", result);
|
||||
switch_status_t status = switch_ivr_play_and_detect_speech(session, file, engine, grammar, &result, 0, NULL);
|
||||
if (status == SWITCH_STATUS_SUCCESS) {
|
||||
if (!zstr(result)) {
|
||||
switch_channel_set_variable(channel, "detect_speech_result", result);
|
||||
}
|
||||
} else if (status == SWITCH_STATUS_GENERR) {
|
||||
response = "GRAMMAR ERROR";
|
||||
} else if (status == SWITCH_STATUS_NOT_INITALIZED) {
|
||||
response = "ASR INIT ERROR";
|
||||
} else {
|
||||
response = "ERROR";
|
||||
}
|
||||
} else {
|
||||
/* bad input */
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
* Copyright (C) 2005-2015, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
* Version: MPL 1.1
|
||||
*
|
||||
@ -4150,7 +4150,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_and_detect_speech(switch_core_se
|
||||
uint32_t input_timeout,
|
||||
switch_input_args_t *args)
|
||||
{
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
int recognizing = 0;
|
||||
switch_input_args_t myargs = { 0 };
|
||||
play_and_detect_speech_state_t state = { 0, "" };
|
||||
@ -4169,7 +4169,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_and_detect_speech(switch_core_se
|
||||
}
|
||||
|
||||
/* start speech detection */
|
||||
if (switch_ivr_detect_speech(session, mod_name, grammar, "", NULL, NULL) != SWITCH_STATUS_SUCCESS) {
|
||||
if ((status = switch_ivr_detect_speech(session, mod_name, grammar, "", NULL, NULL)) != SWITCH_STATUS_SUCCESS) {
|
||||
/* map SWITCH_STATUS_FALSE to SWITCH_STATUS_GENERR to indicate grammar load failed
|
||||
SWITCH_STATUS_NOT_INITALIZED will be passed back to indicate ASR resource problem */
|
||||
if (status == SWITCH_STATUS_FALSE) {
|
||||
status = SWITCH_STATUS_GENERR;
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
recognizing = 1;
|
||||
@ -4186,6 +4191,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_and_detect_speech(switch_core_se
|
||||
}
|
||||
|
||||
if (status != SWITCH_STATUS_BREAK && status != SWITCH_STATUS_SUCCESS) {
|
||||
status = SWITCH_STATUS_FALSE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
@ -4202,11 +4208,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_and_detect_speech(switch_core_se
|
||||
}
|
||||
|
||||
if (status != SWITCH_STATUS_BREAK && status != SWITCH_STATUS_SUCCESS) {
|
||||
status = SWITCH_STATUS_FALSE;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
done:
|
||||
if (recognizing && !(state.done & PLAY_AND_DETECT_DONE_RECOGNIZING)) {
|
||||
switch_ivr_pause_detect_speech(session);
|
||||
@ -4215,11 +4224,10 @@ done:
|
||||
switch_ivr_stop_detect_speech(session);
|
||||
}
|
||||
|
||||
*result = state.result;
|
||||
|
||||
if (!state.done) {
|
||||
status = SWITCH_STATUS_FALSE;
|
||||
if (state.done) {
|
||||
status = SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
*result = state.result;
|
||||
|
||||
arg_recursion_check_stop(args);
|
||||
|
||||
@ -4679,12 +4687,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *
|
||||
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;
|
||||
return SWITCH_STATUS_NOT_INITALIZED;
|
||||
}
|
||||
|
||||
/* Fetch the new speech thread handle */
|
||||
if (!(sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY))) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
return SWITCH_STATUS_NOT_INITALIZED;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user