I have localized my ap. I'm also using TextToSpeech to read some localized strings.

        speech.setLanguage(Locale.getDefault());

My problem is that if the user speaks for example italian, since the app is not localized to italian the interface falls back to english however TextToSpeech still uses the italian voice and pronunciation.

So basically:

  • If the user locale is US_en, UK_en or any other supported he needs to listen the corresponding voice or Locale.getDefault()
  • If the user locale is not supported the app interface will fall back to the strings.xml (which is in english) and I need TextToSpeak to use an English voice too

Any ideas how to do this?


I haven't found a way to know what language the app is currently using but I figured out I can get the language with Locale.getDefault().getLanguage() and compare it with AssetManager.getLocales(), but I haven't managed to call getLocales()

有帮助吗?

解决方案

This is what I'm doing now:

    String deviceLang = Locale.getDefault().getLanguage();
    speech.setLanguage(deviceLang.equals("en") || deviceLang.equals("es") ? Locale.getDefault() : Locale.US);

However I'm not happy with the fact that I have to keep it updated with the languages I'm supporting. A better solution would be to get app supported languages and compare it with deviceLang (this might be possible with AssetManager.getLocales() but I haven't managed to prove it)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top