A simple VoiceXML example

The following example illustrates the basic dialog capabilities of VoiceXML using a menu and a form:

<?xml version=“1.0” encoding="iso-8859-1"?>
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml" xml:lang="en-US">
 
   <menu>
      <prompt>Welcome to the online banking super store.</prompt>
      <prompt>Please choose from the following choices.<enumerate/></prompt>
      <choice next=“http://www.yourbank.example/locations.vxml”>
         Branch Locations
      </choice>
      <choice next=“http://www.yourbank.example/interest.vxml”>
         Interest Rates
      </choice>
      <choice next=“#invest”>
         Investment Information
      </choice>
   </menu>
 
   <form id=“invest”>
      <field name=“investment_amount” type=“currency”>
         <prompt>
            How much would you like to invest?
         </prompt>
      </field>
 
      <field name=“zip_code”> 
         <grammar mode="dtmf" src="builtin:dtmf/digits"/>
         <prompt>Use your telephone keypad to enter the five-digit ZIP code 
            of your location, followed by the # key.
         </prompt>
      </field>
      <filled>
         <submit next=“http://www.yourbank.example/servlet/invest” 
                     namelist=“investment_amount zip_code” />
      </filled>
   </form>
</vxml>

Each menu or form field in a VoiceXML application must define a set of acceptable user responses. The menu uses <choice> elements to do this, while the <field> elements in the above example use the type attribute and the <grammar> element to specify built-in grammars (here, “currency” and “digits”). You can also create your own application-specific grammars. (See Grammars.)

The resulting dialog can proceed in numerous ways, depending on the user's responses. Two possible interactions are described next.