SpeechRecognitionEngine.RecognizeCompleted イベント


SpeechRecognitionEngine が非同期認識操作を終了すると発生します。Raised when the SpeechRecognitionEngine finalizes an asynchronous recognition operation.

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

次の例では、"ジャズカテゴリのアーティストの一覧を表示する" または "アルバムの表示 gospel" のような語句を認識しています。The following example recognizes phrases such as "Display the list of artists in the jazz category" or "Display albums gospel". この例では、 RecognizeCompletedイベントのハンドラーを使用して、コンソールでの認識の結果に関する情報を表示します。The example uses a handler for the RecognizeCompleted event to display information about the results of recognition 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 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("in the", 0, 1);  
        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.RecognizeCompleted +=  
          new EventHandler<RecognizeCompletedEventArgs>(recognizer_RecognizeCompleted);  
        recognizer.LoadGrammarCompleted +=   
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);  
        // Load the grammar object to the recognizer.  
        // Set the input to the recognizer.  
        // Start asynchronous, continuous recognition.  
        // Keep the console window open.  
    // Handle the RecognizeCompleted event.  
    static void recognizer_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e)  
      if (e.Error != null)  
          "RecognizeCompleted, error occurred during recognition: {0}", e.Error);  
      if (e.InitialSilenceTimeout || e.BabbleTimeout)  
          "RecognizeCompleted: BabbleTimeout({0}), InitialSilenceTimeout({1}).",  
          e.BabbleTimeout, e.InitialSilenceTimeout);  
      if (e.InputStreamEnded)  
          "RecognizeCompleted: AudioPosition({0}), InputStreamEnded({1}).",  
          e.AudioPosition, e.InputStreamEnded);  
      if (e.Result != null)  
        Console.WriteLine("  Grammar: " + e.Result.Grammar.Name);  
        Console.WriteLine("  Recognized text: " + e.Result.Text);  
        Console.WriteLine("  Confidence score: " + e.Result.Confidence);  
        Console.WriteLine("  Audio position: " + e.AudioPosition);  
        Console.WriteLine("RecognizeCompleted: No result.");  
      Console.WriteLine("Press any key to exit...");  
    // Handle the LoadGrammarCompleted event.  
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)  
      Console.WriteLine("Grammar loaded:  " + e.Grammar.Name);  


オブジェクトSpeechRecognitionEngineRecognizeAsyncメソッドは、非同期認識操作を開始します。The SpeechRecognitionEngine object's RecognizeAsync method initiates an asynchronous recognition operation. レコグナイザーが非同期操作を終了すると、このイベントが発生します。When the recognizer finalizes the asynchronous operation, it raises this event.

RecognizeCompletedイベントのハンドラーを使用すると、 RecognizeCompletedEventArgsオブジェクトRecognitionResult内のにアクセスできます。Using the handler for the RecognizeCompleted event, you can access the RecognitionResult in the RecognizeCompletedEventArgs object. 認識が成功nullしなかったRecognitionResult場合、はになります。If recognition was not successful, RecognitionResult will be null. タイムアウトまたはオーディオ入力の中断によって認識が失敗したかどうかを判断するにInitialSilenceTimeoutBabbleTimeout、、 InputStreamEnded、またはのプロパティにアクセスします。To determine whether a timeout or an interruption in audio input caused recognition to fail, you can access the properties for InitialSilenceTimeout, BabbleTimeout, or InputStreamEnded.

詳細については、RecognizeCompletedEventArgs クラスを参照してください。See the RecognizeCompletedEventArgs class for more information.

最も拒否されている認識候補の詳細を取得するにはSpeechRecognitionRejected 、イベントのハンドラーをアタッチします。To obtain details on the best rejected recognition candidates, attach a handler for the SpeechRecognitionRejected event.

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