Nov 02

A VoiceXML application consists of a set of VoiceXML documents, and each document contains one or more dialogs describing a specific interaction with the user. Dialogs are used to present the user with information or prompt the user to provide information, and when complete, they direct the flow of control to another dialog in that document,  or to a dialog in another document in the same application. It also allows a dialog in another application entirely.

At the root of every VoiceXML document is a root element, the vxml element. This should contain one or more elements representing dialogs.

VoiceXML 2.x provides two types of dialogs: form and menu. While menu is a convenient shorthand for certain situations, VoiceXML authors will spend most of their time writing form elements; thus, this introduction focuses on the form element.

VoiceXML Reference

image

click on the images to make them reference bigger..

image

Hello World in VoiceXML

VoiceXML's primary user interface consists of a form with a number of elements that either provide information to the user or request input from the user.  The VoiceXML interpreter does much of the same thing. Like HTML  the form tag should be very familiar to all.

<vxml version="2.1"
xmlns="http://www.w3.org/2001/vxml">
  <form>
    <block>
      Hello, world!
      <exit/>
    </block>
  </form>
</vxml>

The exit element instructs the interpreter to end execution of the application and return control to the 'interpreter”.

Transitioning with GOTO

<vxml version="2.1"
 xmlns="http://www.w3.org/2001/vxml">
<form>
  <block>
    Goodbye, world!
    <goto next="document2.vxml"/>
  </block>
</form>


The goto element is like  clicking a link on a Web page; both elements redirects execution (or focus) to another location on the current page or cause the browser to fetch another document across the Web.

User Input

<vxml version="2.1"
 xmlns="http://www.w3.org/2001/vxml">
  <form>
    <field name="famous" type="boolean">
      <prompt>
      would you like to be famous?
      </prompt>

      <filled>
      got it!
      <if cond="famous">
        let's schedule an audition
        <goto next="schedule.vxml" />
      <else />
        infamous is a reasonable 
        alternative.
        <goto next="infamous.vxml" />
      </if>
      </filled>
    </field>
  </form>
</vxml>


This example uses the built in boolean (yes/no) grammar built into voiceXML . The example above contains a single form with a single field. The field first queues the prompt, "would you like to be famous?" This example uses TextToSpeech (TTS), the prompt element also allows any number of audio elements, so you could use a recorded audio file instead instead.

Handling Exceptions in VoiceXML

<vxml version="2.1"
 xmlns="http://www.w3.org/2001/vxml">
  <form>
    <field name="famous" type="boolean">
      <prompt>
      would you like to be famous?
      </prompt>

      <noinput>
      Sorry I didn't hear you.
      For famous press 1.
      For infamous press 2.      
      </noinput>

      <nomatch>
      Sorry I didn't get that.
      To be famous say yes.
      Otherwise, say no.    
      </nomatch>

      <filled>
      got it!
      <if cond="famous">
        let's schedule an audition
      <else />
        infamous is a reasonable 
        alternative.
      </if>
      <clear/>
      </filled>
    </field>
  </form>
</vxml>


In this example we handle an exception where the input wasn’t recognized and this is important because the voice interpreter will not always recognize what the user is saying.

No matter how precise, users won't always provide the input allowed by your grammar. Sometimes they won't provide any input at all.

nomatch or a noinput

When these situations occur, the interpreter throws either a nomatch or a noinput event to your application. To prevent your application from exiting when one of these  occur, you need to author one or more event handlers.

Tags: