VoiceXML 2.1 Development GuideHome  |  Frameset Home

  grXML Multislot Grammars  |  TOC  |  Inline grXML Subgrammars  

XML Subgrammars

The SRGS standard makes for a much cleaner design for complex grammar structures. While string concatenation and sub-rule reference operations are performed much like when coding in GSL, there are a few notable differences in overall structure. Multi-level complex subgrammars can be written with about half the code than with GSL, and offers a superior overall design schema, as the following example shows:


NameCode.vxml

<?xml version="1.0"?>
<vxml version = "2.0">

<form id="F1">

  <field name="F_1">
      <grammar src="NameGram.xml"  type="application/grammar-xml" />
      <prompt>
        what is your name?
      </prompt>
  </field> 

  <filled mode="all" namelist="F_1">
      <prompt>
        the name is <value expr="F_1"/>
        <break strength="medium"/>
      </prompt>
    </filled>
</form>
</vxml>



NameGram.xml

<?xml version= "1.0"?>
  <grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="en-US" root = "TOPLEVEL">

    <rule id="TOPLEVEL" scope="public">
      <item>

      <!-- FIRST NAME RETURN -->
          <item repeat="0-1">
              <ruleref uri="#FIRSTNAME"/>
  <tag>assign(a $return)</tag>
          </item>

        <!-- MIDDLE NAME RETURN -->
            <item repeat="0-1">
              <ruleref uri="#MIDDLENAME"/>
    <tag>assign(b $return)</tag>
            </item>


      <!-- LAST NAME RETURN -->
            <ruleref uri="#LASTNAME"/>
                        <tag>assign(c $return)</tag>
    </item>

      <!-- TOP LEVEL RETURN --> 
                <tag><![CDATA[ <F_1 (strcat($a strcat($b $c)))> ]]> </tag>

        </rule>

  <rule id="FIRSTNAME" scope="public">
          <one-of>
                <item> matthew 
                    <tag> return ("matthew ")  </tag>
                </item>
                <item> dee         
                  <tag> return ("dee ")  </tag>
                </item>
                <item> jon           
                  <tag> return ("jon ")  </tag>
                </item>
                <item> george   
                  <tag> return ("george ")  </tag>
                </item>
                <item> billy         
                  <tag> return ("billy ")  </tag>
                </item>       
            </one-of>
    </rule>

  <rule id="MIDDLENAME" scope="public">
          <one-of>
                <item> warren     
                  <tag> return ("warren ")  </tag>
                </item>
                <item> dee           
                  <tag> return ("dee ")  </tag>
                </item>
                <item> bon           
                  <tag>return ("bon ")  </tag>
                </item>
                <item> double ya 
                  <tag> return ("w ")  </tag>
                </item>
                <item> dee         
                  <tag> return ("dee ")  </tag>
                </item>         
            </one-of>
    </rule>

  <rule id="LASTNAME" scope="public">
          <one-of>
                <item> henry   
                  <tag> return ("henry ")  </tag>
                </item>
                <item> ramone 
                  <tag> return ("dee ")  </tag>
                </item>
                <item> jovi 
                  <tag> return ("jovi ")  </tag>
                </item>
                <item> bush     
                  <tag> return ("bush ")  </tag>
                </item>
                <item> williams 
                  <tag> return ("williams ")  </tag>
                </item>     
            </one-of>
    </rule>
  </grammar>




  ANNOTATIONS: EXISTING POSTS
794L
3/1/2006 7:21 PM (EST)
It appears there should be a <item> tag added immediately below the line containing "<!-- LAST NAME RETURN -->".  Is that correct?
MattHenry
3/1/2006 7:48 PM (EST)


Hiya Warren,

I can see the source of your confusion: Take a closer look at the tag nesting scheme, however:

<rule id="TOPLEVEL" scope="public">
<!-- start of item tag -->
      <item>

    ..
      <!-- LAST NAME RETURN -->
      <ruleref uri="#LASTNAME"/>
        <tag>assign(c $return)</tag>
    </item>
<!-- end of item tag -->

Cheers,

~Matt

polar
7/21/2006 4:29 AM (EDT)
I tried following this example exactly in order to create a dialogue that asks "How old are you?", and then responds by saying "oh, you are [number] years old".

