Prior to the recognition of each utterance the coder object must be prepared and the input source started. The utterance is then recognised by a single call to hapiRecRecognise in synchronous callback mode. This function call takes a pointer to the callback function applicationInterfaceFunction as a final argument. In this example, the callback function is responsible for retrieving and displaying both intermediate and final results. When the utterance recognition is complete we must tidy up by calling hapiCoderComplete.
In the tutorial application these steps are carried out by the RecogniseWithTrace function.
int RecogniseWithTrace(ApplicationHAPIInfo *ahi,
int (*finalFunc)(ApplicationHAPIInfo *ahi),
int traceInterval,void (*traceFunc)(char *string))
{
int fail=0;
/* Set up call back functions */
ahi->finalFunc=finalFunc;
ahi->traceFunc=traceFunc;
/* Get the input channel ready */
fail=fail || (hapiCoderPrepare(ahi->coder)<0);
fail=fail || (hapiSourceStart(ahi->source)<0);
/* Do the recognition - with trace and final callbacks */
/* Includes test for ahi->doneFinal so works in sync and async modes */
ahi->doneFinal=0;
fail=fail || (hapiRecRecognise(ahi->rec,ahi->net,ahi->coder,
ahi->final,traceInterval,ahi->inter,
applicationInterfaceFunction)<0);
/* We have waited for final callback so can do this here rather than */
/* in final callback function or when it signals application that */
/* results ready */
fail=fail || (hapiCoderComplete(ahi->coder)<0);
return(!fail);
}
Note that audio input begins once hapiSourceStart is
called but since hapiCoderPrepare takes very little time
recognition effectively begins when RecogniseWithTrace is
called.