1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-03-01 01:06:11 +00:00

Limit TTS size

This commit is contained in:
M66B 2024-08-30 08:08:51 +02:00
parent 924994fe30
commit bf460e119e
2 changed files with 13 additions and 4 deletions

View file

@ -3673,11 +3673,13 @@ public class FragmentMessages extends FragmentBase
String body = Helper.readText(message.getFile(context));
String text = HtmlHelper.getFullText(context, body);
String preview = HtmlHelper.getPreview(text);
if (!TextUtils.isEmpty(preview))
// Avoid: Not enough namespace quota ... for ...
text = HtmlHelper.truncate(text, TTSHelper.getMaxTextSize() / 3);
if (!TextUtils.isEmpty(text))
sb.append(context.getString(R.string.title_rule_tts_content))
.append(' ').append(preview);
.append(' ').append(text);
return sb.toString();
}

View file

@ -20,6 +20,7 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.os.OperationCanceledException;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
@ -61,7 +62,9 @@ public class TTSHelper {
" available=" + available +
" utterance=" + utteranceId +
" text=" + text);
instance.speak(text, flush ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD, null, utteranceId);
int error = instance.speak(text, flush ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD, null, utteranceId);
if (error != TextToSpeech.SUCCESS)
throw new OperationCanceledException("TTS error=" + error);
} catch (Throwable ex) {
Log.e(ex);
}
@ -126,4 +129,8 @@ public class TTSHelper {
speak.run();
}
}
static int getMaxTextSize() {
return TextToSpeech.getMaxSpeechInputLength();
}
}