I am trying to run the dialog demo of sphinx 4 pre aplha but it gives errors.
I am creating a live speech application.
I imported the project using maven and
As Nickolay explains in the source forge forum (here) the microphone resource needs to be released by the recognizer currently using it for another recognizer to be able to use the microphone. While the API is being fixed, I made the following changes to certain classes in the sphinx API as a temporary workaround. This is probably not the best solution, guess until a better solution is proposed, this will work.
I created a class named MicrophoneExtention
with the same source code as the Microphone
class, and added the following methods:
public void closeLine(){ line.close(); }
Similarly a LiveSpeechRecognizerExtention
class with the source code of LiveSpeechRecognizer
class, and made the following changes:
private final MicroPhoneExtention microphone;
microphone =new MicrophoneExtention(16000, 16, true, false);
public void closeRecognitionLine(){ microphone.closeLine(); }
Finally I edited the main method of the DialogDemo
.
Configuration configuration = new Configuration();
configuration.setAcousticModelPath(ACOUSTIC_MODEL);
configuration.setDictionaryPath(DICTIONARY_PATH);
configuration.setGrammarPath(GRAMMAR_PATH);
configuration.setUseGrammar(true);
configuration.setGrammarName("dialog");
LiveSpeechRecognizerExtention recognizer =
new LiveSpeechRecognizerExtention(configuration);
Recognizer.startRecognition(true);
while (true) {
System.out.println("Choose menu item:");
System.out.println("Example: go to the bank account");
System.out.println("Example: exit the program");
System.out.println("Example: weather forecast");
System.out.println("Example: digits\n");
String utterance = recognizer.getResult().getHypothesis();
if (utterance.startsWith("exit"))
break;
if (utterance.equals("digits")) {
recognizer.stopRecognition();
recognizer.closeRecognitionLine();
configuration.setGrammarName("digits.grxml");
recognizer=new LiveSpeechRecognizerExtention(configuration);
recognizeDigits(recognizer);
recognizer.closeRecognitionLine();
configuration.setGrammarName("dialog");
recognizer=new LiveSpeechRecognizerExtention(configuration);
recognizer.startRecognition(true);
}
if (utterance.equals("bank account")) {
recognizer.stopRecognition();
recognizerBankAccount(Recognizer);
recognizer.startRecognition(true);
}
if (utterance.endsWith("weather forecast")) {
recognizer.stopRecognition();
recognizer.closeRecognitionLine();
configuration.setUseGrammar(false);
configuration.setLanguageModelPath(LANGUAGE_MODEL);
recognizer=new LiveSpeechRecognizerExtention(configuration);
recognizeWeather(recognizer);
recognizer.closeRecognitionLine();
configuration.setUseGrammar(true);
configuration.setGrammarName("dialog");
recognizer=new LiveSpeechRecognizerExtention(configuration);
recognizer.startRecognition(true);
}
}
Recognizer.stopRecognition();
and obviously the method signatures in the DialogDemo
needs changing...
hope this helps...
and on a final note, I am not sure if what I did is exactly legal to start with. If i am doing something wrong, please be kind enough to point out my mistakes :D