Share via


Validating Grammars

  Microsoft Speech Technologies Homepage

A grammar file is valid only if it contains valid XML and follows specific guidelines as outlined in the World Wide Web Consortium Speech Recognition Grammar Specification Version 1.0 (W3C SRGS). When using Speech Grammar Editor to create grammar rules, it is possible to create and save invalid grammar files. Recognition errors occur if the invalid grammar passes to a speech application.

Use the validation tools provided by Speech Grammar Editor to ensure that grammar files are valid.

  • On-load Validation
  • Manual Validation

Note  On-load validation occurs automatically each time a grammar file opens in Speech Grammar Editor. Manual validation occurs only when a developer chooses. It is important to understand the on-load validation process before moving on to the manual validation section.

On-load Validation

Grammar file validation occurs automatically when the file opens. The grammar parser validates a grammar file using the following criteria.

  • The grammar file must contain at least one valid rule XML markup element.
  • Each rule XML markup element must have a unique name attribute value.
  • Any ruleref XML markup element must include valid references.
  • Parent elements must have valid child elements, and child elements must have valid parent elements.
  • The grammar file must be compliant with W3C SRGS standards. For example, all elements must be of a known type.
  • Any property values must be within reasonable ranges. For example, the value of the scope attribute on the rule XML markup element must be either Private or Public; other values are not valid.

If a grammar file is valid and loads successfully, a confirmation appears in the Output window of Visual Studio .NET 2003.

If a grammar file does not load successfully, the following behaviors may occur.

Criteria Failure Behavior
Poorly formed XML If the XML parser is unable to process the grammar file, the file opens in a text editor or in Visual Studio .NET 2003, rather than opening in Speech Grammar Editor. Error information appears in the Output window of Visual Studio .NET 2003.
Not compliant with W3C SRGS If the grammar file contains well-formed XML, but Speech Grammar Editor is unable to parse it, the file opens in a text editor or in Visual Studio .NET 2003. A severe error such as a missing grammar XML markup element causes a File Import Error and the grammar file does not open. Error information appears in the Output window.
Unknown elements or unknown attributes on W3C SRGS-compliant XML elements If the grammar file contains unknown elements or unknown attributes on valid W3C SRGS XML elements, the grammar file opens in Speech Grammar Editor, but the unrecognized data is deleted. Error information appears in the Output window.
Missing information If a W3C SRGS-compliant XML element is missing required information, the file still opens in Speech Grammar Editor, but error information appears in the Output window.
Invalid rule references If the grammar file contains one or more rule references that point to invalid Uniform Resource Identifier (URI) paths (for example, an invalid uri attribute value on a ruleref XML markup element), the file still opens in Speech Grammar Editor, but error information appears in the Output window.

Manual Validation

Perform manual validation on entire grammar files, or on sentences within grammar rules. Manual validation performs more checks than on-load validation. For example, manual validation checks for empty phrases, and on-load validation does not.

Validating Grammar Files Manually

Use the following procedure to validate a grammar file manually.

To validate a grammar file manually

  1. Open an existing grammar file or create a new one.
  2. On the Speech Grammar Editor toolbar, click Validate Grammar.
  3. - or -
  4. In Grammar Explorer, right-click a grammar file, and then on the shortcut menu, click Validate Grammar.
  5. - or -
  6. On the Grammar menu, click Validate Grammar.

If validation is successful, the confirmation "Grammar validation: Done" appears in the Output window, just as it does during on-load validation. If validation is not successful, error information appears in the Output window.

Validating Sentences Manually

Validate either one sentence at a time or multiple sentences at a time.

Validating one sentence at a time

Validate one sentence at a time by typing a text string into the Recognition String text box. Use this text box to validate sentences without compiling and running the application, and to review the Semantic Markup Language (SML) results. This type of validation applies to the rule that is currently open, and will use any RuleRef elements contained within the rule.

Note  When performing sentence validation during application design, Speech Grammar Editor uses text emulation of actual speech recognition. It recognizes text matches based on the entry in the Recognition String text box, regardless of case. When performing sentence validation on an application that is deployed, Speech Grammar Editor must recognize actual user speech.

Note  Speech Grammar Editor automatically saves all unsaved, modified grammar files (.grxml files only) before manual sentence validation occurs. After clicking Check in the previous procedure, a Warning window appears stating that all modified .grxml files will be saved before continuing with validation. Click Continue to save all modified .grxml files and continue with the validation.

To validate an individual sentence manually

  1. Open an existing grammar file or create a new one.
  2. Open a rule in Rule Editor.
  3. In the Recognition String text box, type a word or phrase that should be recognized by the containing rule, and then click Check.

If validation is successful, the selected elements display the path through the rule, and SML results appear in the Visual Studio .NET 2003 Output window. If validation is not successful, error information appears in the Output window.

Individual sentence validation

Validating multiple sentences at a time

Validate multiple sentences in Speech Grammar Editor by running a validation pass against a text file that contains multiple sample sentences. The text file can contain any number of sample sentences. When creating the text file, enter each sample sentence on a single line.

  I would like a small pizza please
I would like a medium pizza
Give me a large pizza please
I'd like a medium

To validate multiple sentences

  1. Create a text file that contains sample sentences.
  2. In Speech Grammar Editor, open an existing grammar file or create a new one.
  3. Open a rule in Rule Editor.
  4. To the right of the Recognition String text box, click File.
  5. In the File Open dialog box, browse to the folder that contains the text file, click the file, and then click Open.

The Visual Studio .NET 2003 Output window displays a summary of the validation.

  • If all sample sentences pass validation, the Output window displays only the number of succeeded and failed sentences.
  • If any sample sentences fail validation, the Output window displays the text of any failed sentences, and the number of succeeded and failed sentences.

Manual Validation Scenarios

The following table describes the possible results of various sentence validation scenarios.

Validation Scenario Speech Grammar Editor Results
Sentence is recognized. The recognition path is highlighted through the elements on Rule Editor, and SML results appear in the Output window.
Sentence is not recognized. The Output window displays the error message "Path not found through this rule."
Sentence fails validation. Error information appears in the Output window.
Sentence matches a rule, but is only a partial sentence. The input is not recognized. Error information appears in the Output window.
Recognition path includes an element in a collapsed List or Group element. The element expands to display the highlighted path.
Text in grammar elements is enclosed by quotes. The input is not recognized; the speech recognition engine does not recognize text enclosed by quotes.

See Also

Enabling Speech Recognition | Creating Grammars | Grammar Design