Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

DisplayAttributes Enumeration

Lists the options that the SpeechRecognitionEngine object can use to specify white space for the display of a word or punctuation mark.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace:  System.Speech.Recognition
Assembly:  System.Speech (in System.Speech.dll)
[FlagsAttribute]
public enum DisplayAttributes
Member nameDescription
NoneThe item does not specify how white space is handled.
ZeroTrailingSpacesThe item has no spaces following it.
OneTrailingSpaceThe item has one space following it.
TwoTrailingSpacesThe item has two spaces following it.
ConsumeLeadingSpacesThe item has no spaces preceding it.

Windows Desktop Speech returns recognized phrases as collections of RecognizedWordUnit or ReplacementText objects. Each object corresponds to a single word or punctuation mark. The DisplayAttributes property of a RecognizedWordUnit or ReplacementText uses a member of the DisplayAttributes enumeration to describe how print spacing is handled around a given word or punctuation mark.

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.

NoteNote

The display formatting that the speech recognizer uses is language specific.

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 returns a RecognizedPhrase containing five RecognizedWordUnit objects containing the following strings with the following DisplayAttributes values.

Item

DisplayAttributes

Hello

OneTrailingSpace

,

OneTrailingSpace | ConsumeLeadingSpaces

he

OneTrailingSpace

said

OneTrailingSpace

.

OneTrailingSpace | ConsumeLeadingSpaces

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

The following example uses the DisplayAttributes property of a list of RecognizedWordUnit objects to format the words as a phrase.


// Use the DisplayAttributes property to format speech as text. 

static string GetDisplayText(List<RecognizedWordUnit> words)
{
  StringBuilder sb = new StringBuilder();

  // Concatenate the word units together. Use the DisplayAttributes
  // property of each word unit to add or remove white space around
  // the word unit.
  foreach (RecognizedWordUnit word in words)
  {
    if ((word.DisplayAttributes
      & DisplayAttributes.ConsumeLeadingSpaces) != 0))
    {
      sb = new StringBuilder(sb.ToString().TrimEnd());
    }

    sb.Append(word.Text);

    if ((word.DisplayAttributes
      & DisplayAttributes.OneTrailingSpace) != 0)
    {
      sb.Append(" ");
    }
    else if ((word.DisplayAttributes
      & DisplayAttributes.TwoTrailingSpaces) != 0)
    {
      sb.Append("  ");
    }
  }

  return sb.ToString();
}

.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.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.