Share via


Note

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

RecognizedPhrase.ReplacementWordUnits Property

Gets information about the text that the speech recognizer changed as part of speech-to-text normalization.

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

Syntax

'Declaration
Public ReadOnly Property ReplacementWordUnits As Collection(Of ReplacementText)
    Get
'Usage
Dim instance As RecognizedPhrase
Dim value As Collection(Of ReplacementText)

value = instance.ReplacementWordUnits
public Collection<ReplacementText> ReplacementWordUnits { get; }

Property Value

Type: System.Collections.ObjectModel.Collection<ReplacementText>
A collection of ReplacementText objects that describe sections of text that the speech recognizer replaced when it normalized the recognized input.

Remarks

As part of the speech recognition process, the speech recognizer normalizes the recognized input into a display form.

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 the ReplacementText class.

Examples

In the example below, information about a RecognizedPhrase object returned by a recognition engine is displayed to a user interface.

internal static void DisplayBasicPhraseInfo(Label label, RecognizedPhrase result, SpeechRecognitionEngine recognizer) 
{
  if (result != null && label != null)
  {// Blank
    if (recognizer != null) 
    { // Clear
      label.Text += String.Format(
          "  Recognizer currently at:   {0} mSec\n" +
          "  Audio Device currently at: {1} mSec\n",
          recognizer.RecognizerAudioPosition.TotalMilliseconds,
          recognizer.AudioPosition.TotalMilliseconds);
    }

    if (result != null) 
    { // Clear
      RecognitionResult recResult = result as RecognitionResult;
      if (recResult != null) 
      {
        RecognizedAudio resultRecognizedAudio = recResult.Audio;
        if (resultRecognizedAudio == null) 
        {
          label.Text += String.Format("  Emulated input\n");
        }
        else 
        {
          label.Text += String.Format(
            "  Candidate Phrase at:       {0} mSec\n" +
            "  Phrase Length:             {1} mSec\n" +
            "  Input State Time:          {2}\n" +
            "  Input Format:              {3}\n",
            resultRecognizedAudio.AudioPosition.TotalMilliseconds,
            resultRecognizedAudio.Duration.TotalMilliseconds,
            resultRecognizedAudio.StartTime.ToShortTimeString(),
            resultRecognizedAudio.Format.EncodingFormat.ToString());
        }
      }

      label.Text += String.Format("  Confidence Level:          {0}\n", result.Confidence);
      if (result.Grammar != null) 
      {
        label.Text += String.Format(
            "  Recognizing Grammar:       {0}\n" +
            "  Recognizing Rule:          {1}\n",
            ((result.Grammar.Name != null) ? (result.Grammar.Name) : "None"),
            ((result.Grammar.RuleName != null) ? (result.Grammar.RuleName) : "None"));
      }

      if (result.ReplacementWordUnits.Count != 0) 
      {
        label.Text += String.Format("  Replacement text:\n");
        foreach (ReplacementText rep in result.ReplacementWordUnits) 
        {
          label.Text += String.Format("      At index {0} for {1} words. Text: {2}\n",
          rep.FirstWordIndex, rep.CountOfWords, rep.Text);
        }
        label.Text+=String.Format("\n\n");

      }
    }

  }
}

See Also

Reference

RecognizedPhrase Class

RecognizedPhrase Members

Microsoft.Speech.Recognition Namespace