5

When I use this line to set Locale for Japanese it works just fine.

tts.setLanguage(Locale.JAPANESE);

When I substitute FRENCH, GERMAN, ITALIAN and CHINESE it also works.

When I substitute SPANISH, RUSSIAN or HINDI Eclipse tells me "SPANISH cannot be resolved or is not a field" [fill in for the other languages].

I am told Android does provide support for these languages, so how is it possible I do not find them?

Peltier Cooler
  • 157
  • 1
  • 12

1 Answers1

3

According to the documentation the Locale object has no constant for spanish defined. You can try to use this (not tested):

Locale locale = new Locale("es", "ES");
tts.setLanguage(locale);

But keep this note in mind (also from the Locale documentation):

It is also a mistake to assume that all devices have the same locales available. A device sold in the US will almost certainly support en_US and es_US, but not necessarily any locales with the same language but different countries (such as en_GB or es_ES), nor any locales for other languages (such as de_DE). The opposite may well be true for a device sold in Europe.

Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78
  • I used a bit of code witchery from this thread http://stackoverflow.com/questions/4872702/get-available-locales-for-tts Locale loc = new Locale("en"); Log.i("-------------",Arrays.toString(loc.getAvailableLocales())); to get a list of locales supported, and es_ES is among them. So, my problem may lie elsewhere. – Peltier Cooler Apr 30 '14 at 03:23
  • So, I ended up using your suggestion after all, and it worked with all my locales. Thank you very much. – Peltier Cooler Apr 30 '14 at 03:55
  • Correction: works for everything except Chinese, which is supported according to the results of getAvailableLocales(), but does not in fact work. – Peltier Cooler May 08 '14 at 02:51
  • Neither Locale("es", "ES") nor Locale("esp", "ESP") nor Locale("sp", "SP") nor Locale("spa", "MEX") e.t.c. These are not working with Locale function on Android target API 30 and below versions. I am hopeful about the future updates. – Bay Jan 01 '21 at 16:36