Share via


RecognizedWordUnit.DisplayAttributes Property

Returns formatting information used in creating the text output from the current RecognizedWordUnit instance.

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

Syntax

'Declaration
Public ReadOnly Property DisplayAttributes As DisplayAttributes
public DisplayAttributes DisplayAttributes { get; }
public:
property DisplayAttributes DisplayAttributes {
    DisplayAttributes get ();
}
/** @property */
public DisplayAttributes get_DisplayAttributes ()
public function get DisplayAttributes () : DisplayAttributes

Property Value

Returns a valid instance of DisplayAttributes, containing formatting for the text output from the current RecognizedWordUnit.

Remarks

The DisplayAttributes object returned by DisplayAttributes specifies if and how many spaces are to be used with a given word.

For a further discussion of how to use this formatting information, see DisplayAttributes.

Example

The example below shows a utility routine (stringFromWordArray) that generates lexical (using LexicalForm), normalized (using P:Microsoft.Speech.Recognition.RecognizedWordUnit.Text), and a phonetic (using Pronunciation) text output (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:Microsoft.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;
      }

Thread Safety

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

Platforms

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition

Target Platforms

See Also

Reference

RecognizedWordUnit Class
RecognizedWordUnit Members
Microsoft.Speech.Recognition Namespace
DisplayAttributes Enumeration

Other Resources

International Phonetic Alphabet