Gets the words generated by a speech recognizer from recognized input.
Namespace:
Microsoft.Speech.Recognition
Assembly:
Microsoft.Speech (in Microsoft.Speech.dll)
Syntax
Visual Basic (Declaration) |
---|
Public ReadOnly Property Words As ReadOnlyCollection(Of RecognizedWordUnit) Get |
Visual Basic (Usage) |
---|
Dim instance As RecognizedPhrase Dim value As ReadOnlyCollection(Of RecognizedWordUnit) value = instance.Words |
C# |
---|
public ReadOnlyCollection<RecognizedWordUnit> Words { get; } |
Property Value
Type: System.Collections.ObjectModel..::..ReadOnlyCollection<(Of <(<'RecognizedWordUnit>)>)>The collection of RecognizedWordUnit objects generated by a speech recognizer for recognized input.
Remarks
This property contains the words produced from the input by the speech recognizer prior to the recognizer's speech-to-text normalization of the result.
For example, the spoken input, "twenty five dollars", generates a recognition result where the Words property contains the words, "twenty", "five", and "dollars", and the Text property contains the phrase, "$25.00". For more information about text normalization, see ReplacementText.
Examples
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.
C# | Copy Code |
---|---|
_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();
} |