【发布时间】:2016-02-27 00:46:46
【问题描述】:
对不起,这个问题太长了,我已经坚持了一个月,我想提供尽可能多的细节......它只是一个在简单库中找不到异常的文件...... :)
我的variances 文件中出现文件未找到异常:
不过,我确实有差异文件:
我试图在我的后台服务中简单地实现语音识别,这样我就可以检测到用户何时说出你好这个词(使用 pocketsphinx)。
这个方法出现问题:createSphinxDir();
这是我的服务:
@Override
public void onCreate() {
super.onCreate();
setupRecog();
}
private void setupRecog() {
String sphinxDir = createSphinxDir();
Log.v(TAG, "ABOUT TO CREATE SETUP");
if (sphinxDir != null) {
try {
Log.v(TAG, "SETTING UP! :)");
mSpeechRecognizer = defaultSetup()
.setAcousticModel(new File(sphinxDir, "en-us-ptm"))
.setDictionary(new File(sphinxDir, "hello.dict"))
.setBoolean("-allphone_ci", true) //WHAT IS THIS
.getRecognizer();
mSpeechRecognizer.addListener(this);
Log.v(TAG, "ADDED LISTENER");
if ((new File(sphinxDir + File.separator + "command.gram")).isFile()) {
mSpeechRecognizer.addKeywordSearch("hello",
new File(sphinxDir + File.separator + "command.gram"));
Log.v(TAG, "ADDED KEYWORD SEARCH! :)");
}
// Or wherever appropriate
mSpeechRecognizer.startListening("wakeup"); //Is this correct?
Log.v(TAG, "STARTED LISTENING");
} catch (IOException e) {
Log.v("ERROR", TAG);
}
}
}
String createSphinxDir() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String sphinxDir = prefs.getString("sphinx", null);
if (sphinxDir == null) {
Assets assets;
Log.v(TAG, "Assets are not synced, should sync now:");
try {
Log.v(TAG, "In try block!");
assets = new Assets(this);
File sphinxDirFile = assets.syncAssets();
Log.v(TAG, "Syncing assets...should set up listener");
if (sphinxDirFile != null) {
sphinxDir = sphinxDirFile.getAbsolutePath();
SharedPreferences.Editor editor = prefs.edit();
editor.putString("sphinx", sphinxDir);
editor.commit();
Log.v(TAG, "Set up listener");
}else{
Log.v(TAG, "sphinxDirFile is null!");
}
} catch (IOException e) { //THIS IS THE PLACE WHERE I AM GETTING THE ERROR!
e.printStackTrace();
Log.d(TAG, e.toString());
}
}
return sphinxDir;
}
我也有所有的回调方法(onPartialResult、onResult 等),但它们从未被调用过。
早些时候我收到一个异常,说差异 .md5 文件不存在,所以我在 variances 和 .md5 之间放了一个空格,但现在我收到了这个错误,我不知道为什么...
请告诉我,
鲁基尔
【问题讨论】:
-
我没有看到您正在处理 AssetManager 以从中加载资产的代码。
-
我可以从堆栈跟踪中看到您正在使用 AssetManager。它在 Assets 类中,我们在这里看不到。
-
在variances文件末尾加个空格,看看是否可以。您不需要 AssetManager,Sphinx 的 syncAssets 方法会为您完成复制。
标签: java android string file voice-recognition