Partilhar via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

RecognitionResult.Alternates Property

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

Namespace:  Microsoft.Speech.Recognition
Assembly:  Microsoft.Speech (in Microsoft.Speech.dll)

Syntax

'Declaration
Public ReadOnly Property Alternates As ReadOnlyCollection(Of RecognizedPhrase)
    Get
'Usage
Dim instance As RecognitionResult
Dim value As ReadOnlyCollection(Of RecognizedPhrase)

value = instance.Alternates
public ReadOnlyCollection<RecognizedPhrase> Alternates { get; }

Property Value

Type: System.Collections.ObjectModel.ReadOnlyCollection<RecognizedPhrase>
A read-only collection of the recognition alternates.

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 (Microsoft.Speech) and Use Speech Recognition Events (Microsoft.Speech).

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);
  }
}

See Also

Reference

RecognitionResult Class

RecognitionResult Members

Microsoft.Speech.Recognition Namespace