SpeechRecognitionEngine Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides the means to access and manage an in-process speech recognition engine.
public ref class SpeechRecognitionEngine : IDisposable
public class SpeechRecognitionEngine : IDisposable
type SpeechRecognitionEngine = class
interface IDisposable
Public Class SpeechRecognitionEngine
Implements IDisposable
- Inheritance
-
SpeechRecognitionEngine
- Implements
The following example shows part of a console application that demonstrates basic speech recognition. Because this example uses the Multiple
mode of the RecognizeAsync method, it performs recognition until you close the console window or stop debugging.
using System;
using System.Speech.Recognition;
namespace SpeechRecognitionApp
{
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());
// Add a handler for the speech recognized event.
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
// Configure 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);
}
}
}
You can create an instance of this class for any of the installed speech recognizers. To get information about which recognizers are installed, use the static InstalledRecognizers method.
This class is for running speech recognition engines in-process, and provides control over various aspects of speech recognition, as follows:
To create an in-process speech recognizer, use one of the SpeechRecognitionEngine constructors.
To manage speech recognition grammars, use the LoadGrammar, LoadGrammarAsync, UnloadGrammar, and UnloadAllGrammars methods, and the Grammars property.
To configure the input to the recognizer, use the SetInputToAudioStream, SetInputToDefaultAudioDevice, SetInputToNull, SetInputToWaveFile, or SetInputToWaveStream method.
To perform speech recognition, use the Recognize or RecognizeAsync method.
To modify how recognition handles silence or unexpected input, use the BabbleTimeout, InitialSilenceTimeout, EndSilenceTimeout, and EndSilenceTimeoutAmbiguous properties.
To change the number of alternates the recognizer returns, use the MaxAlternates property. The recognizer returns recognition results in a RecognitionResult object.
To synchronize changes to the recognizer, use the RequestRecognizerUpdate method. The recognizer uses more than one thread to perform tasks.
To emulate input to the recognizer, use the EmulateRecognize and EmulateRecognizeAsync methods.
The SpeechRecognitionEngine object is for the sole use of the process that instantiated the object. By contrast, the SpeechRecognizer shares a single recognizer with any application that wants to use it.
Nota
Always call Dispose before you release your last reference to the speech recognizer. Otherwise, the resources it is using will not be freed until the garbage collector calls the recognizer object's Finalize
method.
Speech |
Initializes a new instance of the SpeechRecognitionEngine class using the default speech recognizer for the system. |
Speech |
Initializes a new instance of the SpeechRecognitionEngine class using the default speech recognizer for a specified locale. |
Speech |
Initializes a new instance of the SpeechRecognitionEngine using the information in a RecognizerInfo object to specify the recognizer to use. |
Speech |
Initializes a new instance of the SpeechRecognitionEngine class with a string parameter that specifies the name of the recognizer to use. |
Audio |
Gets the format of the audio being received by the SpeechRecognitionEngine. |
Audio |
Gets the level of the audio being received by the SpeechRecognitionEngine. |
Audio |
Gets the current location in the audio stream being generated by the device that is providing input to the SpeechRecognitionEngine. |
Audio |
Gets the state of the audio being received by the SpeechRecognitionEngine. |
Babble |
Gets or sets the time interval during which a SpeechRecognitionEngine accepts input containing only background noise, before finalizing recognition. |
End |
Gets or sets the interval of silence that the SpeechRecognitionEngine will accept at the end of unambiguous input before finalizing a recognition operation. |
End |
Gets or sets the interval of silence that the SpeechRecognitionEngine will accept at the end of ambiguous input before finalizing a recognition operation. |
Grammars |
Gets a collection of the Grammar objects that are loaded in this SpeechRecognitionEngine instance. |
Initial |
Gets or sets the time interval during which a SpeechRecognitionEngine accepts input containing only silence before finalizing recognition. |
Max |
Gets or sets the maximum number of alternate recognition results that the SpeechRecognitionEngine returns for each recognition operation. |
Recognizer |
Gets the current location of the SpeechRecognitionEngine in the audio input that it is processing. |
Recognizer |
Gets information about the current instance of SpeechRecognitionEngine. |
Dispose() |
Disposes the SpeechRecognitionEngine object. |
Dispose(Boolean) |
Disposes the SpeechRecognitionEngine object and releases resources used during the session. |
Emulate |
Emulates input of specific words to the speech recognizer, using text in place of audio for synchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the words and the loaded speech recognition grammars. |
Emulate |
Emulates input of a phrase to the speech recognizer, using text in place of audio for synchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the phrase and the loaded speech recognition grammars. |
Emulate |
Emulates input of a phrase to the speech recognizer, using text in place of audio for synchronous speech recognition. |
Emulate |
Emulates input of specific words to the speech recognizer, using an array of RecognizedWordUnit objects in place of audio for asynchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the words and the loaded speech recognition grammars. |
Emulate |
Emulates input of a phrase to the speech recognizer, using text in place of audio for asynchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the phrase and the loaded speech recognition grammars. |
Emulate |
Emulates input of a phrase to the speech recognizer, using text in place of audio for asynchronous speech recognition. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Installed |
Returns information for all of the installed speech recognizers on the current system. |
Load |
Synchronously loads a Grammar object. |
Load |
Asynchronously loads a speech recognition grammar. |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
Query |
Returns the values of settings for the recognizer. |
Recognize() |
Performs a synchronous speech recognition operation. |
Recognize(Time |
Performs a synchronous speech recognition operation with a specified initial silence timeout period. |
Recognize |
Performs a single, asynchronous speech recognition operation. |
Recognize |
Performs one or more asynchronous speech recognition operations. |
Recognize |
Terminates asynchronous recognition without waiting for the current recognition operation to complete. |
Recognize |
Stops asynchronous recognition after the current recognition operation completes. |
Request |
Requests that the recognizer pauses to update its state. |
Request |
Requests that the recognizer pauses to update its state and provides an offset and a user token for the associated event. |
Request |
Requests that the recognizer pauses to update its state and provides a user token for the associated event. |
Set |
Configures the SpeechRecognitionEngine object to receive input from an audio stream. |
Set |
Configures the SpeechRecognitionEngine object to receive input from the default audio device. |
Set |
Disables the input to the speech recognizer. |
Set |
Configures the SpeechRecognitionEngine object to receive input from a Waveform audio format (.wav) file. |
Set |
Configures the SpeechRecognitionEngine object to receive input from a stream that contains Waveform audio format (.wav) data. |
To |
Returns a string that represents the current object. (Inherited from Object) |
Unload |
Unloads all Grammar objects from the recognizer. |
Unload |
Unloads a specified Grammar object from the SpeechRecognitionEngine instance. |
Update |
Updates the specified setting for the SpeechRecognitionEngine with the specified integer value. |
Update |
Updates the specified speech recognition engine setting with the specified string value. |
Audio |
Raised when the SpeechRecognitionEngine reports the level of its audio input. |
Audio |
Raised when the SpeechRecognitionEngine detects a problem in the audio signal. |
Audio |
Raised when the state changes in the audio being received by the SpeechRecognitionEngine. |
Emulate |
Raised when the SpeechRecognitionEngine finalizes an asynchronous recognition operation of emulated input. |
Load |
Raised when the SpeechRecognitionEngine finishes the asynchronous loading of a Grammar object. |
Recognize |
Raised when the SpeechRecognitionEngine finalizes an asynchronous recognition operation. |
Recognizer |
Raised when a running SpeechRecognitionEngine pauses to accept modifications. |
Speech |
Raised when the SpeechRecognitionEngine detects input that it can identify as speech. |
Speech |
Raised when the SpeechRecognitionEngine has recognized a word or words that may be a component of multiple complete phrases in a grammar. |
Speech |
Raised when the SpeechRecognitionEngine receives input that does not match any of its loaded and enabled Grammar objects. |
Speech |
Raised when the SpeechRecognitionEngine receives input that matches any of its loaded and enabled Grammar objects. |
Produto | Versões |
---|---|
.NET | 8 (package-provided), 9 (package-provided) |
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
Comentários do .NET
O .NET é um projeto código aberto. Selecione um link para fornecer comentários: