Export (0) Print
Expand All

ReplacementText.CountOfWords Property

Gets the number of recognized words replaced by the speech normalization procedure.

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

public int CountOfWords { get; }

Property Value

Type: System.Int32
Returns the number of recognized words replaced by the speech normalization procedure.

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",
                             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=repText.TrimStart();
          }
          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.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft