与here相同的问题,但对我来说仍然没有解决。
我的SpeechRecognizer
可以正常工作,直到我添加EXTRA_PARTIAL_RESULTS
为止。在这种情况下,onPartialResults
会很快触发一次(我不会说完),识别器停止并返回matches
长度为1的空字符串。
如果我删除EXTRA_PARTIAL_RESULTS
行,那么我会说完整的句子,onResults
被解雇,一切都会按预期进行。
有什么想法吗?
@Override
public void onStart() {
Log.d(TAG, "onStart");
super.onStart();
// set up speech recognizer
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(getContext());
mSpeechRecognizer.setRecognitionListener(this);
}
private void startSpeechRecognition() {
Log.d(TAG, "start speech recognition fn");
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.US.toString());
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getActivity().getApplication().getPackageName());
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
mSpeechRecognizer.startListening(intent);
mRecognitionOn = true;
}
@Override
public void onResults(Bundle bundle) {
Log.d(TAG, "results");
this.onPartialResults(bundle);
doSomething();
}
@Override
public void onPartialResults(Bundle bundle) {
Log.d(TAG, "partial results");
ArrayList<String> matches = bundle.getStringArrayList(
SpeechRecognizer.RESULTS_RECOGNITION);
Log.d("debug1", String.valueOf(matches.size()));
Log.d("debug1", "this is the string: " + matches.get(0));
mAnswerEditText.setText(matches.get(0));
}