SpeechRecognitionEngine.RecognizerUpdateReached 이벤트

정의

실행 SpeechRecognitionEngine 이 일시 중지되어 수정을 수락할 때 발생합니다.

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

설명

애플리케이션은 해당 설정 또는 Grammar 개체를 수정하기 전에 실행 중인 인스턴스 SpeechRecognitionEngine 를 일시 중지하는 데 사용해야 RequestRecognizerUpdate 합니다. SpeechRecognitionEngine 수정을 수락할 준비가 되면 이 이벤트가 발생합니다.

예를 들어 일시 중지된 동안 SpeechRecognitionEngine 개체를 로드, 언로드, 사용 및 사용하지 않도록 설정하고 Grammar , 및 InitialSilenceTimeoutEndSilenceTimeout 속성에 BabbleTimeout대한 값을 수정할 수 있습니다. 자세한 내용은 RequestRecognizerUpdate 메서드를 참조하세요.

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

적용 대상

추가 정보