Steady read-aloud highlight and a calmer default pace

The spoken word is now painted behind unchanged text instead of
restyling the paragraph, so words never reshape, shift or rewrap as the
highlight moves. Revealing the word measures its own boxes against the
visible area, so a reversed transcript no longer jumps for a word already
in view. Sentence breaks the reading adds no longer map onto the next
item's first letter. 1.0x now reads at 0.8 of the platform's normal rate.
This commit is contained in:
2026-11-13 09:41:02 +00:00
parent b2736683e7
commit df0614e2f7
7 changed files with 310 additions and 78 deletions
@@ -56,7 +56,7 @@ class FlutterTtsSpeechEngine extends SpeechEngine {
@override
Future<void> setRate(double rate) async =>
_tts.setSpeechRate(_appleScale ? (rate * 0.5).clamp(0, 1) : rate);
_tts.setSpeechRate(platformSpeechRate(rate, appleScale: _appleScale));
@override
Future<void> setVoice(SpeechVoice? voice) async {
@@ -110,3 +110,15 @@ class FlutterTtsSpeechEngine extends SpeechEngine {
];
}
}
/// The app's 1.0× reads at a calm listening pace, a little under the
/// platform's own normal rate, which sounds rushed for long replies.
const readAloudPace = 0.8;
/// The platform rate for the app's [rate] multiplier (1.0× = [readAloudPace]
/// of the platform's normal): AVSpeechSynthesizer's normal is 0.5 on a 0..1
/// scale, Android's TextToSpeech and the Web Speech API use 1.0.
double platformSpeechRate(double rate, {required bool appleScale}) {
final paced = rate * readAloudPace;
return appleScale ? (paced * 0.5).clamp(0, 1) : paced;
}