Larson Technical Services: Voice Technology Consulting

Exercise 10.5

Construct and demonstrate a mixed-initiative version of a dialog in which the caller can order between one and five cans of either Pepsi or Coke.


<?xml version="1.0"?> 

<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" 
 "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
 <vxml version="2.0" xmlns = "http://www.w3.org/2001/vxml">

<!-- exercise 10.5 mixed initiative   -->
<!-- get cans of pepsi or coke-->
<!-- get drink  --> 

<script>

     <![CDATA[

          var drink_size = new Array();
          var drink_content = new Array();  

          // set listindex
          var drink_list_index  = 0;  
     ]]>

</script>

<form id = "get_drink">
<grammar type = "application/grammar+xml" 
          src="cans.grxml"/>  

<initial name = "start">
     <prompt>
          How many cans of coke or pepsi do you want?
     </prompt>
</initial>  

<field name = "current_drink_content">
     <prompt>
          Coke or pepsi?
     </prompt>
     <grammar type = "application/grammar+xml" 
          src="cans.grxml#drink_kind" />
</field>

<field name = "current_drink_size">
     <prompt>
          Number of cans? 
     </prompt>
     <grammar type = "application/grammar+xml" 
          src = "cans.grxml#number_cans"/>
</field>

     <filled>
          <script>

          <![CDATA[

               drink_size[drink_list_index] = current_drink_size;
               drink_content[drink_list_index] = current_drink_content;
               drink_list_index = drink_list_index + 1;

          ]]>

          </script>
     <goto next="#another_drink"/>
     </filled>
</form>

<form id="another_drink">
     <field name="more">
          <prompt>do you want more? </prompt>
               <grammar type = "application/grammar+xml" root = "yes_no">
                    <rule id = "yes_no" scope = "public">
                         <one-of>
                              <item> yes </item>
                              <item> no </item>
                         </one-of>
                    </rule>
               </grammar>
          <filled>
               <if cond = "more == 'yes'"> 
                    <goto next="#get_drink"/>
               </if>
          <submit namelist= "drink_list_index drink_size drink_content"/>
          </filled>
     </field>
</form>   
</vxml>

Grammar saved as cans.grxml:

<grammar type = "application/grammar+xml" root="get_drink"
          xml:lang = "en">
     <rule id = "get_drink" scope = "public">
          <item repeat = "1-">
               <one-of> 
                    <item>
                         <ruleref uri= "#drink_kind" /> 
                    </item>
                    <item>
                         <ruleref uri= "#number_cans" /> 
                    </item>
               </one-of>
          </item>
     </rule>
     <rule id = "number_cans" scope = "public">
          <one-of>
               <item> one<tag>current_drink_size ="1"</tag> </item>
               <item> two<tag>curreint_drink_size="2"</tag> </item>
               <item> three <tag>current_drink_size="3"</tag> </item>
               <item> four<tag>curreint_drink_size="4"</tag> </item>
               <item> five <tag>current_drink_size="5"</tag> </item> 
          </one-of>
     </rule>
     <rule id = "drink_kind" scope = "public">
          <one-of>
               <item> coke<tag>current_drink_content="coke"</tag>  </item>
               <item> pepsi<tag>current_drink_content="pepsi"</tag>  </item></one-of>
     </rule>
</grammar>

Return to the Instructor’s Page

Comments are off for this post