SpeechRecognitionEngine..::..RecognizeAsyncCancel Method |
SpeechRecognitionEngine Class Example See Also Send Feedback |
Terminates asynchronous recognition without waiting for the current recognition operation to complete.
Namespace:
Microsoft.Speech.Recognition
Assembly:
Microsoft.Speech (in Microsoft.Speech.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Sub RecognizeAsyncCancel |
Visual Basic (Usage) |
---|
Dim instance As SpeechRecognitionEngine instance.RecognizeAsyncCancel() |
C# |
---|
public void RecognizeAsyncCancel() |
Remarks
This method immediately finalizes asynchronous recognition. If the current asynchronous recognition operation is receiving input, the input is truncated and the operation completes with the existing input. The recognizer raises the RecognizeCompleted or EmulateRecognizeCompleted event when an asynchronous operation is canceled, and sets the Cancelled property of the RecognizeCompletedEventArgs to true. This method cancels asynchronous operations initiated by the RecognizeAsync and EmulateRecognizeAsync methods.
To stop asynchronous recognition without truncating the input, use the RecognizeAsyncStop()()()() method.
Examples
The following example shows a graphical user interface which uses a button to start and stop a SpeechRecognitionEngine. When the user clicks the start/stop button while the SpeechRecognitionEngineis running, either RecognizeAsyncCancel or RecognizeAsyncStop is called depending on the state of the application.
Copy Code | |
---|---|
private void _startRecogButton_Click(object sender, EventArgs eventArgs) { if (_startRecogButton.Text == "Start Speech Recognition") { //Toggle Speech Recognition on _startRecogButton.Text = "Stop Speech Recognition"; if (_useMultiple) { _recognitionEngine.RecognizeAsync(RecognizeMode.Multiple); } else { _recognitionEngine.RecognizeAsync(RecognizeMode.Single); } } else { //Toggle Speech Recognition off _startRecogButton.Text = "Start Speech Recognition"; if (_friendlyStop) { _recognitionEngine.RecognizeAsyncStop(); //Stop after current phrase is finished. } else { _recognitionEngine.RecognizeAsyncCancel(); //Stop before current phrase is finished. } } } |