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 (programat开发者_如何学Cically) 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.
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.
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
精彩评论