SpeechRecognitionEngine.RecognizeCompleted SpeechRecognitionEngine.RecognizeCompleted SpeechRecognitionEngine.RecognizeCompleted SpeechRecognitionEngine.RecognizeCompleted Event

定義

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

public:
 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) 

次の例では、「ジャズ カテゴリ アーティストの一覧の表示」や「絶対的のアルバムを表示する」などの語句を認識します。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(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.RecognizeCompleted +=  
          new EventHandler<RecognizeCompletedEventArgs>(recognizer_RecognizeCompleted);  
        recognizer.LoadGrammarCompleted +=   
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);  

        // Load the grammar object to the recognizer.  
        recognizer.LoadGrammarAsync(mediaMenuGrammar);  

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

        // Start asynchronous, continuous recognition.  
        recognizer.RecognizeAsync();  

        // Keep the console window open.  
        Console.ReadLine();  
      }  
    }  

    // Handle the RecognizeCompleted event.  
    static void recognizer_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e)  
    {  
      if (e.Error != null)  
      {  
        Console.WriteLine(  
          "RecognizeCompleted, error occurred during recognition: {0}", e.Error);  
        return;  
      }  

      if (e.InitialSilenceTimeout || e.BabbleTimeout)  
      {  
        Console.WriteLine(  
          "RecognizeCompleted: BabbleTimeout({0}), InitialSilenceTimeout({1}).",  
          e.BabbleTimeout, e.InitialSilenceTimeout);  
        return;  
      }  

      if (e.InputStreamEnded)  
      {  
        Console.WriteLine(  
          "RecognizeCompleted: AudioPosition({0}), InputStreamEnded({1}).",  
          e.AudioPosition, e.InputStreamEnded);  
      }  

      if (e.Result != null)  
      {  
        Console.WriteLine("RecognizeCompleted:");  
        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);  
      }  

      else  
      {  
        Console.WriteLine("RecognizeCompleted: No result.");  
      }  

      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  

    // Handle the LoadGrammarCompleted event.  
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)  
    {  
      Console.WriteLine("Grammar loaded:  " + e.Grammar.Name);  
    }  
  }  
}  

注釈

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

ハンドラーを使用して、RecognizeCompletedアクセスできる、イベント、RecognitionResultで、RecognizeCompletedEventArgsオブジェクト。Using the handler for the RecognizeCompleted event, you can access the RecognitionResult in the RecognizeCompletedEventArgs object. 認識が成功すると、なかった場合RecognitionResultなりますnullします。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.

適用対象

こちらもご覧ください