How can I use voice recognition with other languag

2019-07-02 01:24发布

问题:

I have a code that used to worked but for some reason it suddenly just stopped working, I'm trying to use voice recognition in Hebrew but it seems like since a few days ago it just starts voice recognition in English.

Here is my code

 sr = SpeechRecognizer.createSpeechRecognizer(getApplicationContext());
            test_voice_recognitiona listener = new test_voice_recognitiona();
            sr.setRecognitionListener(listener);
            Intent fl = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            fl.putExtra("android.speech.extra.LANGUAGE", "he");
            fl.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "he");
            fl.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                    this.getPackageName());
            sr.startListening(fl);

test_voice_recognitiona is the name of my RecognitionListener class name.

The code runs well but for some reason it keeps listening in English.

What am I doing wrong?

By the way I tried the simpler code with the google dialog and it's working.

  Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "he");
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Talk to Me " + user_name);
        startActivityForResult(intent,REQUEST_CODE);

Perhaps it's the Google now update fault

回答1:

Although I'm late to the party, The following hack works for me:

  Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

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

    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            getString(R.string.speech_prompt));