- VoiceXML Form Structure
- The Field Element
- Baseball Facts Hotline
- Login Form Version 1
- Multiple Prompts
- Understanding the Form Engine
- The <submit> element
- User Confirmation
- <nomatch> and <noinput>
- Baseball Hotline: What Does the User Want?
Baseball Hotline: What Does the User Want?
Now that we’ve set up a login form that delivers a user-id and password to a server, we’re ready to get down to business and ask our users what kind of baseball information they want. Our server contains yearly data for Most Valuable Player (MVP), Home Run leaders, and Cy Young Pitching Award winners. What we need is a VoiceXML form that will prompt the user for category and year. Since there are no built-in data types that will handle our application-specific options, we need to define our own grammar for the selection categories. However, for the year we can again use the built-in type for digits and restrict the number of digits to four.
Listing 3 shows the VoiceXML file that our web server will return to the voice server, upon receipt and validation of the login-id and pin.
Listing 3 A VoiceXML form with a grammar
<vxml version="2.0" xmlns=’http://www.w3.org/2001/vxml’ xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance’ xsi:schemaLocation=’http://www.w3.org/2001/vxml http://www.w3.org/TR/voicexml20/vxml.xsd’> <form id="getRequest"> <field name="cat" > <prompt>Please enter the sports category.</prompt> <grammar type="application/x-gsl" mode="voice"> <![CDATA[ [ [(m v p) (most valuable player)] {<cat "010">} [home run] {<cat "020">} [(pitching) (cy young)] {<cat "030">} ] ]]> </grammar> <noinput>Sorry I did not hear any input for your phone number,</noinput> <nomatch>Sorry, I did not understand that category. please try again.</nomatch> </field> <field name="year" type="digits?length=4"> <prompt>Please say or key in the digits for the year for which you’d like the data</prompt> </field> <block> <prompt> Ok. Got it. </prompt> <submit next="http://www.example.com/servlet/request" method="GET" namelist="cat year"> </block> </form> </vxml>
The main difference between this form and our previous login form is the inclusion of a grammar element. Grammars can be external or inline. Here we use an inline grammar based on the widely available Nuance GSL grammar. In this example, the grammar constrains the allowable phrases a user can say. Note that in our form, the inline grammar is placed inside a CDATA element. This is because the grammar uses symbols such as "<" and ">", which the VoiceXML processor would try and interpret as XML elements.
When the voices server gets a user reply to its prompt, it attempts to match the voice input against one of the words or letter sequences specified in the grammar. To get home run information, the user must say "home run". However, to get data about the most valuable player, the user can either say the letter sequence "M V P" or say the phrase "most valuable player". When there are alternatives for the user, each alternative is enclosed in parentheses.
When a match is made against one of the grammar options, the value inside the angle brackets is returned as the value of the variable. For example, in the following grammar line, if the user says "pitching" or "cy young", the value of "030" is returned as the value of the cat variable:
[(pitching) (cy young)] {<cat "030">}
In our example, it is this value, "030", that is delivered to the server as part of the submit found in the last block. If our server is set up properly, it will use the category and year values, to look up the requested data, and embed it in another VoiceXML document.
Next time we’ll look in more detail at the grammar options available to Voice XML developers and how grammars can be used to create even more complex dialogs.