skip to Main Content

I have a code in my application which recognize "Persian" language and make a Speech-to-text function:

  Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "fa");
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak...");

but now it’s suddenly stopped working and just recognize my STT as English! I didn’t change anything. When I’m changing RecognizerIntent.EXTRA_LANGUAGE to any language like Italian intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "it"); it doesn’t recognize this language either!

What’s wrong?

2

Answers


  1. Try explicitly setting the locale with a Locale object instead of just the language code:

    Locale persianLocale = new Locale("fa");
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, persianLocale.toLanguageTag());
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    Additionally, you can set the EXTRA_LANGUAGE_PREFERENCE and EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE:
    
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "fa");
    intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, "fa");
    

    or

    The default language of the device might be affecting the recognition.

    Solution:
    Try changing the device’s default language to Persian temporarily:

    Go to Settings → System → Languages & Input → Languages.
    Add Persian and set it as the primary language.
    Restart the device and test your app.

    Login or Signup to reply.
  2. Sometimes permission changes or updates to the Android operating system can cause issues with STT.

    Solution:
    Ensure your app has the necessary permissions for recording audio and using the microphone:

    xml

    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    

    Check if runtime permissions are granted:

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, REQUEST_CODE);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search