SpeechRecognitionEngine.AudioStateChanged SpeechRecognitionEngine.AudioStateChanged SpeechRecognitionEngine.AudioStateChanged SpeechRecognitionEngine.AudioStateChanged Event

Definición

Se genera cuando cambia el estado en el sonido que recibe el SpeechRecognitionEngine.Raised when the state changes in the audio being received by the SpeechRecognitionEngine.

public:
 event EventHandler<System::Speech::Recognition::AudioStateChangedEventArgs ^> ^ AudioStateChanged;
public event EventHandler<System.Speech.Recognition.AudioStateChangedEventArgs> AudioStateChanged;
member this.AudioStateChanged : EventHandler<System.Speech.Recognition.AudioStateChangedEventArgs> 
Public Custom Event AudioStateChanged As EventHandler(Of AudioStateChangedEventArgs) 

Ejemplos

En el ejemplo siguiente se usa un controlador AudioStateChanged para que el evento escriba el nuevo AudioState reconocedor en la consola cada vez que cambia, mediante un miembro AudioState de la enumeración.The following example uses a handler for the AudioStateChanged event to write the recognizer's new AudioState to the console each time it changes, using a member of the AudioState enumeration.

using System;  
using System.Speech.Recognition;  
  
namespace SampleRecognition  
{  
  class Program  
  {  
    static void Main(string[] args)  
  
    // Initialize an in-process speech recognition engine.  
    {  
      using (SpeechRecognitionEngine recognizer =  
         new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")))  
      {  
  
        // Create and load a grammar.  
        Choices animals = new Choices(new string[] { "cow", "pig", "goat" });  
        GrammarBuilder farm = new GrammarBuilder("On this farm he had a");  
        farm.Append(animals);  
        Grammar farmAnimals = new Grammar(farm);  
        farmAnimals.Name = "Farm";  
        recognizer.LoadGrammar(farmAnimals);  
  
        // Attach event handlers.  
        recognizer.AudioStateChanged +=  
          new EventHandler<AudioStateChangedEventArgs>(recognizer_AudioStateChanged);  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
        recognizer.LoadGrammarCompleted +=  
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);  
  
        // Set the input to the recognizer.  
        recognizer.SetInputToDefaultAudioDevice();  
  
        // Start recognition.  
        recognizer.RecognizeAsync();  
  
        // Keep the console window open.  
        Console.ReadLine();  
      }  
    }  
  
    // Handle the LoadGrammarCompleted event.  
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)  
    {  
      Console.WriteLine("Grammar loaded: " + e.Grammar.Name);  
    }  
  
    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
      if (e.Result != null && e.Result.Text != null)  
      {  
        Console.WriteLine();  
        Console.WriteLine("  Recognized text =  {0}", e.Result.Text);  
        Console.WriteLine();  
      }  
      else  
      {  
        Console.WriteLine("  Recognized text not available.");  
      }  
  
      Console.WriteLine();  
      Console.WriteLine("Done.");  
      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  
  
    // Handle the AudioStateChanged event.  
    static void recognizer_AudioStateChanged(object sender, AudioStateChangedEventArgs e)  
    {  
      Console.WriteLine("The new audio state is: " + e.AudioState);  
    }  
  }  
}  

Comentarios

Para obtener el estado de audio en el momento del evento, utilice la AudioState propiedad de la clase AudioStateChangedEventArgsasociada.To get the audio state at the time of the event, use the AudioState property of the associated AudioStateChangedEventArgs. Para obtener el estado de audio actual de la entrada al reconocedor, utilice la propiedad del AudioState reconocedor.To get the current audio state of the input to the recognizer, use the recognizer's AudioState property. Para obtener más información sobre el estado de audio AudioState , consulte la enumeración.For more information about audio state, see the AudioState enumeration.

Cuando se crea un delegado AudioStateChanged, se identifica el método que controlará el evento.When you create an AudioStateChanged delegate, you identify the method that will handle the event. Para asociar el evento al controlador, se debe agregar una instancia del delegado al evento.To associate the event with your event handler, add an instance of the delegate to the event. Siempre que se produce el evento, se llama a su controlador, a menos que se quite el delegado.The event handler is called whenever the event occurs, unless you remove the delegate. Para obtener más información sobre los delegados de controladores de eventos, vea eventos y delegados.For more information about event-handler delegates, see Events and Delegates.

Se aplica a

Consulte también: