VoiceXML

 

Menus Page 1 of 6

A menu is a convenient syntactic shorthand for a form containing a single anonymous field that prompts the user to make a choice and transitions to different places based on that choice. Like a regular form, it can have its grammar scoped such that it is active when the user is executing another dialog. The following menu offers the user three choices:


<menu> 
  <prompt>Welcome home. Say one of: <enumerate/></prompt> 
  <choice next="http://www.sports.example/vxml/start.vxml"> 
     Sports
  </choice> 
  <choice next="http://www.weather.example/intro.vxml"> 
     Weather
  </choice> 
  <choice next="http://www.stargazer.example/voice/astronews.vxml"> 
     Stargazer astrophysics news
  </choice> 
  <noinput>Please say one of <enumerate/></noinput> 
</menu> 

This dialog might proceed as follows:

C: Welcome home. Say one of: sports; weather; Stargazer astrophysics news.

H: Astrology.

C: I did not understand what you said. (a platform-specific default message.)

C: Welcome home. Say one of: sports; weather; Stargazer astrophysics news.

H: sports.

C: (proceeds to http://www.sports.example/vxml/start.vxml)

Menu element

This identifies the menu, and determines the scope of its grammars. Menu attributes are:

id The identifier of the menu. It allows the menu to be the target of a <goto> or a <submit>.
scope The menu’s grammar scope. If it is dialog – the default – the menu’s grammars are only active when the user transitions into the menu. If the scope is document, its grammars are active over the whole document (or if the menu is in the application root document, any loaded document in the application).
dtmf When set to true, any choices that do not have explicit DTMF elements are given the implicit ones "1", "2", etc.

Choice element

The <choice> element serves several purposes:

Choice attributes are:

dtmf The DTMF sequence for this choice.
next The URI of next dialog or document.
event Specify an event to be thrown instead of specifying a next.
expr Specify an expression to evaluate instead of specifying a next.
caching Either safe to force a query to fetch the most recent copy of the content, or fast to use the cached copy of the content if it has not expired. If not specified, a value derived from the innermost caching property is used..
fetchaudio The URI of the audio clip to play while the fetch is being done. If not specified, the fetchaudio property is used, and if that property is not set, no audio is played during the fetch.
fetchhint Defines when the interpreter context should retrieve content from the server. prefetch indicates a file may be downloaded when the page is loaded, whereas safe indicates a file that should only be downloaded when actually needed. In the case of a very large file (implying long download times) or a streaming audio source, stream indicates to the interpreter context to begin processing the content as it arrives and should not wait for full retrieval of the content. If not specified, a value derived from the innermost relevant *fetchhint property is used.
fetchtimeout The interval to wait for the content to be returned before throwing an error.badfetch event. If not specified, a value derived from the innermost fetchtimeout property is used.

DTMF in menus. Menus can rely purely on speech, purely on DTMF, or both in combination by including a <property> element in the <menu>. Here is a DTMF-only menu with explicit DTMF sequences given to each choice, using the choice’s dtmf attribute:


<menu> 
  <property name="inputmodes" value="dtmf"/> 
  <prompt> 
   For sports press 1, For weather press 2, For Stargazer
   astrophysics press 3. 
  </prompt> 
  <choice dtmf="1"
    next="http://www.sports.example/vxml/start.vxml"/> 
  <choice dtmf="2" 
    next="http://www.weather.example/intro.vxml"/> 
  <choice dtmf="3" 
    next="http://www.stargazer.example/voice/astronews.vxml"/> 
</menu> 

Alternatively, you can set the <menu>’s dtmf attribute to true to assign sequential DTMF digits to each of the first nine choices: the first choice has DTMF "1", and so on:


<menu dtmf="true"> 
  <property name="inputmodes" value="dtmf"/> 
  <prompt> 
   For sports press 1, For weather
   press 2, For Stargazer astrophysics press 3. 
  </prompt> 
  <choice next="http://www.sports.example/vxml/start.vxml"/> 
  <choice next="http://www.weather.example/intro.vxml"/> 
  <choice 
    next="http://www.stargazer.example/voice/astronews.vxml"/> 
</menu> 

Enumerate element

The <enumerate> element is an automatically generated description of the choices available to the user. It specifies a template that is applied to each choice in the order they appear in the menu. If it is used with no content, a default template that lists all the choices is used, determined by the interpreter context. If it has content, the content is the template specifier. This specifier may refer to two special variables: _prompt is the choice’s prompt, and _dtmf is the choice’s assigned DTMF sequence. For example, if the menu were rewritten as


<menu dtmf="true"> 
  <prompt> 
    Welcome home. 
    <enumerate> 
     For <value expr="_prompt"/>, press <value
     expr="_dtmf"/>.          
   </enumerate> 
   </prompt> 
   <choice next="http://www.sports.example/vxml/start.vxml"> 
      sports </choice> 
   <choice next="http://www.weather.example/intro.vxml"> 
      weather </choice> 
   <choice next="http://www.stargazer.example/voice/astronews.vxml"> 
      Stargazer astrophysics news
   </choice> 
</menu> 

then the menu’s prompt would be:

C: Welcome home. For sports, press 1. For weather, press 2. For Stargazer astrophysics news, press 3.

The <enumerate> element may also be used analogously in prompts for <field> elements that contain a set of <option> elements as discussed in Section 14.1.3

Grammar Generation

Any choice phrase specifies a set of words and phrases to listen for. The user may say any phrase consisting of any subset of the words of the choice phrase in the same order in which they occur in the choice phrase. A choice phrase is constructed from the PCDATA of the elements contained directly or indirectly in the <choice> element. For example, in response to the prompt “Stargazer astrophysics news” a user could say “Stargazer”, “astrophysics”, “Stargazer news”, “astrophysics news”, and so on. The equivalent JSGF rule would be “[Stargazer] [astrophysics] [news]” (where […] indicates optionality).

As an example of the use of PCDATA contained in descendants of the <choice> element, consider the following example:


<choice next="http://www.stargazer.example/voice/astronews.vxml"> 
  <prompt> 
   <audio src="http://www.stargazer.example/space.wav"> 
     Stargazer <emp>astrophysics</emp> news 
   </audio> 
  </prompt> 
</choice> 

This choice would be read from the audio file, or as “Stargazer Astrophysics News” if the file could not be played. The grammar for the choice would be the equivalent of “[Stargazer] [astrophysics] [news] ” gleaned from the PCDATA of the <choice> element’s descendants.

Interpretation model

A menu behaves like a form with a single field that does all the work. The menu prompts become field prompts. The menu event handlers become the field event handlers. The menu grammars become form grammars.

Upon entry, the menu’s grammars are built and enabled, and the prompt is played. When the user input matches a choice, control transitions according to the value of the next, expr, or event attribute of the <choice>, only one of which may be specified.