Ersin Gülbahar Ersin Gülbahar - 1 year ago 123
Android Question

audio input and output (Android in code)

How i change audio input and output language in my android code? Should i edit this code to change audio input output language ? {I want to set one variable to En to speech language English or set variable to Tr to select Turkish if this possible?}

public Intent getRecognizeIntent()
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 100);
return intent;

Or this help me to change? -> EXTRA_LANGUAGE_PREFERENCE

Answer Source

This should work in most cases:

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");


intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, Locale.getDefault());

Where you pick the locale you want and pass it's toString() to EXTRA_LANGUAGE_PREFERENCE

However, to be correct, you should try doing a language check, and observing the returned "voices". Manually or automatically, pick the "voice" string you want and then use that for the RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE value.

Here is some code to execute the language check:

public static void getLanguageDetails(Context context,
        OnLanguageDetailsListener andThen)
    Intent detailsIntent = new Intent(
    LanguageDetailsChecker checker = new LanguageDetailsChecker(andThen);
    context.sendOrderedBroadcast(detailsIntent, null, checker, null,
            Activity.RESULT_OK, null, null);

where LanguageDetailsChecker is something like this:

public class LanguageDetailsChecker extends BroadcastReceiver
    private List<String> supportedLanguages;

    private String languagePreference;

    public void onReceive(Context context, Intent intent)
        Bundle results = getResultExtras(true);
        if (results.containsKey(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE))
            languagePreference =
        if (results.containsKey(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES))
            supportedLanguages =
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download