Skip to content

Instantly share code, notes, and snippets.

@SteveDonie
Forked from mheadd/app.js
Created July 18, 2013 15:53
Show Gist options
  • Save SteveDonie/6030484 to your computer and use it in GitHub Desktop.
Save SteveDonie/6030484 to your computer and use it in GitHub Desktop.
answer();
var date = ask('Please say a date.', {choices: 'http://path/to/date.xml'});
log("*** " + date.value + " ***");
say('You said ' + date.value);
var time = ask('Now, say a time.', {choices: 'http://path/to/time.xml'});
log("*** " + time.value + " ***");
say('You said ' + time.value);
say('Goodbye.');
hangup();
<?xml version="1.0" encoding="ISO-8859-1"?>
<grammar xmlns="http://www.w3.org/2001/06/grammar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/06/grammar http://www.w3.org/TR/speech-grammar/grammar.xsd"
version="1.0" xml:lang="en-US" mode="voice" root="main">
<!-- Main gramar rule -->
<rule id="main" scope="public">
<tag>$="";</tag>
<item>
<ruleref uri="#month" />
<tag>$ = $ + $month;</tag>
</item>
<item>
<ruleref uri="#day" />
<tag>$ = $ + "/" + $day;</tag>
</item>
<item>
<ruleref uri="#year" />
<tag>$ = $ + "/" + $year;</tag>
</item>
</rule>
<!-- Sub rule for month -->
<rule id="month" scope="private">
<tag>$="";</tag>
<one-of>
<item>
january
<tag>$ = $ + "01";</tag>
</item>
<item>
february
<tag>$ = $ + "02";</tag>
</item>
<item>
march
<tag>$ = $ + "03";</tag>
</item>
<item>
april
<tag>$ = $ + "04";</tag>
</item>
<item>
may
<tag>$ = $ + "05";</tag>
</item>
<item>
june
<tag>$ = $ + "06";</tag>
</item>
<item>
july
<tag>$ = $ + "07";</tag>
</item>
<item>
august
<tag>$ = $ + "08";</tag>
</item>
<item>
september
<tag>$ = $ + "09";</tag>
</item>
<item>
october
<tag>$ = $ + "10";</tag>
</item>
<item>
november
<tag>$ = $ + "11";</tag>
</item>
<item>
december
<tag>$ = $ + "12";</tag>
</item>
</one-of>
</rule>
<!-- Sub rule for day -->
<rule id="day" scope="private">
<tag>$="";</tag>
<one-of>
<item>
first
<tag>$ = $ + "01";</tag>
</item>
<item>
second
<tag>$ = $ + "02";</tag>
</item>
<item>
third
<tag>$ = $ + "03";</tag>
</item>
<item>
fourth
<tag>$ = $ + "04";</tag>
</item>
<item>
fifth
<tag>$ = $ + "05";</tag>
</item>
<item>
sixth
<tag>$ = $ + "06";</tag>
</item>
<item>
seventh
<tag>$ = $ + "07";</tag>
</item>
<item>
eight
<tag>$ = $ + "08";</tag>
</item>
<item>
ninth
<tag>$ = $ + "09";</tag>
</item>
<item>
tenth
<tag>$ = $ + "10";</tag>
</item>
<item>
eleventh
<tag>$ = $ + "11";</tag>
</item>
<item>
twetlth
<tag>$ = $ + "12";</tag>
</item>
<item>
thirteenth
<tag>$ = $ + "13";</tag>
</item>
<item>
fourteenth
<tag>$ = $ + "14";</tag>
</item>
<item>
fifteenth
<tag>$ = $ + "15";</tag>
</item>
<item>
sisteenth
<tag>$ = $ + "16";</tag>
</item>
<item>
seventeenth
<tag>$ = $ + "17";</tag>
</item>
<item>
eighteenth
<tag>$ = $ + "18";</tag>
</item>
<item>
ninteenth
<tag>$ = $ + "19";</tag>
</item>
<item>
twentieth
<tag>$ = $ + "20";</tag>
</item>
<item>
twenty first
<tag>$ = $ + "21";</tag>
</item>
<item>
twenty second
<tag>$ = $ + "22";</tag>
</item>
<item>
twenty third
<tag>$ = $ + "23";</tag>
</item>
<item>
twenth fourth
<tag>$ = $ + "24";</tag>
</item>
<item>
twenty fifth
<tag>$ = $ + "25";</tag>
</item>
<item>
twenth sixth
<tag>$ = $ + "26";</tag>
</item>
<item>
twenty seventh
<tag>$ = $ + "27";</tag>
</item>
<item>
twenty eighth
<tag>$ = $ + "28";</tag>
</item>
<item>
twenty ninth
<tag>$ = $ + "29";</tag>
</item>
<item>
thirtieth
<tag>$ = $ + "30";</tag>
</item>
<item>
thirty first
<tag>$ = $ + "31";</tag>
</item>
</one-of>
</rule>
<!-- Sub rule for year -->
<rule id="year" scope="private">
<tag>$="";</tag>
<one-of>
<item>
two thousand eleven
<tag>$ = $ + "2011";</tag>
</item>
<item>
two thousand twelve
<tag>$ = $ + "2012";</tag>
</item>
<item>
two thousand thirteen
<tag>$ = $ + "2013";</tag>
</item>
<item>
two thousand fourteen
<tag>$ = $ + "2014";</tag>
</item>
<item>
two thousand fifteen
<tag>$ = $ + "2015";</tag>
</item>
</one-of>
</rule>
</grammar>
<?xml version="1.0" encoding="ISO-8859-1"?>
<grammar xmlns="http://www.w3.org/2001/06/grammar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/06/grammar http://www.w3.org/TR/speech-grammar/grammar.xsd"
version="1.0" xml:lang="en-US" mode="voice" root="main">
<!-- Main rule -->
<rule id="main" scope="public">
<tag>$="";</tag>
<item>
<ruleref uri="#hour" />
<tag>$ = $ + $hour;</tag>
</item>
<item repeat="0-1">
<item>o clock</item>
</item>
<item repeat="0-1">
<ruleref uri="#minute" />
<tag>$ = $ + ":" + $minute;</tag>
</item>
<item>
<ruleref uri="#dayornight" />
<tag>$ = $ + " " + $dayornight;</tag>
</item>
<item repeat="0-1">
<ruleref uri="#zone" />
<tag>$ = $ + " " + $zone;</tag>
</item>
<item>
<one-of>
<item>time</item>
<item>standard time</item>
</one-of>
</item>
</rule>
<!-- Sub rule for hour -->
<rule id="hour" scope="private">
<tag>$="";</tag>
<one-of>
<item>
one
<tag>$ = $ + "1";</tag>
</item>
<item>
two
<tag>$ = $ + "2";</tag>
</item>
<item>
three
<tag>$ = $ + "3";</tag>
</item>
<item>
four
<tag>$ = $ + "4";</tag>
</item>
<item>
five
<tag>$ = $ + "5";</tag>
</item>
<item>
six
<tag>$ = $ + "6";</tag>
</item>
<item>
seven
<tag>$ = $ + "7";</tag>
</item>
<item>
eight
<tag>$ = $ + "8";</tag>
</item>
<item>
nine
<tag>$ = $ + "9";</tag>
</item>
<item>
ten
<tag>$ = $ + "10";</tag>
</item>
<item>
eleven
<tag>$ = $ + "11";</tag>
</item>
<item>
twelve
<tag>$ = $ + "12";</tag>
</item>
</one-of>
</rule>
<!-- Sub rule for minute -->
<rule id="minute" scope="private">
<tag>$="";</tag>
<one-of>
<item>
oh five
<tag>$ = $ + "05";</tag>
</item>
<item>
ten
<tag>$ = $ + "10";</tag>
</item>
<item>
fifteen
<tag>$ = $ + "15";</tag>
</item>
<item>
twenty
<tag>$ = $ + "20";</tag>
</item>
<item>
twenty five
<tag>$ = $ + "25";</tag>
</item>
<item>
thirty
<tag>$ = $ + "30";</tag>
</item>
<item>
thirty five
<tag>$ = $ + "35";</tag>
</item>
<item>
forty
<tag>$ = $ + "40";</tag>
</item>
<item>
forty five
<tag>$ = $ + "45";</tag>
</item>
<item>
fifty
<tag>$ = $ + "50";</tag>
</item>
<item>
fifty five
<tag>$ = $ + "55";</tag>
</item>
</one-of>
</rule>
<rule id="dayornight" scope="private">
<tag>$="";</tag>
<one-of>
<item>
aye em
<tag>$ = $ + "AM";</tag>
</item>
<item>
A M
<tag>$ = $ + "AM";</tag>
</item>
<item>
pee em
<tag>$ = $ + "PM";</tag>
</item>
<item>
P M
<tag>$ = $ + "AM";</tag>
</item>
</one-of>
</rule>
<!-- Sub rule for zone -->
<rule id="zone" scope="private">
<tag>$="";</tag>
<one-of>
<item>
eastern
<tag>$ = $ + "EST";</tag>
</item>
<item>
central
<tag>$ = $ + "CST";</tag>
</item>
<item>
mountain
<tag>$ = $ + "MST";</tag>
</item>
<item>
pacific
<tag>$ = $ + "PST";</tag>
</item>
</one-of>
</rule>
</grammar>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment