Larson Technical Services: Voice Technology Consulting

Exercise 12.2

Convert the VoiceXML program you wrote for Exercise 10-1 into a reusable subdialog.

A. Demonstrate your subdialog by referencing it from another VoiceXML application


<?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 12.2 A subdialog -->

     <form id="main">
          <block>We're about to call the sub dialog</block>
               <subdialog name="result" src="#job_application_form">
               </subdialog>
          <block>
               <prompt> We're back from the sub dialog. </prompt>
          </block>
     </form> 

<form id = "job_application_form">  <!-- This is the subdialog -->

<!-- Variables are given values by parameters to the subdialog --> 

<block>
     <prompt>
          Welcome to the job application form
     </prompt>
</block> 

<field name = "name">
     <prompt>
          What is your name?
     </prompt>
     <grammar type = "application/grammar+xml" 
               root = "applicant_name">
          <rule id = "applicant_name">
               <one-of>
                    <item> sam </item>
                    <item> fred </item>
               </one-of>
          </rule>
     </grammar>
</field>  

<field name = "age">
     <prompt>
          How old are you?
     </prompt>
     <grammar type = "application/grammar+xml" 
               root = "applicant_age">
          <rule id = "applicant_age">
               <one-of>
                    <item> twenty </item>
                    <item> thirty </item>
               </one-of>
          </rule>
     </grammar>
</field>

<filled>  
     <prompt>
          Your name is <value expr = "name"/>
          Your age is <value expr = "age"/>
          Good Bye
     </prompt>
     <return/>
</filled>
</form>
</vxml>

B. Redesign your subdialog so that another developer can change the prompt messages without changing your subdialog code.

<?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 12.2 B subdialog -->  

<form id="main">
     <block>We're about to call the sub dialog</block>
          <subdialog name="result" src="#job_application_form">
               <param name = "name_prompt" value = "name, please"/>
               <param name = "age_prompt" value = "age, please"/>
          </subdialog>
     <block>
          <prompt> We're back from the sub dialog. </prompt>
     </block>
</form>  

<form id = "job_application_form">  <!-- This is the subdialog -->
<!-- Variables are given values by parameters to the subdialog -->
     <var name="name_prompt" expr = "prompt1"/>
     <var name="age_prompt" expr = "prompt2"/>
<block>
     <prompt>
          Welcome to the job application form
     </prompt>
</block>  

<field name = "name">
     <prompt>
          <value expr = "name_prompt"/>
     </prompt>
     <grammar type = "application/grammar+xml" 
               root = "applicant_name">
          <rule id = "applicant_name">
               <one-of>
                    <item> sam </item>
                    <item> fred </item>
               </one-of>
          </rule>
     </grammar>
</field>  

<field name = "age">
     <prompt>
          <value expr = "age_prompt"/>
     </prompt>
     <grammar type = "application/grammar+xml" 
               root = "applicant_age">
          <rule id = "applicant_age">
               <one-of>
                    <item> twenty </item>
                    <item> thirty </item>
               </one-of>
          </rule>
     </grammar>
</field>       

<filled>  
     <prompt>
          Your name is <value expr = "name"/>
          Your age is <value expr = "age"/>
          Good Bye
     </prompt>   
     <return/>
</filled>
</form>
</vxml>

C. Redesign your subdialog so that another developer can change the grammar used by menus and fields without changing your subdialog code.

<?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 12.2 c subdialog -->  

<form id="main">
     <block>We're about to call the sub dialog</block>
          <subdialog name="result" src="#job_application_form">
               <param name = "name_prompt" value = "name, please"/>
               <param name = "age_prompt" value = "age, please"/>
          </subdialog>
     <block>
          <prompt> We're back from the sub dialog. </prompt>
     </block>
</form>

<form id = "job_application_form">  <!-- This is the subdialog -->
<!-- Variables are given values by parameters to the subdialog -->
     <var name="name_prompt" expr = "prompt1"/>
     <var name="age_prompt" expr = "prompt2"/>
<block>
     <prompt>
          Welcome to the job application form
     </prompt>
</block>  

<field name = "name">
     <prompt>
          <value expr = "name_prompt"/>
     </prompt>
     <grammar type = "application/grammar+xml" 
               src="name1.grxml"/>
</field>  

<field name = "age">
     <prompt>
          <value expr = "age_prompt"/>
     </prompt>
     <grammar type = "application/grammar+xml" 
               root = "applicant_age">
          <rule id = "applicant_age">
               <one-of>
                    <item> twenty </item>
                    <item> thirty </item>
               </one-of>
          </rule>
     </grammar>
</field>       

<filled>  
     <prompt>
          Your name is <value expr = "name"/>
          Your age is <value expr = "age"/>
          Good Bye
     </prompt>   
     <return/>
</filled>
</form>
</vxml>

Using the following grammar: name1.grxml:

<grammar type="application/grammar+xml" version="1.0" 
          xml:lang = "en" root="first_name">
     <rule id = "first_name" scope = "public">
          <one-of>
               <item>abe</item>
               <item>bob</item>
               <item>charles</item>
               <item>dan</item>
               <item>evan</item>
          </one-of>
     </rule>
</grammar>

Return to the Instructor’s Page

Comments are off for this post