VoiceXML 2.1 Development GuideHome  |  Frameset Home

  grXML Hints  |  TOC  |  grXML Built-in Grammars  

grXML DTMF grammars

Since there are many ways to write an XML- DTMF grammar, there should probably be a good starting point for all us folks ready to switch over from the Good Old Days of GSL. As the W3C Grammar specification can indeed be a bit murky when it comes to a few finer points of grammar design, there is a bit of leeway in regards to what certain platform vendors allow, especially when it comes to DTMF grammars. By taking the following examples as Gospel, your grammar files will retain maxiumum compliance to the spec, and still be able to have multi-platform compatibility should you decide to switch to another voice browser.

To start off with, let's take a look at a standard GrXML grammar that uses DTMF as it's mode of input:


<grammar xml:lang="en-US" root = "TOPLEVEL">
    <rule id="TOPLEVEL" scope="public">
<one-of>
          <item> dtmf-1 <tag> <![CDATA[  <F_1 "one"> ]]>  </tag> </item>
          <item> dtmf-2 <tag> <![CDATA[  <F_1 "two"> ]]>  </tag> </item>
          <item> dtmf-star <tag> <![CDATA[  <F_1 "star"> ]]>  </tag> </item>
        </one-of>
</rule>
</grammar>


Say, that looks alright, doesn't it? Well, yes, and no. While this grammar will work, it isn't really up to par with the spec. Let's take another look at a compliant grammar, with the significant differences highlighted for convenience:


<grammar xml:lang="en-US" root = "TOPLEVEL" mode="dtmf">
    <rule id="TOPLEVEL" scope="public">
<one-of>
          <item> 1 <tag> <![CDATA[  <F_1 "one"> ]]>  </tag> </item>
          <item> 2 <tag> <![CDATA[  <F_1 "two"> ]]>  </tag> </item>
          <item> * <tag> <![CDATA[  <F_1 "star"> ]]>  </tag> </item>
        </one-of>
</rule>
</grammar>


The first thing to note is that we have explicitly set the 'mode' attribute of the <grammar> element. This is good coding practice, and really should be made a habit if we don't want to look like hacks. Just imagine what The Neighbors would think if the saw you write a grammar without the 'mode' being set....The Horror!

Secondly, you'll realize that we haven't declared the utterance as 'dtmf-(number)'......that stuff is for amateurs. Instead, we are going to follow the spec, and declare these by their pure numeric values. In the long run, this saves us a bit of code, and makes us all compliant-like to the specification.


So Who Cares About Being Compliant, Anyhow?

While it's certainly healthy to Question Authority, you should care about being compliant to the W3C spec. Like the idea of revisiting code that you wrote two years ago so that you can make it work on a new platform? Neither do we, and sticking to the spec allows you to 'keep it real' and not have to worry about porting code later on, homie. We write sample code that sticks close to the way things should be done to save you hassle down the road.


Mixed-Mode Grammars

Okay, so what if you need a grammar that accepts both dtmf AND voice input? Well, hacks would undoubtedly do something like this:


<grammar xml:lang="en-US" root = "TOPLEVEL">
    <rule id="TOPLEVEL" scope="public">
<one-of>
          <item> 1 <tag> <![CDATA[  <F_1 "yes"> ]]>  </tag> </item>
          <item> yes <tag> <![CDATA[  <F_1 "yes"> ]]>  </tag> </item>
          <item> 2<tag> <![CDATA[  <F_1 "no"> ]]>  </tag> </item>
          <item> no <tag> <![CDATA[  <F_1 "no"> ]]>  </tag> </item>
        </one-of>
</rule>
</grammar>


But the compliant way to do this would be to break up our grammars, and have two grammars active. Note that in the case of external grammar structures, multiple grammar references <grammar src> will be needed within your voice reco fields:


<grammar xml:lang="en-US" root = "TOPLEVEL" mode="dtmf">
    <rule id="TOPLEVEL" scope="public">
<one-of>
          <item> 1 <tag> <![CDATA[  <F_1 "yes"> ]]>  </tag> </item>
          <item> 2 <tag> <![CDATA[  <F_1 "no"> ]]>  </tag> </item>
        </one-of>
</rule>
</grammar>



<grammar xml:lang="en-US" root = "TOPLEVEL" mode="voice">
    <rule id="TOPLEVEL" scope="public">
<one-of>
          <item> yes <tag> <![CDATA[  <F_1 "yes"> ]]>  </tag> </item>
          <item> no <tag> <![CDATA[  <F_1 "no"> ]]>  </tag> </item>
        </one-of>
</rule>
</grammar>




Also note that if we try to get clever, and mix up our syntax, then errors will definitely crop up. For instance, the following will have complilation errors, as having a 'mode' set to 'dtmf' and explicitly having 'dtmf-1' or other derivatives will not be stomached by the browser:


<grammar xml:lang="en-US" root = "TOPLEVEL" mode="dtmf">
    <rule id="TOPLEVEL" scope="public">
<one-of>
          <item> dtmf-1 <tag> <![CDATA[  <F_1 "one"> ]]>  </tag> </item>
          <item> dtmf-2 <tag> <![CDATA[  <F_1 "two"> ]]>  </tag> </item>
          <item> dtmf-star <tag> <![CDATA[  <F_1 "star"> ]]>  </tag> </item>
        </one-of>
</rule>
</grammar>







  ANNOTATIONS: EXISTING POSTS
beta
3/22/2006 11:30 AM (EST)
I'm currently testing on Voxeo Prophecy.
It seems that with mode="dtmf" in an embedded gramamr

