Telephony Isn't All Talk for Java Developers (cont'd)
Outputting the Actual Code
At this point, we're ready to start outputting the actual VoiceXML code. Like any XML document, we should start out with an XML Prolog, following that with the VoiceXML tags. VoiceXML documents consist of "forms" containing a dialog and "fields" within the forms to capture user responses. Add a few logical operators, some structure tags, an exception handler, and miscellaneous flow tags, and you've covered the basics. You can find much more information about VoiceXML at W3C and some coding tips at Voxeo.
This section of the code is very repetitive, since you're just writing text to the HTTP output, where it will be read by the XML user agent responsible for executing the application. Because the VSP will handle the actual execution for you, your server doesn't need to know anything about telephones at all.
// Create the VoiceXML code
out.println( "" );
out.print( " '-" );
out.print( "//Nuance/DTD VoiceXML " );
out.print( "1.0b//EN'" );
out.print( "'http://community.voxeo.com/" );
out.println( "vxml/nuancevoicexml.dtd'>" );
out.println( "" );
out.println( "" );
out.println( "
Dispensing with Print Statements
At this point, we'll dispense with the Java print statements, since they just get in the way of understanding the structure of the VoiceXML code itself. First, we'll recapitulate the code so far and add a bit more describe the voice input form, very similar to an ordinary HTML input form, and get us to the point where we need to describe what our voice input should look like.
<?xml version="1.0"?>
<!DOCTYPE vxml PUBLIC '-//Nuance/DTD VoiceXML 1.0b//EN'
'http://community.voxeo.com/vxml/nuancevoicexml.dtd'>
<vxml version="1.0">
<!-- Label input form so we can branch to it -->
<form id="VoiceApp">
<!-- Exception handlers -->
<catch event="exit">
<goto next="#Goodbye" />
</catch>
<catch event="help">
<audio src="vxmlhelp.wav" />
<reprompt />
</catch>
<catch event="operator">
<audio src="vxmlnoop.wav" />
<reprompt />
</catch>
<noinput>
<audio src="vxmlnoinput.wav" />
<reprompt />
</noinput>
<nomatch>
<audio src="vxmlnomatch.wav" />
<reprompt/>
</nomatch>
<!-- Delimit and name the input field -->
<field name="Destination">
<prompt>
<audio src="vxmlwelcome.wav" />
<audio src="vxmljavachoice.wav" />
</prompt>