In this edition of the VoiceXML tour, we will develop the first three dialogs that will play a greeting, ask for a phone number, and look up the customer's address in the Access database.
Well, we've completed our design work for the pizza ordering application, so it's time to get started with developing the static and dynamic VoiceXML application. I've chosen to use IIS and ASP to serve up the dynamic content for this application. The ASP language I've chosen to use is PerlScript, which provides more advanced text process features than other languages. These features will come in handy as you'll see later on. To develop the VoiceXML content, I used Nuance V-Builder to quickly prototype the dialogs based upon our design, and then used notepad to add the ASP code into the VoiceXML dialog files.
Before we dive into the code, let's revisit our design. We have identified six VoiceXML files and scripts that we need to develop. Each file contains zero or more dialogs. We also have detailed dialog flow diagrams for each, which will help us prototype and develop the VoiceXML content. You should probably take another look at the high level architecture diagram again as a reference. We will be developing the first three files in the diagram. These are main.vxml, telephone_number.vxml, and validate_phone_number.asp. As you can imagine, the last file will contain our PerlScript ASP code.
This file will be executed first when customers call into the system. In addition to playing the greeting, it will store a number of application-level variables that we will refer to throughout the application. That means that main.vxml will be our application root, which all other VoiceXML files will refer to.
When a customer calls, they will hear, "Thank you for calling Frank's Pizza Palace".
1 <?xml version="1.0"?> 2 <vxml version="1.0"> 3 <var name="phone_number" /> 4 <var name="address" /> 5 <form id="greeting"> 6 <block name="play_greeting"> 7 <prompt bargein="false"> 8 <audio src="../prompts/greeting.wav" /> 9 </prompt> 10 <goto next="telephone_number.vxml" /> 11 </block> 12 </form> 13 </vxml>
The very first thing we do on lines 3 and 4 is initialize the phone number and address variables. Other dialogs will set these values. Keeping them at an application level makes the values available to all the other dialogs. Line 8 plays our pre-recorded greeting and line 10 transitions to the next dialog, telephone_number.vxml .
This dialog will capture and confirm the customer's phone number and submit it to validate_phone_number.asp for validation. In the original dialog flow diagram, I had split this file into two separate forms; telephone_number and confirm_phone_number. I decided that it would be easier to roll all of the logic into a single form, so I eliminated the confirm_phone_number form. The dialog below also refers to an external grammar on line 5 named PHONE.grammar which uses the PHONE rule. According to the type attribute, this is a GSL grammar, which means it should work on most Voice ASP platforms. This is the same grammar that was used in a previous example.view example 2
Next, we play the prompt on line 7, "May I have your phone number please", which has been pre-recorded and is contained in the phone_number.wav file. The resulting utterance will fill the phone_number field. When the field is filled, it executes the assign statement on line 10, which assigned the phone number as an application variable, also named phone_number. This will make this value available to all other dialogs in the application that specify main.vxml as the application root in the application attribute of the <vxml> element (see line 2).
Next, on lines 13 through 19, we play back the number that the ASR system recognized and which is now assigned as the application variable phone_number. Users will hear, "I heard xxxxxxxxxx. Is this correct?" where xxxxxxxxxx is the phone number that was recognized.
To catch the user's response to this yes or no question,
we transition into a <subdialog>
element on line 20, which refers to the yes_or_no.vxml dialog file and set the return
variable that will be set as confirm. This
subdialog is actually used in several places, so I've included it below:
1 <?xml version="1.0"?> 2 <vxml version="1.0"> 3 <form id="confirm"> 4 <field name="answer" type="boolean?y=1;n=2"> 5 <filled mode="any"> 6 <return namelist="answer" /> 7 </filled> 8 </field> 9 </form> 10 </vxml>
Line 4 of the yes_or_no.vxml dialog above sets the field type to boolean and can accept a verbal "yes" or "no" answer as well as DTMF 1 for yes and DTMF 2 for no. Once the user has answered yes or no, the value is returned back to the caller on line 6.
Now, back in the main dialog above, when yes_or_no.vxml returns a value, we test the value to see whether it's true or false on line 22. if it is true, this means the customer said yes or pressed 1 on their phone keypad. In either case, we submit the phone number to the validate_phone_number.asp script with the <submit> element on line 23. If the user says no or presses 2, then we return them back to the top of the dialog on line 25, where they are prompted for their phone number again.