Lesson 4: Menus

Lesson goal: Specify menus

Contents

4.1. The <menu> Element
Goal: Ask users to select from among several options

4.2. The <choice> Element
Goal: Specify choices the user may speak

4.3. The <enumerate> Element
Goal:  Generate prompt messages for a <menu> element automatically

4.4. Review Questions

Menus are a simplest type of dialog in VoiceXML. A menu presents several choices to the user, who selects a choice by speaking. Like visual menus, VoiceXML menus enable users to navigate to the relevant part of the voice application or supply one of several values for information requested by the application.

Menus require almost no user training. Users simply answer the question posed by the VoiceXML dialog by speaking. Two principal elements are used to specify menus: the <menu> element which prompts to the user to speak by asking a question, and several <choice> elements which identify possible options the user may select by speaking. Each <choice> option specifies a branch instruction in the event that the user should select that choice.

4.1. The <menu> Element

Goal: Ask users to select from among several options

Purpose: The <menu> element enables the user to choosing from among several alternative destinations.

Attributes: The  <menu> element has the following attributes:
  • id—Identifies the menu.  
  • scope—Indicates where the grammars associated with the choices in this menu are active within the application. Possible values are:
    • dialog—(the default) The grammars are only active when the user is interacting with this menu. 
    • document—This option makes the grammar active across the entire document. If the document happens to be an application root document, then the grammar is active across all documents in the application. If the user speaks a value from one of these menus while in another menu or document, then the user will transition to the selected location.
  • dtmf—Specifies that users may press the buttons on a touchtone telephone to enter their choices.  Possible value are:
    • true—The first nine choices are implicitly numbered 1, 2, …, 9.   
    • false—(the default) There is no implicit numbering of choices.  
      Choices within the <choice> element are implicitly numbered and may be included in the <prompt> element by using the <enumerate> element discussed in Section 4.3. 
  • accept—Determines if the recognition engine has recognized words and phrases described by this grammar. The possible values are:  
    • exact—(the default) Specifies that the spoken phrase must match the grammar exactly.
    • approximate—Specifies that the spoken phrase matches a subphrase contained in the grammar. For example, if the grammar contains the phrase "bob lewis", then the following phrases will be matched:
                            bob
                            lewis
                            bob lewis

Parent Element: The <menu> element has the parent element <vxml>.

Child Elements: The <menu> element may have the the following child elements: the audio elements (<enumerate>, <value>, <audio>), the event handler elements (<choice>, <help>, <noinut>, <nomatch>, <error>), <choice>, <property>, and <prompt>.

A menu solicits a single value in response to a prompt and then branches to various locations depending upon which options the user selected. The following menu was shown in Figure 4-1 in Lesson 3:

<!-- 1 -->  <?xml version="1.0"?>                           
<!-- 2 -->  <vxml version="2.0">                         

<!-- 3 -->  <menu id="travel">                                
<!-- 4 -->       <prompt>                                    
<!-- 5 -->             Do you  want to travel by airplane, rail, or boat?           
<!-- 6 -->       </prompt>                                    
<!-- 7 -->       <choice next="#process_airplane">airplane </choice>                                  
<!-- 8 -->       <choice next="#process_rail"> rail </choice>                                    
<!-- 9 -->       <choice next="#process_boat"> boat </choice>                                    
<!-- 10 --> </menu>                                    

<!-- 11 --> <form id = "process_airplane">                               
<!-- 12 -->     <block><prompt>You said airplane.  Goodbye. </prompt></block>         
<!-- 13 --> </form>                                   

<!-- 14 --> <form id = "process_rail">                               
<!-- 15 -->     <block><prompt>You said train.  Goodbye. </prompt></block>              
<!-- 16 --> </form>                                   

<!-- 17 --> <form id = "process_boat">                               
<!-- 18 -->     <block><prompt>You said boat.  Goodbye. </prompt></block>              
<!-- 19 --> </form>                                   

<!-- 20 --> </vxml>         

Figure 4-1:  Example VoiceXML menu
 

The menu (lines 3–10) begins with a prompt (lines 4–6). The dialog manager instructs the speech synthesizer to render the wording of the prompt as voice.  

The dialog manager instructs the speech speech recognizer to listen for three sets of spoken words (lines 7–9). If the caller utters the word “airplane” specified in the <choice> phrase in line 10, the dialog manager transitions to the process_plane form (lines 11–13). The word “rail” will cause the dialog manager to transition to the process_rail form (lines 14–16), and a the world “boat” will cause the dialog manager to transition to the process_boat form (lines 17–19). The plane, train, and boat forms only present a message to the caller indicating which mode of transportation the caller selected. In a real application, these forms would be more complex.  

A menu is really a  type of form that contains a single field, prompts the user to make a choice, and then transitions to the appropriate location in the VoiceXML application based on the users choice.

The general format of a <menu> element, illustrated below in Figure 4-2, contains a <prompt> element and multiple <choice> elements. The <prompt> element presents a message to the user, who responds by saying on of the phrases in the <choice> elements.  

