我想在服務中使用pocketsphinx監聽單詞Hello不斷無法啓動服務? (語音識別測試)
我得到的錯誤。這裏是full stack trace。這是它的一小部分。
Unable to create service curlybrace.ruchir.myApp.MyService: java.lang.RuntimeException: new_Decoder returned -1
它是由這個原因引起:
setupRecognizer(assetDir); //SETUP
這:
.getRecognizer();
在我onCreate
:
Log.v(TAG, "Voice recognition activated!");
//Register voice recog listener :)
Assets assets = null;
try {
assets = new Assets(MyService.this);
File assetDir = assets.syncAssets();
setupRecognizer(assetDir); //SETUP
Log.v(TAG, "Set up listener");
} catch (IOException e) {
e.printStackTrace();
}
這裏是我的setupRecognizer
方法:
private void setupRecognizer(File assetDir) throws IOException {
recognizer = defaultSetup()
.setAcousticModel(new File(assetDir, "hmm/en-us-semi"))
.setDictionary(new File(assetDir, "lm/cmu07a.dic"))
.setKeywordThreshold(1e-5f)
.getRecognizer();
recognizer.addListener(this);
// recognizer.addKeywordSearch("Hello", assetDir); //I don't know what this does...
recognizer.startListening("Hello"); //Start listeneing
}
這裏的實現方法之一:
@Override
public void onPartialResult(Hypothesis hypothesis) {
String text = hypothesis.getHypstr();
if (text.equals("Hello")) {
// do something
Log.v(TAG, "SPEECH RECOGNIZED HELLO!");
}
}
我將不勝感激任何反饋。積極,消極,甚至一個評論。在這之後,我絕望了,試了兩天!
就像一個想法:你是否在清單中註冊了麥克風權限? – luxer
@luxer不,我沒有 –
即使您使用了庫,您的應用程序也需要獲得聽麥克風的權限。你有沒有試過添加它? – luxer