grammarvoice-recognitionvxmlvoicexml

VoiceXML Grammar Input sequence


I need to allow callers to enter their ID. It is 7 characters long and is a mixture of letters and numbers but there is a structure to it.

Example: F0G0000

Is there any thing that i could do to the grammar to make it switch between letters and numbers according to the structure above?


Solution

  • Absolutely:

    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    <grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="en" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/06/grammar http://www.w3.org/TR/speech-grammar/grammar.xsd" version="1.0" mode="voice" tag-format="semantics/1.0" root="main">
    
      <rule scope="public" id="main">
    
        <!-- a letter -->
        <ruleref uri="#letter" /><tag>out = rules.latest</tag>
    
        <!-- a digit -->    
        <ruleref uri="#digit" /><tag>out += rules.latest</tag>
    
        <!-- a letter or a digit -->
        <one-of>
          <item><ruleref uri="#letter" /></item>
          <item><ruleref uri="#digit" /></item>
        </one-of>
        <tag>out += rules.latest</tag>
    
        <!-- 4 digits -->
        <item repeat="4">
          <ruleref uri="#digit" />
          <tag>out += rules.latest</tag>
         </item>
    
      </rule>
    
      <rule scope="private" id="letter">
        <one-of>
          <item>a</item>
          <item>b</item>
          <item>c</item>
          <item>d</item>
          <item>e</item>
          <item>f</item>
          <item>g</item>
          <item>h</item>
          <item>i</item>
          <item>j</item>
          <item>k</item>
          <item>l</item>
          <item>m</item>
          <item>n</item>
          <item>o</item>
          <item>p</item>
          <item>q</item>
          <item>r</item>
          <item>s</item>
          <item>t</item>
          <item>u</item>
          <item>v</item>
          <item>w</item>
          <item>x</item>
          <item>y</item>
          <item>z</item>
        </one-of>
      </rule>
    
      <rule scope="private" id="digit">
        <one-of>
          <item>
            <one-of>
              <item>zero</item>
              <item>oh</item>
            </one-of>
            <tag>out="0"</tag>
          </item>
          <item> one
            <tag>out = 1;</tag>
          </item>
          <item> two
            <tag>out = 2;</tag>
          </item>
          <item> three
            <tag>out = 3;</tag>
          </item>
          <item> four
            <tag>out = 4;</tag>
          </item>
          <item> five
            <tag>out = 5;</tag>
          </item>
          <item> six
            <tag>out = 6;</tag>
          </item>
          <item> seven
            <tag>out = 7;</tag>
          </item>
          <item> eight
            <tag>out = 8;</tag>
          </item>
          <item> nine
            <tag>out = 9;</tag>
          </item>
        </one-of>
      </rule>
    </grammar>
    

    Disclaimer: I haven't tested it.