I am developing a program using Sphinx4 in java.
I want to reduce the acoustic model and grammar to be very simple and concise that fits my use.
My use is just understanding couple words, recognizing word by word.
For example, the words would be {man, bye, good, yo} and when I say "man", I want the program to immediately recognize it as "man";
The program shouldn't wait for any other words once the program recognizes a word.
Could anyone guide me to a doc or an example/demo that I could reference to create such a thing?
Here is the code I have written so far.
private static void recognizeWord(LiveSpeechRecognizer recognizer) {
String[] words = {"man", "bye", "good", "yo"};
System.out.println("RECOGNIZING A WORD. AVAILABLE WORDS: " + Arrays.toString(words));
recognizer.startRecognition(true);
SpeechResult result;
while ((result = recognizer.getResult()) != null ) {
System.out.format("The word is: %s\n", recognizer.getResult().getResult().toString());
}
recognizer.stopRecognition();
}
public static void main(String[] args) throws Exception {
Configuration configuration = new Configuration();
// Set path to acoustic model.
configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
// Set path to dictionary.
configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
// Set language model.
configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
LiveSpeechRecognizer recognizer = new LiveSpeechRecognizer(configuration);
recognizeWord(recognizer);
}
You can write JSGF grammar like this as described in tutorial:
Put it in a folder
src
with a namehello.jsgf
.You can use it like this: