More Ways to Order Pizza
Welcome to First Words, VoiceXML Review's column that teaches you about VoiceXML and how you can use it. We hope you enjoy the lesson.
Last month we started to develop a small pizza application. This, along with the venerable 'hello world', and some sort of screen-scraping horoscope application, seems to be the first thing that any VoiceXML developer feels compelled to build. This month we're going to take a look at other ways to implement the pizza ordering page.
Those who are just joining might want to look at last month's column. In that column, we put together a pizza-ordering page that collects a food item type, and a quantity using VoiceXML fields. In that example, we defined speech and DTMF grammars to allow input of this information.
VoiceXML provides a convenience mechanism for implementation of fields that follow this model, using the option tag. When you have an interface that allows the user to select from one of a number of well-defined options, you can use the option to enumerate these options within the field. The VoiceXML interpreter will then construct the appropriate grammars for you. Here is the first field from last month's example, converted to use the option tag.
<field name="orderItem">
<noinput>
Say pizza, drinks, salad or wings.
</noinput>
<nomatch>
You can say pizza, drinks, salad or wings.
</nomatch>
<prompt>
What would you like to order?
We have pizza, drinks, salad or wings.
</prompt>
<help>
<reprompt/>
</help>
<option dtmf="1">pizza</option>
<option dtmf="2">drinks</option>
<option dtmf="3">salad</option>
<option dtmf="4">wings</option>
</field>
|
You'll notice that we have also added the DTMF attribute to each option. This defines the DTMF keypress that will correspond to this option entry (if you don't provide a DTMF attribute, then the platform will define DTMF keys for you, in ascending order). The value assigned to the field will be the contents of the option tag (the CDATA content of the option tag, for the XML aficionados among you). This will be the case for either DTMF or speech input. You can alter the data returned using the value attribute of option, as in:
<option dtmf="1" value="pie"> pizza </pizza>
In this example, when the user said 'pizza', or pressed '1' on their keypad, the field variable would receive the value 'pie'.
The option tag is useful in defining dynamic lists (although there are those that will argue that it makes it easy to build bad voice user interfaces). There are some additional VoiceXML tags that allow generation of dynamic prompts to go along with these lists. Here is the field fragment that we showed above, taking advantage of the enumerate tag:
<field name="orderItem">
<noinput>
<prompt>
</enumerate>
</prompt>
</noinput>
<nomatch>
<prompt>
</enumerate>
</prompt>
</nomatch>
<prompt>
</enumerate>
</prompt>
<help>
<reprompt/>
</help>
<option dtmf="1">pizza</option>
<option dtmf="2">drinks</option>
<option dtmf="3">salad</option>
<option dtmf="4">wings</option>
</field>
|
This field uses the enumerate tag to generate a dynamic prompt consisting of instructions based on the elements of the option list. When the caller is presented with the prompt for the orderItem field, the prompt will be built dynamically, and will include each of the options that have been placed within the field. Although the default message format is platform dependent, it will likely be something like:
"Say pizza or press 1; say drinks or press 2; say salad or press 3; say wings or press 4"
This may or may not meet your requirement, so VoiceXML also allows you to customize the prompt further by defining a template prompt. This is contained within an enumerate element as shown below:
<prompt>
What would you like to order?
<enumerate>
Say <value expr="_prompt"/> or press <value expr="_dtmf"/>
</enumerate>
</prompt>
|
In this example, you'll hear:
"What would you like to order? Say pizza or press 1; say drinks or press 2;
say salad or press 3; say wings or press 4"
You can also use the enumerate mechanism within the menu element of VoiceXML.
There is, of course, only so much you can with this structure, so you may want to consider generating the prompts dynamically on the server side, as well as the option list.
back to the top
Copyright © 2001 VoiceXML Forum. All rights reserved.
The VoiceXML Forum is a program of the
IEEE Industry Standards and Technology Organization (IEEE-ISTO).
|