This topic has not yet been rated - Rate this topic

SpeechRecognitionEngine.UnloadGrammar Method

Office 2007 R2

Unloads a grammar, as specified by an instance of Grammar, from an instance of SpeechRecognitionEngine.

Namespace: Microsoft.Speech.Recognition
Assembly: Microsoft.Speech (in microsoft.speech.dll)

Parameters

grammar

An instance of Grammar specify the grammar to remove from an instance of SpeechRecognitionEngine.

If the Grammar specified by the grammar parameter is not currently loaded, TargetInvocationException will be generated.


The example below shows the atomic, synchronous loading and the unloading of instances of Grammar on a running SpeechRecognitionEngine by an anonymous method that handling RecognizerUpdateReached events, based on the user token custom object (GrammarRequest) supplied to the method.

recognizer.RecognizerUpdateReached +=
       delegate(object s, RecognizerUpdateReachedEventArgs args) {
           GrammarRequest request = args.UserToken as GrammarRequest; //cast and check if incoming type is a request
           if (request != null) { // We know this is a Grammar request now
               if (request.Grammar == null)
                   throw new ArgumentException("Invalid grammar used.");
           }
           switch (request.RequestType) {

               case GrammarRequestType.LoadGrammar:
                   RemoveDuplicateGrammar(request.Grammar);
                   _recognizer.LoadGrammar(request.Grammar);
                    break;
               case GrammarRequestType.UnloadGrammar:
                   _recognizer.UnloadGrammar(request.Grammar);
                   UpdateGrammarTree(_grammarTreeView, _recognizer);
                   //DisplayGrammarUnload(request.Grammar);
                   break;
           }

       };

}
All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition

Target Platforms

Did you find this helpful?
(1500 characters remaining)