Adding DTMF input

Dual tone multi-frequency (DTMF) is the system used by touch-tone keypad or telephone. DTMF assigns a specific frequency, or tone, to each key so that it can easily be identified by a microprocessor.

VoiceXML is designed for creating audio dialogs that detect and report characters from DTMF input. Valid DTMF input includes positive numbers entered using digits and * to represent a decimal point. The result is a string of digits from 0 to 9 and may optionally include a decimal point (.) and/or a plus or minus sign.

This topic includes the following examples:

Coding DTMF inline

  1. In the <grammar> tag (see bold line), declare the "dtmf" mode.
  2. Code the elements, just as you do for an SRGS grammar, allowing either keypad or spoken responses.

The following example shows an inline grammar allows DTMF input along with spoken input.

<form id="flavor">
  <field name="flavor">
    <prompt>What is your favorite flavor?</prompt>
    <help>Say one of vanilla, chocolate, or
strawberry.</help>
    <grammar mode="voice" root="flavorgram">
      <rule id="flavorgram" scope="public">
        <one-of>
          <item>
            vanilla <tag>$="van"</tag>
          </item>
          <item>
            chocolate <tag>$="choc"</tag>
          </item>
          <item>
            strawberry <tag>$="straw"</tag>
          </item>
        </one-of>
      </rule>
    </grammar>
    
<grammar mode="dtmf" root="flavordtmf">
      <rule id="flavordtmf" scope="public">
        <one-of>
          <item>
            1
            <tag>$="van"</tag>
          </item>
          <item>
            2
            <tag>$="choc"</tag>
          </item>
          <item>
            3
            <tag>$="straw"</tag>
          </item>
        </one-of>
      </rule>
    </grammar>
  </field>
  <filled>
    You have selected <value expr="flavor" />. Excellent
choice!
  </filled>
</form>

Coding DTMF in an external grammar

  1. Declare the "dtmf" mode within the <grammar> tag.
  2. Then code the elements, just as you do for an SRGS XML grammar, substituting the keypad responses for the spoken responses.

The following is a simple DTMF grammar that accepts a 4-digit PIN followed by a pound terminator. It also permits the sequence of "*" followed by "9" (e.g. to receive a help message).

<?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" 
   xmlns="http://www.w3.org/2001/06/grammar">


<rule id="digit">
 <one-of>
   <item> 0 </item>
   <item> 1 </item>
   <item> 2 </item>
   <item> 3 </item>
   <item> 4 </item>
   <item> 5 </item>
   <item> 6 </item>
   <item> 7 </item>
   <item> 8 </item>
   <item> 9 </item>
 </one-of>
</rule>

<rule id="pin" scope="public">
 <one-of>
   <item>
     <item repeat="4"><ruleref
uri="#digit"/></item>
     #
   </item>
   <item>
     * 9
   </item>
 </one-of>
</rule>

</grammar>

Related Information

Legal notices.