SpeechRecognitionEngine 类

定义

提供访问和管理进程内语音识别引擎。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
继承
SpeechRecognitionEngine
实现

示例

下面的示例演示了演示基本语音识别的控制台应用程序的一部分。The following example shows part of a console application that demonstrates basic speech recognition. 由于本示例使用Multiple RecognizeAsync方法的模式,它会执行识别,直到关闭控制台窗口或停止调试。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. 若要获取有关已安装的识别器的信息, InstalledRecognizers请使用静态方法。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:

SpeechRecognitionEngine对象用于唯一使用实例化对象的进程。The SpeechRecognitionEngine object is for the sole use of the process that instantiated the object. 与此SpeechRecognizer相反,与要使用它的任何应用程序共享单个识别器。By contrast, the SpeechRecognizer shares a single recognizer with any application that wants to use it.

备注

在释放Dispose对语音识别器的最后一个引用之前,始终调用。Always call Dispose before you release your last reference to the speech recognizer. 否则,在垃圾回收器调用识别器对象的Finalize方法之前,不会释放它所使用的资源。Otherwise, the resources it is using will not be freed until the garbage collector calls the recognizer object's Finalize method.

构造函数

SpeechRecognitionEngine()

使用系统的默认语音识别器来初始化 SpeechRecognitionEngine 类的新实例。Initializes a new instance of the SpeechRecognitionEngine class using the default speech recognizer for the system.

SpeechRecognitionEngine(CultureInfo)

使用指定的区域设置的默认语音识别器来初始化 SpeechRecognitionEngine 类的新实例。Initializes a new instance of the SpeechRecognitionEngine class using the default speech recognizer for a specified locale.

SpeechRecognitionEngine(RecognizerInfo)

SpeechRecognitionEngine 对象中的信息初始化 RecognizerInfo 来指定要使用的识别器。Initializes a new instance of the SpeechRecognitionEngine using the information in a RecognizerInfo object to specify the recognizer to use.

SpeechRecognitionEngine(String)

使用字符串参数初始化 SpeechRecognitionEngine 类的新实例,该参数指定要使用的识别器的名称。Initializes a new instance of the SpeechRecognitionEngine class with a string parameter that specifies the name of the recognizer to use.

属性

AudioFormat

获取 SpeechRecognitionEngine 接收的音频格式。Gets the format of the audio being received by the SpeechRecognitionEngine.

AudioLevel

获取 SpeechRecognitionEngine 接收的音频级别.Gets the level of the audio being received by the SpeechRecognitionEngine.

AudioPosition

获取音频流中的当前位置,此音频流由向 SpeechRecognitionEngine 提供输入的设备产生。Gets the current location in the audio stream being generated by the device that is providing input to the SpeechRecognitionEngine.

AudioState

获取 SpeechRecognitionEngine接收的状态音频.Gets the state of the audio being received by the SpeechRecognitionEngine.

BabbleTimeout

获取或设置时间间隔,在此时间间隔内,SpeechRecognitionEngine 将在终结识别之前接受仅包含背景噪音的输入。Gets or sets the time interval during which a SpeechRecognitionEngine accepts input containing only background noise, before finalizing recognition.

EndSilenceTimeout

获取或设置 SpeechRecognitionEngine 将在终结识别操作之前,于明确输入末尾接受的无声段间隔。Gets or sets the interval of silence that the SpeechRecognitionEngine will accept at the end of unambiguous input before finalizing a recognition operation.

EndSilenceTimeoutAmbiguous

获取或设置 SpeechRecognitionEngine 将在终结识别操作之前,于二义性输入末尾接受的无声段间隔。Gets or sets the interval of silence that the SpeechRecognitionEngine will accept at the end of ambiguous input before finalizing a recognition operation.

Grammars

获取在此 Grammar 实例中加载的 SpeechRecognitionEngine 对象的集合。Gets a collection of the Grammar objects that are loaded in this SpeechRecognitionEngine instance.

InitialSilenceTimeout

