SpeechRecognizer.RecognizerUpdateReached SpeechRecognizer.RecognizerUpdateReached SpeechRecognizer.RecognizerUpdateReached SpeechRecognizer.RecognizerUpdateReached Event

定義

認識機能が認識と他の操作を同期するために一時停止すると発生します。Occurs when the recognizer pauses to synchronize recognition and other operations.

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 SpeechRecognizer recognizer;  
    public static void Main(string[] args)  
    {  

      // Initialize a shared speech recognition engine.  
      recognizer = new SpeechRecognizer();  

      // 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.StateChanged +=   
        new EventHandler<StateChangedEventArgs>(recognizer_StateChanged);  

      // Load the Farm grammar.  
      recognizer.LoadGrammar(farmAnimals);  
      Console.WriteLine("Grammar Farm is loaded");  

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

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

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

    // Put the shared speech recognizer into "listening" mode.  
    static void recognizer_StateChanged(object sender, StateChangedEventArgs e)  
    {  
      if (e.RecognizerState != RecognizerState.Stopped)  
      {  
        recognizer.EmulateRecognizeAsync("Start listening");  
      }  
    }  

    // 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("  Grammar {0} is loaded and is {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);  
    }  
  }  
}  

注釈

アプリケーションではRequestRecognizerUpdateGrammarオブジェクトを変更する前SpeechRecognizerに、を使用しての実行中のインスタンスを一時停止する必要があります。Applications must use RequestRecognizerUpdate to pause a running instance of SpeechRecognizer before modifying its Grammar objects. たとえば、 SpeechRecognizerが一時停止されている間は、オブジェクトの読み込み、アンロード、 Grammar有効化、および無効化を行うことができます。For example, while the SpeechRecognizer is paused, you can load, unload, enable, and disable Grammar objects. SpeechRecognizer 、変更を受け入れる準備が整ったときにこのイベントを発生させます。The SpeechRecognizer raises this event when it is ready to accept modifications.

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

適用対象

こちらもご覧ください