-1

I've been using the Microsoft Speech API (SAPI, 5.3) to add speech recognition support to my application (Windows, obviously, C++, Win8 SDK) and aside from a few hoop-jumps relating to loading grammar files it's working quite well.

However, I'm having trouble figuring out how to enumerate rules from a grammar that was loaded from file (or if that's even possible). Obviously, when you build the grammar manually/dynamically, you are creating the rules yourself. However, there doesn't appear to be a way to enumerate the rules from a grammar that was loaded from file. IspRecoGrammar::GetRule() seems to be the closest thing I could find to being able to query for a rule, but it is intended for retrieving a single, known rule (it requires either a rule name or id).

For the time being I'm simply parsing the XML myself and plucking out the rule names, but that's not really a complete solution; I need to support both XML and binary grammar config files, the latter of which sidesteps my current work-around.

Anyone with SAPI experience know how I might accomplish this?

SBD
  • 1
  • 1
  • What is the higher-level goal you're trying to achieve here? (AKA - why do you think you need to enumerate SAPI rules?) – Eric Brown Dec 02 '16 at 17:38
  • Thanks for the reply, Eric. In short, I need to pre-validate other data I have against the rules of the loaded grammar(s). This other data references the rules by name, so at load-time of this other data I want to validate that the grammar rules (names) the data references are in fact valid. – SBD Dec 04 '16 at 06:08
  • In addition to the aforementioned processing of the XML, I can (and have) gotten by simply not validating and then adding the rules to the "known set" as they are encountered via SAPI recognition callback, but that's not a very robust solution for catching data errors. – SBD Dec 04 '16 at 06:27

1 Answers1

0

It seems like IspRecoGrammar::GetRule() would still do what you need. Have a set of known good rule names, and when you load your other data, use IspRecoGrammar::GetRule() to validate the rule name if it's not in the set of known good names. If it's valid, add it to the set. (You could also have a set of known bad names, as well.)

Eric Brown
  • 13,774
  • 7
  • 30
  • 71
  • Good suggestion, it hadn't occurred to me to go at it from that direction. That would certainly address the problem at hand (pre-existing data validation). Thinking forward, it may be the case that for we'd want to present a list of known rules for authoring said referencing data, which would put us back at square one insofar as rules enumeration. I presume that, as far as you know, there's no way to enumerate rules? My own fairly deep internet search didn't turn up anything or anyone attempting something similar. – SBD Dec 15 '16 at 06:46
  • @SBD I did some checking, and most of the grammar compilation work is done on the engine side of the SAPI interface; this means that any rule enumeration done during grammar compilation is being done in an internal matter, and there isn't any other client-side interface for rule enumeration. – Eric Brown Dec 15 '16 at 18:28
  • Thanks for looking into it. Obviously there hasn't been an articulated need for that to this point; perhaps future versions will provide the facility (it seems an easy enough thing to expose). For now I'll go about validating as suggested and cross that other bridge when I get to it. Thanks again. – SBD Dec 17 '16 at 06:46