获取或设置时间间隔,在此时间间隔内,SpeechRecognitionEngine 将在终结识别之前接受仅包含无声段的输入。Gets or sets the time interval during which a SpeechRecognitionEngine accepts input containing only silence before finalizing recognition.

MaxAlternates

获取或设置 SpeechRecognitionEngine 为每个识别操作返回的备用识别结果的最大数量。Gets or sets the maximum number of alternate recognition results that the SpeechRecognitionEngine returns for each recognition operation.

RecognizerAudioPosition

获取在处理的音频输入中的 SpeechRecognitionEngine 当前位置。Gets the current location of the SpeechRecognitionEngine in the audio input that it is processing.

RecognizerInfo

获取有关 SpeechRecognitionEngine 的当前实例的信息。Gets information about the current instance of SpeechRecognitionEngine.

方法

Dispose()

处置此 SpeechRecognitionEngine 对象。Disposes the SpeechRecognitionEngine object.

Dispose(Boolean)

处置 SpeechRecognitionEngine 对象并释放会话期间使用的资源。Disposes the SpeechRecognitionEngine object and releases resources used during the session.

EmulateRecognize(RecognizedWordUnit[], CompareOptions)

使用文本代替同步语音识别的音频来模拟特定字输入到语音识别器,并指定识别器如何处理单词和加载的语音识别语法间的 Unicode 比较。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.

EmulateRecognize(String)

使用文本代替同步语音识别的音频来模拟输入短语到语音识别器。Emulates input of a phrase to the speech recognizer, using text in place of audio for synchronous speech recognition.

EmulateRecognize(String, CompareOptions)

使用文本代替异步语音识别的音频来模拟短语输入到语音识别器,并指定识别器如何处理短语和加载的语音识别语法间的 Unicode 比较。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.

EmulateRecognizeAsync(RecognizedWordUnit[], CompareOptions)

使用 RecognizedWordUnit 对象的数组代替异步语音识别的音频来模拟特定字输入到语音识别器,并指定识别器如何处理单词和加载的语音识别语法间的 Unicode 比较。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.

EmulateRecognizeAsync(String)

使用文本代替异步语音识别的音频来模拟输入到语音识别器。Emulates input of a phrase to the speech recognizer, using text in place of audio for asynchronous speech recognition.

EmulateRecognizeAsync(String, CompareOptions)

使用文本代替异步语音识别的音频来模拟短语输入到语音识别器,并指定识别器如何处理短语和加载的语音识别语法间的 Unicode 比较。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.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InstalledRecognizers()

返回有关当前系统中安装的所有语音识别器的信息。Returns information for all of the installed speech recognizers on the current system.

LoadGrammar(Grammar)

同步加载 Grammar 对象。Synchronously loads a Grammar object.

LoadGrammarAsync(Grammar)

异步加载语音识别语法。Asynchronously loads a speech recognition grammar.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
QueryRecognizerSetting(String)

为识别器返回设置的值。Returns the values of settings for the recognizer.

Recognize()

执行同步语音识别操作。Performs a synchronous speech recognition operation.

Recognize(TimeSpan)

使用指定初始静音超时执行同步语音识别操作。Performs a synchronous speech recognition operation with a specified initial silence timeout period.

RecognizeAsync()

执行单个异步语音识别操作。Performs a single, asynchronous speech recognition operation.

RecognizeAsync(RecognizeMode)

执行一个或多个异步语音识别操作。Performs one or more asynchronous speech recognition operations.

RecognizeAsyncCancel()

停止异步标识,而不必等待当前标识该操作完成。Terminates asynchronous recognition without waiting for the current recognition operation to complete.

RecognizeAsyncStop()

当前标识该操作完成后,停止异步标识。Stops asynchronous recognition after the current recognition operation completes.

RequestRecognizerUpdate()

请求识别器暂停更新其状态。Requests that the recognizer pauses to update its state.

RequestRecognizerUpdate(Object)

请求识别器暂停更新其状态并为关联的事件提供用户标记。Requests that the recognizer pauses to update its state and provides a user token for the associated event.

RequestRecognizerUpdate(Object, TimeSpan)

