0

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 实现单词。但现在我只是在做一些测试,习惯它。

4

1 回答 1

0

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

于 2013-02-13T18:46:12.800 回答