DisplayAttributes 枚举
定义
列出 SpeechRecognitionEngine 可用于为显示单词或标点符号指定空白的选项。Lists the options that the SpeechRecognitionEngine object can use to specify white space for the display of a word or punctuation mark.
此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。
public enum class DisplayAttributes
[System.Flags]
public enum DisplayAttributes
type DisplayAttributes =
Public Enum DisplayAttributes
- 继承
- 属性
字段
ConsumeLeadingSpaces | 16 | 该项不具有其前的空间。The item has no spaces preceding it. |
None | 0 | 该项不指定空白的处理方式。The item does not specify how white space is handled. |
OneTrailingSpace | 4 | 该项不具有其后的一个空间。The item has one space following it. |
TwoTrailingSpaces | 8 | 该项不具有其后的两个空间。The item has two spaces following it. |
ZeroTrailingSpaces | 2 | 该项不具有其后的空间。The item has no spaces following it. |
示例
下面的示例使用DisplayAttributes RecognizedWordUnit对象列表的属性将单词的格式设置为短语。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();
}
注解
Windows 桌面语音将识别的短语作为或RecognizedWordUnit ReplacementText对象的集合返回。Windows Desktop Speech returns recognized phrases as collections of RecognizedWordUnit or ReplacementText objects. 每个对象对应于一个词或标点符号。Each object corresponds to a single word or punctuation mark. 或的属性使用枚举DisplayAttributes的成员来描述如何根据给定的单词或标点符号来处理打印间距。 DisplayAttributes
ReplacementText RecognizedWordUnitThe 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.
DisplayAttributes
枚举的两个或更多成员可以按位OR
组合在一起, 以指定特定单词的显示方式。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.
备注
语音识别器使用的显示格式是特定于语言的。The display formatting that the speech recognizer uses is language specific.
例如, 假设使用提供DictationGrammar的默认系统语法的识别引擎的输入短语为 "Hello 逗点"。For example, suppose the input phrase to a recognition engine using the default system grammar provided by DictationGrammar is "Hello comma he said period". 然后, 识别引擎返回包含RecognizedPhrase包含以下RecognizedWordUnit字符串DisplayAttributes
的五个对象的。Then the recognition engine returns a RecognizedPhrase containing five RecognizedWordUnit objects containing the following strings with the following DisplayAttributes
values.
项Item | DisplayAttributes |
---|---|
HelloHello | OneTrailingSpaceOneTrailingSpace |
,, | OneTrailingSpace | ConsumeLeadingSpacesOneTrailingSpace | ConsumeLeadingSpaces |
hehe | OneTrailingSpaceOneTrailingSpace |
指出said | OneTrailingSpaceOneTrailingSpace |
。. | OneTrailingSpace | ConsumeLeadingSpacesOneTrailingSpace | ConsumeLeadingSpaces |
为此识别的短语返回的文本打印如下:"你好, 他说。"The text returned for this recognized phrase is printed as: "Hello, he said."