SpeechRecognitionEngine..::..Recognize Method (TimeSpan) |
SpeechRecognitionEngine Class Example See Also Send Feedback |
Performs a synchronous speech recognition operation with a specified initial silence timeout period.
Namespace:
Microsoft.Speech.Recognition
Assembly:
Microsoft.Speech (in Microsoft.Speech.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Function Recognize ( _ initialSilenceTimeout As TimeSpan _ ) As RecognitionResult |
Visual Basic (Usage) |
---|
Dim instance As SpeechRecognitionEngine Dim initialSilenceTimeout As TimeSpan Dim returnValue As RecognitionResult returnValue = instance.Recognize(initialSilenceTimeout) |
C# |
---|
public RecognitionResult Recognize( TimeSpan initialSilenceTimeout ) |
Parameters
- initialSilenceTimeout
- Type: System..::..TimeSpan
The interval of time a speech recognizer accepts input containing only silence before finalizing recognition.
Return Value
Type: Microsoft.Speech.Recognition..::..RecognitionResultThe recognition result for the input, or nullNothingnullptrunita null reference (Nothing in Visual Basic) if the operation is not successful.
Remarks
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 nullNothingnullptrunita null reference (Nothing in Visual Basic) 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.
Examples
The following example shows part of a console application that demonstrates basic speech recognition. The example creates a speech recognition grammar for choosing cities for a flight. It then constructs a Grammar object from the grammar, loads it into the SpeechRecognitionEngine object. The Recognize(TimeSpan) method specifies a timeout interval of five seconds, after which it will terminate the single recognition operation.
Copy Code | |
---|---|
using System; using Microsoft.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 a grammar for choosing cities for a flight. Choices cities = new Choices(new string[] { "Los Angeles", "New York", "Chicago", "San Francisco", "Miami", "Dallas" }); GrammarBuilder gb = new GrammarBuilder(); gb.Append("I want to fly from"); gb.Append(cities); gb.Append("to"); gb.Append(cities); // Construct a Grammar object and load it to the recognizer. Grammar cityChooser = new Grammar(gb); cityChooser.Name = ("City Chooser"); recognizer.LoadGrammarAsync(cityChooser); // 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(); } } } |