Reputation: 488
i am using sphinx4 to pause a thread until a specific keyword is spoken. This works great the first time, but the second time i need to pause the thread, the
recognizer.recognize()
seems to not run and the application just starts spamming "Start speaking...".
Here is the function to pause the thread:
public synchronized void waitForKeyword(String in){
if (!microphone.startRecording()) {
System.out.println("Cannot start microphone.");
recognizer.deallocate();
System.exit(1);
}
Result result = null;
while(true) {
if(microphone.isRecording()) {
System.out.println("Start speaking...\n");
result = recognizer.recognize();
}else{
microphone.startRecording();
}
if (result != null) {
String resultText = result.getBestFinalResultNoFiller();
System.out.println("You said: " + resultText + '\n');
if(resultText.equals(in)){
microphone.stopRecording();
speak("At your service!");
break;
}
}
}
}
What am i doing wrong, and how do i fix this problem?
Cheers!
Upvotes: 1
Views: 251
Reputation: 2507
You must call microphone.clear()
after the first use. Works for me with OpenJDK. I am working on a demo application that demonstrates this use case, it should be included in the next release of Sphinx4 so stay tuned.
Upvotes: 2