Enhance postcard puzzles and narration

This commit is contained in:
Hadrian Burkhardt
2026-11-14 08:55:48 +01:00
parent abaab927d9
commit b19295472d
158 changed files with 5257 additions and 1695 deletions
+51 -4
View File
@@ -17,6 +17,12 @@ friends its HTTPS URL. The directory must contain `index.html`, `main.dart.js`,
`index.html` directly from the filesystem. No application backend, database,
Node.js server or Apple account is needed.
Do not serve the repository's `web/` directory with an IDE live server. Its
`flutter_bootstrap.js` is a Flutter build template, not executable output;
serving it directly produces `flutter_js is not defined`. Build the app first
and serve `build/web/`, or use `flutter run -d chrome`. Deploy all files from
the same build together and reload if an old bootstrap is cached.
The default build is for the root of a website, for example
`https://play.example.com/`. If you want a subdirectory such as
`https://example.com/lumen/`, rebuild with:
@@ -39,8 +45,33 @@ fallback page. Keep the directory
layout intact. Everything needed at runtime, including Flutter’s renderer,
fonts and recordings, is included; there is no dependency on a font/renderer CDN.
### Content Security Policy
The Flutter build compiles WebAssembly for its renderer. If the host sends a
Content Security Policy, its `script-src` must permit WebAssembly compilation;
in current browsers, `'wasm-unsafe-eval'` grants that permission without also
allowing JavaScript string evaluation through `eval()` or `new Function()`.
For example, this is a starting policy for the standalone, same-origin build:
```text
Content-Security-Policy: default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self'; media-src 'self' blob:; worker-src 'self' blob:
```
Configure the policy on the hosting server; this project does not set a CSP
itself. Adapt and test it for the actual host and embedding environment. Multiple
policies are enforced together, so adding a permissive policy in `index.html`
cannot override a stricter server header. Older browsers may not support
`'wasm-unsafe-eval'`; check the browsers you intend to support. Avoid adding the
broader `'unsafe-eval'` unless it is required and its security tradeoff is
acceptable.
If DevTools reports a warning from `contentscript.js`, inspect its full URL:
an extension URL (such as `chrome-extension://...`) identifies browser extension
code, not code in the game. Recheck in a clean browser profile with extensions
disabled before attributing an extension's deprecation or CSP warning to Lumen.
For updates, replace the whole build together. Serve `index.html`,
`flutter_bootstrap.js`, `flutter.js`, and `main.dart.js` with
`flutter_bootstrap.js`, `flutter.js`, `narration.js`, and `main.dart.js` with
`Cache-Control: no-cache`. Use revalidation for assets too unless you version
their URLs. This build does not install an offline service worker. Testers need
a connection to load new pages, pictures and recordings.
@@ -48,9 +79,11 @@ a connection to load new pages, pictures and recordings.
## Tell your testers
- Open the link in Safari on iPhone/iPad or Chrome on Android/computer.
- Choose a book from the shelf. Tap **Play this reading** on a narrated page to
hear the recorded voices if your browser blocks the automatic three-second
start. Pause, replay and speed controls remain available. Atmosphere depends on the browser permitting audio.
- Choose a book from the shelf. Your first tap prepares the narrator for the
automatic three-second start on story pages and postcards. Some browsers or
embedded WebViews may still require you to tap **Play this reading**. Pause,
replay and speed controls remain available. Atmosphere depends on the browser
permitting audio.
- Tap puzzle cells to cycle empty → light → crossed out. **Hint** offers a
confirmed, explained deduction without an advertisement.
- Bookmarks, puzzle marks, reading position and settings stay in that browser.
@@ -99,3 +132,17 @@ For the Astro-hosted game, pass its `/lumen/play/` URL instead. Override
`CHROME_DEBUG_URL` if the debugger uses another port. The test creates its own
fresh browser context and checks the actual playing media URL after Next,
Previous and rapid page turns, without touching existing tabs or saved games.
## Checking browser narration
`node scripts/test_web_narration.mjs` checks the audio bridge in headless
Chromium with autoplay blocked until a real user gesture. It requires a built
web bundle and uses the locally cached Chromium by default; set `CHROME_BIN` to
use another binary. For the full Flutter path, serve `build/web` on
`127.0.0.1:18765`, then run `node scripts/test_web_app_autoplay.mjs` and
`LUMEN_POSTCARD=1 node scripts/test_web_app_autoplay.mjs`, and
`LUMEN_MIDNIGHT=1 node scripts/test_web_app_autoplay.mjs`. These exercise the
lighthouse notebook and a leaf turn, a collected postcard in an isolated browser
profile, and the Midnight Invitation opening. Each checks that the correct
recording actually starts. These Chromium checks do not replace testing on iOS Safari or
an embedding app's WebView.
+6 -6
View File
@@ -11,7 +11,7 @@
- **Entry point:** `main()` in `lib/main.dart` → `StoryLibrary.load()` + `Progress.load()` → open selected story/language → `Game(...)` → `await game.restore()` → `game.showLibrary()` → `runApp(LumenApp(game: game))`. The shelf is the first window; `restore()` has already positioned each book's saved leaf so choosing a book resumes it. `Book.load()` remains an English Mara compatibility loader for existing tests/tools.
- **State:** one `Game extends ChangeNotifier` (`lib/domain/game.dart`) owns the current screen, puzzle session, marks, undo history and progress. `_NotebookState` listens to it and rebuilds the active screen.
- **Screens:** `Screen { library, home, story, contents, briefing, game, reveal }`, rendered by seven builder methods in `_NotebookState`.
- **Story content:** an offline catalogue in `assets/library.json`; Mara has twelve authored 7×7 pictures; Paper Boat demonstrates English/German packages; The Midnight Invitation is a complete English Halloween special (38 leaves, twelve puzzles, thirteen illustrations, 26 recorded passages). Daily and classic boards are generated 5×5 puzzles.
- **Story content:** an offline catalogue in `assets/library.json`; Mara has twelve authored 7×7 pictures; Paper Boat demonstrates English/German packages; The Midnight Invitation is a complete English Halloween special (38 leaves, twelve puzzles, thirteen illustrations, 26 recorded passages). Daily and classic boards are generated 7×7 puzzles.
- **Persistence:** local `SharedPreferencesAsync` behind `lib/services/progress.dart`; legacy Java saves are never imported.
- **Platform:** Android is the tested target; iOS scaffolding exists but is unvalidated. `legacy/` is archived Java 1.7 and is excluded from builds and analysis.
@@ -198,8 +198,8 @@ stateDiagram-v2
| `briefing(i)` | Clamp to `accessible`; cottage entry leaf or later `Screen.briefing` |
| `reveal(i, {readAhead})` | Redirect to `briefing(i)` unless recovered, or read-ahead is allowed for an accessible level; otherwise the cottage memory leaf or later `Screen.reveal` |
| `startCampaign(i)` | No-op if `i > accessible`; including recovered levels, load `book.levels[i]` under `story_v1_<i>` and open the cottage puzzle leaf or later `Screen.game` |
| `startDaily(day)` | Load `Puzzle.seeded(epochDay(date) * 7919)` under `d<YYYY-MM-DD>`; `Screen.game` |
| `startPractice([level])` | Generate 5×5 board off the UI isolate with `compute(generatePractice)`; key `v2_<DIFFICULTY>_<level>`; `Screen.game` |
| `startDaily(day)` | Load `Puzzle.generateSeven(epochDay(date) * 7919, Difficulty.medium)` under `d7_<YYYY-MM-DD>`; `Screen.game` |
| `startPractice([level])` | Generate a 7×7 board off the UI isolate with `compute(generatePractice)`; key `v3_<DIFFICULTY>_<level>`; `Screen.game` |
| `mark(i)` / `undo()` / `area(i)` | Cycle a cell 0→1→2→0, restore the previous snapshot, select an A/B/C area |
| `applyHint()` | Return one explained `Hint` and apply it (prefers detecting a conflicting earlier mark) |
| `check()` | Award completion exactly once; cottage solves advance to the matching memory record; later solves advance to the reveal; classic levels advance; daily updates the streak |
@@ -348,8 +348,8 @@ All writes go through `Progress.set` (memory is updated synchronously, disk is w
Board key formats (`<key>`):
- Campaign and the opening story puzzle: `story_v1_<0..11>` — story page 3 and the first campaign entry (index 0) share `story_v1_0` deliberately.
- Daily: `d<YYYY-MM-DD>` based on the local date.
- Classic: `v2_<DIFFICULTY>_<level>`, e.g. `v2_MEDIUM_7`.
- Daily: `d7_<YYYY-MM-DD>` based on the local date.
- Classic: `v3_<DIFFICULTY>_<level>`, e.g. `v3_MEDIUM_7`.
## Content and assets
@@ -499,7 +499,7 @@ Each run checks four discoveries in both orientations at 1.5× text, including n
- **Read-ahead never bypasses access.** `reveal(i, readAhead: true)` still redirects when `i > accessible`.
- **Streaks use UTC epoch days.** Do not compare local `DateTime` values directly; `visibleStreak` drops to zero when the last completion is older than yesterday.
- **`Puzzle.deductionRounds` throws** if a board cannot be solved by singles (plus area comparisons). Generation and tests assume no guessing.
- **Generated boards are 5×5 without regions.** Only authored campaign boards are 7×7 with A/B/C areas; don't run region logic against generated puzzles.
- **Generated boards are 7×7 without regions.** Authored campaign boards can have A/B/C areas. Legacy 5×5 save keys are retained but their marks are not mapped onto new grids.
- **Landscape side columns scroll.** With very large text, notes or hint/undo can need scrolling; never shrink text to force a fit (see the root `ROADMAP.md`: keep vertical scrolling as the accessibility fallback).
- **Gesture layering is deliberate.** `PageSwipeBlocker` wins horizontal drags inside boards/buttons while letting vertical drags scroll. Adding another horizontal recogniser around a board can break page turns or mark gestures.
- **Ads are optional by design.** `adsEnabled: false` in tests, `supported` guard in the service, and `between()` always routes even on no-fill.
+6 -8
View File
@@ -2,14 +2,12 @@
The November 2026 content update adds a reason to return to the bookshelf:
**Island postcards**, fourteen short outings with Mara after the lighthouse
story. Each outing has three fixed 5×5 patterns and an original written scene
story. Each outing has three fixed 7×7 patterns and an original written scene
that stays in the collection once all three patterns are solved. There are
42 distinct boards. All are uniquely solvable with the existing deduction
solver. Opening outings are gentle; later outings mix easy, medium and hard
practice-style reasoning. These grids are abstract patterns, not new picture
puzzles. The postcards are English text without recorded narration; existing
Qwen recordings remain with their original stories. Controls support English
and German.
solver. These 7×7 grids are abstract patterns, not new picture puzzles. The
postcards are English text with Qwen3-TTS Base recordings cloned from the
existing island narrator. Controls support English and German.
The shelf now offers today's puzzle and the postcard collection before the
books. Outings can be taken in any order, never expire, and have no energy,
@@ -95,9 +93,9 @@ production IDs.
- Content: `lib/domain/postcards.dart`; stable boards:
`lib/domain/postcard_patterns.dart`. Do not reorder or change existing boards
under the v1 save keys after release. `dart tool/author_postcard_puzzles.dart`
under the v2 save keys after release. `dart tool/author_postcard_puzzles.dart`
reproduces the initial board set; use new IDs for future content.
- Saved grids/completions use global `postcard_v1_<id>_<slot>` keys. Book saves
- Saved grids/completions use global `postcard_v2_<id>_<slot>` keys. Previously completed v1 puzzles remain counted, while unfinished 5×5 marks do not transfer to 7×7 grids. Book saves
keep their original namespaces. Collected means **all three** completed,
never a rounded total across different outings.
- `test/postcards_test.dart`: all 42 boards, saving/resuming, exactly-once
+102
View File
@@ -0,0 +1,102 @@
# The Midnight Invitation voice audition
The comparison starts at “At the door I knocked twice” and ends at “Hurry.”
It includes Elias and Iris, both warnings, and the reveal at the letter flap.
The existing Kokoro recording lasts about 50 seconds for this excerpt.
All outputs go to `artifacts/voice-audition/`. Production story assets and
manifests are not modified. Each engine gets a dry master, a loudness matched
master, and a mix with the same threshold ambience at 0.07 gain. New readings
retain the script's pauses, Foley and behind-door filter. Delivery duration is
allowed to vary; audio is not stretched to match the baseline.
## Generate
Preparation requires Python and `ffmpeg`:
```sh
python3 scripts/render_voice_audition.py prepare
```
Use separate Python 3.12 environments for Qwen and Chatterbox because their
Transformers requirements differ. Install a matching `torch` / `torchaudio`
pair first, using CPU wheels or ROCm wheels appropriate to the actual host.
Then install `qwen-tts==0.1.1 soundfile` in the Qwen environment and
`chatterbox-tts==0.1.7 soundfile` in the Chatterbox environment. Check that
installing the speech packages preserves your selected PyTorch build.
Run with the corresponding environment's Python:
```sh
python scripts/render_voice_audition.py qwen --device auto
python scripts/render_voice_audition.py chatterbox --device auto
```
`--device cpu` explicitly selects CPU; `--device cuda` requires GPU access.
PyTorch uses the `cuda` device name for AMD ROCm as well. Qwen uses FP32 on
CPU and FP16 on GPU, with eager attention rather than FlashAttention.
Qwen synthesis has been verified on the RX 6800 with these settings.
The first run downloads Hugging Face weights. Set `HF_HOME` to a writable
cache directory when needed. Successful raw takes are cached so interrupted
runs can resume. Use a fresh `--out` directory and run `prepare` there before
changing prompts, seed, model settings or devices for a new experiment.
## What differs
- **Kokoro:** the existing `bm_george` / `bf_emma` performances.
- **Qwen:** VoiceDesign creates an original reference for each character from
the cast direction. The Base model reuses those references across lines.
This preserves character identity better than designing every line afresh.
- **Chatterbox:** existing synthetic Kokoro references anchor both character
identities; exaggeration is 0.65 and CFG weight is 0.3. Chatterbox does not
receive Qwen's natural language performance directions.
This compares practical production workflows, not identical voice identities.
The Qwen Base model carries delivery through its audio reference; it does not
receive a fresh emotion instruction on each line. Model-generated speech may
contain mistakes even when the input text is exact. Listen for omitted or
invented words and voice drift before accepting any take.
## Listen
Compare the `*-dry-mix.wav` files at the same player volume. Use
`*-dry-matched.wav` to judge speech without ambience. Check:
- Does Elias sound like someone remembering an experience?
- Is Iris's warning clear and quietly urgent?
- Does each character keep the same voice across lines?
- Are all words present and pronounced correctly?
- Do pauses and the final “Hurry” feel natural?
Per-engine provenance JSON records package versions, device, seed, settings,
script hash, duration and cue times. Timings from CPU runs are not RX 6800
benchmarks.
## Container GPU diagnosis
The host exposes a Navi 21 GPU in PCI sysfs (`1002:73bf`). The restricted
command sandbox hides `/dev/kfd` and `/dev/dri`, so `rocminfo` fails inside
that sandbox. Outside the command sandbox, the devices are present and
`rocminfo` identifies the AMD Radeon RX 6800 with target `gfx1030`.
Run GPU synthesis outside that sandbox using a compatible ROCm PyTorch build.
The isolated environment at `artifacts/voice-audition/runtime/rocm` uses
`torch==2.14.0+rocm10.1.0`, `torchaudio==2.11.0.3+rocm10.1.0` and the
`device-gfx1030` packages from AMD's stable index. GPU detection and an FP16
matrix multiplication passed on the RX 6800. Install with:
```sh
uv venv --python 3.12 artifacts/voice-audition/runtime/rocm
uv pip install --python artifacts/voice-audition/runtime/rocm/bin/python \
'torch[device-gfx1030]' torchaudio \
--index-url https://stable.repo.amd.com/rocm/whl-next/
uv pip install --python artifacts/voice-audition/runtime/rocm/bin/python \
qwen-tts==0.1.1 soundfile
```
Keep large caches and environments on the workspace disk. In this container,
`/tmp` is a RAM-backed filesystem: storing the models and ROCm runtime there
caused memory pressure. The model cache now lives at
`artifacts/voice-audition/model-cache`, with `/tmp/lumen-audition-hf` pointing
to it for compatibility with the original commands.