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:
@@ -63,6 +63,7 @@ import '../../../ui/layout/app_sheet_header.dart';
|
||||
import '../../../ui/layout/wheel_scroll_forwarding.dart';
|
||||
import 'chat_reading_width.dart';
|
||||
import '../ui/transcript/chat_copy_gutter.dart';
|
||||
import '../speech/speech.dart';
|
||||
import 'chat_pane_presentation.dart';
|
||||
import 'chat_thread_header.dart';
|
||||
import 'chat_transcript_anchor.dart';
|
||||
@@ -655,6 +656,12 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
@override
|
||||
void didUpdateWidget(covariant ChatThreadView oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.sessionId != widget.sessionId ||
|
||||
oldWidget.gateway != widget.gateway) {
|
||||
// A pane reused for another conversation stops reading the previous
|
||||
// one's reply, so neither its audio nor its highlight carries over.
|
||||
unawaited(speechController.stopScope(oldWidget.sessionId));
|
||||
}
|
||||
if (!identical(oldWidget.paneCommands, widget.paneCommands)) {
|
||||
oldWidget.paneCommands?.removeListener(_takeCommands);
|
||||
oldWidget.paneCommands?.setFinished(oldWidget.sessionId, false);
|
||||
@@ -751,6 +758,9 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// Leaving or closing the conversation stops its reply reading aloud; a
|
||||
// reply another pane is reading carries on.
|
||||
unawaited(speechController.stopScope(widget.sessionId));
|
||||
_persistPosition();
|
||||
_saveTranscript(widget.transcripts, widget.sessionId);
|
||||
widget.paneCommands?.removeListener(_takeCommands);
|
||||
@@ -1715,7 +1725,16 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
[delivery, onRemove != null, _images, _controller, _composer, _shellRuns],
|
||||
() => ChatMessageView(
|
||||
row: row,
|
||||
textBuilder: chatMarkdownText,
|
||||
speechScope: widget.sessionId,
|
||||
// The same reader id as the reply's Read aloud button, so the spoken
|
||||
// word is highlighted in this reply's text.
|
||||
textBuilder: (context, text) => ChatMarkdownView(
|
||||
text: text,
|
||||
messageId: speechMessageId(
|
||||
widget.sessionId,
|
||||
'${row['key'] ?? row['id'] ?? ''}',
|
||||
),
|
||||
),
|
||||
footer: [
|
||||
...chips,
|
||||
if (delivery != null)
|
||||
|
||||
Reference in New Issue
Block a user