dcsimg
July 21, 2017
Hot Topics:

VoiceXML Developer Series: A Tour Through VoiceXML, Part III

  • October 3, 2002
  • By Jonathan Eisenzopf
  • Send Email »
  • More Articles »

Use built-in field grammars to match speech and DTMF input

There are seven built-in data types that VoiceXML interpreters can recognize. These are:

  • number
  • date
  • time
  • currency
  • phone
  • digits
  • boolean

All of the built-in types can accept DTMF tones and/or spoken text. We will discuss each built-in type with an example for each.

Number

The number type will recognize spoken whole numbers like "One-Hundred Twenty-Three" as well as numbers with decimal points such as "Fifty-Five Point Nine". When entering a number via DTMF tones, the * character represents the decimal point.

    <field name="age" type="number">
      <prompt bargein="true">How old are you?</prompt>
    </field>

Boolean

The boolean type returns either a true or false. Two parameters can be passed with the boolean type that indicate which DTMF tones correspond with true and false.

    <field name="likebooks" 
type="boolean?y=1;n=2">
      <prompt bargein="true">
Have you read William Shatner's books?</prompt>
    </field>

In the example above, 1 is true and 2 is false. If you evaluate the value of the result, it will be either yes or no. Spoken input (for English) is yes for true and no for false.

Digits

We've already seen this one, but below is an example for completeness:

    <field name="ccnum" type="digits?length=16">
      <prompt bargein="true">
Please say your credit card number.</prompt>
    </field>

As before, you can pass a length parameter, which specifies the exact number of digits to match or you can include a maxlength and/or minlength, which specify the maximum and minimum number of digits to match respectively.

Date

The date type will match the day, month, and year when spoken. For example, "August first nineteen seventy four". When specifying a date with the keypad, the user should enter yyyymmdd where yyyy is the year, mm is the month, and dd is the day. If the year is not specified by the user, the resulting string will contain ???? for the year. In the same manner, if the month or day are not specified, the string value for the month or day will be ?? respectively.

    <field name="ccexpire" type="date">
      <prompt bargein="true">
Please say the expiration date for your 
      credit card.</prompt>
    </field>

Currency

The currency type will recognize dollars and cents (or whatever currency names are used in your locale. i.e. pounds and yen). For example, "Fifty dollars, thirty seven cents". When entering a currency amount via the keypad, use the * character for the decimal point.

    <field name="price" type="currency">
      <prompt bargein="true">What price would 
you like to play for these tickets?</prompt>
    </field>

Time

Time can be spoken in 12 or 24 hour formats. For example, "twelve thirty PM" or "twenty three ten". Time can also be entered via a keypad. The resulting string will contain four numbers plus a p, a, h, or ? character. An a means AM, p means PM, h means 24 hour time, and a ? means the system was not able to determine the format.

    <field name="time" type="time">
      <prompt bargein="true">
What time before the show would you 
      like to pick up your tickets?</prompt>
    </field>

Phone

The phone type can contain a number of digits and alternatively an extension. For example, "eight-zero-zero-five-five-five-one-two-one-two extension one-zero-one". When entering a phone number via the keypad, the * character indicates that the numbers that follow are the extension to the number that was entered previously. The resulting text will contain the phone number with an x character separating the main number and extension if an extension was specified.

    <field name="phone" type="phone">
      <prompt bargein="true">
What phone number can we reach 
      you at if the show gets cancelled?</prompt>
    </field>

Example 2

Now let's pull all the individual fields together into one form. To try this example, call VoiceXML Planet at 510-315-6666; press 1 to listen to the demos, then press 2 to hear this example.

<vxml version="1.0">
  <form id="form1">
    <block name="block1">To purchase tickets 
for William Shatner's Tambourine Man world tour, 
do whatever the robotic man on the phone 
says.</block>
<field modal="false" hotword="false" name="age" type="number">
<prompt bargein="true">
How old are you?</prompt>
</field>
<field name="ticketnum" 
type="number">
<prompt bargein="true">
How many tickets do you need?</prompt>
</field>
<field name="likebooks" 
type="boolean?y=1;n=2">
<prompt bargein="true">
Have you read William Shatner's 
books or watched the made for television 
special?</prompt>
</field>
<field name="ccnum" 
type="digits?length=16">
<prompt bargein="true">
Please say your credit card number.</prompt>
</field>
<field name="ccexpire" type="date">
<prompt bargein="true">Please say 
the expiration date for your 
credit card.</prompt>
</field>
<field name="price" type="currency">
<prompt bargein="true">
What price would you like to play 
      for these tickets?</prompt>
</field>
<field name="time" type="time">
<prompt bargein="true">
What time before the show would 
      you like to pick up your tickets?</prompt>
</field>
<field name="phone" type="phone">
<prompt bargein="true">
What phone number can we reach 
      you at if the show gets cancelled?</prompt>
</field>
<block name="results">You are 
<value expr="age" />years old 
and want to purchase
<value expr="ticketnum" />tickets. 
When asked whether you've read William Shatner's 
books or seen the movie, you said
<value expr="likebooks" />. 
Your credit card number is 
<value expr="ccnum" />, which 
expires on 
<value expr="ccexpire" />. 
If William Shatner 
needs a friend, he can call 
<value expr="phone" />. Thank 
you for your order.
</block>
</form>
</vxml>

Conclusion

In this article, we've learned about creating metadata, manipulating variables, and gathering form field input via built-in grammar types. We are well on our way to being able to create full-fledged VoiceXML applications. Join us next time for another edition of VoiceXML Developer as we continue our tour through VoiceXML.

About Jonathan Eisenzopf

Jonathan is a member of the Ferrum Group, LLC based in Reston, Virginia that specializes in Voice Web consulting and training. He has also written articles for other online and print publications including WebReference.com and WDVL.com. Feel free to send an email to eisen@ferrumgroup.com regarding questions or comments about the VoiceXML Developer series, or for more information about training and consulting services.





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel