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
繼承
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 桌面語音會傳回辨識的片語作為RecognizedWordUnitReplacementText物件的集合。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
執行個體時提供 SQL Server 登入。. OneTrailingSpace | ConsumeLeadingSpacesOneTrailingSpace | ConsumeLeadingSpaces

針對此辨識的片語傳回的文字會列印為:「您好, 他說過」。The text returned for this recognized phrase is printed as: "Hello, he said."

適用於

另請參閱