Sdílet prostřednictvím


SpeechRecognitionEngine.RecognizerUpdateReached Událost

Definice

Vyvolá se, když se spuštění SpeechRecognitionEngine pozastaví, aby bylo možné přijmout úpravy.

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) 

Event Type

Příklady

Následující příklad ukazuje konzolovou aplikaci, která načítá a uvolní objekty Grammar . Aplikace používá metodu RequestRecognizerUpdate k vyžádání pozastavení modulu rozpoznávání řeči, aby mohl obdržet aktualizaci. Aplikace pak objekt načte nebo uvolní Grammar .

Při každé aktualizaci obslužná rutina události RecognizerUpdateReached zapíše název a stav aktuálně načtených Grammar objektů do konzoly. Při načítání a vyložení gramatiky aplikace nejprve rozpozná názvy hospodářských zvířat, pak názvy hospodářských zvířat a názvy ovoce, pak pouze názvy ovoce.

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

Poznámky

Aplikace musí před úpravou nastavení nebo objektů Grammar pozastavit RequestRecognizerUpdate spuštěnou instanci SpeechRecognitionEngine nástroje . Vyvolá SpeechRecognitionEngine tuto událost, jakmile je připraven přijmout úpravy.

Když je například objekt pozastavený SpeechRecognitionEngine , můžete načíst, uvolnit, povolit a zakázat Grammar objekty a upravit hodnoty pro BabbleTimeoutvlastnosti , InitialSilenceTimeouta EndSilenceTimeout . Další informace najdete v RequestRecognizerUpdate metodě .

Při vytváření delegáta RecognizerUpdateReached identifikujete metodu, která bude zpracovávat událost. Pokud chcete událost přidružit k obslužné rutině události, přidejte do události instanci delegáta. Obslužná rutina události je volána při každém výskytu události, dokud neodeberete delegáta. Další informace o delegátech obslužné rutiny událostí najdete v tématu Události a delegáti.

Platí pro

Viz také