SpeechRecognitionEngine.RecognizerUpdateReached SpeechRecognitionEngine.RecognizerUpdateReached SpeechRecognitionEngine.RecognizerUpdateReached SpeechRecognitionEngine.RecognizerUpdateReached Event

定義

変更を受け入れるために実行中の SpeechRecognitionEngine を一時停止すると発生します。Raised when a running SpeechRecognitionEngine pauses to accept modifications.

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

次の例では、コンソール アプリケーションをロードおよびアンロードGrammarオブジェクト。The following example shows a console application that loads and unloads Grammar objects. アプリケーションを使用して、RequestRecognizerUpdate音声認識エンジンの更新プログラムを受信できるようにを一時停止を要求するメソッド。The application uses the RequestRecognizerUpdate method to request the speech recognition engine to pause so it can receive an update. アプリケーション、ロードまたはアンロード、Grammarオブジェクト。The application then loads or unloads a Grammar object.

各更新プログラムのハンドラーでRecognizerUpdateReachedイベントの名前と読み込まれた現在の状態の書き込みGrammarコンソールへのオブジェクト。At each update, a handler for RecognizerUpdateReached event writes the name and status of the currently loaded Grammar objects to the console. 文法が読み込まれ、アンロード、として、アプリケーションは、ファームの動物の名前、ファームの動物の名前と、果物の名前、果物の名前のみに最初に認識します。As grammars are loaded and unloaded, the application first recognizes the names of farm animals, then the names of farm animals and the names of fruits, then only the names of fruits.

using System;  
using System.Speech.Recognition;  
using System.Collections.Generic;  
using System.Threading;  

namespace SampleRecognition  
{  
  class Program  
  {  
    private static SpeechRecognitionEngine recognizer;  
    public static void Main(string[] args)  
    {  

      // Initialize an in-process speech recognition engine and configure its input.  
      using (recognizer = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")))  
      {  
        recognizer.SetInputToDefaultAudioDevice();  

        // Create the first grammar - Farm.  
        Choices animals = new Choices(new string[] { "cow", "pig", "goat" });  
        GrammarBuilder farm = new GrammarBuilder(animals);  
        Grammar farmAnimals = new Grammar(farm);  
        farmAnimals.Name = "Farm";  

        // Create the second grammar - Fruit.  
        Choices fruit = new Choices(new string[] { "apples", "peaches", "oranges" });  
        GrammarBuilder favorite = new GrammarBuilder(fruit);  
        Grammar favoriteFruit = new Grammar(favorite);  
        favoriteFruit.Name = "Fruit";  

        // Attach event handlers.  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
        recognizer.RecognizerUpdateReached +=  
          new EventHandler<RecognizerUpdateReachedEventArgs>(recognizer_RecognizerUpdateReached);  
        recognizer.SpeechRecognitionRejected +=  
          new EventHandler<SpeechRecognitionRejectedEventArgs>(recognizer_SpeechRecognitionRejected);  

        // Load the Farm grammar.  
        recognizer.LoadGrammar(farmAnimals);  

        // Start asynchronous, continuous recognition.  
        recognizer.RecognizeAsync(RecognizeMode.Multiple);  
        Console.WriteLine("Starting asynchronous, continuous recognition");  
        Console.WriteLine("  Farm grammar is loaded and enabled.");  

        // Pause to recognize farm animals.  
        Thread.Sleep(7000);  
        Console.WriteLine();  

        // Request an update and load the Fruit grammar.  
        recognizer.RequestRecognizerUpdate();  
        recognizer.LoadGrammarAsync(favoriteFruit);  
        Thread.Sleep(7000);  

        // Request an update and unload the Farm grammar.  
        recognizer.RequestRecognizerUpdate();  
        recognizer.UnloadGrammar(farmAnimals);  
        Thread.Sleep(7000);  
      }  

      // Keep the console window open.  
      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  

    // At the update, get the names and enabled status of the currently loaded grammars.  
    public static void recognizer_RecognizerUpdateReached(  
      object sender, RecognizerUpdateReachedEventArgs e)  
    {  
      Console.WriteLine();  
      Console.WriteLine("Update reached:");  
      Thread.Sleep(1000);  

      string qualifier;  
      List<Grammar> grammars = new List<Grammar>(recognizer.Grammars);  
      foreach (Grammar g in grammars)  
      {  
        qualifier = (g.Enabled) ? "enabled" : "disabled";  
        Console.WriteLine("  {0} grammar is loaded and {1}.",  
        g.Name, qualifier);  
      }  
    }  

    // Write the text of the recognized phrase to the console.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine("    Speech recognized: " + e.Result.Text);  
    }  

    // Write a message to the console when recognition fails.  
    static void recognizer_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)  
    {  
      Console.WriteLine("    Recognition attempt failed");  
    }  
  }  
}  

注釈

アプリケーションを使用する必要がありますRequestRecognizerUpdateのインスタンスが実行を一時停止するSpeechRecognitionEngineその設定を変更する前に、またはGrammarオブジェクト。Applications must use RequestRecognizerUpdate to pause a running instance of SpeechRecognitionEngine before modifying its settings or its Grammar objects. SpeechRecognitionEngine変更を受け入れる準備ができた場合は、このイベントを発生させます。The SpeechRecognitionEngine raises this event when it is ready to accept modifications.

たとえば、SpeechRecognitionEngineは、一時停止できます読み込み、アンロードを有効にして無効にしたGrammarオブジェクトし、の値を変更、 BabbleTimeoutInitialSilenceTimeoutEndSilenceTimeoutプロパティ。For example, while the SpeechRecognitionEngine is paused, you can load, unload, enable, and disable Grammar objects, and modify values for the BabbleTimeout, InitialSilenceTimeout, and EndSilenceTimeout properties. 詳細については、RequestRecognizerUpdate メソッドを参照してください。For more information, see the RequestRecognizerUpdate method.

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

適用対象

こちらもご覧ください