mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-03 23:56:07 +02:00
Localize TTS
This commit is contained in:
@@ -3,25 +3,27 @@ package eu.faircode.email;
|
||||
import android.content.Context;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class TTSHelper {
|
||||
private static boolean initialized;
|
||||
private static TextToSpeech instance;
|
||||
|
||||
static void speak(Context context, final String utteranceId, final String text, final String language) {
|
||||
static void speak(
|
||||
@NonNull final Context context,
|
||||
@NonNull final String utteranceId,
|
||||
@NonNull final String text,
|
||||
@NonNull final Locale locale) {
|
||||
// https://developer.android.com/reference/android/speech/tts/TextToSpeech
|
||||
// https://android-developers.googleblog.com/2009/09/introduction-to-text-to-speech-in.html
|
||||
|
||||
final Runnable speak = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (language != null) {
|
||||
Locale loc = new Locale(language);
|
||||
if (instance.setLanguage(loc) < 0)
|
||||
EntityLog.log(context, "TTS unavailable language=" + loc);
|
||||
}
|
||||
|
||||
boolean available = (instance.setLanguage(locale) >= 0);
|
||||
EntityLog.log(context, "TTS queued language=" + locale + " available=" + available + " text=" + text);
|
||||
instance.speak(text, TextToSpeech.QUEUE_ADD, null, utteranceId);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user