[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

@@ -1818,9 +1818,17 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (Config.isTtsMessageDelivered())
return;
String languageDisplayName = TtsPlayer.INSTANCE.getLanguageDisplayName();
if (languageDisplayName != null)
{
String navigationStartMessage = getResources().getString(R.string.navigation_start_tts_message);
navigationStartMessage += TtsPlayer.INSTANCE.getLanguageDisplayName();
navigationStartMessage += languageDisplayName;
Toast.makeText(this, navigationStartMessage, Toast.LENGTH_LONG).show();
}
else
Toast.makeText(this, getResources().getString(R.string.navigation_start_tts_disabled_message), Toast.LENGTH_LONG)
.show();
Config.setTtsMessageDelivered();
}

View File

@@ -934,6 +934,7 @@
<string name="delete_track_dialog_title">Delete %s?</string>
<string name="pref_tts_no_system_tts_short">No text-to-speech engine found, check the app settings</string>
<string name="navigation_start_tts_message">"Starting Navigation, voice instruction language: "</string>
<string name="navigation_start_tts_disabled_message">"Voice instructions disabled: TTS engine not available"</string>
<string name="unknown_power_output">unknown</string>
<string name="charge_socket_type2">Type 2 (no cable)</string>
<string name="charge_socket_type2_cable">Type 2 (w/ cable)</string>

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)