Larson Technical Services: Voice Technology Consulting

Exercise 2.1

The grammar for telephoneNumber.grxml is:


<grammar type="application/grammar+xml"  version="1.0"> 
     <rule id = "aTelephone" scope = "public">
          <item>
               <one-of>
                    <item tag="1">one</item>
                    <item tag="2">two</item>
                    <item tag="3">three</item>
                    <item tag="4">four</item>
                    <item tag="5">five</item>
                    <item tag="6">six</item>
                    <item tag="7">seven</item>
                    <item tag="8">eight</item>
                    <item tag="9">nine</item>
                    <item tag="0">zero</item>
                    <item tag="0">oh</item>
               </one-of>
          </item>
     </rule>
</grammar>

This grammar is used by the VoiceXML code for Example 2.1:


<?xml version="1.0"?
<vxml version="2.0">

<!-- Figure 2.1 A VoiceXML Document   -->

<form> <block> <prompt>Welcome to Ajax Travel</prompt> </block>

<field name="UserName">
     <prompt>Say your user name</prompt>
          <grammar type="application/grammar+xml"
               src="http://www.larson-tech.com/VoiceXML/Code/username.grxml"/>
</field>

<field name="telephone">
     <prompt>Say your one digit telephone number</prompt>
          <grammar type="application/grammar+xml"
               src="http://www.larson-tech.com/VoiceXML/Code/telephoneNumber.grxml"/> 
</field>

<filled> <goto next="#travel"/> </filled>
</form>

<menu id="travel">

     <prompt>
          Do you  want to travel by plane, train, or boat?
     </prompt>

     <choice next="#plane">
          <grammar type="application/grammar+xml" version="1.0">
               <rule id = "by_plane" scope = "public">
                    <item> plane </item>
               </rule>
          </grammar>
     </choice>

     <choice next="#train">
          <grammar type="application/grammar+xml" version="1.0">
               <rule id = "by_train" scope = "public">
                    <item> train </item>
               </rule>
          </grammar>
     </choice>

     <choice next="#boat">
          <grammar type="application/grammar+xml" version="1.0">
               <rule id = "by_boat" scope = "public">
                    <item> boat </item>
               </rule>
          </grammar>
     </choice>
</menu>

<form id = "plane">
     <block>
          <prompt>
               You have selected to travel by plane. 
               Details for making travel arrangements
               would be here in a real application
          </prompt>
     </block>
</form>

<form id = "train">
     <block>
          <prompt>
               You have selected to travel by train.
               Details for making travel arrangements
               would be here in a real application 
          </prompt>
     </block>
</form>

<form id = "boat">
     <block>
          <prompt>
               You have selected to travel by boat.
               Details for making travel arrangements
               would be here in a real application                      
          </prompt> 
     </block> 
</form> 
</vxml>

An equivalent grammar that enables the caller to press the keys on a touch-tone phone follows:


<grammar type="application/grammar+xml"  version="1.0" mode="dtmf"> 
     <rule id = "aTelephone" scope = "public">
          <item>
               <one-of>
                    <item tag="1">1</item>
                    <item tag="2">2</item>
                    <item tag="3">3</item>
                    <item tag="4">4</item>
                    <item tag="5">5</item>
                    <item tag="6">6</item>
                    <item tag="7">7</item>
                    <item tag="8">8</item>
                    <item tag="9">9</item>
                    <item tag="0">0</item>
               </one-of>
          </item>
     </rule>
</grammar>

This revised grammar is used by the following VoiceXML application. The only changes to the application is the prompt which solicits the one digit phone number from the caller, and the reference to the revised grammar.


<?xml version="1.0"?>

<vxml version="2.0">  

<!-- Figure 2.1 A VoiceXML Document   -->

<form> <block> <prompt>Welcome to Ajax Travel</prompt> </block>

<field name="UserName">
     <prompt>Say your user name</prompt>
     <grammar type="application/grammar+xml"
          src="http://www.larson-tech.com/VoiceXML/Code/username.grxml"/>
</field>

<field name="telephone">
     <prompt>Press the keys on your telepone to enter a one-digit telephone number</prompt>
     <grammar type="application/grammar+xml" 
          src="http://www.larson-tech.com/VoiceXML/Code/telephoneNumberDTMF.grxml"/>
</field>

<filled> <goto next="#travel"/> </filled>
</form>

<menu id="travel">
     <prompt>
          Do you  want to travel by plane, train, or boat?
     </prompt>

     <choice next="#plane">
          <grammar type="application/grammar+xml" version="1.0">
               <rule id = "by_plane" scope = "public">
                    <item> plane </item>
               </rule>
          </grammar>
     </choice>

     <choice next="#train">
          <grammar type="application/grammar+xml" version="1.0">
               <rule id = "by_train" scope = "public">
                    <item> train </item>
               </rule>
          </grammar>
     </choice>

     <choice next="#boat">
          <grammar type="application/grammar+xml" version="1.0">
               <rule id = "by_boat" scope = "public">
                    <item> boat </item>
               </rule>
          </grammar>
     </choice>
</menu>

<form id = "plane">
     <block>
          <prompt>
               You have selected to travel by plane. 
               Details for making travel arrangements
               would be here in a real application
          </prompt>
     </block>
</form>

<form id = "train">
     <block>
          <prompt>
               You have selected to travel by train.
               Details for making travel arrangements
               would be here in a real application
          </prompt>
     </block>
</form>

<form id = "boat">
     <block>
          <prompt>
               You have selected to travel by boat.
               Details for making travel arrangements
               would be here in a real application 
          </prompt> 
     </block> 
</form> 
</vxml>

Return to the Instructor’s Page

Comments are off for this post