none
SAPI: one grammar, multiple rules? RRS feed

  • Question

  • Hey guys,

     

    I've written a speech recognizer in C++ which makes use of an XML grammar file.

     

    The problem I'm having is that if I do not define a root, none of the rules work. If I do define a root rule however, only *that* rule is followed.

    How do I make my other rules work?

    Sorry for posting this here, the SAPI support is pretty woeful online.


    Clever, witty forum signature.
    Wednesday, February 1, 2012 3:27 AM

Answers

  • I found a workaround, which involved using one root rule, and doing the following:

     

    <rule id="RootRule">
        <item repeat="0-1">
           Hello, this is optional.
        </item
        <item>
        However, unless this is said, the first will never be recognized.
        </item>
    </rule>
    


    The repeat="0-1" indicates that you can either not say it, or say it once. You can also specify more than one time, in case the person is thinking (for example, "um").

     

    Thank you for the answer though, it's pretty close to what I (badly) described.


    Clever, witty forum signature.
    • Marked as answer by Emile Victor Wednesday, February 1, 2012 5:47 AM
    Wednesday, February 1, 2012 5:47 AM

All replies

  • This appears to be by design reading the speech SDK documentation.

    One thing you can do is the following:

    <grammar version="1.0" xml:lang="en-US" root="rootRule"  xmlns="http://www.w3.org/2001/06/grammar">
      <rule id="rootRule">
        <one-of>
          <item> <ruleref uri="#Rule1"/> </item>
          <item> <ruleref uri="#Rule2"/> </item>
          <item> <ruleref uri="#Rule3"/> </item>
          <item> <ruleref uri="#Rule4"/> </item>
        </one-of>
      </rule>
      <rule id="Rule1">
        <item> Hello world </item>
      </rule>
    
    ...

     


    - hope this helps - Mauro.
    Wednesday, February 1, 2012 4:04 AM
  • I found a workaround, which involved using one root rule, and doing the following:

     

    <rule id="RootRule">
        <item repeat="0-1">
           Hello, this is optional.
        </item
        <item>
        However, unless this is said, the first will never be recognized.
        </item>
    </rule>
    


    The repeat="0-1" indicates that you can either not say it, or say it once. You can also specify more than one time, in case the person is thinking (for example, "um").

     

    Thank you for the answer though, it's pretty close to what I (badly) described.


    Clever, witty forum signature.
    • Marked as answer by Emile Victor Wednesday, February 1, 2012 5:47 AM
    Wednesday, February 1, 2012 5:47 AM