I’m using the Android Speech Recognition intent but I would like to know what language the user has set to do the recognition. The docs on the RecognizerIntent imply that you can get this from the intent data, but I keep getting null.
Are these values on useable when calling the Intent? Is there another way to get this data?
Here’s how I call the intent:
private void startVoiceRecognitionActivity() {
Logger.i(AppConfig.LOGTAG, "startVoiceRecognitionActivity");
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "speech recognition demo");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
And I get the results like this:
/**
* Handle the results from the recognition activity.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
Logger.i(AppConfig.LOGTAG, "EXTRA_LANGUAGE = "+data.getStringExtra(RecognizerIntent.EXTRA_LANGUAGE));
Logger.i(AppConfig.LOGTAG, "EXTRA_LANGUAGE_MODEL = "+data.getStringExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL));
Logger.i(AppConfig.LOGTAG, "EXTRA_LANGUAGE_PREFERENCE = "+data.getStringExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE));
} else {
Toast.makeText(getApplicationContext(), "Voice recognition failed.", Toast.LENGTH_LONG).show();
}
super.onActivityResult(requestCode, resultCode, data);
}
It seems that you need to send a broadcast to ask what language is configured in the voice recognition. So, the sequence is
Code below:
}