java – 无法启动服务? (语音识别)
作者:互联网
我想在服务中不断地使用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!");
}
}
我将不胜感激任何反馈.积极的,消极的,甚至是评论.在这一点上,经过2天的努力,我绝望了!
解决方法:
你有这个:
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
}
尝试将其更改为:
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);
//Add this:
File digitsGrammar = new File(modelsDir, "grammar/digits.gram");
recognizer.addKeywordSearch(DIGITS_SEARCH, digitsGrammar);
}
要开始语音侦听,请从按钮调用此方法.当它工作时,从服务中调用它,以使事情更简单:
recognizer.startListening("Hello"); //Start listeneing
现在,创建一个名为digits.gram的新文件,并将其放在一个名为here的文件夹中:/youProjectRootFolder/grammar/digits.gram
这个文件实际上是一个.txt文件,但是当你把这个文本放在里面时,将扩展名更改为.gram:
hello /1e-1/
hi /1e-1/
bye /1e-1/
goodbye /1e-1/
...etc. /1e-1/
在这里你会发现类似的情况:Recognizing multiple keywords using PocketSphinx
祝好运!
标签:android,java,speech-recognition,voice-recognition,cmusphinx 来源: https://codeday.me/bug/20190923/1814538.html