Reputation: 2713
In my android app I have a TTS using Google engine.
Have something like this:
tts=new TextToSpeech(MyClass.this, status -> {
if(status == TextToSpeech.SUCCESS){
tts.setLanguage(locale);
tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onDone(String utteranceId) {
if (utteranceId.equals("***")) {
runOnUiThread(() -> {
Button view2 = findViewById(R.id.speech);
view2.setCompoundDrawablesWithIntrinsicBounds(R.drawable.play, 0, 0, 0);
});
}
}
@Override
public void onError(String utteranceId) {
}
@Override
public void onStart(String utteranceId) {
}
});
}
});
Basically I am using 2 languages, slovak and english. Both are working fine with Google TTS.
The problem is, Samsung devices have their own TTS engine set by default and therefore the app text to speech works not on those devices.
After the users changes their device settings to use Google TTS, then it is working.
But is there a way, that my code will support both TTS engines?
I found out that there might work something like this:
TextToSpeech(Context context, TextToSpeech.OnInitListener listener, String engine)
e.g. using com.google.android.tts
as the engine parameter.
However in my code I have that like new TextToSpeech(MyClass.this, status -> {
... and it doesn't accept engine as a 3rd parameter, and still I don't know how to detect when Samsung engine is needed and switch engines accordingly.
Upvotes: 1
Views: 1281
Reputation: 19273
worth trying forcing TTS engine by passing this third param, so exchange very last line in posted snippet
});
to
}, "com.google.android.tts");
there are also two useful methods for you: getDefaultEngine()
and getEngines()
. just create at start some dummy new TextToSpeech
with two params (empty listener) and check what possibilites you have.
also getAvailableLanguages()
and isLanguageAvailable(Locale loc)
may be useful when Google engine isn't present, but default one still may support your desired langs
Upvotes: 3