VoiceXML 2.1 Development Guide Home  |  Frameset Home

  GSL Hints  |  TOC  |  GSL Grammar Slots  

Universal Grammars

Note: GSL syntax is not considered to be a W3C-compliant syntax for grammars, and the Nuance has discontinued support for GSL grammars in their most recent product offerings. Voxeo will continue to support GSL-specific markup for some time to come, but it is strongly suggested that new applications and their associated grammars leverage the SRGS + SISR grammar syntaxes instead of being reliant upon the deprecated GSL grammar format.

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
anilgalve
9/29/2011 1:12 AM (EDT)
How help will get invoked in case of DTMF input?
VoxeoDante
9/29/2011 11:38 AM (EDT)
Hello,

If you wanted to invoke a help or start-over type function via DTMF you would want to use a Link Grammar. 

The link grammar will allow you to set a DTMF key that will invoke a particular link.

http://www.vxml.org/link.htm

Something like this would work;

  <link eventexpr="MyEvent" dtmf="1" message="'I like Ike'">
    <grammar type="text/gsl"> [help]</grammar>
  </link>

I hope this clears things up.

Regards,
Danté Vitulano
Hosted Solutions Engineer

login
  GSL Hints  |  TOC  |  GSL Grammar Slots  

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