SpeechRecognitionEngine.SpeechRecognitionRejected SpeechRecognitionEngine.SpeechRecognitionRejected SpeechRecognitionEngine.SpeechRecognitionRejected SpeechRecognitionEngine.SpeechRecognitionRejected Event

定義

SpeechRecognitionEngine が読み込み済みで有効な Grammar オブジェクトのどのリストにも一致しない入力を受け取ると、発生します。Raised when the SpeechRecognitionEngine receives input that does not match any of its loaded and enabled Grammar objects.

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 Event SpeechRecognitionRejected As EventHandler(Of SpeechRecognitionRejectedEventArgs) 

次の例では、"ジャズカテゴリのアーティストの一覧を表示する" または "アルバムの表示 gospel" のような語句を認識しています。The following example recognizes phrases such as "Display the list of artists in the jazz category" or "Display albums gospel". この例では、 SpeechRecognitionRejectedイベントのハンドラーを使用して、音声入力を、正しく認識させるために十分Confidenceな文法の内容と照合できない場合に、コンソールに通知を表示します。The example uses a handler for the SpeechRecognitionRejected event to display a notification in the console when the speech input cannot be matched to the contents of the grammar with sufficient Confidence to produce a successful recognition. このハンドラーは、信頼度Alternatesが低いために拒否された認識結果も表示します。The handler also displays recognition result Alternates that were rejected because of low confidence scores.

using System;  
using System.Speech.Recognition;  
  
namespace SampleRecognition  
{  
  class Program  
  {  
    static void Main(string[] args)  
  
    // Initialize an in-process speech recognition engine.  
    {  
      using (SpeechRecognitionEngine recognizer =  
         new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")))  
      {  
  
        // 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);  
  
        // Set the input to the recognizer.  
        recognizer.SetInputToDefaultAudioDevice();  
  
        // Start recognition.  
        recognizer.RecognizeAsync(RecognizeMode.Multiple);  
  
        // 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.");  
      foreach (RecognizedPhrase phrase in e.Result.Alternates)  
      {  
      Console.WriteLine("  Rejected phrase: " + phrase.Text);  
      Console.WriteLine("  Confidence score: " + phrase.Confidence);  
      }  
    }  
  
    // 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);  
      Console.WriteLine("  Confidence score: " + e.Result.Confidence);  
    }  
  }  
}  
  

注釈

認識エンジンは、読み込まれて有効になっGrammarているオブジェクトについて、入力が十分な信頼度と一致しないと判断した場合に、このイベントを発生させます。The recognizer raises this event if it determines that input does not match with sufficient confidence any of its loaded and enabled Grammar objects. のプロパティにResult 、拒否RecognitionResult されたオブジェクトが含まれSpeechRecognitionRejectedEventArgsています。The Result property of the SpeechRecognitionRejectedEventArgs contains the rejected RecognitionResult object. SpeechRecognitionRejectedイベントのハンドラーを使用すると、拒否されAlternatesた認識とそのConfidenceスコアを取得できます。You can use the handler for the SpeechRecognitionRejected event to retrieve recognition Alternates that were rejected and their Confidence scores.

アプリケーションでSpeechRecognitionEngineインスタンスを使用している場合は、いずれかUpdateRecognizerSettingの方法で音声入力が受け入れられるか拒否されるかの信頼レベルを変更できます。If your application is using a SpeechRecognitionEngine instance, you can modify the confidence level at which speech input is accepted or rejected with one of the UpdateRecognizerSetting methods. 、 、、およびBabbleTimeoutEndSilenceTimeoutAmbiguous各プロパティを使用して、音声認識が音声以外の入力にどのように応答するかを変更できます。 EndSilenceTimeout InitialSilenceTimeoutYou can modify how the speech recognition responds to non-speech input using the BabbleTimeout, InitialSilenceTimeout, EndSilenceTimeout, and EndSilenceTimeoutAmbiguous properties.

SpeechRecognitionRejected デリゲートを作成する場合は、イベントを処理するメソッドを指定します。When you create a SpeechRecognitionRejected delegate, you identify the method that will handle the event. イベントをイベント ハンドラーに関連付けるには、デリゲートのインスタンスをイベントに追加します。To associate the event with your event handler, add an instance of the delegate to the event. デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラーが呼び出されます。The event handler is called whenever the event occurs, unless you remove the delegate. イベントハンドラーデリゲートの詳細については、「イベントとデリゲート」を参照してください。For more information about event-handler delegates, see Events and Delegates.

適用対象

こちらもご覧ください