How to Set the Language in Speech Recognition on Android

How to set the language in speech recognition on android?

As pargat says, this will do it:

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");

Also, your app can query for the list of supported languages by sending a RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS ordered broadcast like so:

    Intent detailsIntent =  new Intent(RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS);
sendOrderedBroadcast(
detailsIntent, null, new LanguageDetailsChecker(), null, Activity.RESULT_OK, null, null);

where LanguageDetailsChecker is something like this:

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

private String languagePreference;

@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);
}
}
}

For the complete code check out this github project:
https://github.com/gast-lib

Change default language for Speech recognition in my app

You can try with this code:

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");

Also, your app can query for the list of supported languages by sending a RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS ordered broadcast like so:

 Intent detailsIntent =  new Intent(RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS);
sendOrderedBroadcast(
detailsIntent, null, new LanguageDetailsChecker(), null, Activity.RESULT_OK, null, null);

where LanguageDetailsChecker is something like this:

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

private String languagePreference;

@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);
}
}
}

You can also check out the complete code for that at here:https://github.com/gast-lib

How to set the Voice Search Language in Android programmatically?

Ok, I found I managed to get it to work after using the following line instead:

i.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "zh");

How to teach Android Speech recognizer a new language

Android STT has no tools to add a new languages, other external libraries have them. For example, you can add Mongolian language to Pocketsphinx

The tutorial for adding a new language is provided here.

Android Speech Recognision change return language

Use the following method to achieve the desired output, set bn-BD:

 private void getAudioInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "bn-BD");
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "I am Listening...");
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException ignored) {

}
}

Then use onActivityResult() to receive the result using the same Request Code that you've used in the startActivityForResult() with the intent like this:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQ_CODE_SPEECH_INPUT) {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
if (result != null) {
bangla_text = result.get(0);
textOutput.setText(bangla_text);
}
}
}
}

Google speech to text: Extra language set to kn but not working

After hours of research, I finally found solution.

In the below line of code, I should send "kn_IN" instead of "kn". This made it work.

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "kn_IN");

This method works for all the languages mentioned above. ("te_IN", "ml_IN")



Related Topics



Leave a reply



Submit