Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the language in speech recognition on android?

I've been working on speech Recognition API in android and found out that the speech results vary allot when the language settings are changed , is there a way to set it programmatically ? or is there an intent to lunch the speech language settings screen ? or what else ? note: I tried to use this intent extra:

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

but it was ineffective

like image 555
Mr.Me Avatar asked May 10 '12 16:05

Mr.Me


People also ask

How do I change the language of speech recognition?

Click Start -> Control Panel -> Ease of Access and switch to Speech recognition. Click Advanced speech options and choose the language from the list.

How do I change the dictation language on my Samsung?

In order to add a spoken language on your keyboard, you'll first need to make sure the Google Keyboard is installed from within the Settings app. After doing that, you'll be able to add languages to the dictation menu by tapping the microphone option to access the "Add or Remove Languages" menu.

How do I add another language to my Samsung voice input?

Navigate to and open Settings, and then tap General Management. Tap Language, and then tap Add language. If you don't see the language you are looking for, tap More options (the three vertical dots), tap All languages, and then select your desired language.


3 Answers

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

like image 94
gregm Avatar answered Oct 17 '22 03:10

gregm


This will work:

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

You have to use "en_US" instead of "en-US". The former is the right format of Java locale tag.

It is suggested that you use

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.US.toString()); 

to avoid remembering such detail.

like image 35
orina1123 Avatar answered Oct 17 '22 01:10

orina1123


there is no solution but a hackaround...

intent.putExtra("android.speech.extra.EXTRA_ADDITIONAL_LANGUAGES", new String[]{"en"});

check here the complete story.

like image 43
Arnav M. Avatar answered Oct 17 '22 01:10

Arnav M.