共用方式為


SpeechRecognizer.SpeechRecognitionRejected 事件

定義

當辨識器接收到不符合任何已載入的語音辨識文法的輸入時發生。

public:
 event EventHandler<System::Speech::Recognition::SpeechRecognitionRejectedEventArgs ^> ^ SpeechRecognitionRejected;
public event EventHandler<System.Speech.Recognition.SpeechRecognitionRejectedEventArgs> SpeechRecognitionRejected;
member this.SpeechRecognitionRejected : EventHandler<System.Speech.Recognition.SpeechRecognitionRejectedEventArgs> 
Public Custom Event SpeechRecognitionRejected As EventHandler(Of SpeechRecognitionRejectedEventArgs) 
Public Event SpeechRecognitionRejected As EventHandler(Of SpeechRecognitionRejectedEventArgs) 

事件類型

範例

下列範例會辨識「在音樂類別中顯示藝人清單」或「顯示相簿」等片語。 此範例會使用 事件的處理常式 SpeechRecognitionRejected ,在語音輸入無法與文法內容相符時,在主控台中顯示通知,且有足夠的信心來產生成功的辨識。

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 a grammar.  
        //  Create lists of alternative choices.  
        Choices listTypes = new Choices(new string[] { "albums", "artists" });  
        Choices genres = new Choices(new string[] {   
          "blues", "classical", "gospel", "jazz", "rock" });  

        //  Create a GrammarBuilder object and assemble the grammar components.  
        GrammarBuilder mediaMenu = new GrammarBuilder("Display");  
        mediaMenu.Append("the list of", 0, 1);  
        mediaMenu.Append(listTypes);  
        mediaMenu.Append("in the", 0, 1);  
        mediaMenu.Append(genres);  
        mediaMenu.Append("category", 0, 1);  

        //  Build a Grammar object from the GrammarBuilder.  
        Grammar mediaMenuGrammar = new Grammar(mediaMenu);  
        mediaMenuGrammar.Name = "Media Chooser";  

        // Attach event handlers.  
        recognizer.LoadGrammarCompleted +=  
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
        recognizer.SpeechRecognitionRejected +=   
          new EventHandler<SpeechRecognitionRejectedEventArgs>(recognizer_SpeechRecognitionRejected);  

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

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

    // Handle the SpeechRecognitionRejected event.  
    static void recognizer_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)  
    {  
      Console.WriteLine("Speech input was rejected.");  
    }  

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

    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine("Speech recognized: " + e.Result.Text);  
    }  
  }  
}  

備註

如果共用辨識器判斷輸入不符合任何載入的語音辨識文法,就會引發此事件。 ResultSpeechRecognitionRejectedEventArgs 屬性包含拒絕 RecognitionResult 的物件。

由 管理的 SpeechRecognizer 共用辨識器信賴閾值會與使用者設定檔相關聯,並儲存在 Windows 登錄中。 應用程式不應該將變更寫入共用辨識器屬性的登錄。

當您建立 SpeechRecognitionRejected 事件的委派時,您會識別將處理事件的方法。 若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。 除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。 如需事件處理常式委派的詳細資訊,請參閱 事件和委派

適用於

另請參閱