SpeechRecognizer.RecognizerUpdateReached 이벤트

정의

인식기가 일시 중지되어 인식 및 기타 작업을 동기화할 때 발생합니다.

public:
 event EventHandler<System::Speech::Recognition::RecognizerUpdateReachedEventArgs ^> ^ RecognizerUpdateReached;
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 Custom Event RecognizerUpdateReached As EventHandler(Of RecognizerUpdateReachedEventArgs) 
Public Event RecognizerUpdateReached As EventHandler(Of RecognizerUpdateReachedEventArgs) 

이벤트 유형

예제

다음 예제에서는 개체를 로드하고 언로드하는 콘솔 애플리케이션을 보여 줍니다 Grammar . 애플리케이션은 이 메서드를 RequestRecognizerUpdate 사용하여 음성 인식 엔진이 업데이트를 받을 수 있도록 일시 중지하도록 요청합니다. 그런 다음 애플리케이션은 개체를 로드하거나 언로드합니다 Grammar .

각 업데이트에서 이벤트 처리기는 RecognizerUpdateReached 현재 로드된 Grammar 개체의 이름과 상태를 콘솔에 씁니다. 문법이 로드되고 언로드되면 애플리케이션은 먼저 농장 동물의 이름, 농장 동물의 이름 및 과일 이름, 과일 이름만 인식합니다.

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);
    }
  }
}

설명

애플리케이션은 개체를 수정하기 전에 실행 중인 인스턴스를 SpeechRecognizer 일시 중지하는 데 Grammar 사용해야 RequestRecognizerUpdate 합니다. 예를 들어 일시 중지된 동안 개체를 SpeechRecognizer 로드, 언로드, 사용 및 사용하지 않도록 설정할 Grammar 수 있습니다. SpeechRecognizer 수정을 수락할 준비가 되면 이 이벤트가 발생합니다.

이벤트에 대한 RecognizerUpdateReached 대리자를 만들 때 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 이벤트에 추가합니다. 대리자를 제거하지 않는 한 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다.

적용 대상

추가 정보