Κοινή χρήση μέσω


RecognitionResult.Alternates Property

Definition

Gets the collection of possible matches for input to the speech recognizer.

public:
 property System::Collections::ObjectModel::ReadOnlyCollection<System::Speech::Recognition::RecognizedPhrase ^> ^ Alternates { System::Collections::ObjectModel::ReadOnlyCollection<System::Speech::Recognition::RecognizedPhrase ^> ^ get(); };
public System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Recognition.RecognizedPhrase> Alternates { get; }
member this.Alternates : System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Recognition.RecognizedPhrase>
Public ReadOnly Property Alternates As ReadOnlyCollection(Of RecognizedPhrase)

Property Value

A read-only collection of the recognition alternates.

Examples

The following example shows a handler for the SpeechRecognized event and some of the information about the associated RecognitionResult.

// Handle the SpeechRecognized event.   
void SpeechRecognizedHandler(object sender, SpeechRecognizedEventArgs e)  
{  
  if (e.Result == null) return;  

  // Add event handler code here.  

  // The following code illustrates some of the information available  
  // in the recognition result.  
  Console.WriteLine("Grammar({0}), {1}: {2}",  
    e.Result.Grammar.Name, e.Result.Audio.Duration, e.Result.Text);  

  // Display the semantic values in the recognition result.  
  foreach (KeyValuePair<String, SemanticValue> child in e.Result.Semantics)  
  {  
    Console.WriteLine(" {0} key: {1}",  
      child.Key, child.Value.Value ?? "null");  
  }  
  Console.WriteLine();  

  // Display information about the words in the recognition result.  
  foreach (RecognizedWordUnit word in e.Result.Words)  
  {  
    RecognizedAudio audio = e.Result.GetAudioForWordRange(word, word);  
    Console.WriteLine(" {0,-10} {1,-10} {2,-10} {3} ({4})",  
      word.Text, word.LexicalForm, word.Pronunciation,  
      audio.Duration, word.DisplayAttributes);  
  }  

  // Display the recognition alternates for the result.  
  foreach (RecognizedPhrase phrase in e.Result.Alternates)  
  {  
    Console.WriteLine(" alt({0}) {1}", phrase.Confidence, phrase.Text);  
  }  
}  

Remarks

Recognition Alternates are ordered by the values of their Confidence properties. The confidence value of a given phrase indicates the probability that the phrase matches the input. The phrase with the highest confidence value is the phrase that most likely matches the input.

Each Confidence value should be evaluated individually and without reference to the confidence values of other Alternates. The properties that the RecognitionResult inherits from RecognizedPhrase provide detailed information about the phrase with the highest confidence score.

One use for the Alternates collection is for automated error correction. For example, when designing a directory dialog, an application could prompt the user to check if the application has the correct information from a recognition event, as in, "Did you say 'Anna'?" If the user says "no", then the application could query the user about any alternates that had a high enough Confidence score.

For more information about speech recognition and the use of recognition alternates, see Speech Recognition and Using Speech Recognition Events.

Applies to

See also