Reputation: 21452
I am developing a speech recognition system, I have made one with English language and it worked very well.
But what i am having problem with is that I need to develop the app to recognize Arabic language.
Here is my code :
private static final int RESULT_SPEECH = 1;
Button b1 ;
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.listView1);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent voicerecogize = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
voicerecogize.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "ar-eg");
startActivityForResult(voicerecogize, RESULT_SPEECH);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == RESULT_SPEECH && requestCode == RESULT_OK);
{
ArrayList<String > results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , results));
}
super.onActivityResult(requestCode, resultCode, data);
}
Upvotes: 2
Views: 5110
Reputation: 434
Change the code of the onClick
event to:
Intent voicerecogize = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
voicerecogize.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
voicerecogize.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);// spilling
voicerecogize.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "ar-EG");
startActivityForResult(voicerecogize, RESULT_SPEECH);
Upvotes: 10
Reputation: 2022
FYI, In Kitkat devices, even if i specified the language(arabic) other than the default one(english), it takes the default one(english).
Issue 76347-https://code.google.com/p/android/issues/detail?id=75347
I got a fix for the issue from the above link, That is nothing but adding the following statement with the RecognizerIntent.
intent.putExtra("android.speech.extra.EXTRA_ADDITIONAL_LANGUAGES", new String[]{});
After adding this, my app worked correctly in Kitkat 4.4
Upvotes: 2