<?xml version= "1.0"?>
<grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="en-US" root="AGEGRAM">

<rule id="AGEGRAM" scope="public">
<item>
  <item>i am</item>
  <item><ruleref uri="#NUMBERSUB"/>
        <tag>assign(a $return)</tag></item>
  <item>years old</item>
</item>
<tag><![CDATA[<age $a>]]></tag>
</rule>
. . .
</grammar>

I know that NUMBERSUB works fine. Right now is responds to "i am twenty years old" with "oh, you are i am [age] years old years old" (i.e. the entire utterance is returned, instead of just the age).

The calling vxml code is:

<form id="basic2">
<field name="age">
<grammar type="application/grammar-xml" src="agegram.grxml"/>
<prompt><break strength="small"/>how old are you?</prompt>
<filled>
  <prompt>oh, you are <value expr="age"/> years old</prompt>
</filled>
</field>
</form>

I cannot for the life of me spot how this differs from the code above. Any ideas?
bsmith
7/22/2006 12:34 AM (EDT)
Hello polar,

It's kind of hard to say for sure without seeing your #NUMBERSUB but I would say it probably is not setting a custom return value.

Make sure it uses the <tag> element like so:
___________________________

<rule id="NUMBERSUB" scope="private">
  <one-of>
    <item>
      three
      <tag> return ("lying. You are not three") </tag>
    </item>
  </one-of>
</rule>

Let us know if you have any other questions!

Best Regards,

Ben Smith
Voxeo Corporation
polar
7/23/2006 10:26 PM (EDT)
<?xml version= "1.0"?>
<grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="en-US" root="AGEGRAM">

<rule id="AGEGRAM" scope="public">
<item>
  <item>i am</item>
  <item><ruleref uri="#NUMBERSUB"/>
        <tag>assign(a $return)</tag></item>
  <item>years old</item>
</item>
<tag><![CDATA[<age $a>]]></tag>
</rule>

<rule id="NUMBERSUB" scope="public" mode="voice">
<one-of>
  <item>zero<tag>return("zero")</tag></item>
<item>one</item>
<item>two</item>
<item>three</item>
<item>four</item>
<item>five</item>
<item>six</item>
<item>seven</item>
<item>eight</item>
<item>nine</item>
<item>ten</item>  //shortened
</one-of>
</rule>
</grammar>

The entire grammar is posted above, with numbersub included. You were right that I didnt have the <tag> labels, but after testing (see "zero" for an example), adding them doesnt seem to do anything. I still have the same problem as before. Can you see any errors in my code? Thanks a lot!
bsmith
7/24/2006 2:37 PM (EDT)
Hello polar,

Let me do some further testing regarding that in our labs and see what I can come up with.  I'll post my results as soon as they are complete.

Best Regards,

Ben Smith
Voxeo Corporation
MattHenry
7/25/2006 2:43 PM (EDT)


Hi there,

In looking over your files, I think that this is essentially a case of making the source grammar over-complicated, and I'd like to offer you a more compact, "best practices" grammar structure that will serve your purpose. For this type of grammar, I don't see any need at all for a subgrammar structure; we can do this all in a single <rule>. Also notice the usage of <item repeat>, this allows your callers a lot more flexibility in utterances that can be captured:


<?xml version= "1.0"?>

<grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="en-US" root="NUMBERSUB">

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

<item>
  <item repeat="0-1">
    i am
  </item>

<one-of>
  <item>one
  <tag>return("one_interp_value")</tag>
  </item>

<!-- ETC -->

  <item>zero
  <tag>return("zero_interp_value")</tag>
  </item> 
</one-of>

  <item repeat="0-1">
  years old
  </item>

</item>
</rule>
</grammar>




Hope that this helps illustrate, but if you have any additional questions, by all means let me know.

Regards,

~Matthew henry
Jenny
1/17/2007 5:35 AM (EST)
Hi,


I need to develop a vxml application to accept the account number in both "dtmf" and "voice" mode. If user presses "0" or says "operator" I need to transfer out the call.

How could I achieve it either by using inline /external grammar?

I need this to be done in today itself.....

Please help. I dont know the way to use both dtmf and voice grammar together..

