diff --git a/app/build.gradle b/app/build.gradle index 7d8a87db..210cd168 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { compileSdkVersion 31 buildToolsVersion '29.0.2' useLibrary 'org.apache.http.legacy' - versionCode 125 - versionName "1.7.10" + versionCode 126 + versionName "1.7.11" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/jens/automation2/AutomationService.java b/app/src/main/java/com/jens/automation2/AutomationService.java index 5d754dfb..0119b5f7 100644 --- a/app/src/main/java/com/jens/automation2/AutomationService.java +++ b/app/src/main/java/com/jens/automation2/AutomationService.java @@ -34,6 +34,7 @@ import com.jens.automation2.receivers.PhoneStatusListener; import java.util.Calendar; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -41,6 +42,7 @@ import java.util.Set; public class AutomationService extends Service implements OnInitListener { protected TextToSpeech ttsEngine = null; + protected int ttsStatus = -1; protected final static int notificationId = 1000; protected final static int notificationIdRestrictions = 1005; protected final static int notificationIdLocationRestriction = 1006; @@ -97,6 +99,11 @@ public class AutomationService extends Service implements OnInitListener this.lockSoundChangesEnd = lockSoundChangesEnd; } + public int getTtsStatus() + { + return ttsStatus; + } + protected final IBinder myBinder = new LocalBinder(); protected LocationProvider myLocationProvider; @@ -317,8 +324,26 @@ public class AutomationService extends Service implements OnInitListener if (Settings.useTextToSpeechOnNormal || Settings.useTextToSpeechOnSilent || Settings.useTextToSpeechOnVibrate || Rule.isAnyRuleUsing(Action.Action_Enum.speakText)) { if (ttsEngine == null) - ttsEngine = new TextToSpeech(this, this); - } else + { + ttsEngine = new TextToSpeech(this, new TextToSpeech.OnInitListener() + { + @Override + public void onInit(int status) + { + ttsStatus = status; + + if (status == TextToSpeech.SUCCESS) + { + ttsEngine.setLanguage(Locale.getDefault()); + Miscellaneous.logEvent("i", "TTS engine", "TTS engine available.", 3); + } + else + Miscellaneous.logEvent("i", "TTS engine", "TTS engine not available. Status: " + String.valueOf(status), 3); + } + }); + } + } + else { if (ttsEngine != null) ttsEngine.shutdown(); @@ -673,25 +698,26 @@ public class AutomationService extends Service implements OnInitListener { try { - for(int i = 0; i < 5; i++) + for(int i = 0; i < 60; i++) { - if(ttsEngine != null) - { - break; - } - else + if(ttsEngine == null || ttsStatus != TextToSpeech.SUCCESS) { try { Miscellaneous.logEvent("i", "TTS", "Waiting for a moment to give the TTS service time to load...", 4); - Thread.sleep(1000); // give the tts engine time to load + Thread.sleep(500); // give the tts engine time to load } catch(Exception e) {} } + else + { + Miscellaneous.logEvent("i", "TextToSpeech", "Speaking \"" + text + "\" in language " + ttsEngine.getLanguage().toLanguageTag(), 3); + this.ttsEngine.speak(text, TextToSpeech.QUEUE_ADD, null); + break; + } } - Miscellaneous.logEvent("i", "TextToSpeech", "Speaking " + text + " in language " + ttsEngine.getLanguage().toLanguageTag(), 3); - this.ttsEngine.speak(text, TextToSpeech.QUEUE_ADD, null); + Miscellaneous.logEvent("i", "TextToSpeech", "TTS engine not available after waiting 30 seconds, yet. Aborting.", 3); } catch(Exception e) { diff --git a/fastlane/metadata/android/en-US/changelogs/125.txt b/fastlane/metadata/android/en-US/changelogs/125.txt index f1ddad82..19539b88 100644 --- a/fastlane/metadata/android/en-US/changelogs/125.txt +++ b/fastlane/metadata/android/en-US/changelogs/125.txt @@ -1,4 +1,4 @@ * Fixed: Now allowing negative integers as intent data -* Fixed: Multiple time frames with reoccurence configured would trigger to early executions +* Fixed: Multiple time frames with reoccurrence configured would trigger to early executions * Fixed: Automatic app start at boot might fail in some cases * Translations updated \ No newline at end of file diff --git a/fastlane/metadata/android/en-US/changelogs/126.txt b/fastlane/metadata/android/en-US/changelogs/126.txt new file mode 100644 index 00000000..603c9da9 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/126.txt @@ -0,0 +1,2 @@ +* Fixed: TTS engine wouldn't always speak, especially at the startup of the app +* Added: Possibility to disable toasts for e.g. announcing rule activations \ No newline at end of file