<menu id = "value">
     <prompt> prompt message </prompt>
     <choice list of attributes> choice phrase 1 </choice>
     <choice list of attributes> choice phrase 2 </choice>
     ...
     <choice list of attributes> choice phrase n </choice>

</menu>

Figure 4-2:  General Format of a <menu> Element

Exercise 4-1

Specify a <menu> element with the identifier transaction, grammars are active while the user is interacting with the entire document, and recognizes the exact words specified in the grammar.  

Answer to Exercise 4-1
Exercise 4-2

Rewrite the menu in Figure 4-1 above using DTMF only as input.

Answer Exercise 4-2

4.2. The <choice> Element

Goal: Specify choices the user may speak

Each <menu> element contains two or more <choice> elements. Each <choice> should specify an option which the user selects by speaking or pressing the keys on a touchtone telephone. In addition, the application developer should also:

The general format of a <choice> element is   

<choice list-of-attributes> choice-phrase </choice>

The user speaks the choice-phrase to select this choice. The choice phrase describes the words that the user speaks to select an option (subject to the accept attribute).

Purpose: The <choice> element defines an option within a <menu> element.

Attributes: Attributes for the <choice> element are:
  • dtmf—The  DTMF key (or keys) the user must press to select an option. For example:
    • <choice dtmf = "1" means the user should press 1 to select this choice
  • accept—An override of the setting for the accept attribute in the <menu> element containing this element. For example:
    • <choice accept = "exact">
    • <choice accept = "approximate">
  • next—The Universal Resource Identifier (URI) that identifies the location of the next dialog or document to be processed. For example:
    • <choice next = "myexample/document3.vxml">
  • expr—The ECMAScriptexpression that evaluates to a URI to transition to (rather than specifying next attribute). For example:
    • <choice expr = "'myexample/document' + count + '.vxml'">
  • event—An event to be thrown instead of transitioning to a specific dialog or document:
    • <choice event = "error.application_specific_error_4">
  • eventexpr—An ECMAScript expression that evaluates to the name of the event to be thrown:  
    • <choice eventexpr = "'error.application_specific_error_' +  error_index">
  • message—A message string that contains additional information about the event being thrown:
    • <choice message = "application detected an illegal operation: vector index exceeded">
  • messageexpr—An ECMAScript expression that evaluates to a message string:
    • <choice message = "'application detected the illegal operation:" +  index(4)">
  • fetchaudio, fetchhint, fetchtimeout, maxage, maxstale—Cache optimization parameters to be discussed in Lesson 12 Resource Management.
Parent element: The <choice> element only hasone parent element, <menu>.

Child Element: The <choice> element may have any of the following elements as a child elements: SRGS grammars.

The following <choice> element passes the message "application detected an illegal operation:" following by the value of index(4) and branches to the document www.mydocument3.vxml when the user speaks exactly the words for sure or presses the 1 key:

<choice>  
      dtmf = "1"
      next = "www.mydocument3.vxm."
      accept = "exact"
      message =  "'application detected the illegal operation:' +  index(4)">
          for sure
</choice>
Exercise 4-3

Construct a <menu> element with a <prompt> and three <choice> elements that transitions the user to:
  • http//:www.myapps/radio_guide.vxml if the user says radio
  • http//:www.myapps/television_guide.vxml if the user says television
  • http//:www.myapps/movie_guide.vxml if the user says movies
Answer to Exercise 4-3

Figure 4-3 below illustrates a menu using both DTMF and voice, so the user can either press the keys on the touchtone phone or speak the option:

<!-- 1 -->  <?xml version="1.0"?>                           
<!-- 2 -->  <vxml version="2.0">                         

<!-- 3 -->  <menu id="travel">                                
<!-- 4 -->       <prompt>                                    
<!-- 5 -->             Press the key or speak one of the following options:
                             One, plane.
                             Two, train.
                             Three, boat. 
         
<!-- 6 -->       </prompt>                                    
<!-- 7 -->       <choice dtmf = "1" next="#process_airplane"> airplane </choice>
<!-- 8 -->       <choice dtmf = "2" next="#process_rail"> train </choice>                                    
<!-- 9 -->       <choice dtmf = "3" next="#process_boat"> boat </choice>                                    
<!-- 10 --> </menu>                                    

<!-- 11 --> <form id = "process_airplane">                               
<!-- 12 -->     <block><prompt>You said airplane.  Goodbye. </prompt></block>         
<!-- 13 --> </form>                                   

<!-- 14 --> <form id = "process_rail">                               
<!-- 15 -->     <block><prompt>You said train.  Goodbye. </prompt></block>              
<!-- 16 --> </form>                                   

<!-- 17 --> <form id = "process_boat">                               
<!-- 18 -->     <block><prompt>You said boat.  Goodbye. </prompt></block>               
<!-- 19 --> </form>                                   

