SpeechRecognitionEngine::Recognize Method (TimeSpan)
Performs a synchronous speech recognition operation with a specified initial silence timeout period.
Assembly: System.Speech (in System.Speech.dll)
Parameters
- initialSilenceTimeout
-
Type:
System::TimeSpan
The interval of time a speech recognizer accepts input containing only silence before finalizing recognition.
Return Value
Type: System.Speech.Recognition::RecognitionResult^The recognition result for the input, or null if the operation is not successful or the recognizer is not enabled.
If the speech recognition engine detects speech within the time interval specified by initialSilenceTimeout argument, Recognize(TimeSpan) performs a single recognition operation and then terminates. The initialSilenceTimeout parameter supersedes the recognizer's InitialSilenceTimeout property.
During a call to this method, the recognizer can raise the following events:
SpeechDetected. Raised when the recognizer detects input that it can identify as speech.
SpeechHypothesized. Raised when input creates an ambiguous match with one of the active grammars.
SpeechRecognitionRejected or SpeechRecognized. Raised when the recognizer finalizes a recognition operation.
The recognizer does not raise the RecognizeCompleted event when using this method.
The Recognize() method returns a RecognitionResult object, or null if the operation is not successful.
A synchronous recognition operation can fail for the following reasons:
Speech is not detected before the timeout intervals expire for the BabbleTimeout or for the initialSilenceTimeout parameter.
The recognition engine detects speech but finds no matches in any of its loaded and enabled Grammar objects.
To perform asynchronous recognition, use one of the RecognizeAsync methods.
The following example shows part of a console application that demonstrates basic speech recognition. The example creates a DictationGrammar, loads it into an in-process speech recognizer, and performs one recognition operation.
using System; using System.Speech.Recognition; namespace SynchronousRecognition { class Program { static void Main(string[] args) { // Create an in-process speech recognizer for the en-US locale. using (SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine( new System.Globalization.CultureInfo("en-US"))) { // Create and load a dictation grammar. recognizer.LoadGrammar(new DictationGrammar()); // Configure input to the speech recognizer. recognizer.SetInputToDefaultAudioDevice(); // Start synchronous speech recognition. RecognitionResult result = recognizer.Recognize(TimeSpan.FromSeconds(5)); if (result != null) { Console.WriteLine("Recognized text = {0}", result.Text); } else { Console.WriteLine("No recognition result available."); } } Console.WriteLine(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } } }
Available since 3.0