Thanks in Advance,
Jenny
VoxeoBrian
1/17/2007 2:40 PM (EST)
Hello,

To make this posting as easy to read as possible I will answer your questions in a segmented order.

Your first question:
"a vxml application to accept the account number in both "dtmf" and "voice" mode"

This can be accomplished in GSL through the use of our built in grammars, with the implementation of type="digits"  This will allow for the the capture of both DTMF and Voice input.

IE: <field name="F_1" type="digits">

A link to the specific documentation on built in grammars is found here:
http://docs.voxeo.com/voicexml/2.0/frame.jsp?page=gslbuiltins.htm

To address your second question:
If user presses "0" or says "operator" I need to transfer out the call.

This can done with the use of 2 seperate grammars inline or external the choice is yours:

<grammar type="text/gsl">
<![CDATA[
[
  [(dtmf-1)] {<F_1 "one">}
]
]]>
</grammar>

This can be used to capture the DTMF press of 1 to transfer to the operator as you desired.

A separate grammar will have to used in order to capture a user utterance for "operator".  This is very simple to accomplish:

IE: <field name="F_1">
      [(Operator)]

You desire to have DTMF 1 and operator transfer the caller out at anytime.  It is important to know that this will require the Link element to make the choices available throughout the entire document.

This element can be implemented as such:
<link event="something"
        message="'something'">
    <grammar type="text/gsl"> [democrats republicans]</grammar>
  </link> 

So the grammars you create for both DTMF 1 and the user utterance for operator will have to be contained in a link element.

Additionally as you may have an issue with a caller entering a 0 as part of their account #, thus triggering the operator transfer.  The field attribute Modal can be used to temporarily stop the grammars from listening for 0, thus giving you the desired functionality.

This is an attribute of the field element and is discussed and examples provided in our documentation here:
http://www.vxml.org/frame.jsp?page=grxmlsubg.htm&bm=1

Modal Defined: The modal attribute is a Boolean value that allows fine grained control of active grammars within the field. When the modal attribute is set to false (default), then all higher scoped grammars are enabled, (i.e., form-level document/dialog scoped grammars) while a user is within the field.  If the modal attribute is set to true, then only field grammars are enabled and all other grammars are temporarily disabled.

Hope this helps, and if you have any other questions feel free to ask.

Cheers

Brian


Jenny
1/18/2007 4:19 AM (EST)
Hi Brian,

  Thank you very much for your detailed answer.
According to my project specification I need to do that with .grxml grammar. Is that same task(getting input both in voice and dtmf) possible with GRXML by any way?

  If this requirement can be accomplished only thro gsl, I have few more doubts.
My form will prompt the user as follows " Enter or say your account number to get your account details. At any time you can press "0" or say "Operator" to speak with Customer Service Representative". So with in a <field> element, I will prompt this message to the caller. And for some reasons I could not use, <link> in my application. So now my question is how could I bundle these 3 grammars(viz., 1. Grammar to get account number thro voice and dtmf, 2. Grammar to get "0" as DTMF input and 3. Grammar to get "operator" thro  voice) to make a single slot to be filled? or how can I call more than one grammar to accomplish my task?

As I m new to gsl grammar, I m not getting any idea to do this..

can u help?


Thanks in advance
Jenny
VoxeoBrian
1/18/2007 12:30 PM (EST)
Hello,

There are ways to accomplish the same task in GRXML as we were able to in GSL.  I have cooked up an example using both GSL an GRXML grammars to give you a basis for your coding.  I have commented the code to aid you in understanding.

<?xml version="1.0" encoding="UTF-8"?>

<vxml version = "2.1">

<meta name="author" content="Matthew Henry"/>
<meta name="copyright" content="2005 voxeo corporation"/>
<meta name="maintainer" content="YOUR_EMAIL@HERE.COM"/>

  <catch event="MyEvent">
    <prompt>we caught a link event</prompt>
  </catch>
<!-- Here is the implementation of the link event, and a GRXML grammar that catches both voice for operator and DTMF for 0 -->
  <link event="MyEvent" dtmf="0">
 
<grammar xml:lang="en-US" root = "TOPLEVEL">
    <rule id="TOPLEVEL" scope="public">
<one-of>
          <item> 0 </item>
          <item> operator  </item>
        </one-of>
