字典中缺少单词时的例外情况

时间:2016-01-07 12:52:58

标签: pocketsphinx-android

我尝试了演示应用程序,它运行正常,但是当我尝试集成我自己的.jsgf语法文件时,当我尝试使用同一字典的.lm文件进行同样的操作时,它会出错。

我提到PocketSphinx android demo runtime exception链接,但它没有帮助我

以下是代码段:

private void setupRecognizer(File assetsDir) throws IOException {
        // The recognizer can be configured to perform multiple searches
        // of different kind and switch between them
        File modelsDir = new File(assetsDir, "models");
        mRecognizer = defaultSetup()
                .setAcousticModel(new File(assetsDir, "en-us-ptm"))
                .setDictionary(new File(assetsDir, "cmudict-en-us.dict"))
                .setRawLogDir(assetsDir)
                .setKeywordThreshold(1e-10f)
                .setFloat("-beam", 1e-30f)
                .setBoolean("-allphone_ci", true)
                .getRecognizer();
        mRecognizer.addListener(this);
        File languageModel = new File(assetsDir, "commands_gram.gram");
        mRecognizer.addGrammarSearch(COMMANDS, languageModel);
    }

以下是错误

E/cmusphinx: ERROR: "fsg_search.c", line 141: The word 'next' is missing in the dictionary
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1

Process: java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818) 
Caused by: java.lang.RuntimeException: Decoder_setJsgfFile returned -1
at edu.cmu.pocketsphinx.PocketSphinxJNI.Decoder_setJsgfFile(Native Method)
at edu.cmu.pocketsphinx.Decoder.setJsgfFile(Decoder.java:139)
at edu.cmu.pocketsphinx.SpeechRecognizer.addGrammarSearch(SpeechRecognizer.java:234)
at com.package.ui.SphinxSpeechRecognizerActivity.setupRecognizer(SphinxSpeechRecognizerActivity.java:284)
at com.package.ui.SphinxSpeechRecognizerActivity.access$400(SphinxSpeechRecognizerActivity.java:29)
at com.package.ui.SphinxSpeechRecognizerActivity$3.doInBackground(SphinxSpeechRecognizerActivity.java:239)
at com.package.ui.SphinxSpeechRecognizerActivity$3.doInBackground(SphinxSpeechRecognizerActivity.java:233)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818) 

此外,我意识到我使用它的任何.jsgf语法文件都没有检测到字典中的最后一个单词。在我更改为我自己的.jsgf语法文件之后它正常工作之前它正在提供异常

2 个答案:

答案 0 :(得分:2)

这一行:

E/cmusphinx: ERROR: "fsg_search.c", line 141: The word 'next' is missing in the dictionary 

告诉您需要添加' next'到字典。你在JSGF语法中使用了这个词,但字典中却没有。单词区分大小写,因此您需要确保使用正确的大小写。

答案 1 :(得分:1)

我可能知道你的问题。 你必须以正确的形式制作语法,比如你的空格和制表符。 我建议你检查你的语法块或标签。 对不起,我的英语很差。