Tropo is part of CiscoLearn More

Advanced Grammar (SRGS/GRXML)

While Tropo’s Simple Grammar is pretty awesome, it’s not really suited for extremely large data sets or complex speech tasks. Tropo's philosophy is to give you the tools to make the simple things easier while making complex tasks possible, and speech recognition grammars are no exception. If you hire a speech recognition expert or buy a grammar from a third party, it's likely they'll give you a Grammar XML document (GrXML for short). This is an W3C standard format that's used in speech applications of all types, and you can use them with Tropo as well.

To use GRXML from your Tropo Scripting application, you place that GrXML file on a web server somewhere and then provide the URL to your Tropo application, using the same choices parameter that you used for your Simple Grammar.

var result = ask("What's your destination?", {
    choices:"http://example.com/tropo/destinations.grxml"
});
result = ask "What's your destination?", {
    :choices => "http ://example.com/tropo/destinations.grxml"}
$result = ask("What's your destination?", array(
    "choices" => "http://example.com/tropo/destinations.grxml"
    )
);
result = ask("What's your destination?", {
    "choices":"http://example.com/tropo/destinations.grxml"
   })
result = ask("What's your destination?", [
    choices: "http://example.com/tropo/destinations.grxml"])

When Tropo encounters a URL in the choices attribute, it will download the grammar and use that as the speech grammar. The URL must be publicly accessible over the internet. If you can't reach it from a web browser in a coffee shop without a VPN, Tropo won't be able to reach it either.

For GrXML or other advanced grammars, ensure that the "mode" attribute in the Grammar matches the mode attribute on Tropo's ask() function. The default mode for ask() is mixed DTMF and Voice, but GrXML doesn't support mixed modes. Telling Tropo to use mixed mode when the Grammar doesn't support it will have unpredictable results. With grammars that are for DTMF input only, ensure that the "mode" parameter is set to DTMF in the GrXML <grammar> element as follows: <grammar mode="dtmf">.

Multi-slot grammars are a premium Tropo feature. Developers must ask Tropo support to have an account enabled for multislot grammars. Once enabled, each speech recognition event in your application will be billed as an additional charge. If your account is not enabled for multislot grammars, then attempting to return multiple slots in your grammar will result in an application error.

The Tropo docs can't cover the entire scope of all the potential advanced grammar functionality out there, as there's quite a bit, so we recommend reviewing the following resource for more information:

http://www.w3.org/TR/speech-grammar/

Note
Writing GrXML grammars is usually a job for a professional, and people make their living doing nothing but writing these advanced grammars. We recommend that you start your speech recognition journey with Tropo's simple grammar approach. Once you are confident with that and want to explore further, then consult the GrXML spec for more complex tasks like in the examples nelow. Be aware that Tropo does not support all features of the GrXML spec. Some capabilities need an advanced speech science degree to make work with high accuracy or are extremely resource intensive to our platform and so are disabled in Tropo. GrXML special rules like GARBAGE, and Free Form SLM and SSM fall into this category. If you need these advanced features beyond the standard Directed Dialog approach, please talk to Tropo sales and we will work with you on options.

Need a couple examples of GRXML? Here's a few options you can build on:

<?xml version="1.0"?>
<grammar xmlns="http://www.w3.org/2001/06/grammar" root="main">

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

        <item repeat="1-16">
            <ruleref uri="#digit">
                <tag>out.concept = out.concept + rules.digit;</tag>
            </ruleref>
        </item>
    </rule>

    <rule id="digit">
        <one-of>
            <item>0</item>
            <item>1</item>
            <item>2</item>
            <item>3</item>
            <item>4</item>
            <item>5</item>
            <item>6</item>
            <item>7</item>
            <item>8</item>
            <item>9</item>
        </one-of>
    </rule>
