RecognizedPhrase.Words Property

Returns text obtained from audio input from a recognition engine as a ReadOnlyCollection of RecognizedWordUnit instances.

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

Syntax

'Declaration




Property Value

Returns recognized text as a ReadOnlyCollection of RecognizedWordUnit instances, ordered as their text appears in the String returned by Text.

Remarks

The ReadOnlyCollection of RecognizedWordUnit objects contains detailed information on exactly how a constituent recognized words are to be displayed.

Example

The example code fragment and utility method below, show an application calling the utility method to process the ReadOnlyCollection of RecognizedWordUnit objects and display them to a user interface.

_inputPhraseTextBox.Text = Utils.GetDisplay(_recognizedPhrase.Words);
/*
 */
internal static string GetDisplay(ReadOnlyCollection<RecognizedWordUnit> Words) {
    StringBuilder sb = new StringBuilder();
    DisplayAttributes displayAttribute;
    string text;
    for (int i = 0; i < Words.Count; i++) {


        displayAttribute = Words[i].DisplayAttributes;
        text = Words[i].Text;


        // Remove leading spaces
        if ((displayAttribute & DisplayAttributes.ConsumeLeadingSpaces) != 0) {
            while (sb.Length > 0 && char.IsWhiteSpace(sb[sb.Length - 1])) {
                sb.Remove(sb.Length - 1, 1);
            }
        }

        // Append text
        sb.Append(text);

        // Add trailing spaces
        if ((displayAttribute & DisplayAttributes.ZeroTrailingSpaces) != 0) {
            // no action
        } else if ((displayAttribute & DisplayAttributes.OneTrailingSpace) != 0) {
            sb.Append(" ");
        } else if ((displayAttribute & DisplayAttributes.TwoTrailingSpaces) != 0) {
            sb.Append("  ");
        }
    }
    return sb.ToString().Trim();
}

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

RecognizedPhrase Class
RecognizedPhrase Members
Microsoft.Speech.Recognition Namespace