SpeechRecognizer return ERROR_NO_MATCH in onResults when the device is offline while it's returning the partial results in onPartialResults() call back. The last time I played around with SpeechRecognizer it was working fine offline, I wonder if anyone has found a solution to it.
As a work around I use the partialResults returned in onPartialResults(). In the returned bundle "SpeechRecognizer.RESULTS_RECOGNITION" has all the terms minus the last term and "android.speech.extra.UNSTABLE_TEXT" has the last missing recognized term.
@Override
public void onPartialResults(Bundle partialResults) {
ArrayList<String> data = partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
ArrayList<String> unstableData = partialResults.getStringArrayList("android.speech.extra.UNSTABLE_TEXT");
mResult = data.get(0) + unstableData.get(0);
}
To make the answer a little bit more clear, you need to enable partial results first, and to call UNSTABLE_TEXT in a specific fashion:
// When creating the intent, set the partial flag to true
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS,true);
// When requesting results in onPartialResults(), the UNSTABLE_TEXT parameter to getSTtringArrayList() must be in quotes
ArrayList<String> unstableMatches = partialResults.getStringArrayList("android.speech.extra.UNSTABLE_TEXT");
onPartialResults() gets called multiple times now and onError() still gets called with ERROR_NO_MATCH. I ended up using a solution similar to the one listed here: https://github.com/nenick/QuAcc/blob/master/app/src/main/java/de/nenick/quacc/speechrecognition/speech/RecognizerListenerWithOfflineWorkaround.java
In a nutshell:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With