Limit TTS size

pull/216/head
M66B 1 month ago
parent 924994fe30
commit bf460e119e

@ -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();
}

@ -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();
}
}

Loading…
Cancel
Save