Tellme More - Mother of Perl | 2 | WebReference

Tellme More - Mother of Perl | 2

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

Tellme More

VoiceXML Basics

XML Rules

Since VoiceXML is XML, we must adhere to the basic XML rules. Without going into excruciating detail, you should adhere to the following basic XML guidelines:

Hello World

There are 47 elements (or tags) in the VoiceXML format compared to 91 for HTML. VoiceXML is capable of something as simple as delivering content over the phone or as complex as a full-fledged E-Commerce application. No introduction is complete without a Hello World example.

Example 1.

<?xml version="1.0"?>
<vxml version="1.0"> 
  <form> 
    <block>Hello World!</block> 
  </form>
</vxml>
	

The example above will synthesize "Hello World!" and then exit. Go ahead and try it right now by calling 1-800-555-tell and then 1-73759. Then select 1 from the menu options.

Fortunately, not all VoiceXML dialogs have to be synthesized. We could have also played a recording of someone saying "Hello World" by including an audio element with a src attribute containing the url to the audio file.

<?xml version="1.0"?>
<vxml version="1.0"> 
  <form> 
    <block>
	   <audio src="hello.wav">Hello World!</audio>
	 </block> 
  </form>
</vxml>

Dialogs

Each VoiceXML document contains one or more dialogs. There are two types of dialogs, forms and menus. A form collects a user's inputs from fields, just like an HTML form. Menus present a list of choices that the user can select from, similar to a list of links that a user would select from on a Web site. More advanced applications will contain multiple dialogs and possibly even sub-dialogs.

For example, when you dial the number on the back of a credit card, it might ask you to enter your credit card number and your social security number or zip code. This is an example of a form, because the application is gathering information from you via your touch-tone phone. This information is submitted to the application, which then might give you a list of options. That's an example of a menu dialog.

By default on Tellme.com, if you create a VoiceXML document that contains multiple forms, it will execute each form in the order in which they occur. For example, let's add a second form to our Hello World example and see what happens.

Example 2.

<?xml version="1.0"?>
<vxml version="1.0"> 
  <form> 
    <block>Hello World!</block> 
  </form>
  
  <form>
    <block>My name is mud.</block>
  </form>
</vxml>

If you call Tellme, you will hear:

Tellme: Hello world, my name is mud.

Goto

Sometimes you may want to skip from one form to another in a document, but not sequentially. This is possible via the goto element. With it, you can skip to another location in the current document, or even in a separate document. As a simple example, we'll add a third form to our Hello World example that skips from the first to the third form within the document.

Example 3.

<?xml version="1.0"?>
<vxml version="1.0"> 
  <form id="hello"> 
    <block>Hello World!
	   <goto next="#jack"/>
    </block>
		
  </form>
  
  <form id="mud">
    <block>My name is mud.</block>
  </form>
	
  <form id="jack">
    <block>My name is Jack.</block>
  </form>
</vxml>		

If you demo the example on 800-555-tell, you will hear the following:

Tellme: Hello World, my name is Jack.

Prompts

At some point, you're probably going to want to get input from the user. This is where the prompt element comes in. The prompt element synthesizes the text contained in the element and waits for the user to provide input.

<prompt>Please enter your 
4 digit pin code.</prompt>

You can also play an audio file instead of synthesized text.

<prompt><audio src="pin.wav">Please enter your 
4 digit pin code.</audio></prompt>

The code above will attempt to play the pin.wav file. You're probably wondering why there's text in addition to the audio file . In the case that Tellme cannot retrieve the audio file, it will synthesize the text as a last resort, therefore, it's a good idea to include the text even when you're linking to an audio file.

<?xml version="1.0"?>
<vxml version="1.0"> 
  <form id="hello"> 
    <block>Hello World!</block>
      <field name="name">
        <prompt>What is your name?</prompt>
		</field>
  </form>
</vxml>		

The code above is not a demo on the Mother of Perl Tellme extension. That's because the code isn't ready to run yet. If you tried to run it as is, it would prompt for your name and then report that an error had occurred. This is because we have to add additional logic to handle user input and error conditions. We'll cover these issues in the next three sections.


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

http://www.internet.com

Produced by Jonathan Eisenzopf
All Rights Reserved. Legal Notices.
Created: February 23, 2001

URL: http://www.webreference.com/perl/tutorial/20/2.html