VoiceXML Adventure Game

Before we proceed any further, we need to talk a bit more about
grammars. They are a very important part of any VoiceXML document. A grammar is
a set of expressions that define what DTMF tones and spoken input will be
recognized by the system. These grammars are limited to what you program them
to recognize. Depending on where you place the grammar, the scope can be the
whole document, a form, or a field within a form. The Tellme grammar syntax
uses the Nuance Grammar Specification Language (GSL).

It's not too difficult to define a simple grammar that allows a
user to make a selection via DTMF tones. Let's define a simple grammar that
provides our users with the option to open one of three doors in our adventure.

First, grammars are placed within the grammar
element. You should also surround the grammar with a CDATA
section, which tells the XML parser not to process the text inside. In the
grammar above, we have defined three options. Each option is defined by a
grammar statement. The statement consists of an expression to be matched, and the
corresponding value to return when a match occurs.

The expression used to match a digit is: dtmf-$ where
$ is the number we want to match. For example,
dtmf-1 would be
matched if a user presses 1 on their telephone keypad.

The second part of the expression defines the value that will be
returned when we get a match. For example, {<option "foo">} will
return the text foo when the user input matches
the first part of the expression.

Next we're going to apply this simple grammar to a real
VoiceXML document.

Getting DTMF Input

The first version of our adventure game below will only accept DTMF input. The user can select
1, 2, or 3, which corresponds with one of the three doors.

For more information on using the filled and
result elements, please see
Page 3 of the first
part of this tutorial. You might have also noticed the pause
element in the example above. Using the element forces Tellme.com to pause
between prompts. In this case, we want to stop for 300 milliseconds between
options to duplicate the pause that would occur in natural speech.