SlideShare a Scribd company logo
1 of 13
Download to read offline
VoiceXML Adventure Game
     Jonathan Eisenzopf
     Copyright © 2001 by internet.com
     March 8, 2001

     Continuing from Part I [http://webref.com/perl/tutorial/20] of our comprehensive series
     of VoiceXML tutorials, in Part II we will develop a simple, but fully dynamic
     VoiceXML application in Perl for the Tellme.com voice portal.


Overview
     "You are in an open field west of a big white house with a
     boarded front door. There is a small mailbox here."

     Do you remember the original Zork text adventure game and Choose Your Own Ad-
     venture books? Maybe you're even old enough to remember the original Adventure
     game. If you don't, you're missing out. We're going to develop a simple Zork-like ap-
     plication using VoiceXML. In Part III, we will create a more advanced version that uti-
     lizes its own XML format for building text adventures.


Examples
     As we step through each code example, you will also be able to dial into Tellme and
     demo the code live on the Mother of Perl Tellme extension. Simply dial 1-800-tellme,
     wait for the Tellme main menu, then dial 1-73759. You will hear a greeting and a
     menu of options. Dial 2 for Tutorial 21 and then press the number that corresponds
     with the example in the tutorial. For example, when you see:

     Example 1.

     you can interact with the source code by pressing 1 on your phone. Each example is
     also linked to the XML source code file, where you can examine the file in your Web
     browser, or launch it directly into your favorite XML editor.

     In addition to the live examples, you will find the source code for all examples in the
     tutorial21.zip [tutorial21.zip] file, which you can use for free to create your own
     VoiceXML applications.


Creating a Grammar for DTMF Input

Grammars
                                               1
Before we proceed any further, we need to talk a bit more about grammars. They are a
      very important part of any VoiceXML document. A grammar is a set of expressions
      that define what DTMF tones and spoken input will be recognized by the system.
      These grammars are limited to what you program them to recognize. Depending on
      where you place the grammar, the scope can be the whole document, a form, or a field
      within a form. The Tellme grammar syntax uses the Nuance Grammar Specification
      Language (GSL).

      It's not too difficult to define a simple grammar that allows a user to make a selection
      via DTMF tones. Let's define a simple grammar that provides our users with the option
      to open one of three doors in our adventure.

          <grammar><![CDATA[
                  [
                     [dtmf-1] {<option "door1">}
                     [dtmf-2] {<option "door2">}
                     [dtmf-3] {<option "door3">}
                  ]
                ]]>
          </grammar>


      First, grammars are placed within the grammar element. You should also surround the
      grammar with a CDATA section, which tells the XML parser not to process the text in-
      side. In the grammar above, we have defined three options. Each option is defined by a
      grammar statement. The statement consists of an expression to be matched, and the
      corresponding value to return when a match occurs.

      The expression used to match a digit is: dtmf-$ where $ is the number we want to
      match. For example, dtmf-1 would be matched if a user presses 1 on their telephone
      keypad.

      The second part of the expression defines the value that will be returned when we get a
      match. For example, {<option "foo">} will return the text foo when the user in-
      put matches the first part of the expression.

      Next we're going to apply this simple grammar to a real VoiceXML document.


Getting DTMF Input
      The first version of our adventure game below will only accept DTMF input. The user
      can select 1, 2, or 3, which corresponds with one of the three doors.

      An example user session follows:


                                                 2
Tellme: You are in a small room with three doors.

Tellme: To open the first door, press 1.

Tellme: To open the second door, press 2.

Tellme: To open the third door, press 3.

User: (pressed 1)

Tellme: You see a large hungry monkey.

Now, let's take a look at the VoiceXML document.

Example 1. [example1.xml]

<?xml version="1.0"?>
 <vxml version="1.0">
   <form>
     <field name="answer">
       <grammar><![CDATA[
            [
              [dtmf-1] {<option "door1">}
              [dtmf-2] {<option "door2">}
              [dtmf-3] {<option "door3">}
            ]
          ]]>
       </grammar>
       <prompt><audio>You are in a small room with three
 doors.</audio>
       <pause>300</pause> <audio>To open the first door, press
 1.</audio>
       <pause>300</pause> <audio>To open the second door, press
 2.</audio>
       <pause>300</pause> <audio>To open the third door, press
 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">

                                            3
<audio>You see a man scratching his
      monkey.</audio>
              <reprompt/>
            </result>
          </filled>
        </form>
      </vxml>

     For more information on using the filled and result elements, please see Page 3
     [http://webref.com/perl/tutorial/20/3.html] of the first part of this tutorial. You might
     have also noticed the pause element in the example above. Using the element forces
     Tellme.com to pause between prompts. In this case, we want to stop for 300 millisec-
     onds between options to duplicate the pause that would occur in natural speech.


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. [example2.xml]

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

                                                4
<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 thr
      doors.</audio>
                             <pause>300</pause> <audio>To open the first do
      1.</audio>
                             <pause>300</pause> <audio>To open the second d
      2.</audio>
                             <pause>300</pause> <audio>To open the third do
      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,
      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>



Handling Events
     Next, we need to add handlers for the nomatch and noinput events using the methods
                                             5
specified in Page 4 [http://www.webref.com/perl/tutorial/20/4.html] of the previous tu-
torial.

Example 3. [example3.xml]

<?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 thr
 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>
                      <nomatch>
                        <audio>You fool! That is not a choice I am giv
 you.</audio>
                        <pause>300</pause>
                        <audio>Press or say 1, 2, or
 3.</audio>
                        <listen/>
                      </nomatch>
                      <noinput>
                        <audio>What are you waiting
 for?</audio>
                        <pause>300</pause>
                        <audio>Press or say 1, 2, or
 3.</audio>
                        <listen/>
                      </noinput>
            </field>
            <filled>
               <result name="door1">
                        <audio>You see a large hungry

                                          6
</audio>
                                     <reprompt/>
                                   </result>
                                   <result name="door2">
                                     <audio>You see another room with three doors,
      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>


Adding Help
     In most VoiceXML applications, you'll want to provide some help facility. Most peo-
     ple expect to get some kind of help when they press 0 on their phone, whether it be a
     live operator or automated assistance. In the example below, we've added a DTMF and
     voice grammar item that calls the help element in the document below.

     Example 4. [example4.xml]


     <?xml version="1.0"?>
      <vxml version="1.0">
        <form>
                <field name="answer">
                       <grammar> <![CDATA[
                 [
                   [dtmf-1 one first] {<option "door1">}
                   [dtmf-2 two second] {<option "door2">}
                   [dtmf-3 three third] {<option "door3">}
                   [(touch the monkey)] {<option "monkey">}
                   [dtmf-0 huh help what doh] {<option "help">}
                 ]
               ]]>
                       </grammar>
                       <prompt>
                         <audio>You are in a small room with three

                                              7
</audio>
                   <pause>300</pause>
                   <audio>Which one do you want to
 open?</audio>
                 </prompt>
                 <nomatch count="1">
                   <audio>Wrong door.</audio>
                   <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>
                   <listen/>
                 </nomatch>
                 <nomatch count="2">
                   <audio>You fool! That is not a choice I am giving
 you.</audio>
                   <pause>300</pause> <audio>Press or say 1, 2, or
 3.</audio>
                   <listen/>
                 </nomatch>
                 <nomatch count="3">
                   <audio>Pretend you have a brain and press 1, 2, or
 3.</audio>
                   <listen/>
                 </nomatch>
                 <noinput count="1">
                   <audio>What are you waiting
 for?</audio>
                   <pause>300</pause>
                   <audio>Press or say 1, 2, or 3.</audio>
                   <listen/>
                 </noinput>
                 <noinput count="2">
                   <audio>If you do not press 1, 2, or 3,
                   I am going to kill the monkey!</audio>
                   <listen/>
                 </noinput>
                 <noinput count="3">
                   <audio>Ok. That's it. The monkey is dead and it's
                   your fault because you did not choose 1, 2, or
 3.</audio>
                   <listen/>
                 </noinput>
                 <noinput count="4">
                   <audio>1, 2, or 3.</audio>
                   <listen/>

                            8
</noinput>
                                <help>
                                  <audio>Why are you asking for
      help?</audio>
                         <pause>300</pause>
                         <audio>Go away.</audio>
                         <reprompt/>
                       </help>
                </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>

     If you hadn't noticed, I also added multiple elements for the nomatch and noinput han-
     dlers.


Making Our Adventure Dynamic
     Now that we have a working VoiceXML document that provides some dynamic capa-
     bilities, it's time to tie in into a back-end Perl script that provides true dynamic capabil-
     ities. For this first run of our dynamic Perl script, we'll develop a script that dynami-
     cally generates rooms. Each room will always have three doors. Because the script is
     random, there are many different possible combinations. Initially, users won't be able
     to interact with any of the objects in the rooms, they'll only be able to open doors. In
     Part III, we'll add this capability.



                                                  9
room.pl
          use CGI;
          use strict;
          my @rooms = (
                       'large ball room',
                       'pool hall',
                       'large red barn',
                       'seven eleven',
                       'bedroom',
                       'bathroom',
                       'funeral parlor',
                       'windy room with bark walls',
                       'dimly lit tunnel',
                       'prison cell',
                       'hospital waiting room',
                       'underground parking garage',
                       'circular stairwell',
                       'arboretum',
                       'janitors closet',
                       'closet',
                       'subway car',
                       'cubicle',
                       'lighthouse tower',
                       'graveyard'
                      );
          my @objects = (
                          'full of clowns dressed in red',
                          'full of smoke but no people',
                          'with a dead horse on the floor',
                          'with a broken slurpy machine. In the corner, a troll
                          'with black curtains and something under the covers',
                          'with padded walls',
                          'with wood bark walls',
                          'with flickering florescent lights',
                          'with an oil spotted shag carpet',
                          'full of mad raving lunatics',
                          'with a man and his monkey',
                          'full of monkeys',
                          'with William Shatner singing tambourine man',
                          'with a large hungry monkey',
                          'full of drunken sailors',
                          'full of blind dwarves',
                          'full of Windows programmers',
                          'with a man scratching his monkey'
                         );
          my $q = new CGI;
          print "Content-Type: text/xmlnn";

                                     10
&prompt;
sub prompt {
my $room    = $rooms[int(rand(scalar(@rooms)))];
my $object = $objects[int(rand(scalar(@objects)))];
   print <<VXML;
<?xml version="1.0"?>
<vxml version="1.0">
  <form>
    <field name="answer">
      <grammar>
         <![CDATA[
           [
             [dtmf-1 one first] {<option "door1">}
             [dtmf-2 two second] {<option "door2">}
             [dtmf-3 three third] {<option "door3">}
             [(touch the monkey)] {<option "monkey">}
             [dtmf-0 huh help what doh] {<option "help">}
           ]
         ]]&gt;
      </grammar>
      <prompt>
         <audio>You are in a $room $object. There are three
doors.</audio>
      </prompt>
      <filled>
         <submit
next="http://www.textant.com/cgi-bin/room.pl"/>
      </filled>
      <nomatch count="1">
         <audio>Wrong door.</audio>
         <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>
         <listen/>
      </nomatch>
      <nomatch count="2">
         <audio>You fool! That is not a choice I am giving
you.</audio>
         <pause>300</pause>
         <audio>Press or say 1, 2, or 3.</audio>
         <listen/>
      </nomatch>
      <nomatch count="3">
         <audio>Pretend you have a brain and press 1, 2, or

                           11
</audio>
               <listen/>
             </nomatch>
             <noinput count="1">
               <audio>You need to select a door.</audio>
               <pause>300</pause>
               <audio>Press or say 1, 2, or 3.</audio>
               <listen/>
             </noinput>
             <noinput count="2">
               <audio>If you do not press 1, 2, or 3, I am going to kill
               the monkey!</audio>
               <listen/>
             </noinput>
             <noinput count="3">
               <audio>Ok. That's it. The monkey is dead and it's your
               fault because you did not choose 1, 2, or
      3.</audio>
               <listen/>
             </noinput>
             <noinput count="4">
               <audio>1, 2, or 3.</audio>
               <listen/>
             </noinput>
             <help>
               <audio>Why are you asking for help?</audio>
               <pause>300</pause>
               <audio>Go away.</audio>
               <reprompt/>
             </help>
           </field>
        </form>
      </vxml>
      VXML
      }




Conclusion
     I hope this column has provided a bit of nostalgia for some of you who grew up play-
     ing paper and computer adventure games like D&D, Battletech, Adventure, Zork,
     Leisure Suit Larry, Loom, and Space Quest. Alas, the era of adventure games seems to
     have passed. No longer are games with extensive plots that really draw users into an al-
     ternate universe. Games like BloodNet and Ultima brought a short resurgence, but I'm
     afraid we may not see another for a while. Shootemups like Quake and Half Life have
     all but replaced the adventure games.


                                               12
What's even more depressing is seeing some of the great gaming companies like
FASA, Micropose, Spectrum Holobyte, and Infocom go out of business or get bought
out by larger companies who really don't care too much about making great games.

Well, that's ok, because in Part III, we're going to develop our own text adventure plat-
form in an XML format that will work with HTML, WAP, and VoiceXML. We'll let
our nostalgia run its course and then perhaps we'll look at utilizing this technology for
something truly useful. But right now, it's time to play. We'll see you in Part III. Until
then, I'm going to go back through those sweet memories of yesteryear.




                                           13

More Related Content

Viewers also liked

VIVÊNCIAS DE UM PROFESSOR DE MATEMÁTICA EM INÍCIO DE CARREIRA: RELATO DE UMA ...
VIVÊNCIAS DE UM PROFESSOR DE MATEMÁTICA EM INÍCIO DE CARREIRA: RELATO DE UMA ...VIVÊNCIAS DE UM PROFESSOR DE MATEMÁTICA EM INÍCIO DE CARREIRA: RELATO DE UMA ...
VIVÊNCIAS DE UM PROFESSOR DE MATEMÁTICA EM INÍCIO DE CARREIRA: RELATO DE UMA ...ProfessorPrincipiante
 
2.22 session 23 einheit 5
2.22 session 23 einheit 52.22 session 23 einheit 5
2.22 session 23 einheit 5nblock
 
Pest Awareness for You
Pest Awareness for YouPest Awareness for You
Pest Awareness for YouViresh Karkera
 
Biology Chapter 28 Section 2[1]
Biology  Chapter 28 Section 2[1]Biology  Chapter 28 Section 2[1]
Biology Chapter 28 Section 2[1]Tamara
 
[HAFT] 행복나무 프로젝트 - 행복되감기
[HAFT] 행복나무 프로젝트 - 행복되감기[HAFT] 행복나무 프로젝트 - 행복되감기
[HAFT] 행복나무 프로젝트 - 행복되감기Bloomcompany
 
Verona prof dev presentation singleton elad 540
Verona prof dev presentation singleton elad 540Verona prof dev presentation singleton elad 540
Verona prof dev presentation singleton elad 540Tracey Singleton
 
Curzon, generosity in startup land -it is not just about doing good, phx star...
Curzon, generosity in startup land -it is not just about doing good, phx star...Curzon, generosity in startup land -it is not just about doing good, phx star...
Curzon, generosity in startup land -it is not just about doing good, phx star...Tom Curzon
 
MEMÓRIAS DAS MINHAS PRIMEIRAS EXPERIÊNCIAS COMO DOCENTE DE MÚSICA NO ENSINO R...
MEMÓRIAS DAS MINHAS PRIMEIRAS EXPERIÊNCIAS COMO DOCENTE DE MÚSICA NO ENSINO R...MEMÓRIAS DAS MINHAS PRIMEIRAS EXPERIÊNCIAS COMO DOCENTE DE MÚSICA NO ENSINO R...
MEMÓRIAS DAS MINHAS PRIMEIRAS EXPERIÊNCIAS COMO DOCENTE DE MÚSICA NO ENSINO R...ProfessorPrincipiante
 
Book - Thesis-draft 05- FINAL 2015-12-10
Book - Thesis-draft 05- FINAL 2015-12-10Book - Thesis-draft 05- FINAL 2015-12-10
Book - Thesis-draft 05- FINAL 2015-12-10Msizi Mkhize
 
John Kauffman Resume 2016 (1)
John Kauffman Resume 2016 (1)John Kauffman Resume 2016 (1)
John Kauffman Resume 2016 (1)John kauffman
 

Viewers also liked (15)

Opponeringen
OpponeringenOpponeringen
Opponeringen
 
VIVÊNCIAS DE UM PROFESSOR DE MATEMÁTICA EM INÍCIO DE CARREIRA: RELATO DE UMA ...
VIVÊNCIAS DE UM PROFESSOR DE MATEMÁTICA EM INÍCIO DE CARREIRA: RELATO DE UMA ...VIVÊNCIAS DE UM PROFESSOR DE MATEMÁTICA EM INÍCIO DE CARREIRA: RELATO DE UMA ...
VIVÊNCIAS DE UM PROFESSOR DE MATEMÁTICA EM INÍCIO DE CARREIRA: RELATO DE UMA ...
 
Daniela
DanielaDaniela
Daniela
 
2.22 session 23 einheit 5
2.22 session 23 einheit 52.22 session 23 einheit 5
2.22 session 23 einheit 5
 
Fd1 Class Introduction
Fd1 Class IntroductionFd1 Class Introduction
Fd1 Class Introduction
 
Pest Awareness for You
Pest Awareness for YouPest Awareness for You
Pest Awareness for You
 
Roderik van Zeist
Roderik van Zeist Roderik van Zeist
Roderik van Zeist
 
Biology Chapter 28 Section 2[1]
Biology  Chapter 28 Section 2[1]Biology  Chapter 28 Section 2[1]
Biology Chapter 28 Section 2[1]
 
[HAFT] 행복나무 프로젝트 - 행복되감기
[HAFT] 행복나무 프로젝트 - 행복되감기[HAFT] 행복나무 프로젝트 - 행복되감기
[HAFT] 행복나무 프로젝트 - 행복되감기
 
Verona prof dev presentation singleton elad 540
Verona prof dev presentation singleton elad 540Verona prof dev presentation singleton elad 540
Verona prof dev presentation singleton elad 540
 
Curzon, generosity in startup land -it is not just about doing good, phx star...
Curzon, generosity in startup land -it is not just about doing good, phx star...Curzon, generosity in startup land -it is not just about doing good, phx star...
Curzon, generosity in startup land -it is not just about doing good, phx star...
 
MEMÓRIAS DAS MINHAS PRIMEIRAS EXPERIÊNCIAS COMO DOCENTE DE MÚSICA NO ENSINO R...
MEMÓRIAS DAS MINHAS PRIMEIRAS EXPERIÊNCIAS COMO DOCENTE DE MÚSICA NO ENSINO R...MEMÓRIAS DAS MINHAS PRIMEIRAS EXPERIÊNCIAS COMO DOCENTE DE MÚSICA NO ENSINO R...
MEMÓRIAS DAS MINHAS PRIMEIRAS EXPERIÊNCIAS COMO DOCENTE DE MÚSICA NO ENSINO R...
 
Book - Thesis-draft 05- FINAL 2015-12-10
Book - Thesis-draft 05- FINAL 2015-12-10Book - Thesis-draft 05- FINAL 2015-12-10
Book - Thesis-draft 05- FINAL 2015-12-10
 
Доброта
ДобротаДоброта
Доброта
 
John Kauffman Resume 2016 (1)
John Kauffman Resume 2016 (1)John Kauffman Resume 2016 (1)
John Kauffman Resume 2016 (1)
 

Similar to tutorial21

Automated and Effective Testing of Web Services for XML Injection Attacks
Automated and Effective Testing of Web Services for XML Injection AttacksAutomated and Effective Testing of Web Services for XML Injection Attacks
Automated and Effective Testing of Web Services for XML Injection AttacksLionel Briand
 
The Ring programming language version 1.3 book - Part 10 of 88
The Ring programming language version 1.3 book - Part 10 of 88The Ring programming language version 1.3 book - Part 10 of 88
The Ring programming language version 1.3 book - Part 10 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 18 of 185
The Ring programming language version 1.5.4 book - Part 18 of 185The Ring programming language version 1.5.4 book - Part 18 of 185
The Ring programming language version 1.5.4 book - Part 18 of 185Mahmoud Samir Fayed
 
Lab 4 -Linux Files, Directories and Basic Commands Part-2.pptx
Lab 4 -Linux Files, Directories and Basic Commands Part-2.pptxLab 4 -Linux Files, Directories and Basic Commands Part-2.pptx
Lab 4 -Linux Files, Directories and Basic Commands Part-2.pptxCiceer Ghimirey
 
Chapter 3 Using Unix Commands
Chapter 3 Using Unix CommandsChapter 3 Using Unix Commands
Chapter 3 Using Unix CommandsMeenalJabde
 
Uses of tmux explained
Uses of tmux explainedUses of tmux explained
Uses of tmux explainedStanislas Polu
 
Eff Plsql
Eff PlsqlEff Plsql
Eff Plsqlafa reg
 
tmux - An overview of the features of this powerful terminal multiplexer.
tmux - An overview of the features of this powerful terminal multiplexer.tmux - An overview of the features of this powerful terminal multiplexer.
tmux - An overview of the features of this powerful terminal multiplexer.jhalfmoon
 
The Ring programming language version 1.5.3 book - Part 18 of 184
The Ring programming language version 1.5.3 book - Part 18 of 184The Ring programming language version 1.5.3 book - Part 18 of 184
The Ring programming language version 1.5.3 book - Part 18 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 7 of 210
The Ring programming language version 1.9 book - Part 7 of 210The Ring programming language version 1.9 book - Part 7 of 210
The Ring programming language version 1.9 book - Part 7 of 210Mahmoud Samir Fayed
 
Linux Shortcuts and Commands:
Linux Shortcuts and Commands:Linux Shortcuts and Commands:
Linux Shortcuts and Commands:wensheng wei
 
Simple xml in .net
Simple xml in .netSimple xml in .net
Simple xml in .netVi Vo Hung
 
Introduction to Command Line & Batch files
Introduction to Command Line& Batch filesIntroduction to Command Line& Batch files
Introduction to Command Line & Batch filesHayder F. Shamary
 
CrashCourse: XML technologies
CrashCourse: XML technologiesCrashCourse: XML technologies
CrashCourse: XML technologiesESRI Bulgaria
 
Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapaloozaJenniferBall44
 

Similar to tutorial21 (20)

Automated and Effective Testing of Web Services for XML Injection Attacks
Automated and Effective Testing of Web Services for XML Injection AttacksAutomated and Effective Testing of Web Services for XML Injection Attacks
Automated and Effective Testing of Web Services for XML Injection Attacks
 
tutorial20
tutorial20tutorial20
tutorial20
 
tutorial20
tutorial20tutorial20
tutorial20
 
The Ring programming language version 1.3 book - Part 10 of 88
The Ring programming language version 1.3 book - Part 10 of 88The Ring programming language version 1.3 book - Part 10 of 88
The Ring programming language version 1.3 book - Part 10 of 88
 
The Ring programming language version 1.5.4 book - Part 18 of 185
The Ring programming language version 1.5.4 book - Part 18 of 185The Ring programming language version 1.5.4 book - Part 18 of 185
The Ring programming language version 1.5.4 book - Part 18 of 185
 
Lab 4 -Linux Files, Directories and Basic Commands Part-2.pptx
Lab 4 -Linux Files, Directories and Basic Commands Part-2.pptxLab 4 -Linux Files, Directories and Basic Commands Part-2.pptx
Lab 4 -Linux Files, Directories and Basic Commands Part-2.pptx
 
Chapter 3 Using Unix Commands
Chapter 3 Using Unix CommandsChapter 3 Using Unix Commands
Chapter 3 Using Unix Commands
 
Uses of tmux explained
Uses of tmux explainedUses of tmux explained
Uses of tmux explained
 
Eff Plsql
Eff PlsqlEff Plsql
Eff Plsql
 
tmux - An overview of the features of this powerful terminal multiplexer.
tmux - An overview of the features of this powerful terminal multiplexer.tmux - An overview of the features of this powerful terminal multiplexer.
tmux - An overview of the features of this powerful terminal multiplexer.
 
The Ring programming language version 1.5.3 book - Part 18 of 184
The Ring programming language version 1.5.3 book - Part 18 of 184The Ring programming language version 1.5.3 book - Part 18 of 184
The Ring programming language version 1.5.3 book - Part 18 of 184
 
XML For PHP Developers
XML For PHP DevelopersXML For PHP Developers
XML For PHP Developers
 
The Ring programming language version 1.9 book - Part 7 of 210
The Ring programming language version 1.9 book - Part 7 of 210The Ring programming language version 1.9 book - Part 7 of 210
The Ring programming language version 1.9 book - Part 7 of 210
 
Linux Shortcuts and Commands:
Linux Shortcuts and Commands:Linux Shortcuts and Commands:
Linux Shortcuts and Commands:
 
Bioinformatica 27-10-2011-p4-files
Bioinformatica 27-10-2011-p4-filesBioinformatica 27-10-2011-p4-files
Bioinformatica 27-10-2011-p4-files
 
Unix3
Unix3Unix3
Unix3
 
Simple xml in .net
Simple xml in .netSimple xml in .net
Simple xml in .net
 
Introduction to Command Line & Batch files
Introduction to Command Line& Batch filesIntroduction to Command Line& Batch files
Introduction to Command Line & Batch files
 
CrashCourse: XML technologies
CrashCourse: XML technologiesCrashCourse: XML technologies
CrashCourse: XML technologies
 
Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapalooza
 

More from tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

More from tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Recently uploaded

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Recently uploaded (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

tutorial21

  • 1. VoiceXML Adventure Game Jonathan Eisenzopf Copyright © 2001 by internet.com March 8, 2001 Continuing from Part I [http://webref.com/perl/tutorial/20] of our comprehensive series of VoiceXML tutorials, in Part II we will develop a simple, but fully dynamic VoiceXML application in Perl for the Tellme.com voice portal. Overview "You are in an open field west of a big white house with a boarded front door. There is a small mailbox here." Do you remember the original Zork text adventure game and Choose Your Own Ad- venture books? Maybe you're even old enough to remember the original Adventure game. If you don't, you're missing out. We're going to develop a simple Zork-like ap- plication using VoiceXML. In Part III, we will create a more advanced version that uti- lizes its own XML format for building text adventures. Examples As we step through each code example, you will also be able to dial into Tellme and demo the code live on the Mother of Perl Tellme extension. Simply dial 1-800-tellme, wait for the Tellme main menu, then dial 1-73759. You will hear a greeting and a menu of options. Dial 2 for Tutorial 21 and then press the number that corresponds with the example in the tutorial. For example, when you see: Example 1. you can interact with the source code by pressing 1 on your phone. Each example is also linked to the XML source code file, where you can examine the file in your Web browser, or launch it directly into your favorite XML editor. In addition to the live examples, you will find the source code for all examples in the tutorial21.zip [tutorial21.zip] file, which you can use for free to create your own VoiceXML applications. Creating a Grammar for DTMF Input Grammars 1
  • 2. Before we proceed any further, we need to talk a bit more about grammars. They are a very important part of any VoiceXML document. A grammar is a set of expressions that define what DTMF tones and spoken input will be recognized by the system. These grammars are limited to what you program them to recognize. Depending on where you place the grammar, the scope can be the whole document, a form, or a field within a form. The Tellme grammar syntax uses the Nuance Grammar Specification Language (GSL). It's not too difficult to define a simple grammar that allows a user to make a selection via DTMF tones. Let's define a simple grammar that provides our users with the option to open one of three doors in our adventure. <grammar><![CDATA[ [ [dtmf-1] {<option "door1">} [dtmf-2] {<option "door2">} [dtmf-3] {<option "door3">} ] ]]> </grammar> First, grammars are placed within the grammar element. You should also surround the grammar with a CDATA section, which tells the XML parser not to process the text in- side. In the grammar above, we have defined three options. Each option is defined by a grammar statement. The statement consists of an expression to be matched, and the corresponding value to return when a match occurs. The expression used to match a digit is: dtmf-$ where $ is the number we want to match. For example, dtmf-1 would be matched if a user presses 1 on their telephone keypad. The second part of the expression defines the value that will be returned when we get a match. For example, {<option "foo">} will return the text foo when the user in- put matches the first part of the expression. Next we're going to apply this simple grammar to a real VoiceXML document. Getting DTMF Input The first version of our adventure game below will only accept DTMF input. The user can select 1, 2, or 3, which corresponds with one of the three doors. An example user session follows: 2
  • 3. Tellme: You are in a small room with three doors. Tellme: To open the first door, press 1. Tellme: To open the second door, press 2. Tellme: To open the third door, press 3. User: (pressed 1) Tellme: You see a large hungry monkey. Now, let's take a look at the VoiceXML document. Example 1. [example1.xml] <?xml version="1.0"?> <vxml version="1.0"> <form> <field name="answer"> <grammar><![CDATA[ [ [dtmf-1] {<option "door1">} [dtmf-2] {<option "door2">} [dtmf-3] {<option "door3">} ] ]]> </grammar> <prompt><audio>You are in a small room with three doors.</audio> <pause>300</pause> <audio>To open the first door, press 1.</audio> <pause>300</pause> <audio>To open the second door, press 2.</audio> <pause>300</pause> <audio>To open the third door, press 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"> 3
  • 4. <audio>You see a man scratching his monkey.</audio> <reprompt/> </result> </filled> </form> </vxml> For more information on using the filled and result elements, please see Page 3 [http://webref.com/perl/tutorial/20/3.html] of the first part of this tutorial. You might have also noticed the pause element in the example above. Using the element forces Tellme.com to pause between prompts. In this case, we want to stop for 300 millisec- onds between options to duplicate the pause that would occur in natural speech. 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. [example2.xml] <?xml version="1.0"?> <vxml version="1.0"> <form> 4
  • 5. <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 thr doors.</audio> <pause>300</pause> <audio>To open the first do 1.</audio> <pause>300</pause> <audio>To open the second d 2.</audio> <pause>300</pause> <audio>To open the third do 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, 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> Handling Events Next, we need to add handlers for the nomatch and noinput events using the methods 5
  • 6. specified in Page 4 [http://www.webref.com/perl/tutorial/20/4.html] of the previous tu- torial. Example 3. [example3.xml] <?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 thr 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> <nomatch> <audio>You fool! That is not a choice I am giv you.</audio> <pause>300</pause> <audio>Press or say 1, 2, or 3.</audio> <listen/> </nomatch> <noinput> <audio>What are you waiting for?</audio> <pause>300</pause> <audio>Press or say 1, 2, or 3.</audio> <listen/> </noinput> </field> <filled> <result name="door1"> <audio>You see a large hungry 6
  • 7. </audio> <reprompt/> </result> <result name="door2"> <audio>You see another room with three doors, 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> Adding Help In most VoiceXML applications, you'll want to provide some help facility. Most peo- ple expect to get some kind of help when they press 0 on their phone, whether it be a live operator or automated assistance. In the example below, we've added a DTMF and voice grammar item that calls the help element in the document below. Example 4. [example4.xml] <?xml version="1.0"?> <vxml version="1.0"> <form> <field name="answer"> <grammar> <![CDATA[ [ [dtmf-1 one first] {<option "door1">} [dtmf-2 two second] {<option "door2">} [dtmf-3 three third] {<option "door3">} [(touch the monkey)] {<option "monkey">} [dtmf-0 huh help what doh] {<option "help">} ] ]]> </grammar> <prompt> <audio>You are in a small room with three 7
  • 8. </audio> <pause>300</pause> <audio>Which one do you want to open?</audio> </prompt> <nomatch count="1"> <audio>Wrong door.</audio> <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> <listen/> </nomatch> <nomatch count="2"> <audio>You fool! That is not a choice I am giving you.</audio> <pause>300</pause> <audio>Press or say 1, 2, or 3.</audio> <listen/> </nomatch> <nomatch count="3"> <audio>Pretend you have a brain and press 1, 2, or 3.</audio> <listen/> </nomatch> <noinput count="1"> <audio>What are you waiting for?</audio> <pause>300</pause> <audio>Press or say 1, 2, or 3.</audio> <listen/> </noinput> <noinput count="2"> <audio>If you do not press 1, 2, or 3, I am going to kill the monkey!</audio> <listen/> </noinput> <noinput count="3"> <audio>Ok. That's it. The monkey is dead and it's your fault because you did not choose 1, 2, or 3.</audio> <listen/> </noinput> <noinput count="4"> <audio>1, 2, or 3.</audio> <listen/> 8
  • 9. </noinput> <help> <audio>Why are you asking for help?</audio> <pause>300</pause> <audio>Go away.</audio> <reprompt/> </help> </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> If you hadn't noticed, I also added multiple elements for the nomatch and noinput han- dlers. Making Our Adventure Dynamic Now that we have a working VoiceXML document that provides some dynamic capa- bilities, it's time to tie in into a back-end Perl script that provides true dynamic capabil- ities. For this first run of our dynamic Perl script, we'll develop a script that dynami- cally generates rooms. Each room will always have three doors. Because the script is random, there are many different possible combinations. Initially, users won't be able to interact with any of the objects in the rooms, they'll only be able to open doors. In Part III, we'll add this capability. 9
  • 10. room.pl use CGI; use strict; my @rooms = ( 'large ball room', 'pool hall', 'large red barn', 'seven eleven', 'bedroom', 'bathroom', 'funeral parlor', 'windy room with bark walls', 'dimly lit tunnel', 'prison cell', 'hospital waiting room', 'underground parking garage', 'circular stairwell', 'arboretum', 'janitors closet', 'closet', 'subway car', 'cubicle', 'lighthouse tower', 'graveyard' ); my @objects = ( 'full of clowns dressed in red', 'full of smoke but no people', 'with a dead horse on the floor', 'with a broken slurpy machine. In the corner, a troll 'with black curtains and something under the covers', 'with padded walls', 'with wood bark walls', 'with flickering florescent lights', 'with an oil spotted shag carpet', 'full of mad raving lunatics', 'with a man and his monkey', 'full of monkeys', 'with William Shatner singing tambourine man', 'with a large hungry monkey', 'full of drunken sailors', 'full of blind dwarves', 'full of Windows programmers', 'with a man scratching his monkey' ); my $q = new CGI; print "Content-Type: text/xmlnn"; 10
  • 11. &prompt; sub prompt { my $room = $rooms[int(rand(scalar(@rooms)))]; my $object = $objects[int(rand(scalar(@objects)))]; print <<VXML; <?xml version="1.0"?> <vxml version="1.0"> <form> <field name="answer"> <grammar> <![CDATA[ [ [dtmf-1 one first] {<option "door1">} [dtmf-2 two second] {<option "door2">} [dtmf-3 three third] {<option "door3">} [(touch the monkey)] {<option "monkey">} [dtmf-0 huh help what doh] {<option "help">} ] ]]&gt; </grammar> <prompt> <audio>You are in a $room $object. There are three doors.</audio> </prompt> <filled> <submit next="http://www.textant.com/cgi-bin/room.pl"/> </filled> <nomatch count="1"> <audio>Wrong door.</audio> <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> <listen/> </nomatch> <nomatch count="2"> <audio>You fool! That is not a choice I am giving you.</audio> <pause>300</pause> <audio>Press or say 1, 2, or 3.</audio> <listen/> </nomatch> <nomatch count="3"> <audio>Pretend you have a brain and press 1, 2, or 11
  • 12. </audio> <listen/> </nomatch> <noinput count="1"> <audio>You need to select a door.</audio> <pause>300</pause> <audio>Press or say 1, 2, or 3.</audio> <listen/> </noinput> <noinput count="2"> <audio>If you do not press 1, 2, or 3, I am going to kill the monkey!</audio> <listen/> </noinput> <noinput count="3"> <audio>Ok. That's it. The monkey is dead and it's your fault because you did not choose 1, 2, or 3.</audio> <listen/> </noinput> <noinput count="4"> <audio>1, 2, or 3.</audio> <listen/> </noinput> <help> <audio>Why are you asking for help?</audio> <pause>300</pause> <audio>Go away.</audio> <reprompt/> </help> </field> </form> </vxml> VXML } Conclusion I hope this column has provided a bit of nostalgia for some of you who grew up play- ing paper and computer adventure games like D&D, Battletech, Adventure, Zork, Leisure Suit Larry, Loom, and Space Quest. Alas, the era of adventure games seems to have passed. No longer are games with extensive plots that really draw users into an al- ternate universe. Games like BloodNet and Ultima brought a short resurgence, but I'm afraid we may not see another for a while. Shootemups like Quake and Half Life have all but replaced the adventure games. 12
  • 13. What's even more depressing is seeing some of the great gaming companies like FASA, Micropose, Spectrum Holobyte, and Infocom go out of business or get bought out by larger companies who really don't care too much about making great games. Well, that's ok, because in Part III, we're going to develop our own text adventure plat- form in an XML format that will work with HTML, WAP, and VoiceXML. We'll let our nostalgia run its course and then perhaps we'll look at utilizing this technology for something truly useful. But right now, it's time to play. We'll see you in Part III. Until then, I'm going to go back through those sweet memories of yesteryear. 13