[android] fix crash when no TTS engine

Signed-off-by: gekeleda <git@davidgekeler.eu>
This commit is contained in:
gekeleda
2025-12-09 22:19:16 +01:00
committed by x7z4w
parent 4a96d219f0
commit db888f33c5
3 changed files with 18 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ import android.os.Looper;
import android.provider.Settings;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import android.speech.tts.Voice;
import android.text.TextUtils;
import android.util.Pair;
import androidx.annotation.NonNull;
@@ -280,13 +281,16 @@ public enum TtsPlayer
public Locale getVoiceLocale()
{
return mTts.getVoice().getLocale();
if (INSTANCE.mTts == null)
return null;
Voice voice = INSTANCE.mTts.getVoice();
return voice != null ? voice.getLocale() : null;
}
public String getLanguageDisplayName()
{
Locale locale = getVoiceLocale();
return locale.getDisplayName(locale);
return locale != null ? locale.getDisplayName(locale) : null;
}
public void speak(String textToSpeak)