readest/apps/readest-app/src-tauri
Huang Xin 8e2270aba4
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
Publish Docker image / build (linux/amd64, ubuntu-latest) (push) Waiting to run
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Publish Docker image / merge (push) Blocked by required conditions
Build with Nix / tests (push) Waiting to run
PR checks / koplugin_rust_lint (push) Waiting to run
PR checks / nix_flake_check (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / test_web_app (1) (push) Waiting to run
PR checks / test_web_app (2) (push) Waiting to run
PR checks / test_web_browser (push) Waiting to run
PR checks / test_extensions (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
feat(tts): preview voices and pick a default voice per language (#7322)
* feat(tts): preview voices and pick a default voice per language

Settings > TTS gets a Voice Library page, and the player's voice list
is rebuilt on the same component (VoiceList). Each row shows the
voice's gender, its language and region, and a play button.

- Opened from the library, the page lists every language that has
  voices, with a gender filter. Previews read a sample sentence in the
  voice's language (75 languages, gender-neutral wording).
- With a book open, only the book language's voices are listed, and
  previews read whole sentences from the start of the current page:
  at least 5 s of estimated speech, at most 400 characters.
- Choosing a voice in Settings makes it the default for that language
  only. Picking one in the player sets that language's default too, and
  TTSController switches to a language's engine when the reading
  language changes.
- In the player, a preview pauses reading. Picking the voice just
  heard resumes reading with it; leaving the list keeps it paused.
- Readest Voice previews need a signed-in reader; the other engines
  don't. /api/tts/readest/stream takes a `preview` lane: any signed-in
  plan, any offered voice, one segment of at most 400 characters, and a
  6,000-character daily floor for plans without Readest Voice. The
  voice service sees an ordinary listening window under its own client
  id, so its contract is unchanged.
- Gender comes from a generated map for Edge, from the voice id for
  Kokoro voices (Readest Voice and custom services), and from
  AVSpeechSynthesisVoice on iOS. Android and Web Speech report none, so
  those rows have no badge.
- The Voice Library lists Linux Speech Dispatcher voices (#7314) as it
  does Android and iOS system voices.

Tests that fail without the change (old file put back, new test run):
- tts-readest-stream-route.test.ts: 6 preview tests, e.g. "expected
  403 to be 200" and "expected { error: 'PLAN_REQUIRED' } to deeply
  equal { error: 'VOICE_TIER_REQUIRED' }".
- tts-controller-readest.test.ts: 4 tests on the per-language engine,
  e.g. "expected Mock{ name: 'edge-tts', ... } to be Mock{ name:
  'readest-tts', ... }".
- edgeTTS.test.ts: "expected undefined to be 'female'";
  readest-voice-catalog.test.ts: 2 gender tests.
- useTTSControl.test.tsx: "reads on with the new voice when asked to,
  though reading is stopped" fails with "expected vi.fn() to be called
  at least once".
- tts-voice-library.test.ts, Linux: "expected [] to deeply equal
  [ 'de' ]".

Checks on this tree, rebased on origin/main 6ab667bd2: pnpm test (15365
passed, 16 skipped), pnpm test:browser (934 passed, 1 skipped), pnpm
lint, pnpm format:check, pnpm fmt:check, pnpm clippy:check, pnpm
test:rust (206 passed).

Real use, macOS tauri dev build (before the rebase onto 6ab667bd2,
which changed only the native client and the library's platform list):
- Edge previews synthesized in about 2 s and played 7-12 s samples to
  the end. A macOS system voice spoke its sample. Starting a second
  preview stopped the first.
- In a German EPUB, the Voice Library listed only German voices and
  the preview read the page's heading and first sentence.
- Player: reading, then preview, then picking the voice resumed reading
  with it. Preview, then back, left reading paused until Play.
- Both screens in dark, light, e-ink, RTL and phone width.
- Found while testing: WebKit could not decode the 1-sample silent WAV
  that unlocks autoplay; previews now prime with a 0.1 s clip.

Not run:
- A Readest Voice preview end to end: a dev origin can't reach the
  production voice service, so the route tests cover the lane. Apps can
  preview Readest voices once the web server is deployed.
- iOS (the Swift change was only parsed), Android, and Linux previews.
- OmniVoice voices have no gender badge until the readest-voice catalog
  export adds a gender field.

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

* test(tts): page preview text from a section document without a root

CodeRabbit asked for a guard in textFromBlock for a section document
that a remount left without a root, where createTreeWalker(null) would
throw and leave the preview button loading. The reader's progress
range is a live Range (foliate builds it with doc.createRange()), so
removing the root collapses it onto the document. closestBlock() then
finds no block, getPagePreviewText() returns null before any tree
walker is made, and the preview reads the sample text instead.

The new test removes a page's root and checks that the range now sits
on the document and that the preview text is null. jsdom throws
"parameter 1 is not of type 'Node'" for createTreeWalker(null), so the
test fails if the walker is ever reached in that state.

Checks: tts-voice-preview-text.test.ts (7 passed); the pre-push hook
runs format:check, lint and the full suite on this commit.

Raised by CodeRabbit on #7322.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:37:48 +01:00
..
.cargo chore(linux): catch up the CEF runtime with upstream feat/cef, closes #6397 (#6487) 2026-09-30 04:07:58 +08:00
appimage fix(ci): bundle the audio libraries the CEF AppImage dlopens (#6108) 2026-09-07 12:12:02 +02:00
capabilities fix(windows): make Explorer thumbnails opt-in (#7220) 2026-11-01 17:55:42 +01:00
capabilities-extra perf(import+open): native Rust EPUB/MOBI parser, OPF prefetch, parallel TOC enrichment (#4369) 2026-06-10 16:58:25 +02:00
gen Import pasted text into the library (#6992) 2026-10-23 18:13:47 +02:00
icons feat(android): add monochrome themed launcher icon (#4733) (#4736) 2026-06-22 18:44:57 +02:00
nsis fix(windows): make Explorer thumbnails opt-in (#7220) 2026-11-01 17:55:42 +01:00
plugins feat(tts): preview voices and pick a default voice per language (#7322) 2026-11-04 13:37:48 +01:00
profiles feat(macos): enable icloud sync in direct-distribution builds (#5537) 2026-08-06 15:34:07 +02:00
src fix(auth): keep the sign-in callback URL out of logs (#7305) 2026-11-04 03:26:50 +01:00
.gitignore feat(linux): ship Readest on the tauri CEF runtime (#6074) 2026-09-05 20:09:06 +02:00
build.rs fix(windows): make Explorer thumbnails opt-in (#7220) 2026-11-01 17:55:42 +01:00
Cargo.toml fix(security): remediate Dependabot dependency alerts (#7248) 2026-11-02 11:50:57 +01:00
Info-ios.plist feat(ios): add CarPlay recent books and fix scene handoff (#6339) 2026-09-21 19:57:32 +02:00
Info.plist feat(library): add .rbooks collection bundle export and import (#6945) 2026-10-23 07:49:55 +02:00
tauri.conf.json feat(library): add .rbooks collection bundle export and import (#6945) 2026-10-23 07:49:55 +02:00
tauri.macos-nonestore.conf.json feat(macos): enable icloud sync in direct-distribution builds (#5537) 2026-08-06 15:34:07 +02:00
tauri.windows.conf.json fix(extensions): add missing tauri conf for windows build (#2563) 2025-11-28 05:56:45 +01:00