Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
398 views
in Technique[技术] by (71.8m points)

android - Available languages for speech recognition

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...