Provides the means to access and manage a speech recognition engine.
Inheritance Hierarchy
Namespace:
Microsoft.Speech.Recognition
Assembly:
Microsoft.Speech (in Microsoft.Speech.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Class SpeechRecognitionEngine _ Implements IDisposable |
Visual Basic (Usage) |
---|
Dim instance As SpeechRecognitionEngine |
C# |
---|
public class SpeechRecognitionEngine : IDisposable |
Remarks
You can create an instance of this class for any installed speech recognition engine. To get information about which speech recognition engines are installed, use the static InstalledRecognizers()()()() method. See SpeechRecognitionEngine(CultureInfo) for information about downloading additional speech recognition engines for specific languages.
Applications using SpeechRecognitionEngine can be constructed as clients of a particular recognition engine, as standalone speech recognition applications using an in-process recognition engine, and as servers that provide access to a recognition engine for clients.
Using the functionality provided by the SpeechRecognitionEngine class, you can do the following:
Construct an instance of SpeechRecognitionEngine and specify the speech recognition engine to use. See SpeechRecognitionEngine, InstalledRecognizers()()()(), and RecognizerInfo.
Configure the input to the speech recognition engine. See SetInputToWaveFile, SetInputToAudioStream, SetInputToNull, SetInputToWaveStream, and SetInputToDefaultAudioDevice.
Manage grammars used for speech recognition. See LoadGrammar, UnloadGrammar, UnloadAllGrammars, Grammars, and LoadGrammarCompleted.
Set parameters for speech recognition operations. See BabbleTimeout, InitialSilenceTimeout, EndSilenceTimeout, EndSilenceTimeoutAmbiguous, QueryRecognizerSetting, and MaxAlternates.
Monitor the input to the speech recognition engine. See AudioStateChanged, AudioSignalProblemOccurred, and AudioLevelUpdated.
Create handlers that provide access to the results of speech recognition operations. See SpeechDetected, SpeechHypothesized, SpeechRecognitionRejected, and SpeechRecognized.
Manage synchronous and asynchronous recognition operations. See Recognize, RecognizeAsync, RecognizeAsyncStop, RecognizeAsyncCancel, RecognizeCompleted, and RequestRecognizerUpdate()()()().
Test the effectiveness of speech recognition grammars using emulated recognition. See EmulateRecognize, EmulateRecognizeAsync, and EmulateRecognizeCompleted.
Note |
---|
Always call Dispose before you release your last reference to the SpeechRecognitionEngine object. Otherwise, the resources it is using will not be freed until the garbage collector calls the object's Finalize method. |
Examples
The following example shows part of a console application that demonstrates basic speech recognition. Because this example uses the Multiple mode of the RecognizeAsync(RecognizeMode) method, it performs recognition until you close the console window or stop debugging.
Copy Code | |
---|---|
using System; using Microsoft.Speech.Recognition; namespace SpeechRecognitionApp { class Program { static void Main(string[] args) { // Create a SpeechRecognitionEngine object for the default recognizer in the en-US locale. using ( SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine( new System.Globalization.CultureInfo("en-US"))) { // Create a grammar for finding services in different cities. Choices services = new Choices(new string[] { "restaurants", "hotels", "gas stations" }); Choices cities = new Choices(new string[] { "Seattle", "Boston", "Dallas" }); GrammarBuilder findServices = new GrammarBuilder("Find"); findServices.Append(services); findServices.Append("near"); findServices.Append(cities); // Create a Grammar object from the GrammarBuilder and load it to the recognizer. Grammar servicesGrammar = new Grammar(findServices); recognizer.LoadGrammarAsync(servicesGrammar); // Add a handler for the speech recognized event. recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized); // Configure the input to the speech recognizer. recognizer.SetInputToDefaultAudioDevice(); // Start asynchronous, continuous speech recognition. recognizer.RecognizeAsync(RecognizeMode.Multiple); // Keep the console window open. while (true) { Console.ReadLine(); } } } // Handle the SpeechRecognized event. static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { Console.WriteLine("Recognized text: " + e.Result.Text); } } } |