Reputation: 31
hey i'm trying to create a tts
for 3 different language
they are English, Spanish, and Indonesia
i got no problem with English and Spanish
they work fine, but i got an error with the Indonesian language
i tried different ways and different locale combination but still no luck
here is my code for Indonesia :
Locale locInd = new Locale("IDN");
int result = tts.setLanguage(locInd);
I've tried locale("in","ID");
, locale("ind","IDN");
, locale("in_ID);
but also still no luck
every time i tried, the output is in English rather then Indonesian
i used jellybean(4.2.2) emulator to run it
and there is in_ID
in locale when i run the emulator
EDIT : i found my problem, in pico TTS indonesian is not installed is there a tutorial where each time there is not supported language it will pop up to ask for install?
Upvotes: 2
Views: 4349
Reputation: 715
If you're using "id", "ID"
or Locale("id", "ID")
and not work you can try this code
Kotlin :
private fun askSpeechInput(){
if(!SpeechRecognizer.isRecognitionAvailable(this)){
Toast.makeText(this, "Speech recognition is not available", Toast.LENGTH_SHORT).show()
}else{
val i = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "id-ID")
i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Coba ucapkan sesuatu")
launchSomeActivity.launch(i)
}
}
This work for me
Upvotes: 0
Reputation: 73
set the language while initialising text to speech whenever you change the locale:
textToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
switch (status) {
case TextToSpeech.SUCCESS: {
synchronized (this) {
int result = textToSpeech.setLanguage(set the indonesia id here);
// Take action based on the result of initialisation
}
}
break;
default: {
Toast.makeText(appContext, appContext.getResources().getString(R.string.tts_init_failed), Toast.LENGTH_LONG).show();
}
break;
}
}
});
Upvotes: 0
Reputation: 49
MainActivity.tts.setLanguage(new Locale("id","ID"));
I used that and it works!
And apparently your phone must support Indonesian language. I tried on 2 different phones, one of them can't speak Indonesian
Upvotes: 3