</rule>
</grammar>
</link>

<form id="F1">
<!-- Because of the built in grammars already provided within GSL it is much easier to accomplish the capturing of an account number using the built in type=digits attribute.  If you would like to build your own GRXML grammar I have provided a link to documentation that will help you in the process. -->
  <field name="F_1" type="digits?length=3">
 
  <!-- http://docs.voxeo.com/voicexml/2.0/grxml_dtmf.htm -->
 
    <prompt>
    please enter your acccount #
    </prompt>


  </field>

  <filled>
    <prompt>we caught a field match.    </prompt>
  </filled>
 
 
</form>



</vxml>


Hope this helps, and if you have any more questions please feel free to ask.

Cheers

Brian
nitink
2/13/2007 6:16 AM (EST)
hi,
i am new to grxml grammars. I wanted to develop user interface which accepts pin as voice input and i need to validate it from database. I am using vxml 2.0. How to incorporate it and how to write grxml for that?
I have attempted following grxml:

<?xml version="1.0"?>
<grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar"
xmlns:nuance="http://voicexml.nuance.com/grammar" xml:lang="en"
tag-format="Nuance" root="vdigits" version="1.0">
<rule id="number" mode="voice">
<one-of>
<item>one</item>
<item>two</item>
<item>three</item>
<item>four</item>
<item>five</item>
<item>six</item>
<item>seven</item>
<item>eight</item>
<item>nine</item>
<item>zero</item>
</one-of>
</rule>

<rule id="vdigits" scope="public">
<item repeat="1-15">
<ruleref uri="#number" />
</item>

</rule>
</grammar>


DTMF input is working fine but How can I take combined 4 digit number as voice input and pass it for validation from database?
VoxeoBrian
2/13/2007 1:29 PM (EST)
Hello,

I am glad to see you have got your grammar file functioning properly.  As far as aiding in the integration of server side elements such as a databases, we generally do not offer support for this.  The reason why, is server side scripting is a fairly time intensive procedure and would likely slow our support efforts to a grinding halt. However if you do have any questions related to one our supported languages, we are more then happy to assist!

Cheers

Brian
nitink
2/14/2007 12:46 AM (EST)
Hi Brian,
Thanks for the support and reply. But the problem what I am getting is in entering the voice input of pin in vxml.. Kindly help me out.

How to write grxml in external file to confirm the voice input of say 4 digit pin and how to get back the confirmed pin in vxml whole pin in string format so that I can transfer it to the backend??
Also, I am using Nunace 8.5 ASR

Please help me out regarding this. I need it urgently
VoxeoBrian
2/14/2007 11:44 AM (EST)
Hello,

I have whipped up some sample code for you that illustrates a GRXML grammar which expects voice input for capturing the numbers 1-4, and return their numeric value.  These return values are now associated with a slot value, and can be passed back to your back end database.  As far as providing a code example for doing so, as I mentioned previously our support for server side elements is extremely limited, and I wouldn't be able to provide this for you.  However if you do have any more questions, as always we are more then happy to help.



<?xml version= "1.0"?>

<grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="en-US" root = "MYRULE">

<rule id="MYRULE" scope="public">
    <one-of>

      <item> one won <tag> <![CDATA[  <MySlot "1"> ]]>  </tag>  </item>
      <item> two too <tag> <![CDATA[  <MySlot "2"> ]]>  </tag>  </item>
      <item> three <tag> <![CDATA[  <MySlot "3"> ]]>  </tag>  </item>
      <item> four <tag> <![CDATA[  <MySlot "4"> ]]>  </tag>  </item>
     
  </one-of>
</rule>
</grammar>





Cheers

Brian
wafa
9/28/2007 6:16 AM (EDT)
i need to developpe a pplication that let to user convert GSL to GRXML, please can you help me
voxeojeff
9/28/2007 4:58 PM (EDT)
Hello,

I'm afraid I'm a bit puzzled by this request.  Can you elaborate a bit on what exactly you are attempting to do here?  i.e., the call flow of the application, etc.  Once we have a bit more information we should be able to offer up the best possible advice and/or solution. :-)

Best,

