我对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文件,然后单击run,控制台会显示一个错误,表明该单词是字典中的已知单词。删除该单词后,单击run,然后再次单击:控制台没有显示任何内容。此外,我还使用-mx256m参数添加了额外的堆内存。
我已经尝试了一整天,因为我想用sphinx 4实现我自己语言中的单词,但现在我只是在做一些测试,开始使用它。
发布于 2013-02-14 02:46:13
你是通过麦克风说话的吗,你放在语法文件里的那些单词?或者只是随便说几句话。系统只能识别语法文件和词典中的那些单词。请记住,.gram文件是。DIC文件。
https://stackoverflow.com/questions/14860579
复制相似问题