字典中缺少单词时的异常
Exception when word is missing in the dictionary
我尝试了演示应用程序,它运行良好,但是当我尝试集成我自己的 .jsgf 语法文件时,当我尝试使用 .lm 文件对同一词典进行同样的操作时它运行良好时出现错误。
我提到了 PocketSphinx android demo runtime exception link 但它没有帮助我
以下是代码片段:
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.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.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.access0(SphinxSpeechRecognizerActivity.java:29)
at com.package.ui.SphinxSpeechRecognizerActivity.doInBackground(SphinxSpeechRecognizerActivity.java:239)
at com.package.ui.SphinxSpeechRecognizerActivity.doInBackground(SphinxSpeechRecognizerActivity.java:233)
at android.os.AsyncTask.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor.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 语法文件后它工作正常之前它给出了异常
这一行:
E/cmusphinx: ERROR: "fsg_search.c", line 141: The word 'next' is missing in the dictionary
告诉您需要将单词 'next' 添加到词典中。你在你的 JSGF 语法中使用了这个词,但它在字典中不见了。单词是 case-sensitive,因此您需要确保使用正确的大小写。
我可能知道你的问题。
您必须以正确的形式编写语法,例如 space 和制表符。
我建议您检查块或制表符的语法。
对不起我糟糕的英语。
我尝试了演示应用程序,它运行良好,但是当我尝试集成我自己的 .jsgf 语法文件时,当我尝试使用 .lm 文件对同一词典进行同样的操作时它运行良好时出现错误。
我提到了 PocketSphinx android demo runtime exception link 但它没有帮助我
以下是代码片段:
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.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.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.access0(SphinxSpeechRecognizerActivity.java:29)
at com.package.ui.SphinxSpeechRecognizerActivity.doInBackground(SphinxSpeechRecognizerActivity.java:239)
at com.package.ui.SphinxSpeechRecognizerActivity.doInBackground(SphinxSpeechRecognizerActivity.java:233)
at android.os.AsyncTask.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor.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 语法文件后它工作正常之前它给出了异常
这一行:
E/cmusphinx: ERROR: "fsg_search.c", line 141: The word 'next' is missing in the dictionary
告诉您需要将单词 'next' 添加到词典中。你在你的 JSGF 语法中使用了这个词,但它在字典中不见了。单词是 case-sensitive,因此您需要确保使用正确的大小写。
我可能知道你的问题。 您必须以正确的形式编写语法,例如 space 和制表符。 我建议您检查块或制表符的语法。 对不起我糟糕的英语。