SpeechRecognizer.SpeechRecognized SpeechRecognizer.SpeechRecognized SpeechRecognizer.SpeechRecognized SpeechRecognizer.SpeechRecognized Event

定義

認識機能が読み込んだ音声認識文法のいずれかに一致する入力を受け取ると発生します。Occurs when the recognizer receives input that matches one of its speech recognition grammars.

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) 

次の例は、音声認識の文法を読み込み、共有認識エンジンに対する音声入力、関連する認識結果、音声認識エンジンによって発生した関連イベントを示すコンソールアプリケーションの一部です。The following example is part of a console application that loads a speech recognition grammar and demonstrates speech input to the shared recognizer, the associated recognition results, and the associated events raised by the speech recognizer. Windows 音声認識が実行されていない場合は、このアプリケーションを起動すると、Windows 音声認識も開始されます。If Windows Speech Recognition is not running, then starting this application will also start Windows Speech Recognition.

"シカゴからマイアミへの飛行を希望する" などの音声入力は、 SpeechRecognizedイベントをトリガーします。Spoken input such as "I want to fly from Chicago to Miami" will trigger a SpeechRecognized event. "ヒューストンからシカゴに移動する" という語句は、イベントをSpeechRecognizedトリガーしません。Speaking the phrase "Fly me from Houston to Chicago " will not trigger a SpeechRecognized event.

この例では、 SpeechRecognizedイベントのハンドラーを使用して、正常に認識された語句と、コンソールに含まれるセマンティクスを表示します。The example uses a handler for the SpeechRecognized event to display successfully recognized phrases and the semantics they contain in the console.

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読み込まれた、有効な音声認識文法のいずれかに一致すると判断した場合に、イベントを発生させます。The recognizer raises the SpeechRecognized event if it determines with sufficient confidence that input matches one of the loaded and enabled speech recognition grammars. のプロパティにResultは、受け入れらRecognitionResultれたオブジェクトが含まれています。SpeechRecognitionRejectedEventArgsThe Result property of the SpeechRecognitionRejectedEventArgs contains the accepted RecognitionResult object.

によってSpeechRecognizer管理される共有レコグナイザーの信頼しきい値は、ユーザープロファイルに関連付けられ、Windows レジストリに格納されます。Confidence thresholds for the shared recognizer, managed by SpeechRecognizer, are associated with a user profile and stored in the Windows registry. アプリケーションでは、共有認識エンジンのプロパティに対する変更をレジストリに書き込むことはできません。Applications should not write changes to the registry for the properties of the shared recognizer.

認識エンジンが文法に一致する入力をGrammar受け取ると、オブジェクトがSpeechRecognizedイベントを発生させることができます。When the recognizer receives input that matches a grammar, the Grammar object can raise the SpeechRecognized event. オブジェクトのSpeechRecognizedイベントは、音声認識エンジンのSpeechRecognizedイベントの前に発生します。 GrammarThe Grammar object's SpeechRecognized event is raised prior to the speech recognizer's SpeechRecognized event.

SpeechRecognizedイベントのデリゲートを作成する場合は、イベントを処理するメソッドを指定します。When you create a delegate for a SpeechRecognized event, 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.

適用対象

こちらもご覧ください