我已经下载了Pocketsphinx演示版,但它运行正常。
我向cmudict-en-us.dict
添加了新词并创建了新的
mobile.gram:
#JSGF V1.0;
grammar mobile;
public <companies> = stark | newline | uniqueshop;
在MainActivity.java
中,我将天气识别替换为
// Create grammar-based search for company recognition
File mobileGrammar = new File(assetsDir, "mobile.gram");
recognizer.addGrammarSearch(MOBILE_SEARCH, mobileGrammar);
代码的其余部分在演示中更改,但我收到了错误
Caused by: java.lang.RuntimeException: Decoder_setJsgfFile returned -1
此错误指的是recognizer.addGrammarSearch(MOBILE_SEARCH, mobileGrammar);
menu.gram:
#JSGF V1.0;
grammar menu;
public <item> = digits | mobile | phones;
onPartialResult方法:
@Override
public void onPartialResult(Hypothesis hypothesis) {
if (hypothesis == null)
return;
String text = hypothesis.getHypstr();
if (text.equals(KEYPHRASE))
switchSearch(MENU_SEARCH);
else if (text.equals(DIGITS_SEARCH))
switchSearch(DIGITS_SEARCH);
else if (text.equals(PHONE_SEARCH))
switchSearch(PHONE_SEARCH);
else if (text.equals(MOBILE_SEARCH))
switchSearch(MOBILE_SEARCH);
else
((TextView) findViewById(R.id.result_text)).setText(text);
}