Adding Voice to XHTML 

by Gerald McCobb and Jeff Kusnitz 



Listing One



<?xml version="1.0"?>

<html xmlns="http://www.w3.org/1999/xhtml"

      xmlns:vxml="http://www.w3.org/2001/vxml"

      xmlns:ev="http://www.w3.org/2001/xml-events"

      xmlns:xv="http://www.voicexml.org/2002/xhtml+voice">

  <head><title>Sample X+V Application</title>

    <!-- VoiceXML -->

    <vxml:form id="RunForm">

      <vxml:block>Enter departure and arrival cities</vxml:block>

      <vxml:field xv:id="fieldDeptCity" name="fieldDeptCity">

        <vxml:grammar src="city.grxml"/>

        <vxml:prompt>Where would you like to leave from?

        </vxml:prompt>

      </vxml:field>

      <vxml:field xv:id="fieldDestCity" name="fieldDestCity">

        <vxml:grammar src="city.grxml"/>

        <vxml:prompt>Where would you like to go?</vxml:prompt>

      </vxml:field>

      <vxml:catch event="nomatch noinput help">

          For example, say New York.

      </vxml:catch>

    </vxml:form>

    <!-- sync's -->

    <xv:sync xv:input="txtBoxDeptCity" xv:field="#fieldDeptCity"/>

    <xv:sync xv:input="txtBoxDestCity" xv:field="#fieldDestCity"/>

    <!-- scripts -->

    <script ev:event="vxmlerror" ev:observer="bd1" declare="declare">

    document.getElementById("pg1").innerHTML =

                      "Sorry, there was a speech error";

    </script>

    <script ev:event="vxmldone" ev:observer="bd1" declare="declare">

        document.getElementById("pg1").innerHTML = "Departure city: "

             + document.travelForm.txtBoxDeptCity.value

             + "  Arrival city: "

             + document.travelForm.txtBoxDestCity.value + ".";

    </script>

  </head>

  <body id="bd1" ev:event="load" ev:handler="#RunForm">

    <p id="pg1">Enter departure and arrival cities</p>

    <form name="travelForm" action=".">

      <input name="txtBoxDeptCity" type="text" />&nbsp;

      <input name="txtBoxDestCity" type="text" />

    </form>

  </body>

</html>





Listing Two



<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE grammar PUBLIC "-//W3C//DTD GRAMMAR 1.0//EN"

                  "http://www.w3.org/TR/speech-grammar/grammar.dtd">

<grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar" 

         tag-format="semantics/1.0"

         mode="voice" xml:lang="en-US" root="uscity">

<rule id="california">

    <one-of>

        <item>

            <one-of>

                <item> Los Angeles </item>

                <item> L.A. </item>

            </one-of><tag><![CDATA[$="Los Angeles"]]></tag>

        </item>

        <item> San Francisco 

             <tag><![CDATA[$="San Francisco"]]></tag>

        </item>

    </one-of>

</rule>

<rule id="florida">

    <one-of>

        <item> Miami <tag><![CDATA[$="Miami"]]></tag></item>

    </one-of>

</rule>

<rule id="illinois">

    <one-of>

        <item>Chicago<tag><![CDATA[$="Chicago"]]></tag></item>

    </one-of>

</rule>

<rule id="massachusetts">

    <one-of>

        <item>Boston <tag><![CDATA[$="Boston"]]></tag></item>

    </one-of>

</rule>

<rule id="newyork">

    <one-of>

        <item> New York 

            <item repeat="0-1"> City 

               <tag><![CDATA[$="New York City"]]></tag>

            </item>

        </item>

    </one-of>

</rule>

<rule id="washingtonDC">

    <one-of>

        <item> Washington </item>

        <item>

            <item repeat="0-1"> Washington </item> D.C. 

        </item>

    </one-of><tag><![CDATA[$="District of Columbia"]]></tag>

</rule>

<rule id="uscity" scope="public">

    <one-of>

        <item>

          <ruleref uri="#california"/>

             <tag><![CDATA[ $= $california;]]></tag></item>

        <item><ruleref uri="#florida"/>

             <tag><![CDATA[ $= $florida;]]></tag></item>

        <item><ruleref uri="#illinois"/>

              <tag><![CDATA[ $= $illinois;]]></tag></item>

        <item><ruleref uri="#massachusetts"/>

              <tag><![CDATA[ $= $massachusetts;]]></tag></item>

        <item><ruleref uri="#newyork"/>

              <tag><![CDATA[ $= $newyork;]]></tag></item>

        <item><ruleref uri="#washingtonDC"/>

              <tag><![CDATA[ $= $washingtonDC;]]></tag></item>

    </one-of>

</rule>

</grammar>















8





