mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-23 22:53:43 +00:00
Fixes TTS engine reload
Signed-off-by: hemanggs <hemangmanhas@gmail.com>
This commit is contained in:
committed by
Konstantin Pastbin
parent
09096ac3a3
commit
335a474bb2
@@ -176,6 +176,11 @@ public class VoiceInstructionsSettingsFragment extends BaseXmlSettingsFragment
|
||||
return true;
|
||||
});
|
||||
|
||||
TtsPlayer.sOnReloadCallback = () -> {
|
||||
Toast.makeText(requireContext(), "TTS engine reloaded", Toast.LENGTH_SHORT).show();
|
||||
updateTts();
|
||||
};
|
||||
|
||||
initVolume();
|
||||
initTtsLangInfoLink();
|
||||
initSpeedCamerasPrefs();
|
||||
@@ -190,6 +195,13 @@ public class VoiceInstructionsSettingsFragment extends BaseXmlSettingsFragment
|
||||
updateTts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView()
|
||||
{
|
||||
TtsPlayer.sOnReloadCallback = null;
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
private void onInstallDataResult()
|
||||
{
|
||||
updateTts();
|
||||
|
||||
@@ -2,9 +2,11 @@ package app.organicmaps.sound;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
import android.speech.tts.UtteranceProgressListener;
|
||||
import android.text.TextUtils;
|
||||
@@ -45,8 +47,12 @@ public enum TtsPlayer
|
||||
private static final float SPEECH_RATE = 1.0f;
|
||||
private static final int TTS_SPEAK_DELAY_MILLIS = 50;
|
||||
|
||||
public static Runnable sOnReloadCallback = null;
|
||||
|
||||
private ContentObserver mTtsEngineObserver;
|
||||
private TextToSpeech mTts;
|
||||
private boolean mInitializing;
|
||||
private boolean mReloadTriggered = false;
|
||||
private AudioFocusManager mAudioFocusManager;
|
||||
|
||||
private final Bundle mParams = new Bundle();
|
||||
@@ -185,7 +191,32 @@ public enum TtsPlayer
|
||||
mAudioFocusManager = new AudioFocusManager(context);
|
||||
mParams.putFloat(TextToSpeech.Engine.KEY_PARAM_VOLUME, Config.TTS.getVolume());
|
||||
mInitializing = false;
|
||||
if (mReloadTriggered && sOnReloadCallback != null)
|
||||
{
|
||||
sOnReloadCallback.run();
|
||||
mReloadTriggered = false;
|
||||
}
|
||||
}));
|
||||
|
||||
if (mTtsEngineObserver == null) {
|
||||
mTtsEngineObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
Logger.d(TAG, "System TTS engine changed – reloading TTS engine");
|
||||
mReloadTriggered = true;
|
||||
if (mTts != null) {
|
||||
mTts.shutdown();
|
||||
mTts = null;
|
||||
}
|
||||
initialize(mContext);
|
||||
}
|
||||
};
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.Secure.getUriFor("tts_default_synth"),
|
||||
false,
|
||||
mTtsEngineObserver
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isReady()
|
||||
|
||||
Reference in New Issue
Block a user