<!-- 20 --> </vxml>            

Figure 4-3: Example Menu Using Both DTMF and Voice

4.3. The <enumerate> Element

Goal: Generate prompt messages for a <menu> element automatically

The <enumerate> element is just a shorthand notation for a sequence of choice commands that are generated by the VoiceXML processor. It automatically assigns a DTMF number to each choice, so the developer doesn't need to renumber all of the choices if a choice is inserted or deleted. I consider the <enumerate> element an optional advanced VoiceXML feature which can be learned and used after mastering the more fundamental VoiceXML elements.

Purpose: The <enumerate> element automatically generates a description of the choices available to the users.

Attributes: The <enumerate> element has no attributes.  

Parent Elements: The <enumerate> elementmay have any of the following as parent elements: <audio>, <catch>, <choice>, <error>, <field>, <filled>, <help>, <if>, <initial>, <menu>, <noinput>, <nomach>, <object>, <prompt>, <record>, <subdialog>, or <transfer>.

Child Elements: The <enumerate> element many have any of the following as child elements:  <audio>, <enumerate>, <log>, and <value>.

Rather than explicitly specify the prompt message to enumerate each DTMF option, it is possible to automatically generate a prompt listing the choices. The <enumerate> element specifies a template that generates a prompt message for each <choice> element. This template may refer to two special variables whose values are inserted into the <prompt> text:

  1. _prompt—The word in the text portion of the <choice> statement. This is the word the user speaks to select an option. The use of _prompt is shown in red text below in Figure 4-4.
  2. _dtmf—The position of the <choice> element within sequence of <choice> elements. The use of _dtmf is shown in green text below in Figure 4-4.

Figure 4-4 illustrates an example of the <enumerate> element. The text in red illustrates the use of the _prompt to extract words from the text of each <choice> element and insert the words into the prompt message. The text in green illustrates the use of _dtmf  to insert the position number of the <choice> element within the <menu> element into the prompt message.

<menu id = "department" dtmf="true">
     <prompt>
          <enumerate>
                 For the <value expr = "_prompt"/> department, press <value expr = "_dtmf"/>.
          </enumerate>

     </prompt>
     <choice next = "mydocument.account.vxml"> accounting</choice>
     <choice next = "mydocument.sales.vxml"> sales </choice>
     <choice next = "mydocument.inventory.vxml"> inventory </choice>
</menu>

Figure 4-4:  Example use of <enumerate>, _prompt, and _dtmf

The above <enumerate> element will present the following as a prompt to the user:

        For the accounting department, press 1.
        For the sales department, press 2.
        For the inventory department,  press 3.

Figure 4-5:  Prompt Generated by the <enumerate> Element in Figure 4-4.

where the words accounting, sales, and inventory are the three words that the user may select, with accounting as the text in the first <choice> element, sales in the text of the second <choice> element, and inventory in the text of the third <choice> element.

Exercise 4-4

Rewrite Figure 4-6 below using the <enumerate> element.

<!-- 1 -->  <?xml version="1.0"?>                           
<!-- 2 -->  <vxml version="2.0">                         
<!-- 3 -->
<!-- 6 -->  <menu id="travel">                                
<!-- 7 -->       <prompt>                                    
<!-- 8 -->            To travel by plane, press 1
                           To travel by train, press 2
                           To travel by boat, press 3 
<!-- 9 -->       </prompt>                                    

<!-- 10 -->    <choice dtmf = "1" next = "#plane"> plane </choice>                               
<!-- 11 -->    <choice dtmf = "2" next = "#rail"> train </choice>                                       
<!-- 12 -->    <choice dtmf = "3" next = "#boat">boat </choice>                                 
<!-- 13 --> </menu>                                    

<!-- 14 --> <form id = "plane">                               
<!-- 15 -->     <block><prompt>You said airplane.  Goodbye. </prompt></block>           
<!-- 16 --> </form>                                   

<!-- 17 --> <form id = "rail">                               
<!-- 18 -->     <block><prompt>You said train.  Goodbye. </prompt></block>               
<!-- 19 --> </form>                                   

<!-- 20 --> <form id = "boat">                               
<!-- 21 -->    <block> <prompt>You said boat.  Goodbye. </prompt> </block>              
<!-- 22 --> </form>                                   

<!-- 23 --> </vxml>       

Figure 4-6.  Example Menu Using DTMF

Answer to Exercise 4-4

4.4.  Review Questions

Lesson Summary. Menus are the simplest type of dialog in VoiceXML and are easy to understand and implement. Using menus you can develop VoiceXML applications that collect information form a user to determine where the user’s telephone call should be routed or what segment of a VoiceXML application should process the remainder of the user’s request.

After you understand the concepts in this chapter, have completed the exercises, and answered the review questions, you are ready to begin with a more powerful (and more complex) dialog—the <form> element in Lesson 5: Forms and the Form Interpretation Algorithm (FIA).







© 2002 Larson Technical Services