Writing a Speech Recognition App. in Carbon
Pages: 1, 2, 3, 4

Extracting recognition results

Now our discussion of language models will come full circle. Earlier we declared a list of items we wanted our recognizer to listen for. In a similar manner we need to provide a series of responses for each utterance that is recognized. Our list of pre-defined responses is defined in header file LangModel.h. Figure 5 shows the feedback window with our responses.

/* pre-defined phrases for recognizer to respond
with */
const char *kResponseList[] = {
  "I am monitored to respond to the name Robby",
   "Can I be of Service?",
  "Destroy the Jupiter 2",
  "Does Not Compute!" };
Figure 5. Feedback window with our responses.

Figure 5. Feedback window with our responses.

Perhaps some of the old science-fiction stars' quotes will become more recognizable now. When a user speaks the word "Hello," the recognizer will respond with the phrase, "I am monitored to respond to the name Robby."

Each word or phrase assigned in the language model has a one-to-one correspondence in this coding example. Our recognition result extracting function, which is called from our function MyHandleAESpeechDone (see listing for SpeechEvent.c) is given a reference number of the language model and a reference index of the utterance spoken. When an event is processed, our handler calls the routine ExtractResult. The two parameters passed to this routine are the reference constants: One identifies the language model and the other is the index of the word or phrase spoken from our kRecWordList. With the index of the word or phrase, we can play some games and provide responses to the user using our kResponseList. The function Extractresult achieves this by calling the Speech Recognition Manager routine SRSpeakAndDrawText.

Speech recognition and you

I have presented a very simple language model to get you going in your speech recognition endeavors. This simple code can be easily expanded to include complex phrases. A very comprehensive explanation is available from Apple develop, Issue 27, the Speech Recognition Manager Revealed, which will walk you through more complex speech models.

I used a snippet of code from this article, namely the function ProcessRecognitionResults, and simplified it for my example function ExtractResult. The SpeechRecLib source is also suited for Carbon coding and Mac OS X. It will run under Mac OS 9 using the Carbon SDK CarbonStub9 library.

The information I presented is a road map you may use to usher in a future you may have dreamed of. Perhaps you can apply this newly found knowledge to build that space robot you always wanted as a kid. I know I am. See you in the future!

Michael J. Norton is a software engineer at Cisco Systems.

Related Articles

OS X Brings Unix Stability to the Mac

Connecting PCs to Apple's Wireless Airport

Mac OS X Terms and Definitions

Discuss this article in the O'Reilly Network Forum.

Return to the O'Reilly Network Hub.