This topic has not yet been rated - Rate this topic

RecognizedWordUnit.Text Property

Gets the normalized text for a recognized word.

Namespace:  System.Speech.Recognition
Assembly:  System.Speech (in System.Speech.dll)
public string Text { get; }

Property Value

Type: System.String
A string that contains the normalized text output for a given input word.

In most cases the values returned by Text and LexicalForm will be identical. However, recognition engines may use speech normalization to return more user-friendly or colloquial text representations of audio input.

Speech normalization is the use of special constructs or symbols to express speech in writing. For example, normalization can replace the spoken words "a dollar and sixteen cents" with "$1.16" in output text.

The following example shows a utility routine that generates a string in one of three formats: lexical (using LexicalForm), normalized (using Text), and phonetic (using Pronunciation). The text output is obtained from a ReadOnlyCollection of RecognizedWordUnit objects, which is 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;
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.