Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

Create Grammars Using SRGS XML (Microsoft.Speech)

Although you can author grammars programmatically in your application using the members of the Microsoft.Speech.Recognition and Microsoft.Speech.Recognition.SrgsGrammar namespaces, you may also want to author grammars as static files using XML. You can create grammars in XML format using any text editor. Grammars authored using XML must conform to the Speech Recognition Grammar Specification Version 1.0 (SRGS). The Microsoft Speech Platform SDK 11 provides support for importing XML-format SRGS grammar files for use in recognition by the speech recognition engine.

You can import an entire XML-format SRGS grammar file, or only a specified rule within a grammar file, using an argument for a constructor or a method on a class in the Microsoft.Speech.Recognition or Microsoft.Speech.Recognition.SrgsGrammar namespaces. An imported SRGS grammar or rule may be used in its entirety (complete and ready to load), or as a component in a larger grammar. You can load an XML-format SRGS grammar or rule at run time using the following constructors and methods:

  • Constructors on the Grammar class.

    Import your SRGS grammar directly into a Grammar object that is ready to load by the speech recognition engine. See the Grammar() constructors.

  • AppendRuleReference() methods.

    Create a GrammarBuilder object from an XML-format grammar file, or append the file or one of its rules to the grammar defined by the GrammarBuilder object. Use the imported grammar file or rule as a complete grammar or as a component in a grammar's broader development within the GrammarBuilder object.

  • SrgsDocument(String) constructor on the SrgsDocument class.

    You can develop the grammar further in the SrgsDocument object or build it into a Grammar object for loading by the speech recognition engine.

  • Constructors on the SrgsRuleRef class.

    This class corresponds to the ruleref element as defined by SRGS. Use these constructors to create references to existing grammar files or rules, which the speech recognition engine can use at run time. See the SrgsRuleRef() constructors.

This section includes reference information and examples for creating grammars using XML. You can use the following links to learn about creating grammars, to achieve specific tasks related to speech recognition, and to get detailed information about the support for SRGS by the Speech Platform SDK 11.

In This Section

See Also

Concepts

Grammars Overview (Microsoft.Speech)