<grammar>

Description

Specifies a grammar for speech recognition or dtmf recognition.

Note that inline grammars that use the XML grammar format will be passed into the ASR engine as an XML document. When the VoiceXML page is first parsed by the interpreter, the inline grammar will be decoded. The interpreter will then re-encode the inline grammar into an XML document to pass to the ASR engine.

You must include a VXML grammar header in your VXML scripts. The correct format for an XML grammar header, according to the W3C specification, is:

xmlns="http://www.w3.org/2001/06/grammar"

Syntax


<grammar
    xml:lang="language"
    src="URI"
    srcexpr="ECMAScript_Expression"
    expr="ECMAScript_Expression"
    scope="dialog" | "document"
    type="MIME_Type"
    mode="dtmf" | "voice" | "tdd"
    root="string"
    version="version"
    weight="positive floating_point"
    tag-format="string" | "URI"
    xml:base="URI"
    fetchhint="prefetch" | "safe"
    fetchtimeout="time_interval"
    maxage="integer"
    maxstale="integer">
  inline grammar
</grammar>

Attributes

Attribute

Description

xml:lang

The language identifier of the grammar. The list of supported values for this attribute depends on the ASR engine being used. Optional.

src

The URI specifying the location of the grammar file. The URI can be one of the following formats:

  • External grammar file: URL of the grammar file
  • Built-in grammars: builtin:grammar/type (refer to <field> element for built-in types)

Optional. Exactly one of src, srcexpr, expr, or an inline grammar must be specified.

srcexpr

An ECMAScript expression to be evaluated and used as the URI of the grammar file, as documented under src, above.

Optional. Exactly one of src, srcexpr, expr, or an inline grammar must be specified.

This VoiceXML 2.1 feature will be ignored if the <vxml> version attribute is set to a value lower than 2.1 (i.e. 2.0 or 1.0).

expr

An ECMAScript expression to be evaluated and used as the URI of the grammar file, as documented under src, above.

Optional. Exactly one of src, srcexpr, expr, or an inline grammar must be specified.

This attribute was added as an extension to VoiceXML 2.0. It can only be used if the <vxml> version attribute is set to a value lower than 2.1 (i.e. 2.0 or 1.0). When the <vxml> version attribute is set to 2.1, the srcexpr attribute must be used instead of expr; using expr will cause an error.badfetch event to be thrown.

scope

The scope of the grammar. This attribute can be defined only if the <grammar> element is the child of a <form> or <menu> element. Optional. (Defaults to dialog.)

  • dialog - This grammar is only active within the form.
  • document - This grammar is active throughout the document. If the current page is is an application root document, then the grammar is active throughout the application.

type

The MIME type of the grammar format. The supported types (and default values) for this attribute depend on the ASR engine being used.

mode

The mode of the grammar. Optional. (Defaults to voice.)

  • voice - voice input
  • dtmf - DTMF input (replaces the <dtmf> element)
  • tdd - TDD input (not currently supported on the IP Media Server platform).

root

The root rule of the grammar. The default value depends on the ASR engine being used. Optional.

version

The version of the grammar. Optional. (Defaults to 1.0.)

weight

The weight of a grammar, which indicates the likelihood of using a grammar. This value is passed to the ASR engine and affects the actual recognition results returned by the ASR engine; it is not used by the VoiceXML interpreter to process recognition results after they have been returned by the ASR engine. Different ASR engines and VoiceXML platforms treat weights differently. This attribute is not supported for DTMF grammars and implicit grammars (i.e. <grammar> elements as children of <option> or <choice> tags). The range of values depends on the ASR engine, but it is usually 0.0 to 1.0.

Optional. (Defaults to 1.0.)

 

tag-format

The format that will be used to define tags, for slot filling. Support for this attribute depends on the ASR engine being used.

xml:base

Declares the base URI from which relative URIs in the grammar are resolved. This base declaration has precedence over the <vxml> base URI declaration. Note that if a local declaration is omitted, the value will not be inherited down the document hierarchy. Also note that this attribute can only be used in external grammars, and support depends on the ASR engine being used. Optional.

fetchhint

Defines when the grammar file should be fetched. Optional.

  • prefetch - grammar file may be downloaded when the page is loaded
  • safe - only load the grammar file when needed

fetchtimeout

The length of time to wait for the grammar file to be fetched before throwing an error.badfetch event. Optional.

maxage

Indicates that this document is willing to use a cached copy of the grammar file only while the age of the cached copy is less than or equal to the number of seconds specified by this attribute. Optional.

maxstale

Indicates that this document is willing to use a cached copy of the grammar file that has exceeded its expiration time by as much as the number of seconds specified by this attribute. Optional.

Attribute Notes

Parents

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

Children

#PCDATA

Extensions

Limitations/Restrictions