Share via


RecognizedWordUnit.Text 属性

定义

获取已识别单词的规划化文本。

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

属性值

包含给定输入单词的规范化文本输出的字符串。

示例

以下示例演示一个实用工具例程,该例程以以下三种格式之一生成字符串:使用 LexicalForm) 的词法 (、使用 Text) 的规范化 (以及使用 Pronunciation) 的拼音 (。 文本输出是从 对象的 中ReadOnlyCollection<T>RecognizedWordUnit获取的 ,该对象从 Words 对象的 属性RecognizedPhrase获取。

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;  
}  

注解

在大多数情况下,和 LexicalForm 返回Text的值将相同。 但是,识别引擎可以使用语音规范化来返回更用户友好的音频输入或口语文本表示形式。

语音规范化是使用特殊构造或符号以书面形式表达语音。 例如,规范化可以将输出文本中的口语“1美元和16美分”替换为“$1.16”。

适用于