Read chat replies aloud with word highlighting

An assistant reply gets Read aloud beside Copy; while it reads it becomes
Pause/Resume and Stop, one reply at a time app-wide. The spoken word is
highlighted in the rendered reply (across multi-part replies) and the
transcript scrolls only when that word leaves the viewport. Reading stops
when its chat closes or is swapped, another reply starts, or the app goes
to the background. Markdown is spoken as sentences; code blocks are
announced as "Code block.".

Speech goes through a SpeechEngine seam with a flutter_tts implementation
(Android, macOS, web; hidden on Linux) and a fake for tests. Settings has
a Read aloud section: a voice picker grouped by language (device language
first, a sample per voice), a rate slider and reset, saved per device.

flutter_tts has no Swift package, so macOS/iOS gain the CocoaPods
integration (Podfiles with the Runner deployment targets); Android
declares the TTS_SERVICE query. The capture fixture gains ?speech=fake.
This commit is contained in:
2026-11-13 01:29:04 +00:00
parent 26e68140fd
commit 6367cce68a
40 changed files with 2643 additions and 29 deletions
+4
View File
@@ -33,6 +33,10 @@ URL parameters (the kit sets them from `open=` and the options):
or script's `params`) adds fixture
options such as `chats=2&rich=1`. Use `route=/settings` to open Settings and then
click `Server health`; the fixture channel returns `server_stats` automatically.
`speech=fake` (with `speechStep=<ms>`, default 600) reads replies aloud with a
scripted engine that reports one word per step, since headless Chrome has no
voices: Read aloud, Pause/Resume/Stop, the word highlight and the Settings
voice list can then be captured.
Without `theme`, the app follows the browser's colour
scheme. `--theme` also sets that colour scheme through Chrome emulation.
+92
View File
@@ -0,0 +1,92 @@
import 'dart:async';
import 'package:pipelines_app/features/chat/speech/speech.dart';
/// Opt-in (`?speech=fake`) scripted reader for captures: headless browsers
/// have no speech voices, so this engine "speaks" one word every
/// `?speechStep=` ms (default 600) and reports each as progress, which drives
/// the real controller, buttons, highlight and reveal scrolling.
void installSpeechFixture(Map<String, String> params) {
if (params['speech'] != 'fake') return;
final step = int.tryParse(params['speechStep'] ?? '') ?? 600;
debugSpeechController = SpeechController(
engine: _ScriptedSpeechEngine(Duration(milliseconds: step)),
);
}
class _ScriptedSpeechEngine extends SpeechEngine {
_ScriptedSpeechEngine(this.step);
final Duration step;
Timer? _timer;
String _text = '';
List<Match> _words = const [];
var _next = 0;
var _paused = false;
@override
bool get supported => true;
@override
Future<void> speak(String text) async {
if (_paused && text == _text) {
_paused = false;
onResume?.call();
_run();
return;
}
_text = text;
_words = RegExp(r'\S+').allMatches(text).toList();
_next = 0;
_paused = false;
Timer.run(() => onStart?.call());
_run();
}
void _run() {
_timer?.cancel();
_emit();
_timer = Timer.periodic(step, (_) => _emit());
}
void _emit() {
if (_next >= _words.length) {
_timer?.cancel();
onCompletion?.call();
return;
}
final word = _words[_next++];
onProgress?.call(_text, word.start, word.end);
}
@override
Future<void> pause() async {
_timer?.cancel();
_paused = true;
if (_next > 0) _next -= 1;
onPause?.call();
}
@override
Future<void> stop() async {
_timer?.cancel();
_paused = false;
onCancel?.call();
}
@override
Future<void> setRate(double rate) async {}
@override
Future<void> setVoice(SpeechVoice? voice) async {}
@override
Future<List<SpeechVoice>> voices() async => const [
SpeechVoice(name: 'Samantha', locale: 'en-US'),
SpeechVoice(name: 'Daniel', locale: 'en-GB'),
SpeechVoice(name: 'Karen', locale: 'en-AU'),
SpeechVoice(name: 'Thomas', locale: 'fr-FR'),
SpeechVoice(name: 'Anna', locale: 'de-DE'),
SpeechVoice(name: 'Kyoko', locale: 'ja-JP'),
];
}
@@ -47,6 +47,7 @@ import 'perf/perf_fixture.dart';
import 'probe_folder_fixture.dart';
import 'probe_files_fixture.dart';
import 'probe_usage_fixture.dart';
import 'probe_speech_fixture.dart';
/// The run every run-scoped hit names. Its recorded sequences are deliberately
/// not its row indexes (plan 5, build 2, plan 1), exactly like the unit
@@ -786,6 +787,8 @@ class _FixtureSink implements WebSocketSink {
/// `?terminal=float` opens them at launch (tool/perf/terminal_fixture.dart);
/// `?windows=N` opens N floating probe windows whose content opens every
/// kind of popup and a pushed page (tool/capture/window_probe.dart);
/// `?speech=fake` reads replies aloud with a scripted engine, one word per
/// `?speechStep=` ms (tool/probe_speech_fixture.dart);
/// `?theme=dark` / `?theme=light` pins the platform brightness the app's
/// `ThemeMode.system` follows (omitted: the browser's color scheme).
///
@@ -806,6 +809,7 @@ Future<void> main() async {
return;
}
configurePerfFixture(params);
installSpeechFixture(params);
if (params['files'] == '1') {
probeMissingRememberedFolder = params['filesMissing'] == '1';
installFilesFixture();