次の方法で共有


SpeechRecognizer.EmulateRecognizeCompleted イベント

定義

共有認識機能がエミュレートされた入力の非同期認識操作を終了すると発生します。

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

イベントの種類

次の例は、音声認識文法を読み込み、非同期エミュレートされた入力、関連する認識結果、および音声認識エンジンによって発生する関連イベントを示すコンソール アプリケーションの一部です。 Windows 音声認識が実行されていない場合、このアプリケーションを起動すると、Windows 音声認識も開始されます。 Windows 音声認識が スリープ モードの場合は、常に null を EmulateRecognizeAsync 返します。

using System;
using System.Speech.Recognition;
using System.Threading;

namespace SharedRecognizer
{
  class Program
  {
    // Indicate whether the asynchronous emulate recognition
    // operation has completed.
    static bool completed;

    static void Main(string[] args)
    {

      // Initialize an instance of the shared recognizer.
      using (SpeechRecognizer recognizer = new SpeechRecognizer())
      {
        // Create and load a sample grammar.
        Grammar testGrammar =
          new Grammar(new GrammarBuilder("testing testing"));
        testGrammar.Name = "Test Grammar";
        recognizer.LoadGrammar(testGrammar);

        // Attach event handlers for recognition events.
        recognizer.SpeechRecognized +=
          new EventHandler<SpeechRecognizedEventArgs>(SpeechRecognizedHandler);
        recognizer.EmulateRecognizeCompleted +=
          new EventHandler<EmulateRecognizeCompletedEventArgs>(
            EmulateRecognizeCompletedHandler);

        completed = false;

        // This EmulateRecognizeAsync call generates a SpeechRecognized event.
        recognizer.EmulateRecognizeAsync("testing testing");

        // Wait for the asynchronous operation to complete.
        while (!completed)
        {
          Thread.Sleep(333);
        }

        completed = false;

        // This EmulateRecognizeAsync call does not match the grammar
        // or generate a SpeechRecognized event.
        recognizer.EmulateRecognizeAsync("testing one two three");

        // Wait for the asynchronous operation to complete.
        while (!completed)
        {
          Thread.Sleep(333);
        }
      }

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

    // Handle the SpeechRecognized event.
    static void SpeechRecognizedHandler(
      object sender, SpeechRecognizedEventArgs e)
    {
      if (e.Result != null)
      {
        Console.WriteLine("Recognition result = {0}",
          e.Result.Text ?? "<no text>");
      }
      else
      {
        Console.WriteLine("No recognition result");
      }
    }

    // Handle the EmulateRecognizeCompleted event.
    static void EmulateRecognizeCompletedHandler(
      object sender, EmulateRecognizeCompletedEventArgs e)
    {
      if (e.Result == null)
      {
        Console.WriteLine("No result generated.");
      }

      // Indicate the asynchronous operation is complete.
      completed = true;
    }
  }
}

注釈

EmulateRecognizeAsync メソッドは、非同期認識操作を開始します。 認識エンジンは、非同期操作を EmulateRecognizeCompleted 終了するとイベントを発生させます。

非同期認識操作では、および イベントをSpeechDetectedSpeechHypothesizedSpeechRecognitionRejectedSpeechRecognized発生させることができます。 イベントは EmulateRecognizeCompleted 、認識エンジンが特定の操作に対して発生させる最後のイベントです。

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

適用対象

こちらもご覧ください