Telephony Isn't All Talk for Java Developers (cont'd)
Closing Out the Statement
And we're done. We can close the VoiceXML document with the final </vxml> tag and close the output stream itself. We'll go back to showing the entire Java statements for this last bit remembering that we've been producing this file like this all along.
out.println( "</vxml>" );
out.close();
}
The only thing left to do now is to define the grammar. VoiceXML doesn't define a mandatory grammar language, although it suggests using the Java Speech Grammar Format. The Nuance VoiceXML implementation chosen for this example uses a different specialized grammar definition language called GSL. This grammar defines an utterance in mandatory lower case and then the name of a string variable together with the value to be returned for that variable. GSL is capable of great complexity which we won't go into here but you can approximate natural language voice recognition with a clever grammar description. You have to label the grammar with a name starting with a capital letter.
VXMLgrammar
[
[mail] { < Destination "Mail" > }
[weather] { < Destination "Weather" > }
]
We're done! After compiling the code and placing it on a Java-enabled server, we can try out the application by calling (408) 907-4656 , (415) 723-8917, (510) 870-8391, or (707) 780-8962. The Java code can be seen at www.leeanne.com/javavxml.java and the resulting VoiceXML code can be seen at www.leeanne.com/javavxmlapp.vxml.
If we wanted to, we could include text to speech, which would allow us to output any text data likely to found on our system. Here's a sample text-to-speech version of the last form, just to get you started on variations; but the full VoiceXML language description and DTD is the final arbiter of how to achieve any given task.
<form id="Goodbye">
<block>
Thank you for calling. Goodbye.
<exit />
</block>
</form>