]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
app_speech_utils.c: Allow partial speech results.
authorcmaj <chris@penguinpbx.com>
Fri, 2 Feb 2024 17:27:31 +0000 (10:27 -0700)
committercmaj <chris@penguinpbx.com>
Tue, 6 Feb 2024 18:56:21 +0000 (18:56 +0000)
Adds 'p' option to SpeechBackground() application.
With this option, when the app timeout is reached,
whatever the backend speech engine collected will
be returned as if it were the final, full result.
(This works for engines that make partial results.)

Resolves: #572

UserNote: The SpeechBackground dialplan application now supports a 'p'
option that will return partial results from speech engines that
provide them when a timeout occurs.

apps/app_speech_utils.c

index fa4a75a1488159e2dc99b5199b10f7727a845f25..51975407bf04056d3d828def2a1bd9bc081dd149 100644 (file)
                                        <option name="n">
                                                <para>Don't answer the channel if it has not already been answered.</para>
                                        </option>
+                                       <option name="p">
+                                               <para>Return partial results when backend is terminated by timeout.</para>
+                                       </option>
                                </optionlist>
                        </parameter>
                </syntax>
@@ -700,10 +703,12 @@ static int speech_streamfile(struct ast_channel *chan, const char *filename, con
 
 enum {
        SB_OPT_NOANSWER = (1 << 0),
+       SB_OPT_PARTIALRESULTS = (1 << 1),
 };
 
 AST_APP_OPTIONS(speech_background_options, BEGIN_OPTIONS
        AST_APP_OPTION('n', SB_OPT_NOANSWER),
+       AST_APP_OPTION('p', SB_OPT_PARTIALRESULTS),
 END_OPTIONS );
 
 /*! \brief SpeechBackground(Sound File,Timeout) Dialplan Application */
@@ -933,7 +938,10 @@ static int speech_background(struct ast_channel *chan, const char *data)
                }
        }
 
-       if (!ast_strlen_zero(dtmf)) {
+       if (ast_strlen_zero(dtmf) && speech->state == AST_SPEECH_STATE_READY && ast_test_flag(&options, SB_OPT_PARTIALRESULTS)) {
+               /* Copy to speech structure the results, even partial ones, if desired and available */
+               speech->results = ast_speech_results_get(speech);
+       } else if (!ast_strlen_zero(dtmf)) {
                /* We sort of make a results entry */
                speech->results = ast_calloc(1, sizeof(*speech->results));
                if (speech->results != NULL) {