Mixed-initiative application and form-level grammars

In a machine-directed application, the computer controls all interactions by sequentially executing each form item a single time.

However, VoiceXML also supports mixed-initiative applications in which either the system or the user can direct the conversation. This is done using a combination of form level grammars to control user input and <initial> elements to specify prompts.

Form-level grammars allow a greater flexibility and more natural responses than field-level grammars because the user can fill in the fields in the form in any order and can fill more than one field as a result of a single utterance. For example, the following city/state grammar:

<?xml version="1.0" encoding="ISO-8859-1"?>
<grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar"
  xml:lang="en-US" mode="voice" root="citystate" tag-format="semantics/1.0">
<rule id="citystate">
   <one-of>
      <item>
         <ruleref uri="#cityfirst"/>
            <tag>
             $.city = $cityfirst.city;
             if ( typeof ( $cityfirst.state ) != "undefined" )
                $.state = $cityfirst.state;
            </tag>
      </item>
      <item>
         <ruleref uri="#statefirst"/>
            <tag>
             $.state = $statefirst.state;
             if ( typeof ( $statefirst.city ) != "undefined" )
                $.city = $statefirst.city;
            </tag>
      </item>
   </one-of>
</rule>
<rule id="cityfirst">
   <item>
      <ruleref uri="#citylist"/> <tag>$.city = $citylist;</tag>
   </item>
   <item repeat="0-1">
      <ruleref uri="#statelist"/> <tag>$.state = $statelist;</tag>
   </item>
</rule>
<rule id="statefirst">
   <item>
      <ruleref uri="#statelist"/><tag>$.state = $statelist;</tag>
   </item>
   <item repeat="0-1">
      <ruleref uri="#citylist"/> <tag>$.city = $citylist;</tag>
    </item>
</rule>
<rule id="citylist" scope="public">
   <one-of>
      <item>San Francisco</item>
      <item>New York</item>
      <item>Los Angeles</item>
      <item>Boca Raton</item>
   </one-of>
</rule>
<rule id="statelist" scope="public">
   <one-of>
      <item>California</item>
      <item>New York</item>
      <item>Florida</item>
   </one-of>
</rule>
</grammar>

can be used with this VoiceXML document:

<?xml version="1.0" encoding="iso-8859-1"?>
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml" xml:lang="en-US">
 <form id="getinfo">
  <grammar src="citystate.grxml"/>
  <initial name="start">
   <prompt>City and state please.</prompt>
   <noinput><reprompt/></noinput>
   <nomatch count="2">
    <prompt>
     Sorry, I am having trouble understanding you.  Let's try one piece of
     information at a time.
    </prompt>
    <reprompt/>
    <assign name="start" expr="true"/>
   </nomatch>
  </initial>
  <field name="city">
   <prompt>
    Please say the name of a city.
   </prompt>
   <grammar src="citystate.grxml#citylist"/>
   <filled>
    <prompt>
     The city is <value expr="city"/>
    </prompt>
   </filled>
  </field>
  <field name="state">
   <prompt>
    Please say the name of a state.
   </prompt>
   <grammar src="citystate.grxml#statelist"/>
   <filled>
    <prompt>
     The state is <value expr="state"/>
    </prompt>
   </filled>
  </field>
  <filled>
   <prompt>
    Thank you.  The city and state are <value expr="city"/>,
    <value expr="state"/>.
   </prompt>
  </filled>
 </form>
</vxml>