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 的淺層複本 (Shallow Copy)。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.

適用於

另請參閱