Change in gram file and reloading in sphinx

三世轮回 提交于 2019-12-13 05:06:17

问题


At run time we are populating a list of files and folders. I want to add that list in the Gram file. I really have no idea how to change the gram file and load it again. I have gone through sphinx JSGF but because the lack of time I am not able to read it completely.

I am using sphinx4-1.0beta6 version.


回答1:


If you want to change in your gram file then you need to add them in dictionary file acoustic model.

  • Create a txt file “words.txt”, Write all the names of cities and states in it and save.
  • Open this link : http://www.speech.cs.cmu.edu/tools/lmtool.html
  • On that page, go to “Sentence corpus file:” section, Browse to “words.txt” file and click “Compile Knowledge Base”.
  • On next page, Click on “Dictionary” link and save that .DIC file.
  • Extract WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar file.
  • Go to edu\cmu\sphinx\model\acoustic\WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz\dict folder.
  • Open “cmudict.0.6d” file in that folder
  • Copy data from .DIC file, you have downloaded in PART ONE, paste it in “cmudict.0.6d” file and save. Zip the extracted hierarchy back as it was and Zip file named should be same as JAR file.



回答2:


Here are the steps involved for changing grammar at runtime:

Get the JSGFGrammr component. the JSGFDemo constructor shows how the JSGFGrammar component (called the jsgfGrammarManager in the demo) can be retrieved from the ConfigurationManager:

URL url = JSGFDemo.class.getResource("jsgf.config.xml");
        ConfigurationManager cm = new ConfigurationManager(url);
        jsgfGrammarManager = (JSGFGrammar) cm.lookup("jsgfGrammar");

Use the JSGFGrammar component to load new JSGF Grammars - The new JSGF gramamrs can be loaded via the loadJSGF method. An example of how this is done can be found in the 'loadAndRecognize' method.

private void loadAndRecognize(String grammarName) throws IOException, GrammarException  {
        jsgfGrammarManager.loadJSGF(grammarName);
        dumpSampleSentences(grammarName);
        recognizeAndReport();
     }

Add new rules using a RuleGrammar - a JSGF grammar can be manipulated directly from Java code. Rules can be added, enabled and disabled for your application. The methods 'loadAndRecognizeMusic' and 'addRule' demonstrate how your application can add new rules. Here's the 'addRule' method that shows how a new rule can be added to a ruleGrammar.

private void addRule(RuleGrammar ruleGrammar, String ruleName, 
                String jsgf)   throws GrammarException {
        Rule newRule = ruleGrammar.ruleForJSGF(jsgf);
        ruleGrammar.setRule(ruleName, newRule, true);
        ruleGrammar.setEnabled(ruleName, true);
    }

You can see these resources:

  1. https://stackoverflow.com/a/15867226/1291122
  2. [http://cmusphinx.sourceforge.net/sphinx4/javadoc/edu/cmu/sphinx/jsgf/JSGFGrammar.html]
  3. http://cmusphinx.sourceforge.net/sphinx4/src/apps/edu/cmu/sphinx/demo/jsapi/jsgf/README.html

2



来源:https://stackoverflow.com/questions/17923001/change-in-gram-file-and-reloading-in-sphinx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!