hypothesis.getHypstr()
始終是一個值,即使我更改了關鍵字!onPartialResult始終是一個值,即使在我更改關鍵字之後?
我使用pocketsphinx
做語音識別,我讓用戶改變聽什麼。該值存儲在我的共享首選項中。我的問題是hypothesis.getHypstr()
僅在使用前一個關鍵字時被調用。
例如:
如果它被設置爲默認的關鍵字(橙子和彩虹),然後識別工作正常。但是,如果用戶將其更改爲「hello computer」,則onPartialResult
方法仍然只在用戶打招呼時才被調用,和hypothesis.getHypstr()
仍然是桔子和彩虹。
的onCreate:
try {
Assets assets = new Assets(MyService.this);
File assetDir = assets.syncAssets();
setupRecognizer(assetDir);
Log.v(TAG, "SET UP DIRECTORIES STARTING LISTENING!");
mSpeechRecognizer.startListening("usersKeyword");
} catch (IOException e) {
e.printStackTrace();
Log.v(TAG, e.toString());
}
setupRecognizer()
public void setupRecognizer(File sphinxDir) {
try {
mSpeechRecognizer = defaultSetup()
.setAcousticModel(new File(sphinxDir, "en-us-ptm"))
.setDictionary(new File(sphinxDir, "cmudict-en-us.dict"))
.setBoolean("-allphone_ci", true)
.setKeywordThreshold(1e-40f)
.getRecognizer();
} catch (IOException e) {
e.printStackTrace();
}
mSpeechRecognizer.addListener(this);
mSpeechRecognizer.addKeyphraseSearch("usersKeyword", keyword.getString("keyword", "oranges and rainbows"));
}
onPartialResult:
@Override
public void onPartialResult(Hypothesis hypothesis) {
if (hypothesis == null) { //no one spoke
return;
}
String text = hypothesis.getHypstr();
Log.v(TAG, "TEXT: " + text + "hypothesis.getHypstr: " + hypothesis.getHypstr());
if (text.equals(keyword.getString("keyword", "oranges and rainbows"))) { //Only happens when text is oranges and rainbows, even after changing preference value!!!
Log.v(TAG, "Heard user keyword!");
mSpeechRecognizer.cancel();
mSpeechRecognizer.startListening("usersKeyword");
}
}
爲什麼hypothesis.getHypstr()
總是隻有一個值,即使在我更改addKeyphraseSearch
的值後?
感謝,
Ruchir
編輯: 其實我停下來,每次用戶改變他們輸入時啓動該服務,所以onCreate()
被稱爲每次用戶改變他們的數據的時間。
全碼:
https://gist.github.com/anonymous/47efc9c1ca08d808e0be
您需要顯示完整的代碼,而不僅僅是部分代碼。 –
@NikolayShmyrev問題在於即使在更改用戶關鍵字後,'hypothesis.getHypstr();'總是'桔子和彩虹'。 –
@NikolayShmyrev也許我需要刪除所有的資產文件之前,讓他們?有沒有像'assets.deleteSync'方法? –