I created a simple application inspired by this example in order to test all the available options (ie extra). I read about the EXTRA_PARTIAL_RESULTS
extra and if I enable this option I should receive from the server any partial results related to a speech recognition. However, when I add this extra to the ACTION_RECOGNIZE_SPEECH
intent, the voice recognition does not work anymore: the list does not display any results.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE) {
switch(resultCode) {
case RESULT_OK:
Log.i(TAG, "RESULT_OK");
processResults(data);
break;
case RESULT_CANCELED:
Log.i(TAG, "RESULT_CANCELED");
break;
case RecognizerIntent.RESULT_AUDIO_ERROR:
Log.i(TAG, "RESULT_AUDIO_ERROR");
break;
case RecognizerIntent.RESULT_CLIENT_ERROR:
Log.i(TAG, "RESULT_CLIENT_ERROR");
break;
case RecognizerIntent.RESULT_NETWORK_ERROR:
Log.i(TAG, "RESULT_NETWORK_ERROR");
break;
case RecognizerIntent.RESULT_NO_MATCH:
Log.i(TAG, "RESULT_NO_MATCH");
break;
case RecognizerIntent.RESULT_SERVER_ERROR:
Log.i(TAG, "RESULT_SERVER_ERROR");
break;
default:
Log.i(TAG, "RESULT_UNKNOWN");
break;
}
}
Log.i(TAG, "Intent data: " + data);
super.onActivityResult(requestCode, resultCode, data);
}
private void processResults(Intent data) {
Log.i(TAG, "processResults()");
ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
// list of results
ListView listOfResults = (ListView)(findViewById(R.id.list_of_results));
listOfResults.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, matches));
// number of elements of above list
TextView resultsCount = (TextView)(findViewById(R.id.results_count));
resultsCount.setText(getString(R.string.results_count_label) + ": " + matches.size());
}
When this option is enabled, the number of elements in the list of results is equal to 1 and this one result is an empty string. What is the reason for this behavior?
ADDED DETAILS
I used the following code in order to enable EXTRA_PARTIAL_RESULTS
option (on Android 2.3.5).
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, ...);
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, ...);
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE); // where VOICE_RECOGNITION_REQUEST_CODE is a "global variable"
However, enabling this option, the ArrayList<String> matches
in processResults
method has only one empty element.