SpeechRecognitionEngine.SpeechHypothesized Händelse
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Upphöjt när SpeechRecognitionEngine har identifierat ett ord eller ord som kan vara en komponent i flera fullständiga fraser i en grammatik.
public:
event EventHandler<System::Speech::Recognition::SpeechHypothesizedEventArgs ^> ^ SpeechHypothesized;
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)
Händelsetyp
Exempel
I följande exempel identifieras fraser som "Visa listan över artister i jazzkategorin". I exemplet används SpeechHypothesized händelsen för att visa ofullständiga frasfragment i konsolen när de identifieras.
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);
}
}
}
Kommentarer
SpeechRecognitionEngine Genererar flera SpeechHypothesized händelser när den försöker identifiera en indatafras. Du kan komma åt texten för delvis identifierade fraser i Result egenskapen SpeechHypothesizedEventArgs för objektet i hanteraren för SpeechHypothesized händelsen. Vanligtvis är hanteringen av dessa händelser endast användbar för felsökning.
SpeechHypothesizedEventArgs härleds från RecognitionEventArgs.
Mer information finns i EndSilenceTimeoutAmbiguous egenskapen och Recognizemetoderna , RecognizeAsync, EmulateRecognizeoch EmulateRecognizeAsync .
När du skapar ett SpeechHypothesized ombud identifierar du den metod som ska hantera händelsen. Om du vill associera händelsen med händelsehanteraren lägger du till en instans av ombudet till händelsen. Händelsehanteraren anropas när händelsen inträffar, såvida du inte tar bort ombudet. Mer information om ombud för händelsehanterare finns i Händelser och ombud.