SpeechRecognitionEngine.SpeechHypothesized Événement
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Déclenché lorsqu’il SpeechRecognitionEngine a reconnu un mot ou des mots qui peuvent être un composant de plusieurs expressions complètes dans une grammaire.
public:
event EventHandler<System::Speech::Recognition::SpeechHypothesizedEventArgs ^> ^ SpeechHypothesized;
public event EventHandler<System.Speech.Recognition.SpeechHypothesizedEventArgs> SpeechHypothesized;
member this.SpeechHypothesized : EventHandler<System.Speech.Recognition.SpeechHypothesizedEventArgs>
Public Custom Event SpeechHypothesized As EventHandler(Of SpeechHypothesizedEventArgs)
Type d'événement
Exemples
L’exemple suivant reconnaît les expressions telles que « Afficher la liste des artistes dans la catégorie jazz ». L’exemple utilise l’événement SpeechHypothesized pour afficher des fragments d’expressions incomplets dans la console, car ils sont reconnus.
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 a grammar.
// Create lists of alternative choices.
Choices listTypes = new Choices(new string[] { "albums", "artists" });
Choices genres = new Choices(new string[] {
"blues", "classical", "gospel", "jazz", "rock" });
// Create a GrammarBuilder object and assemble the grammar components.
GrammarBuilder mediaMenu = new GrammarBuilder("Display the list of");
mediaMenu.Append(listTypes);
mediaMenu.Append("in the");
mediaMenu.Append(genres);
mediaMenu.Append("category.");
// Build a Grammar object from the GrammarBuilder.
Grammar mediaMenuGrammar = new Grammar(mediaMenu);
mediaMenuGrammar.Name = "Media Chooser";
// Attach event handlers.
recognizer.LoadGrammarCompleted +=
new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
recognizer.SpeechHypothesized +=
new EventHandler<SpeechHypothesizedEventArgs>(recognizer_SpeechHypothesized);
// Load the grammar object to the recognizer.
recognizer.LoadGrammarAsync(mediaMenuGrammar);
// Set the input to the recognizer.
recognizer.SetInputToDefaultAudioDevice();
// Start asynchronous recognition.
recognizer.RecognizeAsync();
// Keep the console window open.
Console.ReadLine();
}
}
// Handle the SpeechHypothesized event.
static void recognizer_SpeechHypothesized(object sender, SpeechHypothesizedEventArgs e)
{
Console.WriteLine("Speech hypothesized: " + e.Result.Text);
}
// 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();
Console.WriteLine("Speech recognized: " + e.Result.Text);
}
}
}
Remarques
Génère SpeechRecognitionEngine de nombreux SpeechHypothesized événements lors de sa tentative d’identification d’une expression d’entrée. Vous pouvez accéder au texte des expressions partiellement reconnues dans la Result propriété de l’objet SpeechHypothesizedEventArgs dans le gestionnaire de l’événement SpeechHypothesized . En règle générale, la gestion de ces événements est utile uniquement pour le débogage.
SpeechHypothesizedEventArgs dérive de RecognitionEventArgs.
Pour plus d’informations, consultez la EndSilenceTimeoutAmbiguous propriété et les méthodes , RecognizeAsyncet EmulateRecognizeEmulateRecognizeAsync .Recognize
Lorsque vous créez un SpeechHypothesized délégué, vous identifiez la méthode qui gère l’événement. Pour associer l’événement à votre gestionnaire d’événements, ajoutez une instance du délégué à l’événement. Le gestionnaire d’événements est appelé chaque fois que l’événement se produit, sauf si vous supprimez le délégué. Pour plus d’informations sur les délégués de gestionnaire d’événements, consultez Événements et délégués.