RecognizedWordUnit Class

Microsoft Speech Platform SDK 11

Collapse imageExpand ImageCopy imageCopyHover image

Provides the atomic unit of recognized speech.

Inheritance Hierarchy

System..::..Object
  Microsoft.Speech.Recognition..::..RecognizedWordUnit

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

Syntax

Visual Basic (Declaration)
<SerializableAttribute> _
Public Class RecognizedWordUnit
Visual Basic (Usage)
Dim instance As RecognizedWordUnit
C#
[SerializableAttribute]
public class RecognizedWordUnit

Remarks

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 ReplacementText, Text, and LexicalForm.

    NoteNote

    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 characters from a supported phonetic alphabet, such as the International Phonetic Alphabet (IPA) or the Universal Phone Set (UPS). For more information see Pronunciation.

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

Examples

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). 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.

C# Copy imageCopy Code
internal enum WordType {
          Text,
          Normalized = Text,
          Lexical,
          Pronunciation
}
C# Copy imageCopy Code
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;
}

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