Ошибка Pocketsphinx при добавлении новых слов и файла .gram - PullRequest
0 голосов
/ 11 мая 2018

Я скачал демо 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);
}
...