VoiceXML Developer Series: A Tour Through VoiceXML, Part II

by Jonathan Eisenzopf

In Part II of A Tour Through VoiceXML, we're going to focus on building VoiceXML applications with menus that allow callers to make selections via DTMF tones and voice commands.

Welcome back. I hope you enjoyed the last article, which was the first part of a tour through the entire VoiceXML 1.0 language. In Part II, we're going to focus on building VoiceXML applications with menus that allow callers to make selections via DTMF tones and voice commands. The results of this article can be accessed live by calling 510-315-6666.

Create voice menus with the <menu> element

Similar to HTML menu options, VoiceXML menus provide users with lists of information that are selected with DTMF or voice commands. The example below introduces a VoiceXML document than contains a menu with three options preceded by a prompt.

<vxml version="1.0">
    <prompt>What is your favorite color? 
	For red, press 1. For blue, press 2. 
	For yellow, press 3</prompt>
    <choice dtmf="1" next="red.vxml" />
    <choice dtmf="2" next="#blue" />
    <choice dtmf="3" next="yellow.vxml#yel" />

When executed, the example above will play the prompt and wait for the user to press a number on their keypad. Menus contain a list of choices. In this menu, the choices are red, blue, and yellow. The colors are selected by pressing the corresponding number on the phone keypad (1, 2, or 3). When the DTMF tone that matches the dtmf attribute is recognized, it will send the user to the VoiceXML document contained in the next attribute of the choice element. Alternatively, you can have the menu automatically assign DTMF tones to the menu choices by setting the dtmf attribute of the <menu> element to true:

<vxml version="1.0">
  <menu dtmf="true">
    <prompt>What is your favorite color? 
	For red, press 1. For blue, press 2. 
	For yellow, press 3</prompt>
    <choice next="red.vxml" />
    <choice next="#blue" />
    <choice next="yellow.vxml#yel" />

Now let's look at the next attribute of the choice element. The first next attribute points to another VoiceXML document named red.vxml. So when we press 9, the VoiceXML interpreter loads that document and executes it. The linking mechanism that makes this work is quite like HTML links. In fact, the #blue value of the next attribute inside the second <choice> element points to an internal link in the same document. The # notation for in-document references is the same as in HTML. In fact, the third <choice> points to a reference inside a VoiceXML document called yellow.vxml.

Recognizing voice commands in menus

We've learned how to browse menus with DTMF tones, but VoiceXML also enables us to create grammars for each menu choice, which will recognize speech instead of or in addition to DTMF. This is done by including a simple grammars (compared to form grammars) inside the the <choice> element.

<vxml version="1.0">
  <menu dtmf="true">
    <prompt>What is your favorite color?</prompt>
	<enumerate />
    <choice next="red.vxml">red</choice>
    <choice next="#blue.vxml">blue</choice>
    <choice next="yellow.vxml#yel">yellow</choice>

The <choice> elements in the example above contain words. The choice is matched when the VoiceXML system recognizes one of the words (red, blue, or yellow). We've also added the <enumerate /> element, which will synthesize the contents of the choices. So the user will hear:

What is your favorite color? red, blue, yellow.

The previous example only contains single word grammars, but menus may contain multiple words and phrases. The interpreter will match any combination of the phrase or words in the order that they occur. For example, the menu below contains two words each. The first choice would be matched if the user said place or order or place order.

<vxml version="1.0">
  <form id="form1">
    <block name="block1">
      <prompt bargein="true" timeout="5"
>Welcome to franks flute factory.</prompt>
      <goto next="#menu" />
  <menu id="menu" dtmf="true" scope="document">
    <prompt bargein="true">Would you like to 
place an order, check order status, or talk to 
an operator?</prompt>
    <choice next="#orders">place order</choice>
    <choice next="#check">check status</choice>
    <choice next="#operator">talk operator</choice>
    <catch event="noinput nomatch error">
Sorry, I did'nt understand.
      <reprompt />

When considering the words to include in the grammar for each choice, you should follow a few rules. First, no word should occur in more than one choice. Second, avoid using words that *sound* similar. These are words that contain similar or identical phonemes (or the sounds that make up speech). For example, if one choice contained the word mow and another choice contained more, the speech recognition software will have a hard time differentiating between the two. Use a synonym for more such as additional.

Finishing up

Technically, VoiceXML menus can be created very rapidly. Functionally, your users will be familiar with the mechanics of menus, because they are very similar to the majority of IVR applications that are in existance today.

A few other closing thoughts on menus. Include an id attribute in the <menu> element in cases where you want to be able to link to it from other sections or VoiceXML documents. Also, the scope attribute, if set to document, will turn on the menu grammars for the entire VoiceXML document. This technique can be use to create a global menu for the document. Include the menu in your root VoiceXML document to make the menu available to multiple VoiceXML documents.

Lastly, don't forget to try out the new live Voice Web site for VoiceXML Planet. It's sparse right now, but it does include the big VoiceXML example contained in the last article. Thanks for coming back. Let's keep talking and listening in the next edition of the VoiceXML Developer.

About Jonathan Eisenzopf

Jonathan is a member of the Ferrum Group, LLC based in Reston, Virginia that specializes in Voice Web consulting and training. He has also written articles for other online and print publications including WebReference.com and WDVL.com. Feel free to send an email to eisen@ferrumgroup.com regarding questions or comments about the VoiceXML Developer series, or for more information about training and consulting services.

This article was originally published on Wednesday Oct 2nd 2002
Mobile Site | Full Site