我正在使用pocketsphinx来检测单词相机并启动相机应用程序。然而,一旦我说"相机",虽然它打开相机,但屏幕开始闪烁(亮度增加和减少)和相机滞后。此外,按下后退按钮关闭相机后,相机应用程序将再次打开。我不明白这里有什么问题?
public class PocketSphinxActivity extends Activity implements
RecognitionListener {
private static final String trigger = "camera";
//private static final String KWS_SEARCH="wakeup";
private SpeechRecognizer recognizer;
private HashMap<String, Integer> captions;
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
new AsyncTask<Void, Void, Exception>() {
@Override
protected Exception doInBackground(Void... params) {
try {
Assets assets = new Assets(PocketSphinxActivity.this);
File assetDir = assets.syncAssets();
setupRecognizer(assetDir);
} catch (IOException e) {
return e;
}
return null;
}
@Override
protected void onPostExecute(Exception result) {
if (result != null) {
result.printStackTrace();
} else {
recognizer.startListening(trigger);
}
}
}.execute();
}
@Override
public void onBeginningOfSpeech() {
}
@Override
public void onPartialResult(Hypothesis hypothesis) {
if (hypothesis == null)
return;
String text = hypothesis.getHypstr();
if (text.equals(trigger)){
Intent i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(i.resolveActivity(getPackageManager())!=null){
startActivity(i);
}
finish();
}
}
@Override
public void onResult(Hypothesis hypothesis) {
//no use
}
@Override
public void onEndOfSpeech() {
}
@Override
public void onError(Exception error) {
error.printStackTrace();
}
@Override
public void onTimeout() {
}
@Override
public void onDestroy() {
super.onDestroy();
recognizer.cancel();
recognizer.shutdown();
}
private void setupRecognizer(File assetsDir) throws IOException{
recognizer=defaultSetup()
.setAcousticModel(new File(assetsDir, "en-us-ptm"))
.setDictionary(new File(assetsDir, "cmudict-en-us.dict"))
.setKeywordThreshold(1e-45f)
.setBoolean("-allphone_ci", true)
.getRecognizer();
recognizer.addListener(this);
recognizer.addKeyphraseSearch(trigger,"camera");
}
}