Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

RecognizedWordUnit.DisplayAttributes Property

Gets formatting information used in creating the text output from the current RecognizedWordUnit instance.

Namespace:  Microsoft.Speech.Recognition
Assembly:  Microsoft.Speech (in Microsoft.Speech.dll)

Syntax

'Declaration
Public ReadOnly Property DisplayAttributes As DisplayAttributes
    Get
'Usage
Dim instance As RecognizedWordUnit
Dim value As DisplayAttributes

value = instance.DisplayAttributes
public DisplayAttributes DisplayAttributes { get; }

Property Value

Type: Microsoft.Speech.Recognition.DisplayAttributes
Specifies the use of white space to display of the contents of a RecognizedWordUnit object.

Remarks

The DisplayAttributes object returned by DisplayAttributes specifies the leading and trailing spaces to be used with a given word.

For more information about how to use this formatting information, see DisplayAttributes.

Examples

The following example shows a utility routine (stringFromWordArray) that generates lexical output (using LexicalForm), normalized output (using Text), and phonetic text output (using Pronunciation). The text output is formatted by the use of DisplayAttributes objects obtained from the DisplayAttributes property from a ReadOnlyCollection of RecognizedWordUnit objects. The RecognizedWordUnit objects are obtained from the Words property on the RecognizedPhrase object.

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

See Also

Reference

RecognizedWordUnit Class

RecognizedWordUnit Members

Microsoft.Speech.Recognition Namespace

DisplayAttributes