我用的是机器人里的口袋狮身人面像。我已经能够将一个.gram文件中的规则导入另一个.gram文件,并且能够通过指定一个String来使用规则,但似乎不能将两者结合起来。也就是说,我不能从基于字符串的语法中导入基于文件的语法;我总是得到Failed to find grammar错误。
当将语法指定为字符串时,使用:
private SpeechRecognizer mPsRecognizer;
//...
final StringGrammar sg = settings.getStringGrammar();
mPsRecognizer.getDecoder().setJsgfString(sg.getName(), sg.getString());其中的字符串类似于:
name: "initial_grammar",
string: "#JSGF V1.0;\n"
+ "\n"
+ "grammar initial_grammar;\n"
+ "\n"
+ "import <digits.digits>;\n"
+ "import <actions.r_actions>;\n"
+ "import <help.r_help>;\n"
+ "\n"
+ "public <initial_grammar>\n"
+ " = <r_actions>\n"
+ " | <r_help>\n"
+ " ;");我得到了
com.sample.vr.commands E/cmusphinx: ERROR: "jsgf.c", line 775: Failed to find grammar digits.gram
com.sample.vr.commands E/cmusphinx: ERROR: "jsgf.c", line 775: Failed to find grammar actions.gram
com.sample.vr.commands E/cmusphinx: ERROR: "jsgf.c", line 775: Failed to find grammar help.gram
com.sample.vr.commands I/cmusphinx: INFO: jsgf.c(691): Defined rule: PUBLIC <initial_step.initial_grammar>
com.sample.vr.commands E/cmusphinx: ERROR: "jsgf.c", line 338: Undefined rule in RHS: <initial_step.digits>这在某种程度上是预期的,因为没有可以搜索的基本文件。
我尝试过的:1)使用完整的包名,2)使用完整的路径(我从pocketsphinx自己的Asset实用程序中获得的)。
如果我将路径更改为
//...
+ "import <com.sample.vr.commands/files/sync/actions.r_actions>;\n"
+ "import <com.sample.vr.commands/files/sync/help.r_help>;\n"
//...我得到了
com.sample.vr.commands E/cmusphinx: ERROR: "jsgf.c", line 775: Failed to find grammar com/sample/vr/commands/files/sync/help.gram
com.sample.vr.commands E/cmusphinx: ERROR: "jsgf.c", line 775: Failed to find grammar com/sample/vr/commands/files/sync/actions.gram全路径
#JSGF V1.0;
grammar initial_step;
import </storage/emulated/0/Android/data/com.sample.vr.commands/files/sync/actions.r_actions>;
import </storage/emulated/0/Android/data/com.sample.vr.commands/files/sync/help.r_help>;
public <initial_grammar>
= <r_actions>
| <r_help>
;我得到以下错误(请注意,包部分已转换为单独的目录):
com.sample.vr.commands E/cmusphinx: ERROR: "jsgf.c", line 775: Failed to find grammar /storage/emulated/0/Android/data/com/sample/vr/commands/files/sync/help.gram
com.sample.vr.commands E/cmusphinx: ERROR: "jsgf.c", line 775: Failed to find grammar /storage/emulated/0/Android/data/com/sample/vr/commands/files/sync/actions.gram
com.sample.vr.commands I/cmusphinx: INFO: jsgf.c(691): Defined rule: PUBLIC <initial_step.initial_grammar>在pocketsphinx的来源中,我看到他们正在用圆点代替斜杠:
/* Construct a filename. */
for (c = path; *c; ++c)
if (*c == '.')
*c = '/';
strcat(path, ".gram");
newpath = path_list_search(jsgf->searchpath, path);
if (newpath == NULL) {
E_ERROR("Failed to find grammar %s\n", path);
ckd_free(path);
return NULL;
},我怎样才能让知道在哪里找到我想要导入的文件呢?我还没有在SpeechRecognizer或Decoder中找到一个函数。我认为可能有一种方法可以在配置中指定查找语法文件的位置,但我似乎找不到它。在SpeechRecognizerSetup或Config中添加一些参数?或者,我可以将这个命令行参数作为字符串参数添加到Config/Setup对象中吗?
发布于 2016-01-26 10:25:05
在JSGF语法包名称中,将映射到编码的位置,这意味着如果您编写
import com.package.name;对应的语法必须在相对于主语法文件夹的文件夹com/package中。和java包一样。因此,布局必须是:
main.jsgf
com
package
name.jsgf如果从字符串加载了JSGF,则将搜索当前路径以查找导入。搜索路径也由JSGF_PATH环境变量配置。但是,在Java中使用Android设置当前的工作文件夹或环境变量并不容易。因此,最好用硬编码的更改重新编译pocketsphinx,或者从文件中加载jsgf,而不是字符串。
https://stackoverflow.com/questions/35007985
复制相似问题