Partilhar via


Note

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

SpeechRecognitionEngine.EmulateRecognizeAsync Method (RecognizedWordUnit[], CompareOptions)

Emulates input of specific words to the speech recognizer, using text in place of audio for asynchronous 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

'Declaration
Public Sub EmulateRecognizeAsync ( _
    wordUnits As RecognizedWordUnit(), _
    compareOptions As CompareOptions _
)
'Usage
Dim instance As SpeechRecognitionEngine
Dim wordUnits As RecognizedWordUnit()
Dim compareOptions As CompareOptions

instance.EmulateRecognizeAsync(wordUnits, _
    compareOptions)
public void EmulateRecognizeAsync(
    RecognizedWordUnit[] wordUnits,
    CompareOptions compareOptions
)

Parameters

  • wordUnits
    Type: []
    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.

Exceptions

Exception Condition
InvalidOperationException

The recognizer has no speech recognition grammars loaded, or the recognizer has an asynchronous recognition operation that is not yet complete.

ArgumentNullException

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

ArgumentException

wordUnits contains one or more a null reference (Nothing in Visual Basic) elements.

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. When the recognizer completes the asynchronous recognition operation, it raises the EmulateRecognizeCompleted event.

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

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

Examples

In the following example, an application obtains text input through a Textbox, and uses it to asynchronously emulate speech recognition.

Information about the emulated recognition is returned to the user interface by the anonymous method used as the handler for EmulateRecognizeCompleted events.

private void _emulateButton_Click(object sender, EventArgs e) 
{
  _asyncEmulation = true;
  RecognitionResult result = 
    _recognitionEngine.EmulateRecognizeAsync(_emulateTextBox.Text);
}

_recognitionEngine.EmulateRecognizeCompleted += delegate(object sender, EmulateRecognizeCompletedEventArgs eventArgs) 
{
  _asyncEmulation = false;
  Utils.DisplayAudioInputFormat(_audioStateLabel, _recognitionEngine);
  DisplayResult(eventArgs);
};

See Also

Reference

SpeechRecognitionEngine Class

SpeechRecognitionEngine Members

EmulateRecognizeAsync Overload

Microsoft.Speech.Recognition Namespace

SpeechRecognized

EmulateRecognize

EmulateRecognizeAsync

RecognizedWordUnit

CompareOptions

EmulateRecognizeCompleted