To switch between languages, just use the Locale you want for the language and set Locale.toString
for EXTRA_LANGAUGE
in you ACTION_RECOGNIZE_SPEECH
intent.
To check what languages are available, you need something like this:
Intent detailsIntent = new Intent(
RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS);
LanguageDetailsChecker checker = new LanguageDetailsChecker();
sendOrderedBroadcast(detailsIntent, null, checker, null,
Activity.RESULT_OK, null, null);
Where LanguageDetailsChecker is a BroadcastReceiver defined as something like this:
public class LanguageDetailsChecker extends BroadcastReceiver {
private static final String TAG = "LanguageDetailsChecker";
private List<String> supportedLanguages;
private String languagePreference;
public LanguageDetailsChecker() {
supportedLanguages = new ArrayList<String>();
}
@Override
public void onReceive(Context context, Intent intent) {
Bundle results = getResultExtras(true);
if (results.containsKey(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE)) {
languagePreference = results
.getString(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE);
}
if (results.containsKey(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES)) {
supportedLanguages = results
.getStringArrayList(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES);
}
}
}
All this code is part of this project.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…