Speech Calculator
calc.vxml
xml version="1.0" encoding="UTF-8"
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
<meta name="description" content="Calculator"/>
<meta name="author" content="Annu Paganus and Guillaume Quenel"/>
<meta name="copyright" content="free for non commercial purpose"/>
<var name="result" />
<link event="help">
<grammar root="main">
<rule id="main" scope="public">
<item repeat="0-1"> please </item>
<item repeat="0-1"> I need </item>
help
<item repeat="0-1"> me </item>
<item repeat="0-1"> please </item>
</rule>
</grammar>
</link>
<form id="start">
<block> Welcome to the calculator. Please say what you want to do.
<clear namelist="number_a operation number_b"/>
<assign name="mixed" expr="false"/>
</block>
<var name="summarization"/>
<nomatch>
<prompt> I didn't understand you. </prompt>
<reprompt/>
</nomatch>
<nomatch count="3">
<prompt> I didn't understand you again. This is your last chance. </prompt>
<reprompt/>
</nomatch>
<nomatch count="4">
<prompt> Sorry, I didn't understand you again. I am giving up. Bye. </prompt>
<exit/>
</nomatch>
<help>
Sorry, no help is available.
</help>
<noinput cond="true" count="1">
<prompt> Please say something, it is no time to sleep...! </prompt>
</noinput>
<noinput cond="true" count="2">
<prompt> I have no time to play with you. Good Bye </prompt> <exit/>
</noinput>
<grammar src="calc.grxml"/>
<initial name="mixed">
<nomatch>
I didn't understand you. Please specify one number, the operation and the second number.
</nomatch>
<nomatch count="2">
Sorry, I still don't understand you. I will ask you for the information one piece at a time.
<assign name="mixed" expr="true"/>
<reprompt/>
</nomatch>
<help>
You can specify one number, the operation and the second number.
</help>
</initial>
<field name="number_a" slot="calc.numa">
What is the first number?
<grammar src="calc.grxml#thenumber"/>
<nomatch>
I didn't understand you. Say a number
</nomatch>
<nomatch count="2">
I didn't understand you.
</nomatch>
<help>
Please say a number between one and ninety nine
</help>
<filled>
<prompt> Number <value expr="number_a"/> </prompt>
</filled>
</field>
<field name="operation" slot="calc.oper">
What operation do you want to do?
<grammar src="calc.grxml#operation"/>
<nomatch>
I didn't understand you. Please say what operation you want to compute.
</nomatch>
<nomatch count="2">
I didn't understand you. Say plus, minus, divide or multiply.
</nomatch>
<help>
Please say plus, minus, divide or multiply.
</help>
<filled>
<prompt> operation <value expr="operation"/></prompt>
</filled>
</field>
<field name="number_b" slot="calc.numb">
What is the second number?
<grammar src="calc.grxml#thenumber"/>
<nomatch>
I didn't understand you. Say a number
</nomatch>
<nomatch count="2">
I didn't understand you.
</nomatch>
<help>
Please say a number between one and ninety nine
</help>
<filled>
<prompt> number <value expr="number_b"/></prompt>
</filled>
</field>
<block>
<if cond="operation=='divided' && number_b == '0'">
<prompt> I can't divide a number by zero, your operation is impossible </prompt>
<elseif cond="operation=='divided' && number_b != '0'"/>
<assign name="result" expr="number_a / number_b" />
<elseif cond="operation=='minus'" />
<assign name="result" expr="number_a - number_b" />
<elseif cond="operation=='multiply'" />
<assign name="result" expr="number_a * number_b" />
<elseif cond="operation=='plus'" />
<assign name="result" expr="Number(number_a) + Number(number_b)" />
</if>
<script> <![CDATA[
summarization = number_a;
summarization += ' ';
summarization += operation;
summarization += ' ';
summarization += number_b;
summarization += ' equals ';
summarization += result;
]]> </script>
<if cond="operation!='divided' || number_b != '0'">
<prompt> You ask to compute <value expr="summarization"/>. </prompt>
</if>
<goto next="#is_correct"/>
</block>
</form>
<form id="is_correct">
<field name="yesno">
<noinput> Calculator is about to exit. Good bye! <exit/> </noinput>
<nomatch> I didn't understand you. Please say yes or no</nomatch>
<prompt>Do you want to continue?</prompt>
<grammar src="yesno.grxml"/>
<filled>
<if cond="yesno == 'yes'">
<goto next="#start"/>
<else/>
<prompt>Thank you for using this calculator!</prompt>
<exit />
</if>
</filled>
</field>
</form>
</vxml>
calc.grxml
xml version="1.0" encoding="UTF-8"
<grammar version="1.0" root="computation" xmllang="en">
<meta name="description" content="grammar for calculator"/>
<meta name="author" content="Annu Paganus and Guillaume Quenel"/>
<meta name="copyright" content="free for non commercial purpose"/>
<rule id="politness1">
<item repeat="0-1"> please </item>
<item repeat="0-1">I</item>
<item repeat="0-">
<ruleref uri="#what"/>
</item>
<item repeat="0-1">to</item>
<item repeat="0-1">calculate</item>
</rule>
<rule id="politness2">
<item repeat="0-1">
<one-of>
<item> please </item>
<item> thank you </item>
<item> thanks </item>
<item> is equal </item>
<item> is equal to</item>
<item> equals </item>
<item> together </item>
</one-of>
</item>
</rule>
<rule id="computation" scope="public">
<tag>out.calc = new Object;</tag>
<ruleref uri="#politness1"/>
<item repeat="1-">
<one-of>
<item>
<item>
<ruleref uri="#thenumber"/>
<tag>out.calc.numa = meta.current().text;</tag>
</item>
</item>
<item>
<item>
<one-of>
<item><ruleref uri="#op_no_order"/></item>
<item><ruleref uri="#op_in_order"/></item>
</one-of>
<tag>out.calc.oper = meta.current().text;</tag>
</item>
</item>
<item>
<item>
<ruleref uri="#thenumber"/>
<tag>out.calc.numa = meta.current().text;</tag>
</item>
<item>
<one-of>
<item><ruleref uri="#op_no_order"/></item>
<item><ruleref uri="#op_in_order"/></item>
</one-of>
<tag>out.calc.oper = meta.current().text;</tag>
</item>
<item repeat="0-1">
<ruleref uri="#thenumber"/>
<tag>out.calc.numb = meta.current().text;</tag>
</item>
</item>
<item>
<item>
<ruleref uri="#op_no_order"/>
<tag>out.calc.oper = meta.current().text;</tag>
</item>
<item>
<ruleref uri="#thenumber"/>
<tag>out.calc.numa = meta.current().text;</tag>
</item>
<item>
<ruleref uri="#combine"/>
</item>
<item>
<ruleref uri="#thenumber"/>
<tag>out.calc.numb = meta.current().text;</tag>
</item>
</item>
<item>
<item>
<ruleref uri="#op_in_order"/>
<tag>out.calc.oper = meta.current().text;</tag>
</item>
<item>
<ruleref uri="#thenumber"/>
<tag>out.calc.numb = meta.current().text;</tag>
</item>
<item> from </item>
<item>
<ruleref uri="#thenumber"/>
<tag>out.calc.numa = meta.current().text;</tag>
</item>
</item>
</one-of>
</item>
<ruleref uri="#politness2"/>
</rule>
<rule id="thenumber" scope="public">
<one-of>
<item><ruleref uri="#ones" /><tag>out=Number(rules.ones);</tag></item>
<item><ruleref uri="#tens" /><tag>out=Number(rules.tens);</tag></item>
<item><ruleref uri="#twos" /><tag>out=Number(rules.twos);</tag></item>
<item><ruleref uri="#tens" /><tag>out=Number(rules.tens);</tag>
<ruleref uri="#ones" /><tag>out=Number(out)+Number(rules.ones);</tag>
</item>
</one-of>
</rule>
<rule id="ones">
<one-of>
<item>0</item>
<item>zero<tag>out=0</tag></item>
<item>1</item>
<item>one<tag>out=1</tag></item>
<item>2</item>
<item>two<tag>out=2</tag></item>
<item>3</item>
<item>three<tag>out=3</tag></item>
<item>4</item>
<item>four<tag>out=4</tag></item>
<item>5</item>
<item>five<tag>out=5</tag></item>
<item>6</item>
<item>six<tag>out=6</tag></item>
<item>7</item>
<item>seven<tag>out=7</tag></item>
<item>8</item>
<item>eight<tag>out=8</tag></item>
<item>9</item>
<item>nine<tag>out=9</tag></item>
</one-of>
</rule>
<rule id="twos">
<one-of>
<item>10</item>
<item>ten<tag>out=10</tag></item>
<item>11</item>
<item>eleven<tag>out=11</tag></item>
<item>12</item>
<item>twelve<tag>out=12</tag></item>
<item>13</item>
<item>thirteen<tag>out=13</tag></item>
<item>14</item>
<item>fourteen<tag>out=17</tag></item>
<item>15</item>
<item>fifteen<tag>out=15</tag></item>
<item>16</item>
<item>sixteen<tag>out=16</tag></item>
<item>17</item>
<item>seventeen<tag>out=17</tag></item>
<item>18</item>
<item>eighteen<tag>out=18</tag></item>
<item>19</item>
<item>nineteen<tag>out=19</tag></item>
</one-of>
</rule>
<rule id="tens">
<one-of>
<item>20</item>
<item>twenty<tag>out=20</tag></item>
<item>30</item>
<item>thirty<tag>out=30</tag></item>
<item>40</item>
<item>fourty<tag>out=40</tag></item>
<item>50</item>
<item>fifty<tag>out=50</tag></item>
<item>60</item>
<item>sixty<tag>out=60</tag></item>
<item>70</item>
<item>seventy<tag>out=70</tag></item>
<item>80</item>
<item>eighty<tag>out=80</tag></item>
<item>90</item>
<item>ninety<tag>out=90</tag></item>
</one-of>
</rule>
<rule id="operation" scope="public">
<item repeat ="0-1">I</item>
<item repeat ="0-1">want</item>
<item repeat ="0-1">to</item>
<one-of>
<item><ruleref uri="#op_no_order"/></item>
<item><ruleref uri="#op_in_order"/></item>
</one-of>
<tag> out = meta.current().text;</tag>
</rule>
<rule id="op_no_order">
<one-of>
<item> plus </item>
<item> add <tag>out="plus"</tag></item>
<item> sum <tag>out="plus"</tag></item>
<item> multiply </item>
<item> times <tag>out="multiply"</tag></item>
<item> divided </item>
<item> divided by <tag>out="divided"</tag></item>
<item> divide <tag>out="divided"</tag></item>
<item> division <tag>out="divided"</tag></item>
<item> result </item>
<item> equals <tag>out="result"</tag></item>
</one-of>
</rule>
<rule id="op_in_order">
<one-of>
<item> minus </item>
<item> subtract <tag>out="minus"</tag></item>
</one-of>
</rule>
<rule id="combine">
<one-of>
<item>and</item>
<item>with</item>
<item>to</item>
<item>by</item>
<item>plus</item>
</one-of>
</rule>
<rule id="what">
<one-of>
<item> want </item>
<item> would like </item>
<item> could you </item>
<item> can you </item>
<item> what is </item>
<item> tell me </item>
<item> say </item>
<item> to know</item>
<item> please </item>
</one-of>
</rule>
</grammar>
yesno.grxml
xml version="1.0" encoding="UTF-8"
<grammar version="1.0" root="yesno" xmllang="en" tag-format="semantics/1.0-literals">
<meta name="description" content="yes/no grammar"/>
<meta name="author" content="Annu Paganus and Guillaume Quenel"/>
<meta name="copyright" content="free for non commercial purpose"/>
<rule id="yesno" scope="public">
<one-of>
<item><ruleref uri="#yes"/><tag>yes</tag></item>
<item><ruleref uri="#no"/><tag>no</tag></item>
</one-of>
<item repeat="0-1"><ruleref uri="#politness"/></item>
</rule>
<rule id="yes">
<one-of>
<item>yes</item>
<item>yeah</item>
<item>yep</item>
<item>sure</item>
<item>of course</item>
</one-of>
</rule>
<rule id="no">
<one-of>
<item>no</item>
<item>not</item>
<item>nope</item>
</one-of>
</rule>
<rule id="politness">
<one-of>
<item> please </item>
<item> thanks </item>
<item> thank you </item>
</one-of>
</rule>
</grammar>