Add directBoot support. Fixes #917

This commit is contained in:
Beqa Gozalishvili
2022-10-17 17:32:39 +04:00
parent 0ecdd33d18
commit f7f66429a3
10 changed files with 89 additions and 15 deletions
@@ -1,4 +1,5 @@
/*
* Copyright (C) 2022 Beka Gozalishvili
* Copyright (C) 2012-2015 Reece H. Dunn
* Copyright (C) 2011 Google Inc.
*
@@ -61,6 +62,7 @@ public class TtsService extends TextToSpeechService {
public static final String ESPEAK_INITIALIZED = "com.reecedunn.espeak.ESPEAK_INITIALIZED";
private static final String TAG = TtsService.class.getSimpleName();
private static Context storageContext;
private static final boolean DEBUG = false;
private SpeechSynthesis mEngine;
@@ -73,6 +75,8 @@ public class TtsService extends TextToSpeechService {
@Override
public void onCreate() {
storageContext = EspeakApp.getStorageContext();
storageContext.moveSharedPreferencesFrom(this, this.getPackageName() + "_preferences");
initializeTtsEngine();
super.onCreate();
}
@@ -94,7 +98,7 @@ public class TtsService extends TextToSpeechService {
mEngine = null;
}
mEngine = new SpeechSynthesis(this, mSynthCallback);
mEngine = new SpeechSynthesis(storageContext, mSynthCallback);
mAvailableVoices.clear();
for (Voice voice : mEngine.getAvailableVoices()) {
mAvailableVoices.put(voice.name, voice);
@@ -118,7 +122,7 @@ public class TtsService extends TextToSpeechService {
}
private Pair<Voice, Integer> findVoice(String language, String country, String variant) {
if (!CheckVoiceData.hasBaseResources(this) || CheckVoiceData.canUpgradeResources(this)) {
if (!CheckVoiceData.hasBaseResources(storageContext) || CheckVoiceData.canUpgradeResources(storageContext)) {
if (mOnLanguagesDownloaded == null) {
mOnLanguagesDownloaded = new BroadcastReceiver() {
@Override
@@ -131,7 +135,7 @@ public class TtsService extends TextToSpeechService {
registerReceiver(mOnLanguagesDownloaded, filter);
}
final Intent intent = new Intent(this, DownloadVoiceData.class);
final Intent intent = new Intent(storageContext, DownloadVoiceData.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
@@ -303,7 +307,7 @@ public class TtsService extends TextToSpeechService {
mCallback = callback;
mCallback.start(mEngine.getSampleRate(), mEngine.getAudioFormat(), mEngine.getChannelCount());
final VoiceSettings settings = new VoiceSettings(PreferenceManager.getDefaultSharedPreferences(this), mEngine);
final VoiceSettings settings = new VoiceSettings(PreferenceManager.getDefaultSharedPreferences(storageContext), mEngine);
mEngine.setVoice(mMatchingVoice, settings.getVoiceVariant());
mEngine.Rate.setValue(settings.getRate(), request.getSpeechRate());
mEngine.Pitch.setValue(settings.getPitch(), request.getPitch());