<grammar>

Specifies the valid spoken utterances and corresponding string values returned in response to the utterances.

Syntax

<grammar
    fetchhint = "{prefetch | safe}"
    fetchtimeout = "CDATA"
    maxage = "CDATA"
    maxstale = "CDATA"
    mode = "{voice | dtmf}"
    root = "CDATA"
    scope = "{document | dialog}"
    src = "URI"
    srcexpr = "CDATA"
    tag-format = "CDATA"
    type = "CDATA"
    version = "CDATA"
    weight = "CDATA"
    xml:lang = "locale identifier"
    xml:base = "URI"
    xmlns = "CDATA"
    xmlns:xsi = "CDATA"
    xsi:schemalocation = "CDATA"
/>

Attributes

None of the <grammar> attributes are required.

Attribute

Data Type

Required?

Default

Description

fetchhint

{prefetch | safe}

no

None.

Specifies when the VoiceXML Interpreter context should retrieve content from the server. Valid values:

  • prefetch = Fetch the resource when the page is loaded.

  • safe = Fetch the resource when it is specifically called by the application.

fetchtimeout

CDATA

no

NA

Time interval to wait for the content to be returned before throwing an error.badfetch event. Use s for seconds (for example, 1s) and ms for milliseconds (for example, 1ms).

maxage

CDATA

no

NA

Maximum acceptable age, in seconds, of a resource being fetched from the cache. Setting maxage to 0 means that a cached version is never considered fresh.

maxstale

CDATA

no

NA

Maximum acceptable staleness, in seconds, of the resource being fetched, if the fetched resource is cached and expired.

mode

{voice | dtmf}

no

voice

Input type this grammar recognizes. Valid values:

  • voice = Grammar recognizes voice input.

  • dtmf = Grammar recognizes DTMF input.

root

CDATA

no

NA

Root rule for the document.

scope

{document | dialog}

no

dialog

Scope for the grammar contained in the form. Valid values:

  • document = Grammar is active throughout the current document.

  • dialog = Grammar is active only in the current form.

src

URI

no

NA

URI of the grammar file.

srcexpr

CDATA

no

NA

ECMAScript expression that evaluates to the URI of the grammar file.

tag-format

CDATA

no

semantic/1.0-literals

Tag format of the grammar.

type

CDATA

no

NA

MIME type of the grammar. If omitted, the VoiceXML Interpreter attempts to determine the type dynamically. The type attribute can also specify the character encoding of the grammar, as follows:

type="application/srgs+xml;
    charset=UTF-8"
.

version

CDATA

no

1.0

Currently not supported.

weight

CDATA

no

NA

Currently not supported.

xml:lang

locale identifier

no

NA

Language and locale of the document, using an identifier compliant with RFC 1766.

xml:base

URI

no

NA

Base URI from which relative URIs in the grammar are resolved.

xmlns

CDATA

no

NA

(Stand-alone SRGS XML documents only) Designated namespace for the SRGS XML format.

xmlns:xsi

CDATA

no

NA

(Stand-alone SRGS XML documents only) Used with the xsi:schemalocation attribute to indicate the location of the schema for the SRGS XML namespace.

xsi:schemalocation

CDATA

no

NA

Used with xmlns:xsi attribute to indicate the location of the schema for the SRGS XML namespace.

Details

The XML form of the Speech Recognition Grammar Specification (SRGS) is also supported in VoiceXML 2.1 applications.

Parents

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

Children

<lexicon>, <meta>, <rule>

Example

<?xml version="1.0"?>
<vxml version="2.1" xmlns="http://www.w3.org/2001/vxml">
    <form id="creditCard">
        <field name="cardtype">
            <prompt>Which credit card type ?</prompt>
            <grammar type="application/srgs+xml" root="cardtype">
                <rule id="cardtype">
                    <one-of>
                        <item>american express <tag>amex</tag></item>
                        <item>master card <tag>mc</tag></item>
                        <item>visa <tag>visa</tag></item>
                      </one-of>
                </rule>
            </grammar>
            <noinput count="1">
                Sorry I didn't hear you 
                <reprompt/>
            </noinput>
            <noinput count="2">
                Sorry still didn't hear you 
                <reprompt/>
            </noinput>
            <nomatch count="1">
                <prompt>
                    Sorry I didn't understand please repeat the card type
                </prompt>
            </nomatch>
            <nomatch count="2">
                <prompt>
                  I still don't understand please select either american 
                    express or master card or visa
                </prompt>
            </nomatch>
            <filled namelist="cardtype">
                <prompt>
                    You selected <value expr="cardtype"/>
                </prompt>
            </filled>
        </field>
    </form>
</vxml>

See Also

<form>