RecognizedWordUnit.Text Property

Returns a System.String containing the normalized text output.

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

Syntax

'Declaration
Public ReadOnly Property Text As String
public string Text { get; }
public:
property String^ Text {
    String^ get ();
}
/** @property */
public String get_Text ()
public function get Text () : String

Property Value

Returns an instance of System.String containing the normalized text output for a given input word.

Remarks

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.

Example

The example below shows a utility routine (stringFromWordArray) that generates lexical (using LexicalForm), normalized (using P:Microsoft.Speech.Recognition.RecognizedWordUnit.Text), and a phonetic (using Pronunciation) text output (formatted using DisplayAttributes objects obtained from the DisplayAttributes property) from the a System.Collections.ObjectModel.ReadOnlyCollection of RecognizedWordUnit objects, which is obtained from the P:Microsoft.Speech.Recognition.RecognizedPhrase.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;
      }

Thread Safety

All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.

Platforms

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition

Target Platforms

See Also

Reference

RecognizedWordUnit Class
RecognizedWordUnit Members
Microsoft.Speech.Recognition Namespace