Jeff Menkel
Voxeo Corporation
meksof1
4/16/2008 12:04 PM (EDT)
Hello,
I need to build an external file with GRXML grammar.
The user say the sentence "I would like to consult" or "consult the stock" or any sentence contain the word consult , the returned value is "consult".If the user say "I would like to modify" or "modify the stock" or any sentence contain "modify", the returned value is "modify".
Thinks in Advance
MattHenry
4/16/2008 4:42 PM (EDT)


Hi there,

I think that this inquiry is best boiled down to "how can add optional prefixes and suffixes to a grammar?" As chance has it, I happen to have some sample code on this specific topic, which I will post below so that you will have a decent starting point for your development efforts:

[color=blue]
<?xml version= "1.0"?>
<grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="en-US" root="INTRO">
<rule id="INTRO">


<one-of>
    <item>
<!-- PREFIX -->
        <item repeat="0-1">
  can i
</item>
      <one-of> 
        <item>
    repeat     
        </item>

      </one-of>
<tag> <![CDATA[  <MySlot "repeat">  ]]>  </tag>
<!-- SUFFIX -->
              <item repeat="0-1">
please
      </item>
  </item>
</one-of>

    </rule>
</grammar>
[/color]

Hope this helps,

~Matt
virtualme123
6/3/2008 11:50 AM (EDT)
Hello,

I'm just starting out with VoiceXML2.0 and am interested in creating an interrupt that can be picked up across the whole document when a # is pressed. I've looked at the following:

<form scope="document">
  <link next"#menu">
    <grammar mode="dtmf" version="1.0" root="root">
      <rule id="root" scope="document">
        <one-of>
          <item> # </item>
        </one-of>
      </rule>
    </grammar>
  </link>
</form>

... which I hoped would do what I wanted however I'm struggling to find any consistant answers to my problem. Can anyone help?


Thanks,

Chris
VoxeoDustin
6/3/2008 12:17 PM (EDT)
Hey Chris,

When you want to use a document scoped link, you'll need to scope it at the VXML level, e.g:

<vxml version="2.1">

<link next"#menu">
    <grammar mode="dtmf" version="1.0" root="root">
      <rule id="root" scope="document">
        <one-of>
          <item> # </item>
        </one-of>
      </rule>
    </grammar>
</link>

...

</vxml>

Alternately, you could create an application level link grammar by specifying a root document, and placing your link element at the vxml scope in that document, making the link grammar valid in any document that defines the root document.

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

Cheers,
Dustin
virtualme123
6/4/2008 7:16 AM (EDT)
Hello Dustin,

Thanks for your quick reply, but I'm still unable to get the script to react to the # key being pressed. Is it something I am getting wrong with the prompts I'm using? I've looked at bargeintype of speech for instance, is that necessary for it to work because it doens't seem to work for me. Here is my updated example:

<vxml xmlns="http://www.w3.org/2001/vxml"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.w3.org/2001/vxml
  http://www.w3.org/TR/voicexml20/vxml.xsd"
  version="2.0">
<property name="bargeintype" value="dtmf"/>
<link next="#menu">
    <grammar mode="dtmf" version="1.0" root="root">
      <rule id="root">
        <one-of>
          <item>#</item>
        </one-of>
      </rule>
    </grammar>
</link> 
  <form id="test">
<block><prompt>Hello this is a long sentence consisting of words that I am speaking to you with the aid of my voice</prompt></block>
</form>
<form id="menu">
<block>Hello!!!</block>
</form>
</vxml>

Can you see anything you wouldn't expect or recommend?


Cheers,

Chris
voxeojeremyr
6/4/2008 8:42 AM (EDT)
Hi Chris,

What you will want to do is to tell the VXML browser that you expect some kind of input from this form for that grammar to be active.  I put in the <field> attribute like this:
..
<form id="test">
<block><prompt>Hello this is a long sentence consisting of words that I am speaking to you with the aid of my voice</prompt></block>
<field>
<prompt>Testing</prompt>
</field>

</form>
<form id="menu">
<block>Hello!!!</block>
..

I tested it and when I pressed the pound sign ('#') it barge through correctly and played the Hello!! message.

Thanks,
Jeremy Richmond
Voxeo Support

login
  grXML Multislot Grammars  |  TOC  |  Inline grXML Subgrammars  

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