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

Definizione

Generato quando un oggetto SpeechRecognitionEngine in esecuzione viene sospeso per accettare le modifiche.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) 

Esempi

L'esempio seguente illustra un'applicazione console che carica e Scarica Grammar oggetti.The following example shows a console application that loads and unloads Grammar objects. L'applicazione usa il RequestRecognizerUpdate metodo per richiedere il motore di riconoscimento vocale per mettere in pausa per la ricezione di un aggiornamento.The application uses the RequestRecognizerUpdate method to request the speech recognition engine to pause so it can receive an update. L'applicazione quindi carica o scarica un Grammar oggetto.The application then loads or unloads a Grammar object.

In ogni aggiornamento, un gestore per RecognizerUpdateReached eventi scrive il nome e lo stato di attualmente caricati Grammar gli oggetti nella console.At each update, a handler for RecognizerUpdateReached event writes the name and status of the currently loaded Grammar objects to the console. Come le grammatiche vengono caricate e scaricate, l'applicazione prima di tutto riconosce i nomi di animali, i nomi di animali farm e i nomi dei frutti e quindi solo i nomi dei frutti.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");  
    }  
  }  
}  

Commenti

Le applicazioni devono utilizzare RequestRecognizerUpdate sospendere un'istanza in esecuzione SpeechRecognitionEngine prima di modificare le impostazioni o dai relativi Grammar oggetti.Applications must use RequestRecognizerUpdate to pause a running instance of SpeechRecognitionEngine before modifying its settings or its Grammar objects. Il SpeechRecognitionEngine genera questo evento quando è pronto per accettare le modifiche.The SpeechRecognitionEngine raises this event when it is ready to accept modifications.

Ad esempio, se il SpeechRecognitionEngine è in pausa, è possibile caricare, scaricare, abilitare e disabilitare Grammar gli oggetti e modificare i valori per il BabbleTimeout, InitialSilenceTimeout, e EndSilenceTimeout proprietà.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. Per altre informazioni, vedere il metodo RequestRecognizerUpdate.For more information, see the RequestRecognizerUpdate method.

Quando si crea un delegato RecognizerUpdateReached, si identifica il metodo che gestirà l'evento.When you create a RecognizerUpdateReached delegate, you identify the method that will handle the event. Per associare l'evento al gestore eventi in uso, aggiungere all'evento un'istanza del delegato.To associate the event with your event handler, add an instance of the delegate to the event. Il gestore eventi viene chiamato ogni volta che si verifica l'evento, a meno che non venga rimosso il delegato.The event handler is called whenever the event occurs, unless you remove the delegate. Per altre informazioni sui delegati del gestore eventi, vedere eventi e delegati.For more information about event-handler delegates, see Events and Delegates.

Si applica a

Vedi anche