VoiceXML Adventure Game - Mother of Perl | 3 | WebReference

VoiceXML Adventure Game - Mother of Perl | 3

To page 1To page 2current pageTo page 4To page 5To page 6To page 7
[previous] [next]

VoiceXML Adventure Game

Adding Voice Selections

Now that we have a simple interactive application working, we need to add the ability for users to provide voice commands in addition to DTMF input. This is done by adding additional grammar expressions.

  <grammar><![CDATA[
          [
            [dtmf-1 one] {<option "door1">}
            [dtmf-2 two] {<option "door2">}
            [dtmf-3 three] {<option "door3">}
            [(touch the monkey)] {<option "monkey">}
          ]
        ]]>
  </grammar>

If you compare the new grammar element above to the one on the previous page, you'll notice that we've added addition information for each option as well as a new line. The addition information consists of a single word for each option. For example, the first line of the grammar instructs the Tellme VoiceXML parser to match when the user presses 1 on their keypad or if they speak the word one. The last line of the grammar matches on the phrase, "touch the monkey." There will not be a match if the user says "touch" or "monkey." It will only match when the user says "touch the monkey." This is because the phrase is contained within paretheses, which require that the whole phrase be matched.

Example 2.

<?xml version="1.0"?>
<vxml version="1.0"> 
  <form> 
	   <field name="answer"> 
		    <grammar> <![CDATA[
              [
                [dtmf-1 one] {<option "door1">}
                [dtmf-2 two] {<option "door2">}
                [dtmf-3 three] {<option "door3">}
                [(touch the monkey)] {<option "monkey">}
              ]
            ]]>
		    </grammar> 
		    <prompt> <audio>You are in a small room with three doors.</audio>
		      <pause>300</pause> <audio>To open the first door, press or say 1.</audio>
		      <pause>300</pause> <audio>To open the second door, press or say 2.</audio>
		      <pause>300</pause> <audio>To open the third door, press or say 3.</audio>
		    </prompt> 
	   </field> 
	   <filled> 
	 	   <result name="door1"> 
		      <audio>You see a large hungry monkey.</audio> 
		      <reprompt/> 
		    </result> 
		    <result name="door2"> 
		      <audio>You see another room with three doors, a man, and his monkey.</audio> 
		      <reprompt/>
		    </result> 
		    <result name="door3"> 
		      <audio>You see a man scratching his monkey.</audio> 
		      <reprompt/> 
		    </result> 
		    <result name="monkey"> 
		      <audio>No! Do not touch the monkey!</audio> 
		      <reprompt/> 
		    </result>
    </filled> 
  </form>
</vxml>

To page 1To page 2current pageTo page 4To page 5To page 6To page 7
[previous] [next]

http://www.internet.com

Produced by Jonathan Eisenzopf
All Rights Reserved. Legal Notices.
Created: March 8, 2001

URL: http://www.webreference.com/perl/tutorial/21/3.html