问题
I have written an application in Java that utlizes the CloudGarden API to parse JSAPI grammars, return tags from the grammar rules and then process these tags accordingly. The issue with the CloudGarden API is its dependency on Windows. I need a cross-platform library that can perform the same task. I do not need speech synthesis nor do I need speech recognition. Essentially a string is passed to the program containing some transcribed speech. I need to parse this string against my grammar files to retrieve the action tags (the text between { } in a JSGF grammar rule). My program then uses the retrieved action tags to perform other functions.
I have been looking for a free library that can parse JSGF grammar files that conform to JSAPI. The only realistic alternative I found was the speech recognition engine, Sphinx/CMUSphinx. I have been looking into Sphinx which brought me to the ActionTagsParser class in their documentation. I cannot figure out how to parse a grammar and retrieve the tags. Can anyone point me in the right direction or explain it to me?
Thank you, Noah
EDIT:
Does Sphinx need to be configured for the grammars to be parsed? In the following code, RuleParse always evaluates to NULL. The RuleGrammar and text are valid.
try {
if(recognizer == null){
recognizer = new BaseRecognizer();
recognizer.allocate();
}
rg.setEnabled(true);
recognizer.commitChanges();
RuleParse p = rg.parse(text, null);
if (p == null) {
return null;
}
return p.getTags();
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
回答1:
We removed tags, see Travis answer below.
回答2:
The ability to parse tags has been removed according to the forums for the project.
Forum post discussing it not being a feature.
回答3:
I wrote a library yesterday which maybe is what you need :
Link-> https://github.com/goxr3plus/JSFG-Grammar-Rules-Parser-Library-for-Sphinx4-5
Example code to use it(You can find more examples on the github) :
List<String> rules;
rules = JSGFGrammarParser.getAllGrammarRules(JSGFGrammarParserTester.class.getResourceAsStream("grammar1.gram"), false);
System.out.println("Grammar Rules , without definitions: " + rules + "\n");
rules = JSGFGrammarParser.getAllGrammarRules(JSGFGrammarParserTester.class.getResourceAsStream("grammar1.gram"), true);
System.out.println("Grammar Rules , with definitions: " + rules + "\n");
来源:https://stackoverflow.com/questions/14094057/how-do-you-retrieve-tags-from-jsgf-grammars-using-sphinx