SpeechRecognitionEngine.SpeechRecognized Evento

Definición

Se genera cuando SpeechRecognitionEngine recibe una entrada que coincide con cualquiera de los objetos Grammar cargados y habilitados.Raised when the SpeechRecognitionEngine receives input that matches any of its loaded and enabled Grammar objects.

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

Ejemplos

El siguiente ejemplo forma parte de una aplicación de consola que crea la gramática de reconocimiento de voz Grammar , construye un objeto y lo carga SpeechRecognitionEngine en para realizar el reconocimiento.The following example is part of a console application that creates speech recognition grammar, constructs a Grammar object, and loads it into the SpeechRecognitionEngine to perform recognition. En el ejemplo se muestra la entrada SpeechRecognitionEnginede voz para, los resultados de reconocimiento asociados y los eventos asociados generados por el reconocedor de voz.The example demonstrates speech input to a SpeechRecognitionEngine, the associated recognition results, and the associated events raised by the speech recognizer.

La entrada oral, como "quiero volar desde Chicago a Miami", desencadenará un SpeechRecognized evento.Spoken input such as "I want to fly from Chicago to Miami" will trigger a SpeechRecognized event. Hablar de la frase "volar conmigo desde Houston a Chicago" no desencadenará SpeechRecognized un evento.Speaking the phrase "Fly me from Houston to Chicago " will not trigger a SpeechRecognized event.

En el ejemplo se usa un controlador SpeechRecognized para que el evento muestre frases reconocidas correctamente y la semántica que contienen en la consola.The example uses a handler for the SpeechRecognized event to display successfully recognized phrases and the semantics they contain in the console.

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())  
      {  
  
        // Create SemanticResultValue objects that contain cities and airport codes.  
        SemanticResultValue chicago = new SemanticResultValue("Chicago", "ORD");  
        SemanticResultValue boston = new SemanticResultValue("Boston", "BOS");  
        SemanticResultValue miami = new SemanticResultValue("Miami", "MIA");  
        SemanticResultValue dallas = new SemanticResultValue("Dallas", "DFW");  
  
        // Create a Choices object and add the SemanticResultValue objects, using  
        // implicit conversion from SemanticResultValue to GrammarBuilder  
        Choices cities = new Choices();  
        cities.Add(new Choices(new GrammarBuilder[] { chicago, boston, miami, dallas }));  
  
        // Build the phrase and add SemanticResultKeys.  
        GrammarBuilder chooseCities = new GrammarBuilder();  
        chooseCities.Append("I want to fly from");  
        chooseCities.Append(new SemanticResultKey("origin", cities));  
        chooseCities.Append("to");  
        chooseCities.Append(new SemanticResultKey("destination", cities));  
  
        // Build a Grammar object from the GrammarBuilder.  
        Grammar bookFlight = new Grammar(chooseCities);  
        bookFlight.Name = "Book Flight";  
  
        // Add a handler for the LoadGrammarCompleted event.  
        recognizer.LoadGrammarCompleted +=  
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);  
  
        // Add a handler for the SpeechRecognized event.  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
  
        // Load the grammar object to the recognizer.  
        recognizer.LoadGrammarAsync(bookFlight);  
  
        // 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);  
      Console.WriteLine();  
    }  
  
    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine("Speech recognized:  " + e.Result.Text);  
      Console.WriteLine();  
      Console.WriteLine("Semantic results:");  
      Console.WriteLine("  The flight origin is " + e.Result.Semantics["origin"].Value);  
      Console.WriteLine("  The flight destination is " + e.Result.Semantics["destination"].Value);  
    }  
  }  
}  
  

Comentarios

Puede iniciar una operación de reconocimiento con uno de los Recognize métodos o. RecognizeAsyncYou can initiate a recognition operation using the one of the Recognize or RecognizeAsync methods. El reconocedor genera SpeechRecognized el evento si determina que la entrada coincide con uno de Grammar sus objetos cargados con un nivel de confianza suficiente para constituir el reconocimiento.The recognizer raises the SpeechRecognized event if it determines that input matches one of its loaded Grammar objects with a sufficient level of confidence to constitute recognition. La Result propiedad RecognitionResult de contiene el objeto aceptado. SpeechRecognitionRejectedEventArgsThe Result property of the SpeechRecognitionRejectedEventArgs contains the accepted RecognitionResult object. Los controladores de SpeechRecognized eventos pueden obtener la frase reconocida, así como una lista de reconocimiento Alternates con puntuaciones de confianza más bajas.Handlers of SpeechRecognized events can obtain the recognized phrase as well as a list of recognition Alternates with lower confidence scores.

Si la aplicación usa una SpeechRecognitionEngine instancia de, puede modificar el nivel de confianza en el que se acepta o rechaza la entrada de voz con uno de los UpdateRecognizerSetting métodos.If your application is using a SpeechRecognitionEngine instance, you can modify the confidence level at which speech input is accepted or rejected with one of the UpdateRecognizerSetting methods. Puede modificar el modo en que el reconocimiento de voz responde a la entrada que no BabbleTimeoutes InitialSilenceTimeoutde voz mediante EndSilenceTimeoutAmbiguous las propiedades,, EndSilenceTimeouty.You can modify how the speech recognition responds to non-speech input using the BabbleTimeout, InitialSilenceTimeout, EndSilenceTimeout, and EndSilenceTimeoutAmbiguous properties.

Cuando el reconocedor recibe una entrada que coincide con una Grammar gramática, el objeto SpeechRecognized puede generar su evento.When the recognizer receives input that matches a grammar, the Grammar object can raise its SpeechRecognized event. El Grammar evento del SpeechRecognized objeto se produce antes del evento del reconocedor SpeechRecognized de voz.The Grammar object's SpeechRecognized event is raised prior to the speech recognizer's SpeechRecognized event. Cualquier tarea específica de una gramática determinada siempre debe realizarla un controlador para el SpeechRecognized evento.Any tasks specific to a particular grammar should always be performed by a handler for the SpeechRecognized event.

Cuando se crea un delegado SpeechRecognized, se identifica el método que controlará el evento.When you create a SpeechRecognized 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: