SpeechRecognitionEngine.SpeechRecognized SpeechRecognitionEngine.SpeechRecognized SpeechRecognitionEngine.SpeechRecognized SpeechRecognitionEngine.SpeechRecognized Event

Definizione

Generato quando SpeechRecognitionEngine riceve input che corrisponde a un oggetto Grammar caricato e abilitato.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) 

Esempi

Nell'esempio seguente fa parte di un'applicazione console che crea la grammatica di riconoscimento vocale, costrutti una Grammar dell'oggetto e viene caricato il SpeechRecognitionEngine per eseguire il riconoscimento.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. Nell'esempio viene illustrato l'input vocale di un SpeechRecognitionEngine, i risultati di riconoscimento associati e gli eventi associati generati dal riconoscimento vocale.The example demonstrates speech input to a SpeechRecognitionEngine, the associated recognition results, and the associated events raised by the speech recognizer.

Parlata input, ad esempio "I want to entrata da Chicago a Miami" attiverà un SpeechRecognized evento.Spoken input such as "I want to fly from Chicago to Miami" will trigger a SpeechRecognized event. Pronuncia della frase "Pilotare me da Houston a Chicago" non attiverà una SpeechRecognized eventi.Speaking the phrase "Fly me from Houston to Chicago " will not trigger a SpeechRecognized event.

L'esempio Usa un gestore per il SpeechRecognized evento da visualizzare è stato riconosciuto frasi e la semantica contengono nella console.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);  
    }  
  }  
}  

Commenti

È possibile avviare un'operazione di riconoscimento usando uno del Recognize o RecognizeAsync metodi.You can initiate a recognition operation using the one of the Recognize or RecognizeAsync methods. Il riconoscimento genera il SpeechRecognized evento se determina che input corrisponda a uno dei relativi caricato Grammar oggetti con un livello sufficiente di confidenza costituire il riconoscimento.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. Il Result proprietà del SpeechRecognitionRejectedEventArgs contiene accettato RecognitionResult oggetto.The Result property of the SpeechRecognitionRejectedEventArgs contains the accepted RecognitionResult object. Gestori dei SpeechRecognized gli eventi possono ottenere la frase riconosciuta, nonché un elenco di riconoscimento Alternates con punteggi di confidenza inferiore.Handlers of SpeechRecognized events can obtain the recognized phrase as well as a list of recognition Alternates with lower confidence scores.

Se l'applicazione usa una SpeechRecognitionEngine istanza, è possibile modificare il livello di confidenza quali sintesi e riconoscimento vocale è accettato o rifiutato con uno degli input di UpdateRecognizerSetting metodi.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. È possibile modificare come il riconoscimento vocale risponde a non a funzionalità di input usando la BabbleTimeout, InitialSilenceTimeout, EndSilenceTimeout, e EndSilenceTimeoutAmbiguous proprietà.You can modify how the speech recognition responds to non-speech input using the BabbleTimeout, InitialSilenceTimeout, EndSilenceTimeout, and EndSilenceTimeoutAmbiguous properties.

Quando il riconoscimento riceve input che corrisponde a una grammatica, il Grammar possono generare oggetti relativo SpeechRecognized evento.When the recognizer receives input that matches a grammar, the Grammar object can raise its SpeechRecognized event. Il Grammar dell'oggetto SpeechRecognized evento viene generato prima del riconoscimento vocale SpeechRecognized evento.The Grammar object's SpeechRecognized event is raised prior to the speech recognizer's SpeechRecognized event. Qualsiasi attività specifiche a una grammatica particolare devono essere sempre eseguite da un gestore per il SpeechRecognized evento.Any tasks specific to a particular grammar should always be performed by a handler for the SpeechRecognized event.

Quando si crea un delegato SpeechRecognized, si identifica il metodo che gestirà l'evento.When you create a SpeechRecognized 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