我想知道如何使用 GRAM 文件在 Java 中使用 sphinx 4 将自定义关键字添加到语音识别中?
喜欢:public =(设置歌曲);
我将如何做到这一点,以便在“设置歌曲”之后用户可以说出他想要的任何内容并且它仍然会被解析?
URL url = LulzSpeech.class.getResource("lulzspeech.config.xml");;
System.out.println("Loading input...");
ConfigurationManager cm = new ConfigurationManager(url);
Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
Microphone microphone = (Microphone) cm.lookup("microphone");
recognizer.allocate();
if (microphone.startRecording()) {
System.out.println("Loading input completed, mic working, ready!");
try{
while (true) {
Thread.sleep(50);
Result result = recognizer.recognize();
if (result != null)
if(result.getBestFinalResultNoFiller().toLowerCase().contains(MainLulz.programName.toLowerCase()))
MainLulz.mainVoiceHandler.handleInput(result.getBestFinalResultNoFiller());
}
}catch(Exception e){
e.printStackTrace();
}
} else {
System.out.println("Cannot start microphone.");
recognizer.deallocate();
System.exit(1);
}
} catch (IOException e) {
System.err.println("Problem when loading LulzSpeech input: " + e);
e.printStackTrace();
} catch (PropertyException e) {
System.err.println("Problem configuring LulzSpeech input: " + e);
e.printStackTrace();
} catch (InstantiationException e) {
System.err.println("Problem creating LulzSpeech input: " + e);
e.printStackTrace();
}