Export (0) Print
Expand All

RecognizedPhrase.Grammar Property

Returns the Grammar used by a recognition engine to return the current RecognizedPhrase.

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

public Grammar Grammar { get; }
/** @property */
public Grammar get_Grammar ()

public function get Grammar () : Grammar

Not applicable.

Property Value

Returns and instance of Grammar corresponding the the Grammar used to obtain the current RecognizedPhrase.

RecognizedPhrase object returned by a recognition engine is displayed to a user interface.

The section the Grammar used by the recognition engine to return the current RecognizedPhrase 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");
      }
    }
    
  }
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft