Bug fixed in TTS

This commit is contained in:
jens 2023-02-06 14:24:46 +01:00
parent 6a7875cc61
commit a6c6dfc6ba
4 changed files with 42 additions and 14 deletions

View File

@ -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"
}

View File

@ -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)
{}
}
}
Miscellaneous.logEvent("i", "TextToSpeech", "Speaking " + text + " in language " + ttsEngine.getLanguage().toLanguageTag(), 3);
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", "TTS engine not available after waiting 30 seconds, yet. Aborting.", 3);
}
catch(Exception e)
{

View File

@ -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

View File

@ -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