</grammar> 
<?xml version="1.0"?>
<grammar xmlns="http://www.w3.org/2001/06/grammar" root="MAINRULE">

    <rule id="MAINRULE"> 
        <item>
            <ruleref uri="#choices">
                <tag> out.concept = out.concept;</tag> 
            </ruleref>
        </item>
    </rule> 
    
    <rule id="choices">
        <one-of>
            <item>
                <item repeat="0-1"> need a </item>
                <item repeat="0-1"> i need a </item>
                <one-of> 
                    <item> clue </item>
                </one-of>
            </item>
            <item>
                <item repeat="0-1"> have an </item>
                <item repeat="0-1"> i have an </item>
                <one-of> 
                    <item> answer </item>
                </one-of>
            </item>
        </one-of>
    </rule>

</grammar>
<grammar xmlns="http://www.w3.org/2001/06/grammar" root="MAIN">
 
    <rule id="MAIN" scope="public">
 
        <one-of>
            <item repeat="1-16">
                <ruleref uri="#digit">
                    <tag>out.concept = out.concept + rules.digit;</tag>
                </ruleref>
            </item>
 
            <item>
                help <tag>out.concept="help";</tag>
            </item>
 
            <item>
                back <tag>out.concept="back";</tag>
            </item>
        </one-of>
    </rule>
 
 
    <rule id="digit">
        <one-of>
            <item>
                <one-of>
                    <item>one</item>
                    <item>dtmf-1</item>
                </one-of>
                <tag>out="1";</tag>
            </item>
            <item>
                <one-of>
                    <item>two</item>
                    <item>dtmf-2</item>
                </one-of>
                <tag>out="2";</tag>
            </item>
            <item>
                <one-of>
                    <item>three</item>
                    <item>dtmf-3</item>
                </one-of>
                <tag>out="3";</tag>
            </item>
            <item>
                <one-of>
                    <item>four</item>
                    <item>dtmf-4</item>
                </one-of>
                <tag>out="4";</tag>
            </item>
            <item>
                <one-of>
                    <item>five</item>
                    <item>dtmf-5</item>
                </one-of>
                <tag>out="5";</tag>
            </item>
            <item>
                <one-of>
                    <item>six</item>
                    <item>dtmf-6</item>
                </one-of>
                <tag>out="6";</tag>
            </item>
            <item>
                <one-of>
                    <item>seven</item>
                    <item>dtmf-7</item>
                </one-of>
                <tag>out="7";</tag>
            </item>
            <item>
                <one-of>
                    <item>eight</item>
                    <item>dtmf-8</item>
                </one-of>
                <tag>out="8";</tag>
            </item>
            <item>
                <one-of>
                    <item>nine</item>
                    <item>dtmf-9</item>
                </one-of>
                <tag>out="9";</tag>
            </item>
            <item>
                <one-of>
                    <item>zero</item>
                    <item>dtmf-0</item>
                </one-of>
                <tag>out="0";</tag>
            </item>
        </one-of>
    </rule>
 
