RecognitionResult Class

Microsoft Speech Platform SDK 11

Collapse image Expand Image Copy image CopyHover image

Contains detailed information about input that was recognized by instances of SpeechRecognitionEngine or DtmfRecognitionEngine.

Inheritance Hierarchy

System..::..Object
  Microsoft.Speech.Recognition..::..RecognizedPhrase
    Microsoft.Speech.Recognition..::..RecognitionResult

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

Syntax

Visual Basic (Declaration)
<SerializableAttribute> _
Public NotInheritable Class RecognitionResult _
	Inherits RecognizedPhrase _
	Implements ISerializable
Visual Basic (Usage)
Dim instance As RecognitionResult
C#
[SerializableAttribute]
public sealed class RecognitionResult : RecognizedPhrase, 
	ISerializable

Remarks

This class derives from RecognizedPhrase and provides detailed information about recognition of speech and DTMF tones, including the following:

  • The Grammar property references the Grammar that the recognizer used to identify the speech.

  • The Text property contains the normalized text for the phrase. For more information about text normalization, see ReplacementText.

  • The Semantics property references the semantic information contained in the result. The semantic information is a dictionary of the key names and associated semantic data.

  • The Alternates property contains a collection of RecognizedPhrase objects that represent other candidate interpretations of the audio input. See Alternates for additional information.

  • The Words property contains an ordered collection of RecognizedWordUnit objects that represent each recognized word in the input. Each RecognizedWordUnit contains display format, lexical format, and pronunciation information for the corresponding word.

Certain members of the SpeechRecognitionEngine, DtmfRecognitionEngine, and Grammar classes can generate a RecognitionResult. For more information, see the following methods and events.

For more information about recognition events, see Use Speech Recognition Events (Microsoft.Speech).

Examples

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

C# Copy imageCopy Code
// 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);
  }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also