February 20, 2019
Hot Topics:

VoiceXML Adventure Game

  • December 1, 2002
  • By Jonathan Eisenzopf
  • Send Email »
  • More Articles »

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.

            [dtmf-1] {<option "door1">}
            [dtmf-2] {<option "door2">}
            [dtmf-3] {<option "door3">}

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.

An example user session follows:

Tellme: You are in a small room with three doors.

Tellme: To open the first door, press 1.

Tellme: To open the second door, press 2.

Tellme: To open the third door, press 3.

User: (pressed 1)

Tellme: You see a large hungry monkey.

Now, let's take a look at the VoiceXML document.

Example 1.

<?xml version="1.0"?>
<vxml version="1.0">
<field name="answer">
[dtmf-1] {<option "door1">}
[dtmf-2] {<option "door2">}
[dtmf-3] {<option "door3">}
<prompt><audio>You are in a small room with three doors.</audio>
<pause>300</pause> <audio>To open the first door, press 1.</audio>
<pause>300</pause> <audio>To open the second door, press 2.</audio>
<pause>300</pause> <audio>To open the third door, press 3.</audio></prompt>
<result name="door1">
<audio>You see a large hungry monkey.</audio>
<result name="door2">
<audio>You see another room with three doors, a man, and his monkey.</audio>
<result name="door3">
<audio>You see a man scratching his monkey.</audio>

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.

Page 2 of 7

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date