Partager via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

SpeechRecognitionEngine.EmulateRecognize Method (String, CompareOptions)

Emulates audio input to the recognition engine, using text in place of audio for synchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the phrase and the loaded speech recognition grammars

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

Syntax

'Declaration
Public Function EmulateRecognize ( _
    inputText As String, _
    compareOptions As CompareOptions _
) As RecognitionResult
'Usage
Dim instance As SpeechRecognitionEngine
Dim inputText As String
Dim compareOptions As CompareOptions
Dim returnValue As RecognitionResult

returnValue = instance.EmulateRecognize(inputText, _
    compareOptions)
public RecognitionResult EmulateRecognize(
    string inputText,
    CompareOptions compareOptions
)

Parameters

  • inputText
    Type: System.String
    The text to use as the input phrase.
  • 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 a null reference (Nothing in Visual Basic) if the operation is not successful.

Exceptions

Exception Condition
InvalidOperationException

The recognizer has no speech recognition grammars loaded.

ArgumentNullException

inputText is a null reference (Nothing in Visual Basic).

ArgumentException

inputText is the empty string ("").

NotSupportedException

compareOptions contains the IgnoreNonSpace, IgnoreSymbols, or StringSort flag. See CompareOptions.

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 a null reference (Nothing in Visual Basic).

Examples

In the following example, an application obtains text input through a Textbox, and uses it to emulate speech recognition. The recognition emulation is performed ignoring case and performing an ordinal comparison.

private void EmulateTextBox_KeyPress(object sender, KeyPressEventArgs eventArgs) 
{
  if ((Keys)eventArgs.KeyChar == Keys.Enter) 
  {
    _recognitionEngine.EmulateRecognize(_emulateTextBox.Text, System.Globalization.CompareOptions.OrdinalIgnoreCase);
  }
}

// Emulate a button click in the emulateTextBox.
private void _emulateButton_Click(object sender, EventArgs e) 
{
  RecognitionResult result = _recognitionEngine.EmulateRecognize(_emulateTextBox.Text);
}

See Also

Reference

SpeechRecognitionEngine Class

SpeechRecognitionEngine Members

EmulateRecognize Overload

Microsoft.Speech.Recognition Namespace