]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add support for configurable timeout and passing of args to play_and_detect_speech
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 5 Jan 2012 16:38:08 +0000 (10:38 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 5 Jan 2012 16:38:08 +0000 (10:38 -0600)
src/include/switch_ivr.h
src/mod/applications/mod_dptools/mod_dptools.c
src/switch_ivr_async.c

index 6f883a933ca537a70e084651853b25f783696fde..39ce354e9f4bea7e5ef5853fbdb5ccbfb5d37309 100644 (file)
@@ -162,13 +162,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
   \param mod_name the module name of the ASR library
   \param grammar the grammar text, URI, or local file name
   \param result of speech recognition, allocated from the session pool
+  \param input_timeout time to wait for input
+  \param args arguements to pass for callbacks etc
   \return SWITCH_STATUS_SUCCESS if all is well
 */
 SWITCH_DECLARE(switch_status_t) switch_ivr_play_and_detect_speech(switch_core_session_t *session, 
-                                                                                                               const char *file,
-                                                                                                               const char *mod_name,
-                                                                                                               const char *grammar,
-                                                                                                               char **result);
+                                                                                                                                 const char *file, 
+                                                                                                                                 const char *mod_name,
+                                                                                                                                 const char *grammar,
+                                                                                                                                 char **result,
+                                                                                                                                 uint32_t input_timeout,
+                                                                                                                                 switch_input_args_t *args);
+
 
 /*!
   \brief Engage background Speech detection on a session
index 592bfb40deb14ba54755b5cbbc795bb8e89b32a4..9d804bdfc44b90cdd219836107dfe130d8e38cb3 100755 (executable)
@@ -495,7 +495,7 @@ 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);
+               switch_ivr_play_and_detect_speech(session, file, engine, grammar, &result, 0, NULL);
                switch_channel_set_variable(channel, "detect_speech_result", result);
        } else {
                /* bad input */
index 1a4ee43ae68c71e834367b6bd306e1c7fe2677f3..8958d10813af8f20bc40841ca6153a2649ed04da 100644 (file)
@@ -3220,11 +3220,17 @@ static switch_status_t play_and_detect_input_callback(switch_core_session_t *ses
        return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_play_and_detect_speech(switch_core_session_t *session, const char *file, const char *mod_name, const char *grammar, char **result)
+SWITCH_DECLARE(switch_status_t) switch_ivr_play_and_detect_speech(switch_core_session_t *session, 
+                                                                                                                                 const char *file, 
+                                                                                                                                 const char *mod_name, 
+                                                                                                                                 const char *grammar, 
+                                                                                                                                 char **result, 
+                                                                                                                                 uint32_t input_timeout,
+                                                                                                                                 switch_input_args_t *args)
 {
-       switch_status_t status;
+       switch_status_t status = SWITCH_STATUS_SUCCESS;
        int recognizing = 0;
-       switch_input_args_t args = { 0 };
+       switch_input_args_t myargs = { 0 };
        play_and_detect_speech_state_t state = { 0, "" };
        switch_channel_t *channel = switch_core_session_get_channel(session);
 
@@ -3232,6 +3238,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_and_detect_speech(switch_core_se
                goto done;
        }
 
+       if (!input_timeout) input_timeout = 5000;
+
+       if (!args) {
+               args = &myargs;
+       }
+
        /* start speech detection */
        if (switch_ivr_detect_speech(session, mod_name, grammar, grammar, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
                goto done;
@@ -3239,10 +3251,16 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_and_detect_speech(switch_core_se
        recognizing = 1;
 
        /* play the prompt, looking for detection result */
-       args.input_callback = play_and_detect_input_callback;
-       args.buf = &state;
-       args.buflen = sizeof(state);
-       status = switch_ivr_play_file(session, NULL, file, &args);
+       args->input_callback = play_and_detect_input_callback;
+       args->buf = &state;
+       args->buflen = sizeof(state);
+       status = switch_ivr_play_file(session, NULL, file, args);
+
+       if (args->dmachine && (switch_ivr_dmachine_get_match(args->dmachine) || switch_ivr_dmachine_get_failed_digits(args->dmachine))) {
+               state.done = 1;
+               goto done;
+       }
+
        if (status != SWITCH_STATUS_BREAK && status != SWITCH_STATUS_SUCCESS) {
                goto done;
        }
@@ -3252,7 +3270,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_and_detect_speech(switch_core_se
                switch_ivr_detect_speech_start_input_timers(session);
                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "(%s) WAITING FOR RESULT\n", switch_channel_get_name(channel));
                while (!state.done && switch_channel_ready(channel)) {
-                       status = switch_ivr_sleep(session, 5000, SWITCH_FALSE, &args);
+                       status = switch_ivr_sleep(session, input_timeout, SWITCH_FALSE, args);
+                       
+                       if (args->dmachine && (switch_ivr_dmachine_get_match(args->dmachine) || switch_ivr_dmachine_get_failed_digits(args->dmachine))) {
+                               state.done = 1;
+                               goto done;
+                       }                       
+
                        if (status != SWITCH_STATUS_BREAK && status != SWITCH_STATUS_SUCCESS) {
                                goto done;
                        }
@@ -3268,9 +3292,10 @@ done:
        *result = state.result;
 
        if (!state.done) {
-               return SWITCH_STATUS_FALSE;
+               status = SWITCH_STATUS_FALSE;
        }
-       return SWITCH_STATUS_SUCCESS;
+
+       return status;;
 }
 
 struct speech_thread_handle {