0 out of 1 rated this helpful - Rate this topic

RecognizedWordUnit Class

Provides the atomic unit of recognized speech.

Namespace:  System.Speech.Recognition
Assembly:  System.Speech (in System.Speech.dll)
[SerializableAttribute]
public class RecognizedWordUnit

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

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

Addition to providing a measure of recognition certainty (Confidence) an instance of RecognizedWordUnit provides:

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

    Note Note:

    Normalization of text from speech input is the use of special constructs or symbols to express speech in writing. For example, normalization can replace the spoken words "a dollar and sixteen cents" with "$1.16" in output text.

  • Pronunciation information using the International Phonetic Alphabet. For more information see Pronunciation and InternationalPhoneticAlphabet.

  • Printing formatting. For more information see DisplayAttributes and DisplayAttributes.

The example below shows a utility routine (stringFromWordArray) that generates strings containing lexical output (using LexicalForm), normalized text ([using]Text), or a phonetic information in the International Phonetic Alphabet (using Pronunciation), formatted using DisplayAttributes objects obtained from the DisplayAttributes property, from the a [System.Collections.ObjectModel.ReadOnlyCollection] of RecognizedWordUnit objects, which is obtained from the P[:System.Speech.Recognition.RecognizedPhrase.Words] property on the RecognizedPhrase object.


internal enum WordType {
          Text,
          Normalized = Text,
          Lexical,
          Pronunciation
}
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;
              } else {
                  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;
      }


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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