<item> dtmf-1 <tag> <![CDATA[  <F_1 "one"> ]]>  </tag> </item>
works fine, which contradicts the last statement
"Also note that if we try to get clever, and mix up our syntax, then errors will definitely crop up"

but
<item> 1 <tag> <![CDATA[  <F_1 "one"> ]]>  </tag> </item>
as stated above, which should work, does not work.

I tried to use
<item> dtmf-1 <tag> <![CDATA[  <F_1 "one"> ]]>  </tag> </item>
without  mode="dtmf" and this works fine as well.

I'm confused.
MattHenry
3/22/2006 2:43 PM (EST)


Hi there,

I should point out that this set of documentation was written for the Voice Center 5.5 release, and is not meant to be used specifically for Prophecy application development. As such, discrepancies will exist between the documentation, and how Prophecy behaves.

As Prophecy is still a Beta product, we have not written a dedicated set of documentation for it, but we plan on doing so sometime in the next few months.

Hope this clears things up,

~Matthew Henry

yana
6/27/2006 7:38 AM (EDT)
I still don't understand how DTMF grammar looks for any x digits (for example - enter you ID)
MattHenry
6/27/2006 12:56 PM (EDT)


Hello Yana,

As I understand it, you want to capture a variable length digit input from your callers. Your choices are as follows:


1) Create a grxml grammar using one-of/item/ruleref that allows you to capture the string. Examples that illustrate the general subgrammar structure to use can be found in the below link:


http://docs.voxeo.com/voicexml/2.0/grxmlsubg.htm


2) Use the predefined 'num2sixteen' GSL grammar in our downloadables section:

http://evolution.voxeo.com/library/grammar/library.jsp


3) Leverage the field type grammars, as illustrated in the below link:

http://docs.voxeo.com/voicexml/2.0/gslbuiltins.htm


Chances are that if you find yourself stuck on a particular concept specific to VXML, our documentation has this fully detailed already, and more than likely has sample code that illustrates this plainly to minimize confusion.


Regards,

~Matthew Henry





Jenny
1/10/2007 12:43 AM (EST)
Hi All
  I need a grxml grammar to accept 4 digits from the user
Can any body help ASAP????


Thanks in advance
jbassett
1/10/2007 3:58 AM (EST)
Hello,

Have you tried something like utilizing the built-in field type grammars like the example below?

<field name="pin" type="digits?length=4">

Let me know if this is what you were looking for.

Thanks
Jesse Bassett
Voxeo Support
Jenny
1/10/2007 5:13 AM (EST)
Thanks Jesse..
Actually I want grxml grammar to work in different platform.
I could not use built-in types.

My expectation solved with the following grammar

<?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" root ="Pin" xmlns="http://www.w3.org/2001/06/grammar">
   
    <rule id = "Pin" scope ="public">
    <item repeat = "4"><ruleref uri="#digit"/></item>
    </rule>
<rule id = "digit">
<one-of>
<item>one</item>
<item>two</item>
<item>three</item>
<item>four</item>
              ......

</one-of>
    </rule>
</grammar>


Thanks,
Jenny
jbassett
1/10/2007 6:51 AM (EST)
Hello,

I am glad things worked out for you. I will go ahead and mark this ticket as closed. Feel free to re-open it, or ask any further questions.

Thanks
Jesse Bassett
Voxeo Support
Jenny
1/25/2007 2:17 AM (EST)
Hi,

Thanks for ur support. As per my requirement I modified the previous grammar to either accept any 4 digit number or "0" as user input.

<?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" root ="Pin" xmlns="http://www.w3.org/2001/06/grammar">
 
    <rule id = "Pin" scope ="public">
    <one-of>
          <item repeat = "4"><ruleref uri="#digit"/></item>
          <item>0</item>
    </one-of>
    </rule>

    <rule id = "digit">
          <one-of>
              <item>one</item>
              <item>two</item>
              <item>three</item>
              <item>four</item>
              ......

          </one-of>
    </rule>

</grammar>



when I am using with in vxml as inline grammar within "field" element it is ok. But if I want to use this grammar in some other tool so I want to return back the slots filled. The slot might be either any four digit number or "0".

Using Tag with in Grammar how could I achieve that?

I need to collect the user values in particular slot...or particular variable...
How could I do that?




Jenny
2/2/2007 2:36 AM (EST)
Hi,

Can any body tell me with one user input how can i fill two slots?
if we are getting the input as "12 Main street" how can I fill the slots <streetNumber> as "12" and <streetName> as "Main Street"

This grammar need to be dynamic enough to accept different street numbers and street names?

I need this to be a grxml grammar..
Can anybody help.

Thanks in Advance,
Jenny
jefo12
6/24/2008 2:06 AM (EDT)
how to enable dynamic grammar using dtmf...



<prompt> The appointments are </prompt>


          <foreach item="applist" array="myarr">
            <prompt><value expr="applist"/><break/></prompt>
        </foreach>

//palys all the appointments the callerid has.....

<prompt> Do you want to cancelorreschedule any of those appointments say cancel or
    reschedule or
    if you want to take an new appointment say schedule..
</prompt>
If the user selects cancel...then
<prompt>To cancel any of the appointments press the corresponding dtmf button to cancel </prompt>
//how can i do this dynamiclaly....

plz suggest me.....
vikesh
7/9/2008 8:10 AM (EDT)
Hi,
I need to take username (e.g xyz123) and password input through touch tone (DTMF), how can I do that, that user enter his username and press # to end it and password and store it in variable to submit it in database. I read the grammar rules but didn't understand how to do that.
Please help, as i have to complete my task very soon.


login
  grXML Hints  |  TOC  |  grXML Built-in Grammars  

© 2008 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site