RecognizedWordUnit.Text 屬性

定義

取得所辨識之單字的標準化文字。

public:
 property System::String ^ Text { System::String ^ get(); };
public string Text { get; }
member this.Text : string
Public ReadOnly Property Text As String

屬性值

字串,包含指定輸入單字的標準化文字輸出。

範例

下列範例顯示公用程式常式,其會以下列三種格式之一產生字串:使用) 的語彙 (、使用 LexicalFormText) 正規化 (,以及使用) 的 Pronunciation 注音 (。 文字輸出是從 物件的 取得 ReadOnlyCollection<T>RecognizedWordUnit ,從 物件的 屬性 RecognizedPhrase 取得 Words

internal enum WordType   
{  
  Text,  
  Normalized = Text,  
  Lexical,  
  Pronunciation  
}  
internal static string stringFromWordArray(  
          ReadOnlyCollection<RecognizedWordUnit> words,   
          WordType type)   
{  
  string text = "";  
  foreach (RecognizedWordUnit word in words)   
  {  
    string wordText = "";  
    if (type == WordType.Text || type == WordType.Normalized)   
    {  
      wordText = word.Text;  
    }   
    else if (type == WordType.Lexical)   
    {  
      wordText = word.LexicalForm;  
    }   
    else if (type == WordType.Pronunciation)   
    {  
      wordText = word.Pronunciation;  
    }   
    else   
    {  
      throw new InvalidEnumArgumentException(  
           String.Format("[0}: is not a valid input", type));  
    }  

    // Use display attribute  
    if ((word.DisplayAttributes & DisplayAttributes.OneTrailingSpace) != 0)   
    {  
      wordText += " ";  
    }  
    if ((word.DisplayAttributes & DisplayAttributes.TwoTrailingSpaces) != 0)   
    {  
      wordText += "  ";  
    }  
    if ((word.DisplayAttributes & DisplayAttributes.ConsumeLeadingSpaces) != 0)   
    {  
      wordText = wordText.TrimStart();  
    }  
    if ((word.DisplayAttributes & DisplayAttributes.ZeroTrailingSpaces) != 0)   
    {  
      wordText = wordText.TrimEnd();  
    }  

    text += wordText;  

  }  
  return text;  
}  

備註

在大部分情況下,和 LexicalFormText 傳回的值會相同。 不過,辨識引擎可能會使用語音正規化來傳回更方便使用者或音訊輸入的定序文字表示。

語音正規化是使用特殊建構或符號來表達書寫中的語音。 例如,正規化可以在輸出文字中以 「$1.16」 取代口說文字 「a dollar and sixteen cents」。

適用於