Compartilhar via


Note

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

SpeechRecognitionEngine.EmulateRecognizeAsync Method (String)

Emulates input of a phrase to the speech recognizer, using text in place of audio for asynchronous speech recognition.

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

Syntax

'Declaration
Public Sub EmulateRecognizeAsync ( _
    inputText As String _
)
'Usage
Dim instance As SpeechRecognitionEngine
Dim inputText As String

instance.EmulateRecognizeAsync(inputText)
public void EmulateRecognizeAsync(
    string inputText
)

Parameters

  • inputText
    Type: System.String
    The input for the 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

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

ArgumentException

inputText is the empty string ("").

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.

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 emulate speech recognition.

private void EmulateTextBox_KeyPress(object sender, KeyPressEventArgs eventArgs) 
{
  if ((Keys)eventArgs.KeyChar == Keys.Enter) 
  {
  _recognitionEngine.EmulateRecognizeAsync(_emulateTextBox.Text);
  }
}


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

See Also

Reference

SpeechRecognitionEngine Class

SpeechRecognitionEngine Members

EmulateRecognizeAsync Overload

Microsoft.Speech.Recognition Namespace

SpeechRecognized

EmulateRecognize

EmulateRecognizeAsync

EmulateRecognizeCompleted