Android上的Pocketsphinx无法找到声学模型定义mdef

时间:2014-08-27 07:02:33

标签: android ant voice-recognition cmusphinx

我在libs文件夹中复制了so文件,并在资产中复制了sync文件夹和assets.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 / en-us-semi'不包含声学模型定义'mdef'

有人可以帮我解决这个问题或给我一些建议吗?

1 个答案:

答案 0 :(得分:2)

此:

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

下次保重。