I was wondering how to add custom keywords to voice recognition using sphinx 4 in Java using the GRAM file?
Like: public = (set song);
How would I make this so after 'set song' the user could say anything he wants and it would still get parsed?
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();
}