【问题标题】:Sphinx 4 - Console狮身人面像 4 - 控制台
【发布时间】:2013-02-14 02:46:12
【问题描述】:

我对 Java 中的 Sphinx 4 有点问题。我实现了下面的代码:

package test.ionut;

import edu.cmu.sphinx.frontend.util.Microphone;
import edu.cmu.sphinx.recognizer.Recognizer;
import edu.cmu.sphinx.result.Result;
import edu.cmu.sphinx.util.props.ConfigurationManager;


public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        ConfigurationManager manager;

        if(args.length > 0){  
            manager=new ConfigurationManager(args[0]);
            }else{

            manager=new ConfigurationManager(Test.class.getResource("test.config.xml"));

        }

        Recognizer recognizer=(Recognizer)manager.lookup("recognizer");
        recognizer.allocate();
        Microphone mic=(Microphone)manager.lookup("microphone");
        if(!mic.startRecording()){

            System.out.println("Mic not identified.");
            recognizer.deallocate();
            System.out.println(1);

            System.out.println("Say: (Good morning | Hello | Hi | Welcome) (Dipayan | Paul | Philip | Rita | Will )");

            while(true){
                System.out.println("Start speaking. Press Ctrl-C to quit.\n");
                Result result = recognizer.recognize();
                if(result != null) {
                String resultText = result.getBestFinalResultNoFiller();
            //  System.out.println((new StringBuilder()).append("You said: ").append(resultText).append('\n').toString());
                System.out.println("You said: "+resultText+"...");
                } else {
                System.out.println("I can't hear what you said.\n");
                }
                }

        }


    }

}

this is the grammar file:

***#JSGF V1.0;***

***grammar hello;***

***public <greet>= (Good morning | Hello | Hi | Welcome) ( Paul | Philip | Rita | Will );***

and in the xml file i have modified so that the program knows what to do with the gram file.



Bellow is the part of the code where i modified the xml:

    <!-- ******************************************************** -->
    <!-- The Grammar  configuration                               -->
    <!-- ******************************************************** -->

    <component name="jsgfGrammar" type="edu.cmu.sphinx.jsgf.JSGFGrammar">
        <property name="dictionary" value="dictionary"/>
        <property name="grammarLocation"
             value="resource:/test/ionut/"/>
        <property name="grammarName" value="mydict"/>
    <property name="logMath" value="logMath"/>
    </component>


Any help is appreciated.

问题是,当我编译代码时,我没有收到任何错误,但控制台没有显示任何内容,甚至第一次打印也没有。如果我通过添加一个不在字典中的单词来修改 gram 文件,然后点击运行,控制台会向我显示该单词是字典中的已知单词的错误。删除这个词后,点击运行,然后再次:控制台什么也没显示。我还使用 -mx256m 参数添加了额外的堆内存。

我整天都在尝试这个,因为我想用我自己的语言用 sphinx 4 实现单词。但现在我只是在做一些测试,习惯它。

【问题讨论】:

  • 抱歉编辑不好,不知道这个问题为什么会这样发布。如果您阅读滚动窗格中的文本,您就会明白我在解释什么。再次,对不起...

标签: java xml console speech-recognition sphinx4


【解决方案1】:

你是通过麦克风说话的,你在语法文件中输入的那些词吗?或者只是说出随机的话。系统只能识别语法文件和字典中的单词。请记住,.gram 文件是 .gram 文件的子集。 DIC 文件。

【讨论】:

  • 是的,我说得对。事实证明,当我实现 if 原因时,我不小心在 if 中实现了 while 原因。问题已通过以下方式解决: if(!mic.startRecording()){ System.out.println("Mic not identify.");识别器.deallocate(); System.out.println(1); System.out.println("说:(早上好 | 你好 | 你好 | 欢迎)(Dipayan | Paul | Philip | Rita | Will )");之后它就可以正常工作了。
  • 还有 Dipayan Dev,非常感谢您的教程。真的很有帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-05
  • 1970-01-01
  • 1970-01-01
  • 2011-06-17
  • 2015-10-12
相关资源
最近更新 更多