Share via


SpeechRecognitionEngine.EmulateRecognize Method (RecognizedWordUnit[], CompareOptions)

Synchronously simulate audio input to the recognition engine with an array of RecognizedWordUnit objects and specified case sensitivity.

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

Syntax

'Declaration

Parameters

  • wordUnits
    Array of RecognizedWordUnit objects used as an input phrase in place of audio input during recognition emulation.
  • compareOptions
    A member of the CompareOptions enumeration determining whether the emulation is case sensitive or case insensitive.

Return Value

Returns an instance of RecognitionResult containing the results of speech recognition. The instance is null if recognition fails, or if the recognitionEngine is not enabled.

Remarks

EmulateRecognize(RecognizedWordUnit[],CompareOptions) is useful when attempting to examine the recognition properties of candidate phrases, for example those obtained through Alternates.

Successful emulated recognition will generate the standard events also associated with audio recognition events such as SpeechRecognized.

The only supported values of the compareOptions argument are OrdinalIgnoreCase and IgnoreCase.

All other members of will generate a NotSupportedException exception or return a null.

Emulated recognition ignores new lines and extra white space and treats punctuation literally, rather than letting it define phrases.

Example

In the example below, an array of RecognizedWordUnit objects is obtained from a recognized candidate and tested against the other grammars the recognition engine supports.

private void checkOtherGrammars(RecognizedPhrase candidate) {
    string msg = "";
    if (candidate != null && candidate.Grammar != null) {
//unload successful grammar and try again, see if other grammars 
Collection<Grammar> unloadList= new Collection<Grammar>(); //keep track of unloaded grammars and reload.
_recognitionEngine.UnloadGrammar(candidate.Grammar);
unloadList.Add(candidate.Grammar);
RecognizedWordUnit[] words = new RecognizedWordUnit[candidate.Words.Count];
candidate.Words.CopyTo(words, 0);
//Iterate over remaining grammars
msg = String.Format("Candidate \"{0}\"\nSelected by Grammar: \"{1}\"\n\n",
  candidate.Text, candidate.Grammar);
while (_recognitionEngine.Grammars.Count != 0) {
RecognitionResult emResult = _recognitionEngine.EmulateRecognize(words, System.Globalization.CompareOptions.OrdinalIgnoreCase);
if (emResult == null) {
    break;
} else {
    msg += String.Format("Emulation returns \"{0}\"\nSelected by Grammar: \"{1}\" \n",
    emResult.Text, emResult.Grammar.Name);
    _recognitionEngine.UnloadGrammar(emResult.Grammar);
    unloadList.Add(emResult.Grammar);
}

}
MessageBox.Show(msg);
// restore grammars
for (int i=0;i<unloadList.Count;i++){
_recognitionEngine.LoadGrammar(unloadList[i]);
}
    }
}

Thread Safety

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

Platforms

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

See Also

Reference

SpeechRecognitionEngine Class
SpeechRecognitionEngine Members
Microsoft.Speech.Recognition Namespace
SpeechRecognize
SpeechRecognitionEngine.EmulateRecognize Method
EmulateRecognizeAsync
RecognizedWordUnit Class
System.Globalization.CompareOptions