DisplayAttributes Enumeration
Enumerates formats for the display of words in a recognized phrase.
This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.
Namespace: System.Speech.RecognitionAssembly: System.Speech (in System.Speech.dll)
| Member name | Description | |
|---|---|---|
| None | Indicates no display attributes. | |
| ZeroTrailingSpaces | Indicates no trailing space following the given word. | |
| OneTrailingSpace | Indicates one trailing space following the given word. | |
| TwoTrailingSpaces | Indicates two trailing space following the given word. | |
| ConsumeLeadingSpaces | Indicates that spaces preceding the given word be removed. |
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.
Under Windows Desktop Speech, 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.
|
"Hello" |
OneTrailingSpace |
|
"," |
OneTrailingSpace | ConsumeLeadingSpaces |
|
"he" |
OneTrailingSpace |
|
"said" |
OneTrailingSpace |
|
"." |
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
sb.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();
}
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.