收听多个KeyphraseSearch

时间:2014-12-25 08:50:19

标签: java android speech-recognition cmusphinx

我一直在创建一个Android应用程序,它在使用以下配置监听一个KeyPhrase时工作正常:

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);

如何添加另一个也被识别的关键短语? 我尝试了以下方法:

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);
}

谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

您可以使用以下表单的关键短语列表在资产中创建文件(每行一个,具有以下阈值):

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

并使用addKeywordSearch创建搜索,该搜索会加载文件而不是addKeyphraseSearch