共用方式為


SpeechRecognizedEventArgs 類別

定義

提供 SpeechRecognizedSpeechRecognized,以及 SpeechRecognized 事件的資訊。

public ref class SpeechRecognizedEventArgs : System::Speech::Recognition::RecognitionEventArgs
public class SpeechRecognizedEventArgs : System.Speech.Recognition.RecognitionEventArgs
[System.Serializable]
public class SpeechRecognizedEventArgs : System.Speech.Recognition.RecognitionEventArgs
type SpeechRecognizedEventArgs = class
    inherit RecognitionEventArgs
[<System.Serializable>]
type SpeechRecognizedEventArgs = class
    inherit RecognitionEventArgs
Public Class SpeechRecognizedEventArgs
Inherits RecognitionEventArgs
繼承
SpeechRecognizedEventArgs
屬性

範例

下列範例是主控台應用程式的一部分,它會載入語音辨識文法,並示範共用辨識器的語音輸入、相關聯的辨識結果,以及語音辨識器所引發的相關聯事件。 如果 Windows 語音辨識未執行,啟動此應用程式也會啟動 Windows 語音辨識。

口語輸入,例如「我想要從芝加哥飛到紐約」,將會觸發 SpeechRecognized 活動。 說出「從芝加哥飛出我」這個片語將不會觸發 SpeechRecognized 事件。

此範例會使用 SpeechRecognized 事件的處理常式來顯示成功辨識的片語及其包含在主控台中的語意。

using System;  
using System.Speech.Recognition;  

namespace SampleRecognition  
{  
  class Program  
  {  
    static void Main(string[] args)  

    // Initialize a shared speech recognition engine.  
    {  
      using (SpeechRecognizer recognizer = new SpeechRecognizer())  
      {  

        // Create SemanticResultValue objects that contain cities and airport codes.  
        SemanticResultValue chicago = new SemanticResultValue("Chicago", "ORD");  
        SemanticResultValue boston = new SemanticResultValue("Boston", "BOS");  
        SemanticResultValue miami = new SemanticResultValue("Miami", "MIA");  
        SemanticResultValue dallas = new SemanticResultValue("Dallas", "DFW");  

        // Create a Choices object and add the SemanticResultValue objects, using  
        // implicit conversion from SemanticResultValue to GrammarBuilder  
        Choices cities = new Choices();  
        cities.Add(new Choices(new GrammarBuilder[] { chicago, boston, miami, dallas }));  

        // Build the phrase and add SemanticResultKeys.  
        GrammarBuilder chooseCities = new GrammarBuilder();  
        chooseCities.Append("I want to fly from");  
        chooseCities.Append(new SemanticResultKey("origin", cities));  
        chooseCities.Append("to");  
        chooseCities.Append(new SemanticResultKey("destination", cities));  

        // Build a Grammar object from the GrammarBuilder.  
        Grammar bookFlight = new Grammar(chooseCities);  
        bookFlight.Name = "Book Flight";  

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

        // Add a handler for the SpeechRecognized event.  
        recognizer.SpeechRecognized +=   
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  

        // Load the grammar object to the recognizer.  
        recognizer.LoadGrammarAsync(bookFlight);  

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

    // Handle the LoadGrammarCompleted event.  
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)  
    {  
      Console.WriteLine("Grammar loaded: " + e.Grammar.Name);  
      Console.WriteLine();  
    }  

    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine("Speech recognized:  " + e.Result.Text);  
      Console.WriteLine();  
      Console.WriteLine("Semantic results:");  
      Console.WriteLine("  The flight origin is " + e.Result.Semantics["origin"].Value);  
      Console.WriteLine("  The flight destination is " + e.Result.Semantics["destination"].Value);  
    }  
  }  
}  

備註

SpeechRecognized事件是由 GrammarSpeechRecognizerSpeechRecognitionEngine 類別引發。

SpeechRecognized 當辨識作業中的一或多個替代專案具有足夠的信賴分數可接受時,就會產生事件。 若要取得已辨識片語的詳細資訊,請存取 Result 事件處理常式中的 屬性。

SpeechRecognizedEventArgs 衍生自 RecognitionEventArgs 類別。

屬性

Result

取得與語音辨識事件關聯的辨識結果資料。

(繼承來源 RecognitionEventArgs)

方法

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

適用於

另請參閱