SimpleSR is a C++ module which greatly simplifies Apple's Speech Recognition toolkit. With this module, you don't have to worry about Recognition Systems, or Recognizers, or deallocating all these things when you're done. You just create a LanguageModel (or several such), and receive the spoken commands through three special methods.

Creating a Language Model

  1. Using AddText

    You can create an empty LanguageModel by constructing it with a single parameter (its reference constant):

    		myLMptr = new LanguageModel(1);

    Then, you give it a set of strings to recognize by using the AddText method; each string gets an associated reference constant as well.

    		myLMptr->AddText("\pMeaning of Life", 42);
    		myLMptr->AddText("\pQuit", 'quit');

  2. Loading from a Resource

    For more complicated language models, create and test the model using the SRLanguageModeler application (it comes in the "SR Goodies" folder in the Speech Recoginition Development Kit). Save the model into a resource file. Then constuct the model with a resource type and number (if no parameters are given, the model will be built from lmdl number 128):

    		myLMptr = new LanguageModel('lmdl', 129);

    If you wish, you can add additional phrases to this model at runtime by using the AddText method as above.

    Note that there currently is a bug somewhere in this procedure which causes reference numbers to get lost. I suspect it's in SRLanguageModeler, but I'm not sure yet.

  3. Using SR Routines

    A LanguageModel (C++ object) can be passed to any Speech Recognition Manager routine which requires a SRLanguageModel (SR object). So if you're really gung-ho, you can just create an empty LanguageModel (as in method 1) and build a complex model using the normal SR routines.

Responding to Speech Input

To use SimpleSR, your must define three functions. They could be null (do-nothing) functions, but they must still be defined. The functions are:
// function called when a new speech command has been heard:
void StartHearing();

// function called for each word or phrase in the command:
void HearPhrase( const long refcon, const Str255 text );

// function called after the last word or phrase has been passed:
void EndHearing();
Their use should be fairly obvious: when a speech command is heard, the current LanguageModel first calls StartHearing, then calls HearPhrase for each word or phrase, and finally calls EndHearing. HearPhrase receives the word or phrase as both a reference constant, and as a string.

Cleaning Up

All you have to do to clean up and shut down the Speech Recognition Manager is delete your LanguageModel:

		delete myLMptr;

When the last LanguageModel has been deleted, the Speech Recognition Manager will be cleaned up and shut down. As with any C++ object, if you create your LanguageModel as an included variable (rather than using a pointer with new), it will automatically be destroyed when the variable goes out of scope.

Questions? Comments?

That's all there is to it! I hope this helps you add speech support to your application, because it's a great technology and I'd love to see more use. The source is public domain, but if you do make use of it, I'd appreciate hearing about it.

If you have any questions or comments about the code or its use, please write to me at
Last updated: 11/10/96 . . . . . Joe Strout