SpeechRecognitionRejectedEventArgs Class
Provides information for the SpeechRecognizer::SpeechRecognitionRejected and SpeechRecognitionEngine::SpeechRecognitionRejected events.
System::EventArgs
System.Speech.Recognition::RecognitionEventArgs
System.Speech.Recognition::SpeechRecognitionRejectedEventArgs
Assembly: System.Speech (in System.Speech.dll)
The SpeechRecognitionRejectedEventArgs type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Result | Gets the recognition result data associated with the speech recognition event. (Inherited from RecognitionEventArgs.) |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
The SpeechRecognitionRejected event is raised by the SpeechRecognizer and SpeechRecognitionEngine classes.
SpeechRecognitionRejected events are generated by a speech recognition engine when none of the alternates from a recognition operation have a high enough confidence score to be accepted. Detailed information about rejected phrases is available through the Result property.
SpeechRecognitionRejectedEventArgs derives from RecognitionEventArgs.
The following example recognizes phrases such as "Display the list of artists in the jazz category" or "Display albums gospel". The example uses a handler for the SpeechRecognitionRejected event to display a notification in the console when the speech input cannot be matched to the contents of the grammar with sufficient confidence to produce a successful recognition.
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 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");
mediaMenu.Append("the list of", 0, 1);
mediaMenu.Append(listTypes);
mediaMenu.Append("in the", 0, 1);
mediaMenu.Append(genres);
mediaMenu.Append("category", 0, 1);
// 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.SpeechRecognitionRejected +=
new EventHandler<SpeechRecognitionRejectedEventArgs>(recognizer_SpeechRecognitionRejected);
// Load the grammar object to the recognizer.
recognizer.LoadGrammarAsync(mediaMenuGrammar);
// Keep the console window open.
Console.ReadLine();
}
}
// Handle the SpeechRecognitionRejected event.
static void recognizer_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
{
Console.WriteLine("Speech input was rejected.");
foreach (RecognizedPhrase phrase in e.Result.Alternates)
{
Console.WriteLine(" Rejected phrase: " + phrase.Text);
Console.WriteLine(" Confidence score: " + phrase.Confidence);
}
}
// Handle the LoadGrammarCompleted event.
static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)
{
Console.WriteLine("Grammar loaded: " + e.Grammar.Name);
}
// Handle the SpeechRecognized event.
static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
Console.WriteLine("Speech recognized: " + e.Result.Text);
}
}
}
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
