I'm using onPartialResult
method to look if the hypotesis
is one of the keyword I'm interested in and it works well.
Here's my code:
@Override
public void onPartialResult(Hypothesis hypothesis) {
Log.d(TAG, "onPartialResult");
if (hypothesis == null) {
return;
}
String text = hypothesis.getHypstr();
String wordWithProb = "";
String mostProbableWord = "";
int probability = -10000;
if (text.contains("|")) {
for (Segment seg : recognizer.getDecoder().seg()) {
wordWithProb += "|" + seg.getWord() + " " + seg.getProb() + "|";
if (seg.getProb() > probability)
mostProbableWord = seg.getWord().trim();
}
}
else
mostProbableWord = text.trim();
Log.i(TAG, "onPartialResults: " + mostProbableWord);
String recognizedCommand = "Please repeat";
if (mostProbableWord.equals("one")) {
//do something...
} else if (mostProbableWord.equals("two")) {
//do something...
} else if (mostProbableWord.equals("three")) {
//do something...
}
//text to speech
speak(recognizedCommand);
startListening(KWS_SEARCH);
}
Now I would like to handle the case where a user say something and it is not recognized as a keyword; in this case the hypotesis in the onPartialResult
method is always null
: is this expected? I was expecting a not null hypotesis here...
Considering that onPartialResult
method is automatically called by pocketsphinx consinuously (also when there isn't any sound in the air) I cannot use the null
hypothesis as my driving condition.
Moreover there is a text to speech after every recognition and so the recognition listener restart has to be handled carefully: recognizer must not be listening while text to speech is ongoing...
I tried some solution with onEndOfSpeech
but none was good until now...
Any idea?
in this case the hypotesis in the onPartialResult method is always null: is this expected?
Yes
Moreover there is a text to speech after every recognition and so the recognition listener restart has to be handled carefully: recognizer must not be listening while text to speech is ongoing
Correct