grammardtmfvxmlvoicexml

VXML dtmf grammar with unknown number of digits and specific terminating character


I am new to VXML and trying to construct an inline dtmf grammar that will allow any sequence of digits between 1 and 5 terminated with digit 6 be returned.

So all three of the following sequences should result in a fill:

1123236, 236, 55555555552342346

I've tried implementing the grammar like so:

<grammar mode="dtmf">
  <rule>
    <item>
      <item repeat"0-">1|2|3|4|5<item>6</item>
    </item>
  </rule>
</grammar>

and also like so:

<grammar mode="dtmf">
  <rule>
    <item repeat"0-">1|2|3|4|5</item>
    <item>6</item>
  </rule>
</grammar>

I am out of ideas and would greatly appreciate your help


Solution

  • Here is a grammar you may use:

    <grammar mode="dtmf" version="1.0" root="oneToFiveSequence">
    
        <rule id="onetofive">
            <one-of>    
                <item>1</item>
                <item>2</item>
                <item>3</item>
                <item>4</item>
                <item>5</item>
            </one-of>   
        </rule>
    
        <rule id="oneToFiveSequence" scope="public" >
            <one-of>    
                <item repeat="0-">
                    <ruleref uri="#onetofive"/>
                </item>     
            </one-of>   
        </rule>
    </grammar>
    

    To stop recognition with digit "6" set a property in your VXML form:

    <property name="termchar" value="6" />
    

    In the form while processing "filled" event you will know that the sequence was terminated with "6" so you may append it to data if it needs be.

    An equivalent single rule grammar as requested in comments

     <grammar mode="dtmf" version="1.0" root="oneToFiveSequence">
        <rule id="oneToFiveSequence" scope="public" >
            <one-of>    
                <item repeat="0-">      
                    <one-of>                
                        <item>1</item>          
                        <item>2</item>          
                        <item>3</item>          
                        <item>4</item>          
                        <item>5</item>          
                    </one-of>               
                </item>                 
            </one-of>   
        </rule>
    </grammar>
    

    Both variants are tested with Holly Connects Voice Platform

    Here is an app you may use for quick testing.

    <?xml version="1.0" encoding="utf-8"?>
    <vxml version="2.1" xmlns="http://www.w3.org/2001/vxml">
      <property name="inputmodes" value="dtmf"/>
      <form id="welcome">
        <field name="option">
          <property name="termchar" value="6"/>
          <grammar mode="dtmf" version="1.0" root="oneToFiveSequence">
              <rule id="oneToFiveSequence" scope="public" >
            <one-of>                
                <item repeat="0-">      
              <one-of>                      
                  <item>1</item>                
                  <item>2</item>                
                  <item>3</item>                
                  <item>4</item>                
                  <item>5</item>                
              </one-of>                     
                </item>                 
            </one-of>               
              </rule>           
          </grammar>        
            <prompt>Enter digits</prompt>
          <filled>          
            <log> You entered <value expr="option"/></log>
          </filled>         
        </field>    
      </form>
    </vxml>