對不起,我一直堅持這一個月,我想提供儘可能多的細節......它只是一個文件沒有發現異常在一個簡單的庫...: )文件未找到異常? (語音識別)
我對我的variances
文件中獲取文件未發現異常:
,不過我會,有差異文件:
我試圖簡單地在我的後臺服務中實現語音識別,以便我可以檢測到用戶說出單詞hello(使用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
之間,但現在我得到這個錯誤,我不知道爲什麼...
請讓我知道,
Ruchir
我沒有看到你所處理的AssetManager通過其加載的資產的代碼。 –
我可以從堆棧跟蹤中看到您正在使用AssetManager。它在Assets類中,我們在這裏看不到。 –
在差異文件末尾添加一個空格,看看它是否可以。您不需要AssetManager,Sphinx的syncAssets方法爲您完成副本。 –