Skip to content

Commit

Permalink
Call done after tts error, enable http on localhost
Browse files Browse the repository at this point in the history
- call `done` after every `error` call in TTS engine
- enable local cleartext http traffic
  • Loading branch information
BentiGorlich committed Oct 2, 2023
1 parent ccf3374 commit 1185da1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Mimic3TTSEngineWrapper"
android:networkSecurityConfig="@xml/network_security_config"
tools:targetApi="31">
<activity
android:name=".activities.LogActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ private void synthesizeTextFromUrl(SharedPreferences preferences, int speechRate
_Logger.severe("Malformed server url: " + ex.getMessage());
ex.printStackTrace();
synthesisCallback.error();
synthesisCallback.done();
} catch (IOException ex) {
_Logger.severe("Connection error: " + ex.getMessage());
ex.printStackTrace();
Expand All @@ -499,6 +500,7 @@ private void synthesizeTextFromUrl(SharedPreferences preferences, int speechRate
in.close();
} catch (IOException ex2) {
synthesisCallback.error();
synthesisCallback.done();
_Logger.severe("Cache error loading default_no_connection: " + ex2.getMessage());
ex.printStackTrace();
for (StackTraceElement el : ex.getStackTrace()) {
Expand All @@ -507,10 +509,12 @@ private void synthesizeTextFromUrl(SharedPreferences preferences, int speechRate
}
} else {
synthesisCallback.error();
synthesisCallback.done();
_Logger.severe("default_no_connection was in cache, but file doesn't exist");
}
} else {
synthesisCallback.error();
synthesisCallback.done();
_Logger.severe("default_no_connection was not in cache");
}
}
Expand All @@ -522,15 +526,19 @@ private void synthesizeTextFromCache(boolean specialKeySet, String specialKey, S
try {
key = Mimic3TTSEngineWrapperApp.getSha256Hex(text);
} catch (NoSuchAlgorithmException e) {
_Logger.severe("sha256 is not supported, should never happen...");
synthesisCallback.error();
synthesisCallback.done();
return;
}
} else {
key = specialKey;
}
File cacheFile = new File(Mimic3TTSEngineWrapperApp.getStorageContext().getCacheDir(), key);
if(!cacheFile.exists())
if(!cacheFile.exists()) {
_Logger.severe("Should synthesize from cache, but there is no cache file...");
throw new FileNotFoundException(key);
}

_Logger.info("Synthesizing text with cache: " + text);
try {
Expand All @@ -550,6 +558,7 @@ private void synthesizeTextFromCache(boolean specialKeySet, String specialKey, S
_Logger.warning("at " + el.toString());
}
synthesisCallback.error();
synthesisCallback.done();
}
}

Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>

0 comments on commit 1185da1

Please sign in to comment.