SpeechRecognizer.SpeechRecognized イベント

定義

認識機能が読み込んだ音声認識文法のいずれかに一致する入力を受け取ると発生します。

public:
 event EventHandler<System::Speech::Recognition::SpeechRecognizedEventArgs ^> ^ SpeechRecognized;
public event EventHandler<System.Speech.Recognition.SpeechRecognizedEventArgs> SpeechRecognized;
member this.SpeechRecognized : EventHandler<System.Speech.Recognition.SpeechRecognizedEventArgs> 
Public Event SpeechRecognized As EventHandler(Of SpeechRecognizedEventArgs) 
Public Custom Event SpeechRecognized As EventHandler(Of 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 読み込まれた有効な音声認識文法のいずれかに一致する入力が十分な信頼度で判断された場合、イベントを発生させます。 の プロパティにはResultSpeechRecognitionRejectedEventArgs、受け入れ可能な オブジェクトがRecognitionResult含まれています。

によって SpeechRecognizer管理される共有認識エンジンの信頼度しきい値は、ユーザー プロファイルに関連付けられて、Windows レジストリに格納されます。 アプリケーションは、共有認識エンジンのプロパティの変更をレジストリに書き込むべきではありません。

認識エンジンが文法に一致する入力を受け取ると、オブジェクトは Grammar イベントを SpeechRecognized 発生させることができます。 Grammarオブジェクトの SpeechRecognized イベントは、音声認識エンジンSpeechRecognizedのイベントの前に発生します。

イベントのデリゲート SpeechRecognized を作成するときは、イベントを処理するメソッドを特定します。 イベント ハンドラーにイベントを関連付けるには、イベントにデリゲートのインスタンスを追加します。 イベント ハンドラーは、デリゲートを削除しない限り、イベントが発生するたびに呼び出されます。 イベント ハンドラー デリゲートの詳細については、「 イベントとデリゲート」を参照してください。

適用対象

こちらもご覧ください