SpeechRecognitionEngine.SpeechRecognized SpeechRecognitionEngine.SpeechRecognized SpeechRecognitionEngine.SpeechRecognized SpeechRecognitionEngine.SpeechRecognized Event

定義

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

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) 

次の例は、音声認識文法の構造を作成するコンソール アプリケーションの一部をGrammarオブジェクト、およびそれを読み込んだ、SpeechRecognitionEngine認識を実行します。The following example is part of a console application that creates speech recognition grammar, constructs a Grammar object, and loads it into the SpeechRecognitionEngine to perform recognition. 音声入力の例を示します、 SpeechRecognitionEngine、関連付けられている認識結果、および音声認識エンジンによって生成される、関連するイベントです。The example demonstrates speech input to a SpeechRecognitionEngine, the associated recognition results, and the associated events raised by the speech recognizer.

トリガーは「miami シカゴから飛行する」などの入力を読み上げ、SpeechRecognizedイベント。Spoken input such as "I want to fly from Chicago to Miami" will trigger a SpeechRecognized event. "飛行 me ヒューストンからシカゴに"というフレーズを話すはトリガーされません、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 an in-process speech recognition engine.  
    {  
      using (SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine())  
      {  

        // 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);  

        // Set the input to the recognizer.  
        recognizer.SetInputToDefaultAudioDevice();  

        // Start recognition.  
        recognizer.RecognizeAsync();  

        // 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);  
    }  
  }  
}  

注釈

いずれかを使用して認識操作を開始することができます、RecognizeまたはRecognizeAsyncメソッド。You can initiate a recognition operation using the one of the Recognize or RecognizeAsync methods. 認識エンジンが発生、SpeechRecognized入力は、ロードのいずれかに一致するいると判断した場合、イベントGrammar認識を構成するために信頼のための十分なレベルのオブジェクト。The recognizer raises the SpeechRecognized event if it determines that input matches one of its loaded Grammar objects with a sufficient level of confidence to constitute recognition. Resultのプロパティ、SpeechRecognitionRejectedEventArgs承諾を含むRecognitionResultオブジェクト。The Result property of the SpeechRecognitionRejectedEventArgs contains the accepted RecognitionResult object. ハンドラーのSpeechRecognizedイベントは、認識された語句と認識の一覧を取得できますAlternates低い信頼度スコアを持つ。Handlers of SpeechRecognized events can obtain the recognized phrase as well as a list of recognition Alternates with lower 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. 音声認識が非音声を使用して入力に応答する方法を変更することができます、 BabbleTimeoutInitialSilenceTimeoutEndSilenceTimeout、およびEndSilenceTimeoutAmbiguousプロパティ。You can modify how the speech recognition responds to non-speech input using the BabbleTimeout, InitialSilenceTimeout, EndSilenceTimeout, and EndSilenceTimeoutAmbiguous properties.

認識エンジンは、文法に一致する入力を受け取るときに、Grammarオブジェクトが生成できるそのSpeechRecognizedイベント。When the recognizer receives input that matches a grammar, the Grammar object can raise its SpeechRecognized event. GrammarオブジェクトのSpeechRecognized音声認識エンジンの前にイベントが発生したSpeechRecognizedイベント。The Grammar object's SpeechRecognized event is raised prior to the speech recognizer's SpeechRecognized event. 特定の文法に固有のすべてのタスクは、のハンドラーによって常に実行する必要があります、SpeechRecognizedイベント。Any tasks specific to a particular grammar should always be performed by a handler for the SpeechRecognized event.

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

適用対象

こちらもご覧ください