<grammar>

<grammar>

The <grammar> element is used to provide a speech (or DTMF) grammar that:

  • Specifies a set of utterances or DTMF key presses that a user may speak or type to perform an action or supply information.

  • Returns a corresponding semantic interpretation for a matching input.

Attributes

NameData typeDescription

fetchhint

This attribute is not supported.

fetchtimeout

String

(defaults to “fetchtimeout” global property value) The timeout for fetches. Must be specified with the appropriate time units (e.g., “120s” for 120 seconds).

maxage

String

(defaults to “grammarmaxage” global property value) Tells the platform the maximum acceptable age, in seconds, of cached grammars.

maxstale

String

(defaults to “grammarmaxstale” global property value) Tells the platform the maximum acceptable staleness, in seconds, of expired cached grammars.

scope

String

Accepted values include "document" or "dialog".

“document” makes the grammar active in all dialogs of the current document (and relevant application leaf documents).

“dialog” makes the grammar active throughout the current form. If this attribute is omitted, the grammar scoping is resolved by looking at the parent element.

src

String

The URI specifying the location of the grammar.

Specifying the rule name within the URI is not supported. If you wish to load a particular rule from a grammar, declare that rule “public”.

See Section 3.2 for details.

srcexpr

String

Dynamically determine the URI to fetch by evaluating this ECMAScript expression.

type

String

The media type of the grammar. Supported values are “application/x-jsgf” and “application/srgs+xml”.

This attribute takes precedence over other possible sources of the media type (for instance, the “Content-type” field in an HTTP or RTSP exchange, or the file extension).

xml:base

String

Declares the base URI from which relative URIs are resolved.

tag-format

This attribute is not supported.

version

This attribute is not supported.

xml:lang

String

The language declaration provides the language identifier that indicates the primary language contained by the grammar and optionally indicates a country or other variation.

root

String

Declares a single rule to be the root rule of the grammar. Becomes required when specifying inline SRGS+XML grammars.

The declared rule 1) must be defined within the scope of the grammar and 2) may be scoped as either public or private.

mode

String

Defines the type of grammar to be loaded. Accepted values are “dtmf” or “voice”.

weight

Integer

Specifies the weight of the grammar.

maxdigits

String

Specifies the maximum digits allowed for your grammar.

Can be used with the property type, termmaxdigits.

Notes

Plum DEV includes support for JSGF and SRGS+XML. The default grammar format is JSGF. Grammar types are specified using the “type” attibute. For JSGF, use “application/x-jsgf” and for SRGS+XML, use “application/srgs+xml”.

Example

<?xml version="1.0"?>
<vxml version="2.0">
  <form>
    <field name="myfield">
      <!-- Multiple grammars can be specified either by including -->
      <!-- several grammar blocks within the field item or by -->
      <!-- specifying a built-in grammar with the "field" tag's -->
      <!-- "type" attribute. -->
      <grammar type="application/x-jsgf" mode="dtmf">
        ( 1 | 2 )+
      </grammar>
      <grammar type="application/x-jsgf" mode="voice">
        ( one | two )+
      </grammar>
      <prompt>
        Say or enter any number of the digits one or two.
      </prompt>
      <filled>
        You entered <value expr="myfield"/>.
      </filled>
      <nomatch>
        You did not say or enter any ones or twos.
        <reprompt/>
      </nomatch>
      <noinput>
        You did not enter anything.
        <reprompt/>
      </noinput>
    </field>
  </form>
</vxml>

The output of the above script would be:

Computer: Say or enter any number of the digits one or two. Human: (enters DTMF-5) Computer: You did not say or enter any ones or twos. Computer: Say or enter any number of the digits one or two. Human: (silently waits for prompt to timeout) Computer: You did not enter anything. Computer: Say or enter any number of the digits one or two. Human: One two one two. Computer: You entered one two one two.

Child Tags

<lexicon>, <meta>, <metadata>, <rule>

Parent Tags

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

Last updated