Question

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);
}
Était-ce utile?

La solution

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

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top