Reputation: 20916
i Try to use JAPANESE
language on my Android 4 device.
int value = tts.setLanguage(Locale.JAPANESE);
but value is -2.
this is my code for checking
protected void check(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
switch (resultCode) {
case TextToSpeech.Engine.CHECK_VOICE_DATA_PASS:
tts = new TextToSpeech(this, this);
break;
case TextToSpeech.Engine.CHECK_VOICE_DATA_BAD_DATA:
case TextToSpeech.Engine.CHECK_VOICE_DATA_MISSING_DATA:
case TextToSpeech.Engine.CHECK_VOICE_DATA_MISSING_VOLUME:
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
break;
case TextToSpeech.Engine.CHECK_VOICE_DATA_FAIL:
default:
Log.e(TAG, "Got a failure. TTS not available");
}
}
}
and i want to install language if not exist. But app crashes. Is this correct wy ir what can i do? How to get japanese language?
Upvotes: 2
Views: 2832
Reputation: 12058
You start your method by testing result code is equal to 0 and then have a swith on result code value (which you already know is equal to 0):
if (requestCode == 0) {
switch (resultCode) {
As written in your code, if language is not installed tts
will not be initialized and any further reference to it will crash you application.
You can see the correct way to do it in An introduction to Text-To-Speech in Android
Regards.
Upvotes: 2