SpeechRecognitionEngine.SpeechHypothesized Událost
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Vyvolá se, když SpeechRecognitionEngine rozpoznal slovo nebo slova, která mohou být součástí více úplných frází v gramatikě.
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)
Event Type
Příklady
Následující příklad rozpozná fráze, jako je například "Zobrazení seznamu umělců v kategorii jazzu". Příklad používá SpeechHypothesized událost k zobrazení neúplných fragmentů frází v konzole při jejich rozpoznání.
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);
}
}
}
Poznámky
Generuje SpeechRecognitionEngine mnoho SpeechHypothesized událostí při pokusu o identifikaci vstupní fráze. Můžete získat přístup k textu částečně rozpoznaných frází ve Result vlastnosti objektu SpeechHypothesizedEventArgs v obslužné rutině SpeechHypothesized události. Zpracování těchto událostí je obvykle užitečné pouze pro ladění.
SpeechHypothesizedEventArgs je odvozeno z RecognitionEventArgs.
Další informace naleznete vlastnosti EndSilenceTimeoutAmbiguous a Recognize, RecognizeAsync, EmulateRecognize, a EmulateRecognizeAsync metody.
Při vytváření delegáta SpeechHypothesized identifikujete metodu, která bude zpracovávat událost. Pokud chcete událost přidružit k obslužné rutině události, přidejte do události instanci delegáta. Obslužná rutina události se volá při každém výskytu události, pokud delegáta neodeberete. Další informace o delegátech obslužné rutiny událostí naleznete v tématu Události a delegáty.