Compile Grammar Command-Line Syntax

The command-line syntax for CompileGrammar.exe has the following format.

CompileGrammar /In <input file name> /Out <output file name> /InFormat <format of input file>

The following table describes the command-line option names and values for Prepare Grammar.exe.

Option Name



Required. The file name and extension of the grammar file to compile, for example "MyGrammar.grxml" or “”.


Optional. The file name and extension of the compiled grammar file, for example "MyGrammar.cfg". Files of the CFG format are optimized for the speech platform.

If no output file is specified, a file with the name <inputfilename>.cfg is created, and the output is sent to it.


Optional. The format of the input file. Acceptable values are SRGS and ARPA. The default file format is SRGS. SRGS files must be in XML format.


Optional. The name of the configuration file to use for the speech recognition engine. If not specified, the tool will look for a default configuration file named “RecoConfig.xml” in the current working directory and in the directory that contains CompileGrammar.exe. The tool will generate an error if you do not supply it with a configuration file.


Optional. Displays a list of acceptable option/value pairs.

  • Command-line options and values are not case-sensitive.

  • Command-line options can be preceded by a forward slash (0x002F), a dash (0x002d), an en dash (0x2013), an em dash (0x2014), or a horizontal bar (0x2015).

  • You can enter option/value pairs in any sequence.

Caution noteCaution

If an existing file has the same name as the file name specified by the /Out option, it will be overwritten. The tool does not warn that a file will be overwritten.

You must either specify a recognition engine configuration file using the /RecoConfig option, or create a default configuration file named "RecoConfig.xml" either in the current directory (the directory for the command line) or in the directory that contains CompileGrammar.exe. Use the configuration file to specify a speech recognition engine to use, to configure the parameters for connecting to it, and to configure its behavior. For more information, see Setting Up the Grammar Development Tools.

CompileGrammar.exe will follow rule references to external documents. For example, if MyGrammar.grxml contains a reference to a rule in MyExternalGrammar.grxml, the rule contained in MyExternalGrammar.grxml is included in MyGrammar.cfg.

It is an accepted convention to use the .grxml file extension for XML-based grammar documents that conform to the Speech Recognition Grammar Specification (SRGS) Version 1.0.

For ARPA-format source grammars only, the Compile Grammar tool will look for a language declaration in the configuration file specified by the /RecoConfig option. The Compile Grammar tool will use the language declaration in the configuration file to set the language of the compiled grammar file. You can specify the language for a grammar file compiled from ARPA source in the enginerequiredattributes attribute of the properties element in the configuration file. See Speech Recognition Engine Configuration File Settings. If the configuration file does not declare a language, then the language of the compiled file will be US English.

The following is an example command-line entry for CompileGrammar.exe.

CompileGrammar /In InputFile.grxml /InFormat SRGS /Out OutputFile.cfg