In previous posts, we’ve compared VoiceXML to HTML and discussed the similarities in the way one would develop applications with both programming languages. Because we often make this comparison, developers who are new to building voice applications often ask for example VoiceXML code, so we’ve listed some below. In addition we’ve included links to some other great resources for developers.
The following example comes from the W3C’s Voice Extensible Markup Language (VoiceXML) Version 2.0 specification which can be found at http://www.w3.org/TR/voicexml20/:
VoiceXML is designed for creating audio dialogs that feature synthesized speech, digitized audio, recognition of spoken and DTMF key input, recording of spoken input, telephony, and mixed initiative conversations. Its major goal is to bring the advantages of Web-based development and content delivery to interactive voice response applications.
Here are two short examples of VoiceXML. The first is the venerable “Hello World”:
<?xml version=”1.0″ encoding=”UTF-8″?>
<vxml 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”
version=”2.0″>
<form>
<block>Hello World!</block>
</form>
</vxml>
The top-level element is <vxml>, which is mainly a container for dialogs. There are two types of dialogs: forms and menus. Forms present information and gather input; menus offer choices of what to do next. This example has a single form, which contains a block that synthesizes and presents “Hello World!” to the user. Since the form does not specify a successor dialog, the conversation ends.
Our second example asks the user for a choice of drink and then submits it to a server script:
<?xml version=”1.0″ encoding=”UTF-8″?>
<vxml 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”
version=”2.0″>
<form>
<field name=”drink”>
<prompt>Would you like coffee, tea, milk, or nothing?</prompt>
<grammar src=”drink.grxml” type=”application/srgs+xml”/>
</field>
<block>
<submit next=”http://www.drink.example.com/drink2.asp”/>
</block>
</form>
</vxml>
A field is an input field. The user must provide a value for the field before proceeding to the next element in the form. A sample interaction is:
C (computer): Would you like coffee, tea, milk, or nothing?
H (human): Orange juice.
C: I did not understand what you said. (a platform-specific default message.)
C: Would you like coffee, tea, milk, or nothing?
H: Tea
C: (continues in document drink2.asp)
For more VoiceXML examples, please visit Plum’s developer documentation page at VoiceXML Documentation
The VoiceXML Forum is another great resource for information about the VoiceXML community.
1