DisplayAttributes Enumeration

Enumerates formats for the display of words in a recognized phrase.

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


<FlagsAttribute> _
Public Enumeration DisplayAttributes
public enum DisplayAttributes
public enum class DisplayAttributes
/** @attribute FlagsAttribute() */ 
public enum DisplayAttributes
public enum DisplayAttributes


Member name Description
ConsumeLeadingSpaces Indicates that spaces preceding the given word be removed.
None Indicates no display attributes.
OneTrailingSpace Indicates one trailing space following the given word.
TwoTrailingSpaces Indicates two trailing space following the given word.
ZeroTrailingSpaces Indicates no trailing space following the given word.


Members of the DisplayAttributes enumeration are returned by the RecognizedWordUnit.DisplayAttributes property and by the ReplacementText.DisplayAttributes property.

Two or more members of the DisplayAttributes enumeration may be combined by a bit-wise OR to specify how a particular word should be displayed.

Phrases are specified by collections of RecognizedWordUnit or ReplacementText objects; each object corresponds to a single word or punctuation mark.

The print spacing of these words and punctuation marks is determined by the value of the DisplayAttributes assigned to each RecognizedWordUnit or ReplacementText.

For example, suppose the input phrase to a recognition engine using the default system grammar provided by DictationGrammar is "Hello comma he said period".

Then the recognition engine will return a RecognizedPhrase containing five RecognizedWordUnit objects containing the following strings and values of DisplayAttributes.




OneTrailingSpace | ConsumeLeadingSpaces






OneTrailingSpace | ConsumeLeadingSpaces

The text returned for this recognized phrase would then be printed as: "Hello, he said."


The following example shows a utility method that returns a formatted phrase from a collection of RecognizedWordUnits returned by a recognition engine.

static string GetDisplay(ReadOnlyCollection<RecognizedWordUnit> Words) {
    StringBuilder sb = new StringBuilder();
    DisplayAttributes displayAttribute;
    string text;
    for (int i = 0; i < Words.Count; i++) {

        displayAttribute = Words[i].DisplayAttributes;
        text = Words[i].Text;

        // Remove leading spaces
        if ((displayAttribute & DisplayAttributes.ConsumeLeadingSpaces) != 0) {
            while (sb.Length > 0 && char.IsWhiteSpace(sb[sb.Length - 1])) {
                sb.Remove(sb.Length - 1, 1);

        // Append text

        // Add trailing spaces
        if ((displayAttribute & DisplayAttributes.ZeroTrailingSpaces) != 0) {
            // no action
        } else if ((displayAttribute & DisplayAttributes.OneTrailingSpace) != 0) {
            sb.Append(" ");
        } else if ((displayAttribute & DisplayAttributes.TwoTrailingSpaces) != 0) {
            sb.Append("  ");
    return sb.ToString().Trim();


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


Microsoft.Speech.Recognition Namespace