3

From what I've read, speech recognition is available for 3 languages: English (UK, US, Au ..), Japanese and Chinese (Mandarin).

Does anyone know more details about how to switch between these languages? Is there a way to know (programatically) which language is active for speech recognition on a certain device? (maybe in Japan the only have Japanese ... but can I get this information somehow ... like a property or anything?).

Any help regarding this will be appreciated.

Thanks guys.

1
  • Please try to make your titles more descriptive. For example: "Available languages for speech recognition"
    – Casebash
    May 6, 2010 at 22:42

2 Answers 2

3

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.

2
  • Great! this is useful. Only one thing we found incomplete. When running on Android 8.x, Bundle results got nothing inside "Bundle[{}]"! Do you have any idea about this problem?
    – Fisher
    Apr 16, 2018 at 8:49
  • But the problem is when you want to use it, it does not work perfectly, for e.g. with Chinese language because you simply cannot create Locale to start recognition Sep 3, 2018 at 15:53
0

You might want to take a look at android.speech.RecognizerIntent It looks like you can get Language support info from there by calling getVoiceDetailsIntent().

Have a look at the API docs here

1
  • Unfortunately it doesn't work, always returning null bundle. I found similar issues raised across internet. Can anyone tell if it works, and how to use it properly? Feb 23, 2011 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.