0

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?

salvolds
  • 201
  • 2
  • 14

1 Answers1

0

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

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
  • Hello @Nikolay, sometimes (rarely) it happens also that a not null hypothesis is generated and this is not matching a keyword. This happens when the speech is very similar to a keyword... Anyway... How can I handle the case where a user say something and it is not recognized as a keyword? Is onEndOfSpeech the solution? Is there a way to distinguish between noise and speech at least? – salvolds May 02 '17 at 21:26
  • 1
    There is no solution to distinguish between noise and speech yet, you have to implement it yourself. – Nikolay Shmyrev May 03 '17 at 11:37