<分区>
我一直在创建一个 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);
}
谢谢你的帮助!