RecognizedPhrase.ReplacementWordUnits Property

Returns information about the location and content of text originally recognized and then replaced by text normalization when a recognition engine creates the value of the Text property on an instance of RecognizedPhrase.

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

Syntax

'Declaration




Property Value

Returns a Collection object containing ReplacementText instances corresponding to each phrase or text replaced by the recognition engine during speech normalization.

Remarks

Speech normalization is the use of special constructs or symbols to replace spoken elements for currency, numbers, and ordinal values with more convenient text or symbols.. For example, normalization can replace the spoken words "a dollar and sixteen cents" with "$1.16" in output text.

If the Text property of an instance of RecognizedPhrase has been normalized, the Collection object returned by the ReplacementWordUnits property on that instance of RecognizedPhrase will contain the original location and content of each replace phrase.

For example, if an audio input was:

july four at twelve thirty one PM, I bought a one point six kilograms of fish for fourteen dollars and six cents, at the pike market in seattle washington nine eight one two two

the normalized output might be:

July 4 at 12:31 PM, I bough a 1.6 kg of fish for $14.06, at the pike market in Seattle WA 98122

The Collection object would contain five instances of ReplacementText. Each instance would contain the location of the replacement and the original text replaced.

Example

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

The section where information about text replaced by normalization is displayed using ReplacementWordUnits is highlighted.

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

    if (result != null) { //Clear
      RecognitionResult recResult = result as RecognitionResult;
      if (recResult != null) {
        RecognizedAudio resultAudio = recResult.Audio;
        if (resultAudio == 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",
                                      resultAudio.AudioPosition.TotalMilliseconds,
                                      resultAudio.Duration.TotalMilliseconds,
                                      resultAudio.StartTime.ToShortTimeString(),
                                      resultAudio.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) {
          string repText = rep.Text;
          // Add trailing spaces

          if ((rep.DisplayAttributes & DisplayAttributes.OneTrailingSpace) != 0) {
            repText += " ";
          }
          if ((rep.DisplayAttributes & DisplayAttributes.TwoTrailingSpaces) != 0) {
            repText += "  ";
          }
          if ((rep.DisplayAttributes & DisplayAttributes.ConsumeLeadingSpaces) != 0) {
            repText.TrimStart();
          }
          label.Text += String.Format("      At index {0} for {1} words. Text: \"{2}\"\n",
                                      rep.FirstWordIndex, rep.CountOfWords, repText);
        }
        label.Text += String.Format("\n\n");
      }
    }

  }
}

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