Search code examples
windowsvisual-c++speech-recognitionsapi

Detecting phone numbers using sapi?


I am currently using sapi 5.4 and I want to detect a phone number which is sure of 10 digits from 0-9 what is the best way to specify in grammar file ?


Solution

  • Here's a simple sapi-format grammar ruleset that defines a rule that has 7-10 digits:

    <rule name="phoneno">
      <phrase min="7" max="10">
        <ruleref name="digit" propname="digit"/>
      </phrase>
    </rule>
    
    <rule name="digit">
      <l>
        <p val="0">0</p>
        <p val="1">1</p>
        <p val="2">2</p>
        <p val="3">3</p>
        <p val="4">4</p>
        <p val="5">5</p>
        <p val="6">6</p>
        <p val="7">7</p>
        <p val="8">8</p>
        <p val="9">9</p>
      </l>
    </rule>
    

    This also sets up semantic properties so you can build the phone number by walking the semantic properties tree.