Last reviewed: 3/23/2024 12:18:15 PM

<grammar>

A <grammar> element specifies a speech recognition or DTMF grammar.

Syntax

<grammar fetchhint="fetchtype"
         fetchtimeout="secondsormilliseconds"
         maxage="seconds"
         maxstale="seconds"
         mode="string"
         root="string"
         scope="scopetype"
         src="uri"
         srcexpr="expression"
         tag-format="tagtype"
         type="encodingtype"
         version="float"
         weight="float"
         xml:base="uri"
         xml:lang="langid"/>

Attributes

fetchhint

Defines when the interpreter context should retrieve content from the server. If not specified, a value derived from the innermost relevant fetchhint property is used. The default value is the grammarfetchhint property.

Fetch Type Description
prefetch Indicates a file may be downloaded when the page is loaded.
safe Indicates a file that should only be downloaded when actually needed.

fetchtimeout

The interval to wait for the content to be returned before throwing an error.badfetch event. The value is a Time Designation. The default value is the fetchtimeout property.

maxage

Indicates that the document is willing to use content whose age is no greater than the specified time in seconds. The document is not willing to use stale content, unless maxstale is also provided. If not specified, a value derived from the innermost relevant maxage property, if present, is used. The default value is the grammarmaxage property.

maxstale

Indicates that the document is willing to use content that has exceeded its expiration time. If maxstale is assigned a value, then the document is willing to accept content that has exceeded its expiration time by no more than the specified number of seconds. If not specified, a value derived from the innermost relevant maxstale property, if present, is used. The default value is the grammarmaxstale property.

mode

Defines the mode of the grammar that indicates the type of input that the user agent should be detecting. The default mode is "voice" for speech recognition grammars. An alternative input mode defined is "dtmf" input.

root

Defines the rule which acts as the root rule of the grammar.

scope

The default scope of the form's grammars. Note that the scope of individual form grammars takes precedence over the default scope; for example, in non-root documents a form with the default scope "dialog", and a form grammar with the scope "document", then that grammar is active in any dialog in the document.

Scope Type Description
dialog The form grammars are active only in the form.
document The form grammars are active during any dialog in the same document.

src

The URI specifying the location of the grammar and optionally a rulename within that grammar, if it is external. The URI is interpreted as a rule reference of the Speech Recognition Grammar Specification [SRGS] but not all forms of rule reference are permitted from within VoiceXML.

srcexpr

(2.1) Equivalent to src, except that the URI is dynamically determined by evaluating the given ECMAScript expression in the current scope (e.g. the current form item). The expression must be evaluated each time the grammar needs to be activated. If srcexpr cannot be evaluated, an error.semantic event is thrown.

tag-format

Defines the tag content format for all tags within the grammar.

Tag Type Description
semantics/1.0 The tag contents are ECMAScript
semantics/1.0-literals The tag contents are string literals.

type

The preferred media type of the grammar. A resource indicated by the URI reference in the src attribute may be available in one or more media types.

Tag Type Description
application/srgs W3C ABNF grammar format
application/srgs+xml W3C XML grammar format

version

Defines the version of the grammar.

weight

Specifies the weight of the grammar.

xml:base

Declares the base URI from which relative URIs in the grammar are resolved. This base declaration has precedence over the []<vxml>](xref:voicexmlkit-reference-vxml "Vxml Element") base URI declaration. If a local declaration is omitted, the value is inherited down the document hierarchy.

xml:lang

The language identifier of the grammar (for example, "fr-CA" for Canadian French.) If omitted, the value is inherited down from the document hierarchy.

Children

Refer to the GrammarKit documentation section entitled Grammar Syntax Quick Reference and the W3C specification Recognition Grammar Specification Version 1.0 for more information about SRGS XML grammars.

Parents

<choice>, <field>, <form>, <link>, <record>, and <transfer>.

Variables

none

Example

The following example illustrates using example elements.

<grammar type="application/srgs+xml" src="http://www.grammar.example.com/date.grxml" />

Version Information

Supported in: VoiceXML 1.0, VoiceXML 2.0, and VoiceXML 2.1.