A complete discussion of grammar syntax is beyond the scope of this Programmer's Guide. The information provided in this section is merely to acquaint you with the basics of writing grammars. The VoiceXML browser supports both SRGS XML format and SRGS ABNF. The examples in this section are in the XML format.
<grammar version="1.0" type="application/srgs+xml" root="startHere" mode="dtmf">A standalone grammar header would include additional information, including the XML namespace:
<grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar" mode="voice" root="citystate" tag-format="semantics/1.0">
For external grammars, the mode attribute must be specified on the grammar tag within the VoiceXML document as well as in the header of the external grammar.
<rule id="rulename" scope="rule-scope"> rule contents </rule>
<rule id="direction" scope="public"> <one-of> <item>left</item> <item>right</item> </one-of> </rule>
Comments within a grammar are the same as they are anywhere in an XML document. They start with the characters<!-- and end with -->. For example:
<!-- this is a comment -->
<grammar src="citystate.grxml#citylist"/>
The following example defines an inline DTMF grammar that enables the user to make a selection by pressing the numbers 1 through 4, the asterisk or the pound sign.
<grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar" mode="dtmf" root="digits" tag-format="semantics/1.0"> <rule id="digits"> <one-of> <item>1</item> <item>2</item> <item>3</item> <item>4</item> <item>*</item> <item>#</item> </one-of> </rule> </grammar>If you are using external grammars, make sure you include the mode=“dtmf” attribute in the <grammar> element.
You can also use the bargein=dtmf_only attribute of the <prompt> element to enable the user to stop the audio output by pressing any DTMF key. See Comparing barge-in detection methods