</grammar>
<grammar xmlns="http://www.w3.org/2001/06/grammar" root="MAIN">

    <rule id="MAIN" scope="public">
        <item>
            <item>
                <ruleref uri="#MONTH"/>
                <tag>out.month = rules.MONTH.firstSubslot;</tag>
            </item>

            <item>
                <ruleref uri="#DAY"/>
                <tag>out.day = rules.DAY.secondSubslot;</tag>
            </item>

            <item>
                <ruleref uri="#BEG"/>
                <tag>out.year = rules.BEG.yearOneSubslot;</tag>
            </item>

            <item>
                <ruleref uri="#MID"/>
                <tag>out.year = out.year + rules.MID.yearTwoSubslot;</tag>
            </item>

            <item>
                <ruleref uri="#END"/>
                <tag>out.year = out.year + rules.END.yearThreeSubslot;</tag>
            </item>
        </item>
        <tag> out.F_1= out.month + " " + out.day + ", " + out.year; </tag>
    </rule>

    <rule id="MONTH" scope="public">
        <one-of>
            <item>
                <one-of>
                    <item>one</item>
                    <item>1</item>
                    <item>January</item>
                </one-of>
                <tag>out.firstSubslot="January";</tag>
            </item>
            <item>
                <one-of>
                    <item>two</item>
                    <item>2</item>
                    <item>February</item>
                </one-of>
                <tag>out.firstSubslot="February";</tag>
            </item>
            <item>
                <one-of>
                    <item>three</item>
                    <item>3</item>
                    <item>March</item>
                </one-of>
                <tag>out.firstSubslot="March";</tag>
            </item>
            <item>
                <one-of>
                    <item>four</item>
                    <item>4</item>
                    <item>April</item>
                </one-of>
                <tag>out.firstSubslot="April";</tag>
            </item>
            <item>
                <one-of>
                    <item>five</item>
                    <item>5</item>
                    <item>May</item>
                </one-of>
                <tag>out.firstSubslot="May";</tag>
            </item>
            <item>
                <one-of>
                    <item>six</item>
                    <item>6</item>
                    <item>June</item>
                </one-of>
                <tag>out.firstSubslot="June";</tag>
            </item>
            <item>
                <one-of>
                    <item>seven</item>
                    <item>7</item>
                    <item>July</item>
                </one-of>
                <tag>out.firstSubslot="July";</tag>
            </item>
            <item>
                <one-of>
                    <item>eight</item>
                    <item>8</item>
                    <item>August</item>
                </one-of>
                <tag>out.firstSubslot="August";</tag>
            </item>
            <item>
                <one-of>
                    <item>nine</item>
                    <item>9</item>
                    <item>September</item>
                </one-of>
                <tag>out.firstSubslot="September";</tag>
            </item>
            <item>
                <one-of>
                    <item>ten</item>
                    <item>10</item>
                    <item>October</item>
                </one-of>
                <tag>out.firstSubslot="October";</tag>
            </item>
            <item>
                <one-of>
                    <item>eleven</item>
                    <item>11</item>
                    <item>November</item>
                </one-of>
                <tag>out.firstSubslot="November";</tag>
            </item>
            <item>
                <one-of>
                    <item>twelve</item>
                    <item>12</item>
                    <item>December</item>
                </one-of>
                <tag>out.firstSubslot="December";</tag>
            </item>
        </one-of>
    </rule>

    <rule id="DAY" scope="public">
        <one-of>
            <item>
                <one-of>
                    <item>one</item>
                    <item>first</item>
                    <item>1</item>
                </one-of>
                <tag>out.secondSubslot="01";</tag>
            </item>
            <item>
                <one-of>
                    <item>second</item>
                    <item>two</item>
                    <item>2</item>
                </one-of>
                <tag>out.secondSubslot="02";</tag>
            </item>
            <item>
                <one-of>
                    <item>third</item>
                    <item>three</item>
                    <item>3</item>
                </one-of>
                <tag>out.secondSubslot="03";</tag>
            </item>
            <item>
                <one-of>
                    <item>forth</item>
                    <item>four</item>
                    <item>4</item>
                </one-of>
                <tag>out.secondSubslot="04";</tag>
            </item>
            <item>
                <one-of>
                    <item>fifth</item>
                    <item>five</item>
                    <item>5</item>
                </one-of>
                <tag>out.secondSubslot="05";</tag>
            </item>
            <item>
                <one-of>
                    <item>sixth</item>
                    <item>six</item>
                    <item>6</item>
                </one-of>
                <tag>out.secondSubslot="06";</tag>
            </item>
            <item>
                <one-of>
                    <item>seventh</item>
                    <item>seven</item>
                    <item>7</item>
                </one-of>
                <tag>out.secondSubslot="07";</tag>
            </item>
            <item>
                <one-of>
                    <item>eighth</item>
                    <item>eight</item>
                    <item>8</item>
                </one-of>
                <tag>out.secondSubslot="08";</tag>
            </item>
            <item>
                <one-of>
                    <item>ninth</item>
                    <item>nine</item>
                    <item>9</item>
                </one-of>
                <tag>out.secondSubslot="09";</tag>
            </item>
            <item>
                <one-of>
                    <item>tenth</item>
                    <item>ten</item>
                    <item>10</item>
                </one-of>
                <tag>out.secondSubslot="10";</tag>
            </item>
            <item>
                <one-of>
                    <item>eleventh</item>
                    <item>eleven</item>
                    <item>11</item>
                </one-of>
                <tag>out.secondSubslot="11";</tag>
            </item>
            <item>
                <one-of>
                    <item>twelfth</item>
                    <item>twelve</item>
                    <item>12</item>
                </one-of>
                <tag>out.secondSubslot="12";</tag>
            </item>
            <item>
                <one-of>
                    <item>thirteenth</item>
                    <item>thirteen</item>
                    <item>13</item>
                </one-of>
                <tag>out.secondSubslot="13";</tag>
            </item>
            <item>
                <one-of>
                    <item>fourteenth</item>
                    <item>fourteen</item>
                    <item>14</item>
                </one-of>
                <tag>out.secondSubslot="14";</tag>
            </item>
            <item>
                <one-of>
                    <item>fifteenth</item>
                    <item>fifteen</item>
                    <item>15</item>
                </one-of>
                <tag>out.secondSubslot="15";</tag>
            </item>
            <item>
                <one-of>
                    <item>sixteenth</item>
                    <item>sixteen</item>
                    <item>16</item>
                </one-of>
                <tag>out.secondSubslot="16";</tag>
            </item>
            <item>
                <one-of>
                    <item>seventeenth</item>
                    <item>seventeen</item>
                    <item>17</item>
                </one-of>
                <tag>out.secondSubslot="17";</tag>
            </item>
            <item>
                <one-of>
                    <item>eighteenth</item>
                    <item>eighteen</item>
                    <item>18</item>
                </one-of>
                <tag>out.secondSubslot="18";</tag>
            </item>
            <item>
                <one-of>
                    <item>nineteenth</item>
                    <item>nineteen</item>
                    <item>19</item>
                </one-of>
                <tag>out.secondSubslot="19";</tag>
            </item>
            <item>
                <one-of>
                    <item>twentieth</item>
                    <item>twenty</item>
                    <item>20</item>
                </one-of>
                <tag>out.secondSubslot="20";</tag>
            </item>
            <item>
                <one-of>
                    <item>twenty first</item>
                    <item>twenty one</item>
                    <item>21</item>
                </one-of>
                <tag>out.secondSubslot="21";</tag>
            </item>
            <item>
                <one-of>
                    <item>twenty second</item>
                    <item>twenty two</item>
                    <item>22</item>
                </one-of>
                <tag>out.secondSubslot="22";</tag>
            </item>
            <item>
                <one-of>
                    <item>twenty third</item>
                    <item>twenty three</item>
                    <item>23</item>
                </one-of>
                <tag>out.secondSubslot="23";</tag>
            </item>
            <item>
                <one-of>
                    <item>twenty forth</item>
                    <item>twenty four</item>
                    <item>24</item>
                </one-of>
                <tag>out.secondSubslot="24";</tag>
            </item>
            <item>
                <one-of>
                    <item>twenty fifth</item>
                    <item>twenty five</item>
                    <item>25</item>
                </one-of>
                <tag>out.secondSubslot="25";</tag>
            </item>
            <item>
                <one-of>
                    <item>twenty sixth</item>
                    <item>twenty six</item>
                    <item>26</item>
                </one-of>
                <tag>out.secondSubslot="26";</tag>
            </item>
            <item>
                <one-of>
                    <item>twenty seventh</item>
                    <item>twenty seven</item>
                    <item>27</item>
                </one-of>
                <tag>out.secondSubslot="27";</tag>
            </item>
            <item>
                <one-of>
                    <item>twenty eighth</item>
                    <item>twenty eight</item>
                    <item>28</item>
                </one-of>
                <tag>out.secondSubslot="28";</tag>
            </item>
            <item>
                <one-of>
                    <item>twenty ninth</item>
                    <item>twenty nine</item>
                    <item>29</item>
                </one-of>
                <tag>out.secondSubslot="29";</tag>
            </item>
            <item>
                <one-of>
                    <item>thirtieth</item>
                    <item>thirty</item>
                    <item>30</item>
                </one-of>
                <tag>out.secondSubslot="30";</tag>
            </item>
            <item>
                <one-of>
                    <item>thirty first</item>
                    <item>thirty one</item>
                    <item>31</item>
                </one-of>
                <tag>out.secondSubslot="31";</tag>
            </item>
        </one-of>
    </rule>


    <rule id="BEG" scope="public">
        <one-of>
            <item>
                <one-of>
                    <item>nineteen</item>
                    <item>one thousand nine hundred</item>
                </one-of>
                <tag>out.yearOneSubslot="19"</tag>
            </item>
            <item>
                <one-of>   
                    <item>two thousand</item>
                    <item>twenty</item>
                </one-of>
                <tag>out.yearOneSubslot="20"</tag>
            </item>
        </one-of>
    </rule>

    <rule id="MID" scope="public">
        <one-of>
            <item>
                <one-of>
                    <item>O</item>
                    <item>oh</item>
                    <item>0</item>
                    <item>zero</item>
                </one-of>
                <tag>out.yearTwoSubslot="0"</tag>
            </item>
            <item>
                <one-of>   
                    <item>ten</item>
                    <item>1</item>
                    <item>10</item>
                </one-of>
                <tag>out.yearTwoSubslot="1"</tag>
            </item>
            <item>
                <one-of>   
                    <item>twenty</item>
                    <item>2</item>
                    <item>20</item>
                </one-of>
                <tag>out.yearTwoSubslot="2"</tag>
            </item>
            <item>
                <one-of>   
                    <item>thirty</item>
                    <item>3</item>
                    <item>30</item>
                </one-of>
                <tag>out.yearTwoSubslot="3"</tag>
            </item>
            <item>
                <one-of>   
                    <item>forty</item>
                    <item>4</item>
                    <item>40</item>
                </one-of>
                <tag>out.yearTwoSubslot="4"</tag>
            </item>
            <item>
                <one-of>   
                    <item>fifty</item>
                    <item>5</item>
                    <item>50</item>
                </one-of>
                <tag>out.yearTwoSubslot="5"</tag>
            </item>
            <item>
                <one-of>   
                    <item>sixty</item>
                    <item>6</item>
                    <item>60</item>
                </one-of>
                <tag>out.yearTwoSubslot="6"</tag>
            </item>
            <item>
                <one-of>   
                    <item>seventy</item>
                    <item>7</item>
                    <item>70</item>
                </one-of>
                <tag>out.yearTwoSubslot="7"</tag>
            </item>
            <item>
                <one-of>   
                    <item>eighty</item>
                    <item>8</item>
                    <item>80</item>
                </one-of>
                <tag>out.yearTwoSubslot="8"</tag>
            </item>
            <item>
                <one-of>   
                    <item>ninety</item>
                    <item>9</item>
                    <item>90</item>
                </one-of>
                <tag>out.yearTwoSubslot="9"</tag>
            </item>
        </one-of>
    </rule>

    <rule id="END" scope="public">
        <one-of>
            <item>
                <one-of>
                    <item>one</item>
                    <item>1</item>
                </one-of>
                <tag>out.yearThreeSubslot="1";</tag>
            </item>
            <item>
                <one-of>
                    <item>two</item>
                    <item>2</item>
                </one-of>
                <tag>out.yearThreeSubslot="2";</tag>
            </item>
            <item>
                <one-of>
                    <item>three</item>
                    <item>3</item>
                </one-of>
                <tag>out.yearThreeSubslot="3";</tag>
            </item>
            <item>
                <one-of>
                    <item>four</item>
                    <item>4</item>
                </one-of>
                <tag>out.yearThreeSubslot="4";</tag>
            </item>
            <item>
                <one-of>
                    <item>five</item>
                    <item>5</item>
                </one-of>
                <tag>out.yearThreeSubslot="5";</tag>
            </item>
            <item>
                <one-of>
                    <item>six</item>
                    <item>6</item>
                </one-of>
                <tag>out.yearThreeSubslot="6";</tag>
            </item>
            <item>
                <one-of>
                    <item>seven</item>
                    <item>7</item>
                </one-of>
                <tag>out.yearThreeSubslot="7";</tag>
            </item>
            <item>
                <one-of>
                    <item>eight</item>
                    <item>8</item>
                </one-of>
                <tag>out.yearThreeSubslot="8";</tag>
            </item>
            <item>
                <one-of>
                    <item>nine</item>
                    <item>9</item>
                </one-of>
                <tag>out.yearThreeSubslot="9";</tag>
            </item>
        </one-of>
    </rule>
</grammar>