Building VoiceXML Dialogs
As mentioned earlier, each field specifies the set of acceptable user responses. Limiting the acceptable responses serves two purposes. First, it allows the responses to be verified and for help in the case of an invalid response to be provided locally without delay of a round-trip over the network to the application server. Second, it is essential to achieving good speech-recognition accuracy - particularly over a relatively low-quality audio channel like a telephone - for the user input to be constrained to particular sets and patterns of words.
In the earlier example, the set of acceptable user inputs is specified implicitly using the "type" attribute ("phone" and "digits" in the example) in the field element. The VoiceXML 2.0 specification defines a number of built-in types that a VoiceXML browser may optionally provide:
In addition to these built-in types, a VoiceXML application can specify its own input types using grammars. A grammar is essentially an enumeration in a compact form of a set of allowable phrases. The following VoiceXML fragment illustrates the use of grammars in an online voice-enabled restaurant application:
<form> <field name="drink"> <prompt>What would you like to drink?</prompt> <grammar mode="voice" xml:lang="en-US" version="1.0" root="drink"> <rule id="drink"> <one-of> <item> coffee </item> <item> tea </item> <item> orange juice </item> <item> milk </item> <item> nothing </item> </one-of> </rule> </grammar> </field> <field name="sandwich"> <prompt>What sandwich would you like?</prompt> <grammar src="sandwiches.grxml"/> </field> <block> <submit next="http://www.example.com/servlet/getOrder"/> </block> </form>
The grammars in this example are specified using the W3C Speech Recognition Grammar Specification [SRGS] format. The first grammar is in-line, and it simply identifies a list of words and phrases ("coffee", "tea", and so on) that the user may say in response to the prompt for that field. Surrounding the list of items with a <one-of> element tells the VoiceXML browser that the user can speak only one of these items at a time.
The second grammar is contained in the dile "sandwiches.grxml" and is referenced via a URI:
<grammar mode="voice" xml:lang="en-US" version="1.0" xmlns="http://www.w3.org/2001/06/grammar" root="sandwich"> <rule id="bread"> <one-of> <item> rye </item> <item> white </item> <item> whole wheat </item> </one-of> </rule> <rule id="ingredient"> <one-of> <item> ham </item> <item> roast beef </item> <item> tomato </item> <item> lettuce </item> <item> <item> swiss </item> <item repeat="0-1"> cheese </item> </item> </one-of> </rule> <rule id="sandwich"> <ruleref uri="#ingredient"/> <item repeat="0-"> <item repeat="0-1"> and </item> <ruleref uri="#ingredient"/> </item> <item> on </item> <ruleref uri="#bread"/> </rule> </grammar>
This grammar consists of three rules. The first rule, named "bread" is just a list of bread types, similar to "drink" grammar which was place in-line in the form. It allows the user to say either "rye" or "white" or "whole wheat."
The second rule in this grammar, named "ingredient" is also a fairly simple list of items, but one of its items included an optional part. The last item in the rule includes a repeat attribute on the "cheese" item, which makes "cheese" optional. To match this rule, the user can say either "swiss" or "swiss cheese".
The third rule, named "sandwich", specifies that a complete description of a sandwich consists of a series of rule references, to the other rules defined within this grammar. It states that a "sandwich" is made up of at least one ingredient, followed by zero or more additional ingredients optionally separated by the word "and", and ending finally with the word "on" followed by the name of a bread. This rule would accept phrases such as "ham and swiss on rye" and "lettuce and tomato on whole wheat."
Page 2 of 3