Many times on the forum I’ve seen developers use JSGF grammars in their IVR code when they should be using SRGS+XML and vice versa. Typically, for production IVR code, we use JSGF grammars for small-sized grammars and use SRGS+XML grammars for medium to large-sized grammars.
Why use JSGF for small-sized grammars over SRGS+XML? Because of the sheer verbosity that’s included with using SRGS+XML over JSGF. Let’s take a look at an IVR example.
Let’s say we wanted a VoiceXML grammar that captures a phone keypad entry from 1 to 5.
Here’s the JSGF version of that grammar:
<grammar type=”application/x-jsgf” mode=”dtmf”>
1|2|3|4|5
</grammar>
Pretty simple, huh? Now, let’s take a look at the SRGS+XML version of that grammar:
<grammar type=”application/srgs+xml” root=”ROOT” mode=”dtmf”>
<rule id=”ROOT”>
<one-of>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
</one-of>
</rule>
</grammar>
Wow, that’s a whole lot different. I mean, look at all those VoiceXML tags. And all we want to do is capture a one digit entry from the caller. Thus, for these small grammar situations, we want to use JSGF.
Now, let’s take a look at a more complicated example. Let’s say we want a grammar for pets, where if the caller says “Puppy” or “Dog”, the grammar captures “Dog”. If the user says “Cat”, “Kitten”, and “Kitty”, the grammar captures “Cat”. Lastly, if the user says “Turtle” or “Tortoise”, the grammar captures “Turtle”.
Here’s the JSGF version of that grammar:
<grammar type=”application/x-jsgf” mode=”voice”>
(
((Puppy | Dog) {Dog}) |
((Cat | Kitten | Kitty) {Cat}) |
((Turtle | Tortoise) {Turtle})
)
</grammar>
Here’s the SRGS+XML version of that grammar:
<grammar type=”application/srgs+xml” root=”ROOT” mode=”voice”>
<rule id=”ROOT”>
<one-of>
<item>Dog <tag>pet=’Dog’</tag> </item>
<item>Puppy <tag>pet=’Dog’</tag> </item>
<item>Cat <tag>pet=’Cat’</tag> </item>
<item>Kitten <tag>pet=’Cat’</tag> </item>
<item>Kitty <tag>pet=’Cat’</tag> </item>
<item>Turtle <tag>pet=’Turtle’</tag> </item>
<item>Tortoise <tag>pet=’Turtle’</tag> </item>
</one-of>
</rule>
</grammar>
In this case, although the SRGS+XML version of this grammar looks more wordy in this example, it will perform better than its JSGF counterpart due to less processing/pre-parsing during the startup of the application.
Hope this example helps you developers out there who’ve had questions on when to choose JSGF or SRGS+XML format for your grammar.
-
-
1