Important: The information in this document is obsolete and should not be used for new development.
Opening Recognition Systems and Recognizers
Before calling any other Speech Recognition Manager routines, you need to call theSROpenRecognitionSystem
function to open a recognition system. Then you need to callSRNewRecognizer
to create a recognizer associated with that recognition system. Listing 1-3 shows how to use these functions to initialize speech recognition for your application.Listing 1-3 Initializing speech recognition
SRRecognitionSystem gRecSystem = NULL;/* our recognition system */ SRRecognizer gRecognizer = NULL;/* our recognizer */ OSErr MyInitSpeechRecognition (void) { OSErr myErr; /* Ensure that the Speech Recognition Mgr is available. */ if (!MyHasSpeechRecognitionMgr()) return(kSRNotAvailable); /* Open the default recognition system. */ myErr = SROpenRecognitionSystem(&gRecSystem, kSRDefaultRecognitionSystemID); /* Use standard feedback window and listening modes. */ if (!myErr) { short myModes = kSRHasFeedbackHasListenModes; myErr = SRSetProperty(gRecSystem, kSRFeedbackAndListeningModes, &myModes, sizeof(myModes)); } /* Create a new recognizer. */ if (!myErr) myErr = SRNewRecognizer(gRecSystem, &gRecognizer, kSRDefaultSpeechSource); /* Set reference constant of rejected word. */ if (!myErr) myErr = MySetRejectedWordRefCon(gRecSystem); return(myErr); }Note that theMyInitSpeechRecognition
function defined in Listing 1-3 explicitly sets the feedback and listening modes property of the recognition system to the valuekSRHasFeedbackHasListenModes
immediately after it calls theSROpenRecognitionSystem
function. This instructs the recognition system to use the standard feedback and listening behavior for any recognizers associated with it, which helps ensure that the user has a consistent experience when using any applications that use the Speech Recognition Manager. In general, you should use other feedback and listening modes values only if your application provides its own feedback mechanism.The
MyInitSpeechRecognition
function defined in Listing 1-3 also creates a recognizer by calling theSRNewRecognizer
function.SRNewRecognizer
takes a reference to an existing recognition system and a speech source ID, which specifies a speech source.SRNewRecognizer
returns a reference to the new recognizer through its second parameter (here,gRecognizer
).MyInitSpeechRecognition
also callsMySetRejectedWordRefCon
(shown in Listing 1-8 on page 1-24) to simplify the processing of recognition results.You can terminate your connection to the Speech Recognition Manager by calling
SRReleaseObject
to dispose of your recognizer and thenSRCloseRecognitionSystem
to close your recognition system, as illustrated in Listing 1-4.Listing 1-4 Ending speech recognition
OSErr MyTerminateSpeechRecognition (void) { OSErr myErr; /* Stop processing any incoming sound. */ myErr = SRStopListening(gRecognizer); /* Balance call to SRNewRecognizer in MyInitSpeechRecognition. */ myErr = SRReleaseObject(gRecognizer); /* Balance call to SROpenRecognitionSystem in MyInitSpeechRecognition. */ myErr = SRCloseRecognitionSystem(gRecSystem); return(myErr); }