Сфинкс 4 - Консоль
У меня есть небольшая проблема со Сфинксом 4 в Java. Я реализовал код ниже:
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.
Проблема в том, что когда я компилирую код, я не получаю ошибки, но консоль не показывает ничего, даже первую печать. Если я изменяю файл грамм, добавляя слово, которого нет в словаре, а затем нажимаю "Выполнить", консоль показывает мне ошибку, что это слово является известным словом в словаре. После удаления слова нажмите run и снова: консоль ничего не показывает. Также я добавил дополнительную память кучи с аргументом -mx256m.
Я пробовал весь день с этим, так как я хочу реализовать слова из моего собственного языка с sphinx 4. Но сейчас я просто делаю некоторый тест, привыкаю к нему.
1 ответ
Вы говорите через микрофон, те слова, которые вы вставили в файл грамматики? Или просто произносить случайные слова. система может распознавать только те слова, которые есть в файле Grammer, а также в словаре. помните, что файл.gram является подмножеством. Файл DIC.