我在Android中使用pocketsphinx。我已經能夠將一個.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自己的資產同步實用程序中得到的)。
使用包名 如果我改變import
路徑
//...
+ "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;
}
我能做些什麼讓pocketsphinx-android知道在哪裏可以找到我想要導入的文件?我還沒有在SpeechRecognizer
和Decoder
中找到函數。 我在想,也許有一種方法可以在配置中指定查找語法文件的位置,但我似乎無法找到它。將一些參數添加到SpeechRecognizerSetup
或Config
? 或者是否有一個pocketsphinx中的命令行參數,我可以將其作爲字符串參數添加到配置/設置對象?
我不明白爲什麼這會在發佈的第一秒鐘內發生downvote。 –
我也不明白 –