Android RecognitionListener: onResults being called twice
I found this open issue: https://issuetracker.google.com/issues/152628934
As I commented, I assume it is an issue with the "speech recognition service" and not with the Android RecognitionListener class.
this is my temporary workaround
singleResult=true;@Override public void onResults(Bundle results) { Log.d(TAG, "onResults"); //$NON-NLS-1$ if (singleResult) { ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); if (matches != null && matches.size() > 0) { Log.d("single Result", "" + matches.get(0)); } singleResult=false; } getHandler().postDelayed(new Runnable() { @Override public void run() { singleResult=true; } },100); }
I had the same problem and I've just added a boolean flag in my code, but ofcourse it's a temporary solution and I don't know the source of this problem.
val recognizer = SpeechRecognizer.createSpeechRecognizer(context)recognizer.setRecognitionListener( object : RecognitionListener { var singleResult = true override fun onResults(results: Bundle?) { if (singleResult) { results?.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION).let { // do something with result } // next result will be ignored singleResult = false } } }