请求识别器暂停更新其状态并为关联的事件提供偏移量和用户标记。Requests that the recognizer pauses to update its state and provides an offset and a user token for the associated event.

SetInputToAudioStream(Stream, SpeechAudioFormatInfo)

配置 SpeechRecognitionEngine 对象以接收来自音频流的输入。Configures the SpeechRecognitionEngine object to receive input from an audio stream.

SetInputToDefaultAudioDevice()

配置 SpeechRecognitionEngine 对象以接收来自默认音频设备的输入。Configures the SpeechRecognitionEngine object to receive input from the default audio device.

SetInputToNull()

禁用到语音识别器的输入。Disables the input to the speech recognizer.

SetInputToWaveFile(String)

配置 SpeechRecognitionEngine 对象以接收从波形音频格式 (.wav) 文件的输入。Configures the SpeechRecognitionEngine object to receive input from a Waveform audio format (.wav) file.

SetInputToWaveStream(Stream)

配置 SpeechRecognitionEngine 对象以接收来自包含波形音频格式 (.wav) 数据的流的输入。Configures the SpeechRecognitionEngine object to receive input from a stream that contains Waveform audio format (.wav) data.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)
UnloadAllGrammars()

从卸载识别器的所有 Grammar 对象。Unloads all Grammar objects from the recognizer.

UnloadGrammar(Grammar)

从指定的 Grammar 实例卸载一个指定的 SpeechRecognitionEngine 对象。Unloads a specified Grammar object from the SpeechRecognitionEngine instance.

UpdateRecognizerSetting(String, Int32)

指定的整数值的 SpeechRecognitionEngine 指定设置。Updates the specified setting for the SpeechRecognitionEngine with the specified integer value.

UpdateRecognizerSetting(String, String)

更新指定字符串值设定的指定语音识别引擎。Updates the specified speech recognition engine setting with the specified string value.

事件

AudioLevelUpdated

SpeechRecognitionEngine 报告其音频输入的级别的时候引发。Raised when the SpeechRecognitionEngine reports the level of its audio input.

AudioSignalProblemOccurred

SpeechRecognitionEngine 检测在音频信号的问题的时候引发。Raised when the SpeechRecognitionEngine detects a problem in the audio signal.

AudioStateChanged

当状态在 SpeechRecognitionEngine 接收的音频更改的时候引发。Raised when the state changes in the audio being received by the SpeechRecognitionEngine.

EmulateRecognizeCompleted

SpeechRecognitionEngine 完成模拟输入的异步标识操作的时候引发。Raised when the SpeechRecognitionEngine finalizes an asynchronous recognition operation of emulated input.

LoadGrammarCompleted

SpeechRecognitionEngine 完成 Grammar 对象的异步加载时候引发。Raised when the SpeechRecognitionEngine finishes the asynchronous loading of a Grammar object.

RecognizeCompleted

SpeechRecognitionEngine 完成异步标识操作的时候引发。Raised when the SpeechRecognitionEngine finalizes an asynchronous recognition operation.

RecognizerUpdateReached

当运行的 SpeechRecognitionEngine 暂停接受修改时引发。Raised when a running SpeechRecognitionEngine pauses to accept modifications.

SpeechDetected

SpeechRecognitionEngine 检测它可以标识为语音的输入的时候引发。Raised when the SpeechRecognitionEngine detects input that it can identify as speech.

SpeechHypothesized

SpeechRecognitionEngine 识别了可能是一个语法的多个完整的短语的组件的一个或多个单词的时候引发。Raised when the SpeechRecognitionEngine has recognized a word or words that may be a component of multiple complete phrases in a grammar.

SpeechRecognitionRejected

SpeechRecognitionEngine 采用不与其加载启用的 Grammar 对象匹配的输入的时候引发。Raised when the SpeechRecognitionEngine receives input that does not match any of its loaded and enabled Grammar objects.

SpeechRecognized

SpeechRecognitionEngine 采用与其加载启用的 Grammar 对象匹配的输入的时候引发。Raised when the SpeechRecognitionEngine receives input that matches any of its loaded and enabled Grammar objects.

适用于

另请参阅