VoiceXML 2.1 Development GuideHome  |  Frameset Home

  GSL Hints  |  TOC  |  GSL Grammar Slots  

Universal Grammars

The Universal Grammar feature allows developers to take advantage of predefined grammars and responses to catch and handle common voice commands within the VoiceXML application. These grammars will need to be specifically enabled in order for the developer to include them into the application, by way of the W3C 'universals' property, (see below), otherwise, the grammars will be ignored.  Please note that grammars other than "help" and "exit" will need <catch> sections as they do not have any built-in functionality other than being a short hand grammar.  The included utterances for Universal events are:

There are also two additional values for using all or none of the above grammars:

To enable a Universal Grammar in an application, you can place the following code at the <vxml> level of your root document.

All enables the help, cancel, exit and repeat grammars
<property name="universals" value="all"/>


None disables all universal grammars
<property name="universals" value="none"/>


Help will enable the help grammar.  When a user says "help", your application will move execution to the <help> tags within your current form.  For example:


<field name="helpfield">
  <help>
    You said help!
  </help>
</field>



Exit will terminate the application when the user says "exit".  No additional programming needed!


Cancel and Repeat will both require a <catch> to function properly.  When a user says "cancel" or "repeat" the application will look for a <catch> with the "event" attribute set to either "cancel" or "repeat".  For example:


<catch event="cancel">
  <prompt>
    You said cancel!
  </prompt>
</catch>


Or for repeat:


<field name="options_field">
  <catch event="repeat">
    <reprompt />
  </catch>
</field>


If these predefined grammars don't do exactly what you want, you can simply define your own universal grammar using the <link> element to handle these user utterances. To customize your event processing for these occurrences, keep in mind that you must assign <catch> elements in your script to handle the event, else the default handlers and audio files will be executed.

Here is an example of how to use the <link> element:

<link event="custom">
  <grammar type="text/gsl">
    <![CDATA[
      [custom]
    ]]>
  </grammar>
</link>

<catch event="custom">
  <prompt>
    YAY you caught the custom grammar event!
  </prompt>
</catch>


I'm sure by this point you are anxious to see an example of all this nifty stuff in action.  Well, you're in luck! 


<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.1">
  <!-- Set the universals property to the grammars we want to use -->
  <!-- remember this can be global, field level or both -->
  <!-- help uses the <help> element -->
  <!-- repeat and cancel require a <catch> to properly execute -->
  <!-- exit will automatically exit the application when the caller says "exit" -->
  <!-- Universals can also be set to all and none for "help repeat exit cancel" or disabled respectively -->

  <property name="universals" value="help cancel exit repeat" />
 
  <!-- Set up a link-type global grammar -->
  <!-- This is essentially what a universal grammar is -->

  <link event="global">
    <grammar type="text/gsl">
      <![CDATA[
        [global]
      ]]>
    </grammar>
  </link>
 
  <!-- Set up our main form and field -->
  <form id="frm_main">
    <field name="main_menu">
      <!-- This is our local field-level grammar that we would use for
        field specific options -->

      <grammar type="text/gsl">
        <![CDATA[
          [
            [( one )] 
            [( two )] 
            [( three )]
          ]
        ]]>
      </grammar>

      <!-- Start the main menu TTS -->
      <prompt>
        Welcome to the main menu
        Please choose one of the following options
        Say one two or three for the local grammar
        Say help for help
        Say repeat to repeat these options
        Say cancel to cancel
        Say exit to disconnect
      </prompt>
     
      <!-- An utterance from our field level grammar has been recorded -->
      <filled>
        <prompt>
          You are in filled
          The utterance was <value expr="lastresult$.utterance" />
        </prompt>
       
        <!-- restart this form so we can try again -->
        <goto next="#frm_main" />
      </filled>

      <!-- The help universal will always look for the <help> tags -->
      <!-- when a help tag is found the execution will continue here -->
      <help>
        <prompt>
          YAY you asked for help so I give you cheese burger
        </prompt>
      </help>
     
      <!-- Set up a catch for the repeat universal grammar -->
      <catch event="repeat">
        <prompt>
          I found a repeat event
        </prompt>
       
        <!-- Do what repeat does, repeat the prompt! -->
        <reprompt />
      </catch>
     
     
      <!-- Set up a catch for the cancel universal grammar -->
      <catch event="cancel">
        <prompt>
          This is cancel, cancelling the thing you wanted to cancel
        </prompt>
      </catch>
    </field>
  </form>
 
  <!-- set up a global catch for our link global grammar -->
  <catch event="global">
    <prompt>
      YAY we are in the custom global grammar catch!
    </prompt>
  </catch>
</vxml>


Download the Code!

  Universals Source Code




  ANNOTATIONS: EXISTING POSTS
0 posts - click the button below to add a note to this page

login
  GSL Hints  |  TOC  |  GSL Grammar Slots  

© 2008 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site