readest/apps/readest-app/docs
Huang Xin 50c4ae8258
feat(tts): read aloud with Speech Dispatcher voices on Linux (#7314)
* feat(tts): read aloud with Speech Dispatcher voices on Linux

Read Aloud on Linux can now use the voices installed in Speech
Dispatcher (eSpeak NG, or Piper through a module) under System TTS.
The native-tts plugin speaks SSIP over the daemon's Unix socket with
no speech library linked, so the AppImage uses the host daemon and the
Flatpak needs --filesystem=xdg-run/speech-dispatcher:ro
(docs/linux-system-tts.md). Each reader window gets its own
connection, closed when the window is destroyed. If the daemon or its
voices are unavailable, the other engines remain.

- Voices keep their Speech Dispatcher names; eSpeak NG's per-variant
  copies ("English (America)+Annie") are dropped, so English lists 9
  voices instead of 945. The module is appended only when two modules
  list voices.
- Pause stops the sentence and Play reads it again, as on Android. A
  speechd PAUSE holds back the restarted SPEAK, and RESUME then
  cancels it, so Play skipped the paused sentence.
- A closing window cancels its speech: speechd finishes a disconnected
  client's message.
- Events that arrive before the speak reply are kept, and an aborted
  utterance is canceled by ID so a late reply cannot stop its
  replacement. Rates go to speechd as given, without the mobile
  exponent.

Tests that fail without the change:
- Rust (plugin): pause_cancels_so_the_restarted_sentence_is_not_held_back
  (left "PAUSE SELF\r\n", right "CANCEL SELF\r\n");
  lists_each_espeak_voice_once_rather_than_once_per_variant (4 voices,
  expected 2); closing_a_reader_window_silences_its_speech (left "",
  right "CANCEL SELF\r\n").
- TS: 8 tests in native-tts-client.test.ts and tts-controller.test.ts
  fail against the old NativeTTSClient/TTSController, 7 on assertions
  (e.g. "expected [] to deeply equal [ 'boundary', 'end' ]",
  "expected null not to be null" for the Linux system voices) and one
  on its 5 s timeout (overlapping speak replies).

Real use, Linux CEF dev build, isolated HOME, host speech-dispatcher
0.12.1 with its eSpeak NG module:
- Pause/Play 3 of 3 re-read the paused sentence with no "Speech
  interrupted"; before the fix 3 of 3 skipped it.
- Speak on a selection while paused speaks (before: silent).
- Picker lists 9 System TTS voices; choosing another voice and pressing
  Play reads on in that voice.
- Speed: 2.7 s per sentence at 1.5x, 5.2 s at 0.95x.
- Closing the book at +1.4 s into a sentence: speech ends 1 s later;
  without the cancel it ran 3.6 s to the sentence's end.
- SPEECHD_ADDRESS at a missing socket: "System TTS unavailable" is
  logged and Read Aloud falls back to Edge TTS.

Checks: plugin cargo test (36 passed), pnpm test:rust (204 passed),
the two TS suites (171 passed), pnpm lint, pnpm fmt:check, pnpm
clippy:check, cargo check of the plugin for x86_64-pc-windows-gnu and
aarch64-linux-android.

Not run: the AppImage and Flatpak packages, two reader windows reading
at once, light/dark/e-ink (no UI changed). Chinese books get no System
TTS voice: eSpeak NG labels them cmn/yue and language matching expects
zh.

Closes #6805

Reported by ell1e on GitHub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(tts): keep a slow Speech Dispatcher voice list from disabling System TTS

Every command waited at most 3 s, and a timeout closes the connection
because a late reply would answer the next command. eSpeak NG sends
about 15k voice rows for LIST SYNTHESIS_VOICES: 0.4 s here, warm or
cold, so a slow machine or module could run past 3 s. voices() then
took the dead connection for a module without voices and failed with
"Speech Dispatcher has no installed voices".

The voice list now gets 10 s, under the reader's 15 s engine init
limit. A lost connection ends the listing with its cause ("Speech
Dispatcher did not answer in time while listing piper voices"); a
module that answers with an error is still skipped.

Raised by CodeRabbit on #7314.

Tests that fail without the change:
- waits_for_a_slow_voice_list: the reply comes 3.5 s after the request;
  fails at "a voice list slower than one command must still arrive".
- a_lost_connection_while_listing_voices_reports_the_cause: left
  Some("Speech Dispatcher has no installed voices"), right
  Some("Speech Dispatcher disconnected while listing espeak-ng voices").

Checks: plugin cargo test --lib (38 passed), pnpm test:rust (204
passed), pnpm fmt:check, pnpm clippy:check, cargo fmt --check in the
plugin. Real daemon (speech-dispatcher 0.12.1, eSpeak NG): init()
lists 141 voices in 0.43 s.

Not run: a real slow module (the delay is simulated in the test), and
the Tauri app after this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(tts): give every reader speed its own Speech Dispatcher rate

The reader offers 0.5x to 3x (the speed ruler and RSVP's rate list),
but the Linux bridge sent (rate - 1) * 100 clamped to SSIP's -100..100,
so 2x, 2.5x and 3x all became 100 and sounded the same, and 0.5x only
reached -50. 0.5x-1x now spreads over -100..0 and 1x-3x over 0..100.

Raised by CodeRabbit on #7314.

Test that fails without the change:
every_reader_speed_has_its_own_ssip_rate, left
[-50, -25, 0, 50, 100, 100, 100], right [-100, -50, 0, 25, 50, 75, 100]
for 0.5, 0.75, 1, 1.5, 2, 2.5, 3.

Real daemon (speech-dispatcher 0.12.1, eSpeak NG), one sentence spoken
through SpeechDispatcher at each speed, begin to end: 0.5x 12.17 s,
1x 5.57 s, 1.5x 3.91 s, 2x 2.97 s, 2.5x 2.29 s, 3x 1.82 s (0.46x,
1.42x, 1.88x, 2.44x, 3.05x of 1x).

Checks: plugin cargo test --lib (39 passed), pnpm test:rust (204
passed), pnpm fmt:check, pnpm clippy:check, cargo fmt --check in the
plugin.

Not run: the speed ruler in the Tauri app after this change; the
mapping from the ruler to set_rate is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 10:38:54 +01:00
..
superpowers refactor(wordlens): rename "Word Wise" to "Word Lens" (#4633) 2026-06-17 19:09:29 +02:00
architecture.md fix(build): repair the Docker and Nix builds after #6368 (#6379) 2026-09-23 15:13:35 +02:00
book-config.md feat(reader): pair local audiobooks with ebooks (#5754) 2026-08-17 08:46:00 +02:00
bookshelves.md fix(library): improve e-ink pagination and bookshelf sync (#6330) 2026-09-21 10:44:19 +02:00
code-layout.md feat(dictionaries): add bundled plugin and Yomitan support (#5764) 2026-08-18 13:43:58 +02:00
contributors.md chore(agent): maintenance loops with a Reply Desk, lessons and acceptance rules (#6796) 2026-10-14 16:00:36 +02:00
google-play-all-files-access.md fix(android): keep All Files Access on the Play build (#5372) (#2862) (#5378) 2026-07-28 16:59:48 +02:00
i18n.md feat(i18n): add Uzbek and Brazilian Portuguese translations (#4061) 2026-05-05 09:20:44 +02:00
linux-system-tts.md feat(tts): read aloud with Speech Dispatcher voices on Linux (#7314) 2026-11-04 10:38:54 +01:00
page-curl.md fix(android): keep the page-turn cover below the keyboard, closes #7171 (#7191) 2026-10-31 20:01:26 +01:00
read-along-narration.md fix(tts): play local AAC narration natively on Linux (#7240) 2026-11-02 08:54:20 +01:00
safe-area-insets.md feat(ios): book mode on iPhone Duo's inner display (#7137) 2026-10-31 01:31:12 +08:00
sentry-symbolication.md feat(sentry): upload browser source maps for symbolicated JS crashes (#5027) 2026-07-09 09:18:48 +02:00
stats-archive.md fix(stats): survive PostgREST's row cap when building archive segments (#5844) 2026-08-24 15:07:01 +02:00
testing.md test: use four workers for unit tests (#7242) 2026-11-02 08:27:07 +01:00
view-settings.md refactor: rename ColorPanel to ThemePanel (#5042) 2026-07-11 12:48:13 +09:00