EmulateRecognize Method (RecognizedWordUnit[], CompareOptions)

Microsoft Speech Platform SDK 11

Collapse imageExpand ImageCopy imageCopyHover image

Emulates input of specific words to the speech recognizer, using an array of RecognizedWordUnit objects in place of audio for synchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the words and the loaded speech recognition grammars.

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

Syntax

Visual Basic (Declaration)
Public Function EmulateRecognize ( _
	wordUnits As RecognizedWordUnit(), _
	compareOptions As CompareOptions _
) As RecognitionResult
Visual Basic (Usage)
Dim instance As SpeechRecognitionEngine
Dim wordUnits As RecognizedWordUnit()
Dim compareOptions As CompareOptions
Dim returnValue As RecognitionResult

returnValue = instance.EmulateRecognize(wordUnits, _
	compareOptions)
C#
public RecognitionResult EmulateRecognize(
	RecognizedWordUnit[] wordUnits,
	CompareOptions compareOptions
)

Parameters

wordUnits
Type: array<Microsoft.Speech.Recognition..::..RecognizedWordUnit>[]()[][]

An array of word units that contains the input for the recognition operation.

compareOptions
Type: System.Globalization..::..CompareOptions

A bitwise combination of the enumeration values that describe the type of comparison to use for the emulated recognition operation.

Return Value

Type: Microsoft.Speech.Recognition..::..RecognitionResult

The result for the recognition operation, or nullNothingnullptrunita null reference (Nothing in Visual Basic) if the operation is not successful.

Remarks

The speech recognizer raises the SpeechDetected, SpeechHypothesized, SpeechRecognitionRejected, and SpeechRecognized events as if the recognition operation is not emulated. The recognizer ignores new lines and extra white space and treats punctuation as literal input.

The only supported values of the compareOptions argument are the OrdinalIgnoreCase and IgnoreCase members of the CompareOptions enumerated type. All other members will generate a NotSupportedException exception or return a nullNothingnullptrunita null reference (Nothing in Visual Basic).

Examples

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.

 Copy imageCopy Code
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]);
    }
  }
}

See Also