Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
RecognizedWordUnit Class

RecognizedWordUnit Class

Provides the atomic unit of recognized speech.


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

public class RecognizedWordUnit

The RecognizedWordUnit type exposes the following members.

Public methodRecognizedWordUnitInitializes a new instance of the RecognizedWordUnit class.

Public propertyConfidenceGets a value, assigned by the recognizer, that represents the likelihood that a recognized word matches a given input.
Public propertyDisplayAttributesGets formatting information used to create the text output from the current RecognizedWordUnit instance.
Public propertyLexicalFormGets the unnormalized text of a recognized word.
Public propertyPronunciationGets the phonetic spelling of a recognized word.
Public propertyTextGets the normalized text for a recognized word.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

All results returned by a recognition engine are constructed of RecognizedWordUnit objects.

An array of RecognizedWordUnit objects is accessible for any recognition operation through the Words property on the RecognizedPhrase object.

In addition to providing a measure of recognition certainty (Confidence) a RecognizedWordUnit instance provides:

  • Normalized and exact (or lexical) text representations for a recognized word. For more information, see ReplacementText, Text, and LexicalForm.

  • Pronunciation information using characters from a supported phonetic alphabet, such as the International Phonetic Alphabet (IPA) or the Universal Phone Set (UPS). For more information see Pronunciation.

  • Formatting for printing. For more information see the DisplayAttributes class and its DisplayAttributes property.

The following example shows a utility routine (stringFromWordArray) that generates strings. The strings contain lexical output (using LexicalForm), normalized text (using Text), or phonetic characters from the International Phonetic Alphabet (using Pronunciation). Strings are formatted using DisplayAttributes objects obtained from the DisplayAttributes property from a ReadOnlyCollection of RecognizedWordUnit objects. The RecognizedWordUnit objects are obtained from the Words property on the RecognizedPhrase object.

internal enum WordType 
  Normalized = Text,
internal static string stringFromWordArray(ReadOnlyCollection<RecognizedWordUnit> words, WordType type) 
  string text = "";
  foreach (RecognizedWordUnit word in words) 
    string wordText = "";
    if (type == WordType.Text || type == WordType.Normalized) 
      wordText = word.Text;
    else if (type == WordType.Lexical) 
      wordText = word.LexicalForm;
    else if (type == WordType.Pronunciation) 
      wordText = word.Pronunciation;
      throw new InvalidEnumArgumentException(String.Format("[0}: is not a valid input", type));
    // Use display attribute

    if ((word.DisplayAttributes & DisplayAttributes.OneTrailingSpace) != 0) 
      wordText += " ";
    if ((word.DisplayAttributes & DisplayAttributes.TwoTrailingSpaces) != 0)
      wordText += "  ";
    if ((word.DisplayAttributes & DisplayAttributes.ConsumeLeadingSpaces) != 0) 
      wordText = wordText.TrimStart();
    if ((word.DisplayAttributes & DisplayAttributes.ZeroTrailingSpaces) != 0)
      wordText = wordText.TrimEnd();

    text += wordText;

  return text;

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

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.

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

Community Additions

© 2015 Microsoft