我已经复制了libs文件夹中的so文件和资产中的sync文件夹以及asset.lst文件。还向应用程序添加了pocketsphinx-android-0.8-nolib.jar
我还补充说:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


清单文件的权限。

然后我添加了用于设置SpechRecognizer的代码

private void setUpRecognizer(){
    Assets assets = new Assets(context);
    File assetDir = assets.syncAssets();
    File modelsDir = new File(assetsDir, "models");
    recognizer = defaultSetup()
        .setAcousticModel(new File(assetsDir, "hmm/en-us-semi"))
        .setDictionary(new File(assetsDir, "dict/cmu07a.dic"))
        .setRawLogDir(assetsDir).setKeywordThreshold(1e-40f)
        .getRecognizer();
    recognizer.addListener(this);
    File modelsDir = new File(assetsDir, "models");
    recognizer = defaultSetup()
        .setAcousticModel(new File(assetsDir, "hmm/en-us-semi"))
        .setDictionary(new File(assetsDir, "dict/cmu07a.dic"))
        .setRawLogDir(assetsDir).setKeywordThreshold(1e-40f)
        .getRecognizer();
    recognizer.addListener(this);
    recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);
    File menuGrammer = new File(modelsDir, "grammar/menu.gram");
    recognizer.addGrammarSearch(MENU_SEARCH, menuGrammer);
    File digitGrammer = new File(modelsDir, "grammar/digits.gram");
    recognizer.addGrammarSearch(DIGITS_SEARCH, digitGrammer);
    File languageModel = new File(modelsDir, "lm/weather.dmp");
    recognizer.addNgramSearch(FORECAST_SEARCH, languageModel);
}


运行该应用程序后,出现异常:


  08-26 13:42:38.301:E / cmusphinx(14405):错误:“ acmod.c”,第90行:文件夹'/storage/sdcard0/Android/data/com.perscitussln.sherbet/files/sync/hmm/ zh-cn-semi'不包含声学模型定义'mdef'


谁能帮助我解决这个问题或给我一些建议?

最佳答案

这个:

   File modelsDir = new File(assetsDir, "models");
   recognizer = defaultSetup()
        .setAcousticModel(new File(assetsDir, "hmm/en-us-semi"))


必须更改为

   File modelsDir = new File(assetsDir, "models");
   recognizer = defaultSetup()
        .setAcousticModel(new File(modelsDir, "hmm/en-us-semi"))


或对此:

    recognizer = defaultSetup()
         .setAcousticModel(new File(assetsDir, "models/hmm/en-us-semi"))


下次要保重。

10-08 15:54