SpeechRecognizedEventArgs SpeechRecognizedEventArgs SpeechRecognizedEventArgs SpeechRecognizedEventArgs Class

Definizione

Fornisce informazioni per gli eventi SpeechRecognized, SpeechRecognized e SpeechRecognized.Provides information for the SpeechRecognized, SpeechRecognized, and SpeechRecognized events.

public ref class SpeechRecognizedEventArgs : System::Speech::Recognition::RecognitionEventArgs
[System.Serializable]
public class SpeechRecognizedEventArgs : System.Speech.Recognition.RecognitionEventArgs
type SpeechRecognizedEventArgs = class
    inherit RecognitionEventArgs
Public Class SpeechRecognizedEventArgs
Inherits RecognitionEventArgs
Ereditarietà
SpeechRecognizedEventArgsSpeechRecognizedEventArgsSpeechRecognizedEventArgsSpeechRecognizedEventArgs
Attributi

Esempi

L'esempio seguente fa parte di un'applicazione console che carica una grammatica di riconoscimento vocale e Mostra l'input vocale per il riconoscimento condiviso, i risultati di riconoscimento associati e gli eventi associati generati dal riconoscimento vocale.The following example is part of a console application that loads a speech recognition grammar and demonstrates speech input to the shared recognizer, the associated recognition results, and the associated events raised by the speech recognizer. Se il riconoscimento vocale di Windows non è in esecuzione, l'avvio dell'applicazione avvierà anche il riconoscimento vocale di Windows.If Windows Speech Recognition is not running, then starting this application will also start Windows Speech Recognition.

L'input vocale, ad esempio "Desidero volare 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. Pronunciando la frase "Fly me from Houston to Chicago", non verrà SpeechRecognized attivato alcun evento.Speaking the phrase "Fly me from Houston to Chicago " will not trigger a SpeechRecognized event.

Nell'esempio viene usato un gestore per SpeechRecognized l'evento per visualizzare le frasi riconosciute correttamente e la semantica che 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 a shared speech recognition engine.  
    {  
      using (SpeechRecognizer recognizer = new SpeechRecognizer())  
      {  

        // 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);  

        // 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

Un SpeechRecognized evento viene generato Grammardalle classi, SpeechRecognizer e SpeechRecognitionEngine .A SpeechRecognized event is raised by the Grammar, SpeechRecognizer and SpeechRecognitionEngine classes.

SpeechRecognizedgli eventi vengono generati quando una o più alternative di un'operazione di riconoscimento hanno un punteggio di attendibilità sufficientemente elevato da accettare.SpeechRecognized events are generated when one or more of the alternates from a recognition operation have a high enough confidence score to be accepted. Per ottenere informazioni dettagliate su una frase riconosciuta, accedere alla Result proprietà nel gestore per l'evento.To obtain detailed information about a recognized phrase, access the Result property in the handler for the event.

SpeechRecognizedEventArgsderiva dalla RecognitionEventArgs classe.SpeechRecognizedEventArgs derives from the RecognitionEventArgs class.

Metodi

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

(Inherited from Object)

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Funge da funzione hash predefinita.Serves as the default hash function.

(Inherited from Object)

GetType() GetType() GetType() GetType()

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

(Inherited from Object)

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

(Inherited from Object)

ToString() ToString() ToString() ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.Returns a string that represents the current object.

(Inherited from Object)

Proprietà

Result Result Result Result

Ottiene i dati dei risultati di riconoscimento associati all'evento di riconoscimento vocale.Gets the recognition result data associated with the speech recognition event.

(Inherited from RecognitionEventArgs)

Si applica a

Vedi anche