Reputation: 3889
I am trying to use google TTS inside my Android app. Within this part of my code:
@Override
public void onInit(int status)
{
if(status == TextToSpeech.SUCCESS)
{
int result=tts.setLanguage(Locale.);
if(result==TextToSpeech.LANG_MISSING_DATA || result==TextToSpeech.LANG_NOT_SUPPORTED)
{
Log.e("error", "This Language is not supported");
}
else{
ConvertTextToSpeech();
}
}
else
Log.e("error", "Initilization Failed!");
}
});
In this line int result=tts.setLanguage(Locale.);
I am trying to use Locale.fa_IR
But it says Error:(37, 54) error: cannot find symbol variable fa_IR
. How can I fix this?
I think I should install something on the emulator, but don't know what, and how?
Upvotes: 1
Views: 1027
Reputation: 2955
Use language code from https://www.w3schools.com/tags/ref_language_codes.asp.
mLanguage = new Locale(language_codes);
tts = new TextToSpeech(mContext, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
int result = tts.setLanguage(mLanguage);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("Text2SpeechWidget", result + " is not supported");
}
}
}
});
Upvotes: 0
Reputation: 526
because Locale.fa_IR
is not a language understand by Text To Speech.
To Know how many language it supoort. Just do one thing.
tts.setLanguage(Locale.);
after Locale dot you get multiple option so the only set of language suppoted shown there choose whichever country language you want to support in you application
Upvotes: 1