1

I have been creating an Android app which works fine when it is listening to one KeyPhrase with following config:

private static final String KWS_SEARCH = "wakeup";
private static final String KEYPHRASE = "oh mighty computer";

    recognizer = SpeechRecognizerSetup.defaultSetup()
            .setAcousticModel(new File(modelsDir, "hmm/en-us-semi"))
            .setDictionary(new File(modelsDir, "dict/cmu07a.dic"))
            .setKeywordThreshold(1e-20f)
            .getRecognizer();

    recognizer.addListener(this);

    recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);

How can I add a second keyphrase which is recognized too? I tried the following:

private static final String KWS_SEARCH2 = "up";
private static final String KEYPHRASE2 = "hello my name is";

recognizer.addKeyphraseSearch(KWS_SEARCH2, KEYPHRASE2);

@Override
public void onPartialResult(Hypothesis hypothesis) {
    if (hypothesis == null)
        return;

    String text = hypothesis.getHypstr();

    if (text.equals(KWS_SEARCH))
        restartRecognizer(KWS_SEARCH);
    else if (text.equals(KWS_SEARCH2))
        restartRecognizer(KWS_SEARCH2);
}

Thank you for help!

Kevin
  • 51
  • 1
  • 5

1 Answers1

1

You can create the file in assets with keyphrase list of the following form (one per-line with the following threshold):

 oh mighty computer /1e-40/
 hello my name is /1e-38/

and create a search with addKeywordSearch which loads a file instead of addKeyphraseSearch.

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87