Skip to content

Commit

Permalink
Optimization: use compiled regular expressions in normalization
Browse files Browse the repository at this point in the history
Do most regex matches via compiled regular expressions to stay reliably
under 100ms for the normalization phase (on a Pixel 6 phone)

Additionally: small optimizations and Logging level changes

Signed-off-by: Daniel Schnell <[email protected]>
  • Loading branch information
lumpidu committed Feb 3, 2024
1 parent 0c54f82 commit b7759d3
Show file tree
Hide file tree
Showing 8 changed files with 539 additions and 470 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/grammatek/simaromur/TTSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void onCreate(Bundle savedInstanceState) {
*/
@Override
public void onInit(final int status) {
Log.v(LOG_TAG, "onInit: status: " + status);
Log.i(LOG_TAG, "onInit: status: " + status);
if (status == TextToSpeech.SUCCESS) {
mTtsClient.setLanguage(new Locale("isl", "ISL"));
}
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/java/com/grammatek/simaromur/TTSService.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void onCreate() {
// This calls onIsLanguageAvailable() and must run after Initialization
super.onCreate();
applyCachePolicy();
Log.i(LOG_TAG, "onCreate() finished");
}

private void applyCachePolicy() {
Expand All @@ -65,23 +66,23 @@ private void applyCachePolicy() {
// mandatory
@Override
protected int onIsLanguageAvailable(String language, String country, String variant) {
Log.v(LOG_TAG, "onIsLanguageAvailable("+language+","+country+","+variant+")");
Log.i(LOG_TAG, "onIsLanguageAvailable("+language+","+country+","+variant+")");
if (variant.endsWith(ApiDbUtil.NET_VOICE_SUFFIX)) {
if (!ConnectionCheck.isTTSServiceReachable()) {
Log.v(LOG_TAG, "onIsLanguageAvailable: TTS API NOT reachable");
return TextToSpeech.LANG_MISSING_DATA;
}
}
int rv = mRepository.isLanguageAvailable(language, country, variant);
Log.v(LOG_TAG, "onIsLanguageAvailable("+language+","+country+","+variant+"): " + rv);
Log.i(LOG_TAG, "onIsLanguageAvailable("+language+","+country+","+variant+"): " + rv);
return rv;
}

// @todo: seems to be deprecated, but still it's mandatory to implement it ...
@Override
protected String[] onGetLanguage() {
// @todo: return currently set language as selected from the settings menu
Log.e(LOG_TAG, "onGetLanguage()");
Log.i(LOG_TAG, "onGetLanguage()");
return new String[] {"isl", "ISL", ""};
}

Expand Down Expand Up @@ -141,7 +142,7 @@ protected void onSynthesizeText(SynthesisRequest request,
} catch (Exception ex) {
ex.printStackTrace();
}
Log.v(LOG_TAG, "onSynthesizeText: " + text);
Log.i(LOG_TAG, "onSynthesizeText: " + text);
Log.v(LOG_TAG, "onSynthesizeText: (" + language + "/" + country + "/" + variant
+ "), callerUid: " + callerUid + " speed: " + speechrate + " pitch: " + pitch
+ " bundle: " + params);
Expand Down Expand Up @@ -181,9 +182,9 @@ protected void onSynthesizeText(SynthesisRequest request,
return;
}
if (text.isEmpty()) {
Log.i(LOG_TAG, "onSynthesizeText: End of TTS session");
playSilence(callback);
//playSilence(callback);
mShouldPlayNetworkError = true;
Log.i(LOG_TAG, "onSynthesizeText: End of TTS session");
return;
}
// if cache item for text already exists: retrieve it, otherwise create a new cache
Expand Down Expand Up @@ -228,7 +229,7 @@ protected void onSynthesizeText(SynthesisRequest request,
break;
}
handleProcessingResult(callback, item, ttsRequest, voice);
Log.v(LOG_TAG, "onSynthesizeText: finished (" + item.getUuid() + ")");
Log.i(LOG_TAG, "onSynthesizeText: finished (" + item.getUuid() + ")");
}

/**
Expand Down Expand Up @@ -475,6 +476,7 @@ private void playSilence(SynthesisCallback callback) {
if (! callback.hasFinished() && callback.hasStarted()) {
callback.done();
}
Log.v(LOG_TAG, "playSilence() finished");
}

@Override
Expand Down Expand Up @@ -518,8 +520,8 @@ public List<Voice> onGetVoices()
Voice ttsVoice = new Voice(voice.name, voice.getLocale(), quality, latency,
needsNetwork, features);
announcedVoiceList.add(ttsVoice);
Log.v(LOG_TAG, "onGetVoices: " + ttsVoice);
}
Log.i(LOG_TAG, "onGetVoices: " + announcedVoiceList);
return announcedVoiceList;
}

Expand All @@ -529,7 +531,7 @@ public int onIsValidVoiceName(String name)
Log.i(LOG_TAG, "onIsValidVoiceName("+name+")");
for (final com.grammatek.simaromur.db.Voice voice : mRepository.getCachedVoices()) {
if (voice.name.equals(name)) {
Log.v(LOG_TAG, "voice name is valid");
Log.i(LOG_TAG, "onIsValidVoiceName: successful");
return TextToSpeech.SUCCESS;
}
}
Expand All @@ -550,7 +552,7 @@ public int onLoadVoice(String name)
Log.i(LOG_TAG, "onLoadVoice("+name+")");
if (onIsValidVoiceName(name) == TextToSpeech.SUCCESS) {
if (TextToSpeech.SUCCESS == mRepository.loadVoice(name)) {
Log.v(LOG_TAG, "voice loading successful");
Log.i(LOG_TAG, "onLoadVoice successful");
return TextToSpeech.SUCCESS;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static Date fromTimestampString(String value) {
try {
return df.parse(value);
} catch (Exception e) {
e.printStackTrace();
// e.printStackTrace();
}
}
// return current date, in case no valid date string has been provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ public long[] convertToPhonemeIds(String ipaString) {

// add phoneme ids
for (String phoneme : phonemeList) {
if (phoneme.isEmpty()) {
continue;
}
addPhonemeIdToList(phoneme, phonemeIdList);
}
if (!space_removed && !token.matches(PunctuationSymbols)) {
Expand Down
Loading

0 comments on commit b7759d3

Please sign in to comment.