共用方式為


RecognizeCompletedEventArgs 類別

定義

提供 SpeechRecognitionEngineSpeechRecognizer 物件引發之 RecognizeCompleted 事件的資料。

public ref class RecognizeCompletedEventArgs : System::ComponentModel::AsyncCompletedEventArgs
public class RecognizeCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
type RecognizeCompletedEventArgs = class
    inherit AsyncCompletedEventArgs
Public Class RecognizeCompletedEventArgs
Inherits AsyncCompletedEventArgs
繼承
RecognizeCompletedEventArgs

範例

下列範例使用 方法搭配同進程辨識器, SpeechRecognitionEngine.RecognizeAsync 在語音辨識文法上執行非同步語音辨識。 此範例會使用 ChoicesGrammarBuilder 物件,先建立語音辨識文法,再將其建置成 Grammar 物件。 事件的處理常式會將 SpeechRecognitionEngine.RecognizeCompleted 辨識作業的相關資訊輸出至主控台。

using System;  
using System.Speech.Recognition;  

namespace SampleRecognition  
{  
  class Program  
  {  
    private static SpeechRecognitionEngine recognizer;  
    public static void Main(string[] args)  
    {  

      // Initialize a SpeechRecognitionEngine object and set its input.  
      recognizer = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));  
      recognizer.SetInputToDefaultAudioDevice();  

      // Configure recognition parameters.  
      recognizer.InitialSilenceTimeout = TimeSpan.FromSeconds(5.0);  
      recognizer.BabbleTimeout = TimeSpan.FromSeconds(3.0);  
      recognizer.EndSilenceTimeout = TimeSpan.FromSeconds(1.0);  
      recognizer.EndSilenceTimeoutAmbiguous = TimeSpan.FromSeconds(1.0);  

      // Add a handler for the LoadGrammarCompleted event.  
      recognizer.LoadGrammarCompleted +=  
        new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);  

      // Add a handler for the RecognizeCompleted event.  
      recognizer.RecognizeCompleted +=   
        new EventHandler<RecognizeCompletedEventArgs>(recognizer_RecognizeCompleted);  

      // Create a speech recognition grammar and build it into a Grammar object.  
      Choices bankingMenu = new Choices(new string[]   
      { "Access accounts", "Transfer funds", "Pay bills", "Get loan balance" });  
      GrammarBuilder banking = new GrammarBuilder(bankingMenu);  
      Grammar bankGrammar = new Grammar(banking);  
      bankGrammar.Name = "Banking Menu";  

      // Load the Grammar objects to the recognizer.  
      recognizer.LoadGrammarAsync(bankGrammar);  

      // Start asynchronous, continuous recognition.  
      recognizer.RecognizeAsync();  

      // Keep the console window open.  
      Console.ReadLine();  
    }  

    // Handle the RecognizeCompleted event.  
    static void recognizer_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e)  
    {  
      if (e.Error != null)  
      {  
        Console.WriteLine(  
          "RecognizeCompleted, error occurred during recognition: {0}", e.Error);  
        return;  
      }  

      if (e.InitialSilenceTimeout || e.BabbleTimeout)  
      {  
        Console.WriteLine(  
          "RecognizeCompleted: BabbleTimeout({0}), InitialSilenceTimeout({1}).",  
          e.BabbleTimeout, e.InitialSilenceTimeout);  
        return;  
      }  

      if (e.InputStreamEnded)  
      {  
        Console.WriteLine(  
          "RecognizeCompleted: AudioPosition({0}), InputStreamEnded({1}).",  
          e.AudioPosition, e.InputStreamEnded);  
      }  

      if (e.Result != null)  
      {  
        Console.WriteLine(  
          "RecognizeCompleted: Grammar ({0}), Text ({1}), Confidence ({2}), AudioPosition ({3}).",  
          e.Result.Grammar.Name, e.Result.Text, e.Result.Confidence, e.AudioPosition);  
      }  

      else  
      {  
        Console.WriteLine("RecognizeCompleted: No result.");  
      }   

      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  

    // Handle the LoadGrammarCompleted event.   
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)  
    {  
      string grammarName = e.Grammar.Name;  
      bool grammarLoaded = e.Grammar.Loaded;  
      bool grammarEnabled = e.Grammar.Enabled;  

      if (e.Error != null)  
      {  
        Console.WriteLine("LoadGrammar for {0} failed with a {1}.",  
        grammarName, e.Error.GetType().Name);  

        // Add exception handling code here.  
      }  

      Console.WriteLine("Grammar {0} {1} loaded and {2} enabled.", grammarName,   
        (grammarLoaded) ? "is" : "is not", (grammarEnabled) ? "is" : "is not");  
    }  
  }            
}  

備註

SpeechRecognitionEngineSpeechRecognizer 物件在完成 RecognizeAsync 作業之後引發其 SpeechRecognized 事件時,就會建立 的 RecognizeCompleted 實例。 如需語音辨識事件的詳細資訊,請參閱 使用語音辨識事件

屬性

AudioPosition

取得在與 RecognizeCompleted 事件相關聯之輸入裝置音訊資料流中的位置。

BabbleTimeout

取得值,這個值表示是否人聲混串 (Babble) 逾時產生了 RecognizeCompleted 事件。

Cancelled

取得值,指出非同步作業是否已取消。

(繼承來源 AsyncCompletedEventArgs)
Error

取得值,指出非同步作業期間是否發生錯誤。

(繼承來源 AsyncCompletedEventArgs)
InitialSilenceTimeout

取得值,這個值表示是否初始無聲 (Silence) 逾時產生了 RecognizeCompleted 事件。

InputStreamEnded

取得值,指出輸入資料流是否結束。

Result

取得辨識結果。

UserState

取得非同步工作的唯一識別項。

(繼承來源 AsyncCompletedEventArgs)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
RaiseExceptionIfNecessary()

如果非同步作業失敗,引發使用者提供的例外狀況。

(繼承來源 AsyncCompletedEventArgs)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