This documentation is archived and is not being maintained.

ReplacementText Class

Contains information about a speech normalization procedure that has been performed on recognition results.


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

public class ReplacementText

The ReplacementText type exposes the following members.

Public propertyCountOfWordsGets the number of recognized words replaced by the speech normalization procedure.
Public propertyDisplayAttributesGets information about the leading and trailing spaces for the text replaced by the speech normalization procedure.
Public propertyFirstWordIndexGets the location of the first recognized word replaced by the speech normalization procedure.
Public propertyTextGets the recognized text replaced by the speech normalization procedure.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Speech normalization is the use of special constructs or symbols to express speech in writing.

For example, suppose that this is recognized text:

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

This is the same text after normalization:

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

In this example there are five substitutions, each of which would be described by an instance of ReplacementText.

Using the ReplacementText object, an application can determine:

Instances of ReplacementText are typically obtained as members of the Collection object returned by the ReplacementWordUnits property on RecognizedPhrase (or classes that inherit from RecognizedPhrase, such as RecognitionResult) when returned text has been normalized.

The example below displays information in a user interface about a RecognizedPhrase object returned by a recognition engine.

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",
    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");
          label.Text += String.Format(
                               "  Candidate Phrase at:       {0} mSec\n" +
                               "  Phrase Length:             {1} mSec\n" +
                               "  Input State Time:          {2}\n" +
                               "  Input Format:              {3}\n",
      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)  
          if ((rep.DisplayAttributes & DisplayAttributes.ZeroTrailingSpaces) != 0) 
            repText = repText.TrimEnd();
          label.Text += String.Format(
                           "      At index {0} for {1} words. Text: \"{2}\"\n",
                           rep.FirstWordIndex,  rep.CountOfWords, repText);

        label.Text += String.Format("\n\n");

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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