An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
feat(skill): lint and export follow findWords; export --lufs; tools say what they skip
yzrfc7f8b7d9db5
diff --git a/.claude/skills/papermorph/references/core/publish.md b/.claude/skills/papermorph/references/core/publish.mdindex 1fc1cff..ef3fd35 100644--- a/.claude/skills/papermorph/references/core/publish.md+++ b/.claude/skills/papermorph/references/core/publish.md@@ -42,7 +42,10 @@ uv run --with playwright --with numpy SKILL/scripts/export.py chNN --url http://It renders the beats to `OUT/chNN.mp4` (1080p, or 1080 × 1920 on the upright stage; 30 fps) plus `OUT/chNN.srt` to upload with it. Frames come from seeking the beat clock and the sound is mixed by the page's own rules (each beat's `pre`, effects and music), so the video matches the page.-- A lesson's question beats are left out and its video ends on a card pointing to the interactive lesson. In a film with `CHAPTER.film` they stay: each holds its picture for the beat's `hold` s with the music up at 70 %, as the page plays it while waiting, then the next beat plays as if the reader had acted ([documentary.md](../films/documentary.md#interactive-moments)). A picture book's point-and-read beat (`tapWords`, [picture-books/stories.md](../picture-books/stories.md#point-and-read)) holds instead while it shows each word beside its thing and says it, one every two seconds, with the music ducked under each word, plus a second at the end (a `hold` set on the beat still wins); a word whose clip is missing is named in the run's output and left silent.-- A mix that would clip is turned down as a whole, and the run says by how much; odd sizes are cut to even ones (an upright `--height 720` gives 404 × 720). The video is written beside the old one and renamed when done, so a failed run leaves an earlier `chNN.mp4` alone.+- A lesson's question beats are left out and its video ends on a card pointing to the interactive lesson. In a film with `CHAPTER.film` they stay: each holds its picture for the beat's `hold` s with the music up at 70 %, as the page plays it while waiting, then the next beat plays as if the reader had acted ([documentary.md](../films/documentary.md#interactive-moments)).+- **`video`** in a beat's fourth slot is read only by `export.py`. `video: false` leaves the beat out; `video: S` ends it S s into its clock, its sound and captions cut there, with no wait. A game that only works on the page goes out this way: *The Little Horse* leaves its river stop out (`video: false`) and keeps the first line of its mill stop, "brought the wheat to the mill.", with `video: PRE8 + 3.6`. The run names the beats it left out, and a film that skips beats gets no "the questions are in the interactive lesson" card.+- **Loudness.** The sound is levelled to `--lufs` integrated (default −16, which video sites and phones play without turning it up much; YouTube plays louder uploads at −14) with its true peak under −1.5 dBTP, by a gain and a limiter as `level.py` levels a clip. The run prints the mix's loudness as the page plays it, after levelling, and of the finished MP4: *The Little Horse*'s first scene measures −19.9 LUFS as mixed and −16.1 LUFS, −1.7 dBTP in the MP4. `--lufs off` keeps the page's mix, turned down as a whole only if it would clip.+- The mix is read from the engine's own lists (`sfx()`, `music()`, `window.MUSIC_OFF`). A page with a sound player of its own (an older book's `const SFX`, `BGM` or `function sfx`) hides that sound from the engine; the run names each such global and says its sound is not in the video.+- `--to BEAT` stops after that beat, for a quick look at the opening scenes (the beats before it stay in, so the music stands where the film has it). Odd sizes are cut to even ones (an upright `--height 720` gives 404 × 720). The video is written beside the old one and renamed when done, so a failed run leaves an earlier `chNN.mp4` alone.- Frames are shot by `--jobs` browsers at once (default half the CPU threads, at most 8) on the GPU where there is one, and encoded on the first hardware H.264 encoder that works, else libx264; the run prints which. The video is limited-range BT.709 H.264, tagged so (the frames are full-range JPEGs; a full-range MP4 played too bright in browsers, its paper ground off the page's), so a still from it matches the page. An 82 s upright short took 45 s on a 20-thread PC with an NVIDIA card, 1 min 22 s there with no GPU and libx264, and 3 min with one browser; `--height 720 --fps 10` makes a quick check copy.- Video files are large (tens of megabytes for a 1080p episode, more than a static host such as Cloudflare Pages takes per file): upload them to the video site, not into `site/`.diff --git a/.claude/skills/papermorph/references/core/review.md b/.claude/skills/papermorph/references/core/review.mdindex 0a6d954..f908fe8 100644--- a/.claude/skills/papermorph/references/core/review.md+++ b/.claude/skills/papermorph/references/core/review.md@@ -25,8 +25,8 @@ uv run --with playwright --with pillow SKILL/scripts/playlog.py chNN --out OUT -- A strip shows one beat at small steps; a sheet of strips is the contact sheet every review works from. `@w` adds a motion WebP; `@o` adds an onion skin, the frames laid over each other with later ones stronger, so spacing reads at a glance: even gaps are even speed, bunched ghosts are easing, a ghost that jumps is a pop. An onion skin reads only within one shot, so give it that shot's range (`roll:2..4`, ends may be marks); `@c` draws a picture book's frames in the set's own framing, so under a pan a planted foot stays one sharp ghost and a sliding one smears.- Look at each action as a viewer would: does the picture do what the narration says while it is said, does the thing named appear, do props stay in hands, does the camera move with purpose, do labels and numbers agree with the motion? The worst defects in the first films were pictures that contradicted the narration, and they show on a contact sheet at once.- Watch every beat to its end; problems hide in the beats nobody looked at.-- A strip cannot show that nothing moves: a wave drawn once at a fixed phase looks right in every frame and is dead on screen. `uv run --with playwright --with pillow SKILL/scripts/still.py chNN --url …` lists the stretches of each beat where the stage does not change (in a picture book it first switches off the kit's hand jitter and flicker, so a puppet that only breathes and blinks measures about 1–1.5 and acting 2 and up; the default threshold is 1.5). Some holds are right (a moment to read a result); something that stands for motion should move whenever it is on screen.-- Then watch a few beats live in Firefox with sound, as the user does. An agent that cannot listen runs `playlog.py`: it logs when each sound and caption starts in real playback and shows the stage rebuilt at that moment, so a clack can be checked against the piece landing and a line against the mouth that says it. `--from`/`--to` play only some beats; a lesson stops at its first question.+- A strip cannot show that nothing moves: a wave drawn once at a fixed phase looks right in every frame and is dead on screen. `uv run --with playwright --with pillow SKILL/scripts/still.py chNN --url …` lists the stretches of each beat where the stage does not change (in a picture book it first switches off the kit's hand jitter and flicker, so a puppet that only breathes and blinks measures about 1–1.5 and acting 2 and up; the default threshold is 1.5). Some holds are right (a moment to read a result); something that stands for motion should move whenever it is on screen. A film's ask beat (a listen-and-find stop) is measured up to where the page starts waiting; a lesson's question beats are skipped, and the run names them.+- Then watch a few beats live in Firefox with sound, as the user does. An agent that cannot listen runs `playlog.py`: it logs when each sound and caption starts in real playback, and when each `music()` track comes in or goes out (a `MUSIC_OFF` moment is marked), and shows the stage rebuilt at that moment, so a clack can be checked against the piece landing, a line against the mouth that says it and a music cut against its picture. `--from`/`--to` play only some beats; a lesson stops at its first question.## Framesdiff --git a/.claude/skills/papermorph/scripts/export.py b/.claude/skills/papermorph/scripts/export.pyindex a439d86..781f5db 100644--- a/.claude/skills/papermorph/scripts/export.py+++ b/.claude/skills/papermorph/scripts/export.py@@ -3,20 +3,28 @@uv run --with playwright --with numpy export.py ch12 --url http://localhost:8765/<book>/ --out OUT... --fps 30 --height 1080 --link https://example.org/<book>/ch12/+ ... --lufs -14 (the sound's loudness; default -16, off: as mixed) --to scene1 (stop after that beat)The engine draws every frame as a pure function of the beat time, so frames are rendered by seeking, not byrecording playback: the video is exact and the same on every run. The sound is mixed the way the page plays it:each beat's clip from its `pre` on, and in a film (a picture book or a documentary) the sfx() effects (cut at the end-of their scene, as a scene change stops them) and the BGM tracks with their crossfades, ducking and MUSIC_OFF. Question beats (quick+of their scene, as a scene change stops them; a bed, { loop: true }, laid again and again to its `to` or the beat's end) and the BGM tracks with their crossfades, ducking and MUSIC_OFF. Question beats (quickchecks and practice) are left out, and then the video ends on a card saying they are in the interactive lesson(--link adds its address); in a film with interactive moments (CHAPTER.film, e.g. the reader fires a rifle) they stay in,-each holding its last picture for its `hold` seconds (1.5 by default, the music up at 70 % as the page plays it while-it waits) before the next beat plays as if the reader had acted. A beat with `video: false` in its fourth slot is left+each holding its picture for its `hold` seconds (1.5 by default; the scene's breathing and blinking go on and its beds+play, the music up at 70 %, as the page plays it while it waits) before the next beat plays as if the reader had acted. A beat with `video: false` in its fourth slot is leftout, and `video: S` ends it S seconds into its clock, sound and captions cut there, with no wait: a game that only-works on the page (a listen-and-find stop) stays out of the video. A point-and-read beat (tapWords) holds while it shows-and says each word in turn, 2 s apart (its `hold`, if set, still wins); a word clip that is missing is named and-left silent. With --link and no question beats left out, the end-card shows the title and the link only. A mix that would clip is turned down as a whole (the run prints by how much).+works on the page (a listen-and-find stop, findWords) stays out of the video. With --link and no question beats left+out, the end card shows the title and the link only.++Loudness: the mix is levelled to --lufs integrated (default -16, a level video sites and phones play without turning+it up much; YouTube plays louder ones at -14) with its true peak under -1.5 dBTP, by a gain and a limiter as level.py+levels a clip; the run prints the loudness before and after, and of the finished MP4. --lufs off keeps the mix as the+page plays it (a picture book's comes out near -19), turned down as a whole only if it would clip.++The sound comes from the engine's own lists (sfx(), music(), MUSIC_OFF and MUSIC_UP_IN_PRE as window properties). A+page that declares its own SFX, BGM, sfx(), music() or MUSIC_OFF (an older book's sound player) hides them from the+engine: the run names each such global and says that sound is not in the video.Odd sizes (an upright --height 720 is 405 wide) are cut to even ones, as H.264 needs. The video is written toOUT/chNN.tmp.mp4 and renamed when done, so a failed run leaves an earlier OUT/chNN.mp4 alone. Captions are not burnedin: upload OUT/chNN.srt with the video. Needs ffmpeg; serve the site over HTTP first.@@ -34,8 +42,11 @@ import numpy as npfrom pathlib import Pathfrom playwright.async_api import async_playwrightfrom browsers import exe+import level as lvEND_SECONDS = 4+PEAK = -1.5 # true-peak ceiling of a levelled mix, dBTP+BED_OVERLAP = .5 # as the engine's: a looping bed's next lay starts this long before the last one endsFLAT = '#frame { border-radius: 0 !important; box-shadow: none !important; }' # square corners in the videoEND_CARD = """([link, asks]) => {@@ -89,7 +100,20 @@ def srt_time(t):return f'{ms // 3600000:02d}:{ms // 60000 % 60:02d}:{ms // 1000 % 60:02d},{ms % 1000:03d}'-SFX_JS = "typeof SFX === 'undefined' ? [] : SFX.map(e => ({...e, src: new URL(`audio/sfx/${e.name}.mp3`, location.href).href}))"+SFX_JS = "SND.sfx.map(e => ({...e, src: new URL(`audio/sfx/${e.name}.mp3`, location.href).href}))"++# A page's own sound globals (an older book's player, or a const the engine cannot see): each hides its sound from the+# engine's lists, which are what the video mixes. Indirect eval reads a page's const/let as the page's code does.+CLASH_JS = """(() => {+ const own = n => { try { return (0, eval)(n); } catch { return undefined; } }, out = [];+ for (const [n, v] of [['SFX', SND.sfx], ['SFX_BED', SND.bed], ['BGM', SND.bgm]])+ if (own(n) !== undefined && own(n) !== v) out.push(`${n} (the page's own, not the engine's sfx()/music() list)`);+ for (const [n, k] of [['sfx', 'SND.sfx'], ['music', 'SND.bgm']])+ if (typeof own(n) === 'function' && !String(own(n)).includes(k)) out.push(`${n}() (the page's own, replacing the engine's)`);+ for (const n of ['MUSIC_OFF', 'MUSIC_UP_IN_PRE'])+ if (own(n) !== undefined && own(n) !== window[n]) out.push(`${n} (a const or let: the engine reads window.${n})`);+ return out;+})()"""QUERY = '' # extra page query (--query), e.g. 'tags&'@@ -123,16 +147,25 @@ async def main(a):await pg.goto(base + f'?{QUERY}beat=0&t=0'); await pg.wait_for_timeout(500)if errs:sys.exit(f'page errors: {errs}')+ if clash := await pg.evaluate(CLASH_JS):+ print('warning: the page declares sound globals of its own, which the engine does not play and the video leaves out:\n '+ + '\n '.join(clash) + '\n move that sound to the engine\'s sfx() and music(), or set window.MUSIC_OFF', flush=True)info = await pg.evaluate("""({lang: CHAPTER.language || 'en', film: !!CHAPTER.film,beats: BEATS.map(b => ({id: b.id, ask: !!b.ask, pre: b.pre || 0, hold: b.hold ?? null, video: b.video ?? null})),- bgm: typeof BGM === 'undefined' ? [] : BGM.map(m => ({src: m.a.src, beats: m.beats, gain: m.gain, fade: m.fade ?? .8})),+ bgm: SND.bgm.map(m => ({src: m.a.src, beats: m.beats, gain: m.gain, fade: m.fade ?? .8})),upInPre: window.MUSIC_UP_IN_PRE || false})""")# a film's question beats (CHAPTER.film: the reader acts, e.g. fires) stay in the video: their picture holds `hold` s# (BEATS[i].hold, 1.5 by default) where the page waits for the reader, then the next beat plays as if they had actedbeats = [(i, x['id']) for i, x in enumerate(info['beats']) if (not x['ask'] or info['film']) and x['video'] is not False]# `video` in a beat's fourth slot: false leaves it out of the video; a number (seconds on its clock) ends it# there, its sound and captions cut, with no wait (a point-and-read game that only works on the page)- skipped = [x['id'] for x in info['beats'] if x['video'] is False]+ if a.to: # a first part of the film: every beat up to this one, so the music stands where the film has it+ ids = [x['id'] for x in info['beats']]+ if a.to not in ids: sys.exit(f'--to {a.to}: no such beat; the beats are {", ".join(ids)}')+ beats = [(i, bid) for i, bid in beats if i <= ids.index(a.to)]+ print(f'up to {a.to}: {len(beats)} beats')+ last = beats[-1][0] if beats else -1+ skipped = [x['id'] for i, x in enumerate(info['beats']) if x['video'] is False and i <= last]if skipped: print(f'left out of the video (video: false): {", ".join(skipped)}')info['sfx'] = []asks = not info['film'] and any(x['ask'] for x in info['beats']) # a lesson's questions, left out: the end card says where they are@@ -143,7 +176,6 @@ async def main(a):# Pass 1: the sound track and the captions, beat by beat at the beat's length on screen.end_s = END_SECONDS if asks or a.link else 0 # a picture book ends on its own last scenelengths, starts, counts, music_off, cues, offset, waits, silent = [], [], [], [], [], 0.0, {}, set()- words, spoken = {}, [] # a point-and-read beat (tapWords): its word clips and the seconds between them; when each is saidfor i, bid in beats:await open_beat(pg, base, i)end, T = await pg.evaluate('[P.end, TIMINGS[BEATS[P.i].id]]')@@ -152,9 +184,6 @@ async def main(a):if isinstance(cut, (int, float)) and not isinstance(cut, bool): end = min(end, cut)elif info['beats'][i]['ask']: # from P.end the page waitswaits[bid], hold = end, info['beats'][i]['hold']- if demo := await pg.evaluate('P.tapDemo ? [P.tapDemo.clips, P.tapDemo.step] : null'):- words[bid] = demo- if hold is None: hold = len(demo[0]) * demo[1] + 1end += 1.5 if hold is None else hold# a scene lists its sfx() when its beat is built, so they are collected beat by beatfor e in await pg.evaluate(SFX_JS):@@ -175,14 +204,16 @@ async def main(a):for k, (i, bid) in enumerate(beats):o, pre = starts[k], info['beats'][i]['pre']if bid not in silent: put(track, o + pre, decode(f'{a.url}{a.chapter}/audio/{info["lang"]}/{bid}.mp3'), 1, o + lengths[k])- for n, name in enumerate(words.get(bid, [[]])[0]): # the words, said in turn while the picture holds- src, at = f'{a.url}{a.chapter}/audio/{info["lang"]}/{name}.mp3', waits[bid] + n * words[bid][1]- try: said = decode(src)- except subprocess.CalledProcessError: print(f'{bid}: no word clip {src}: that word is silent'); continue- put(track, o + at, said, 1, o + lengths[k]); spoken.append((bid, at, at + len(said) / RATE))for e in info['sfx']: # effects sit at half volume under the voices; a new scene stops them- if e['beat'] == bid and 0 <= e['at'] < lengths[k]:- put(track, o + e['at'], decode(e['src']), .5 * e['vol'], o + lengths[k])+ if e['beat'] != bid: continue+ fx = decode(e['src'])+ if e.get('loop'): # a bed: laid again every (its length - BED_OVERLAP) s to `to`, else the beat's end and its hold+ stop = lengths[k] if e.get('to') is None else min(lengths[k], e['to'])+ step, at = max(.5, len(fx) / RATE - BED_OVERLAP), e['at']+ while 0 <= at < stop:+ put(track, o + at, fx, .5 * e['vol'], o + stop); at += step+ elif 0 <= e['at'] < waits.get(bid, lengths[k]): # a one-shot due past the beat's own end never plays+ put(track, o + e['at'], fx, .5 * e['vol'], o + lengths[k])# music: the engine's music player (soundTick), frame by frame: crossfades of the track's `fade` (0.8 s by default), ducked to 30 % in a# scene with voices; with MUSIC_UP_IN_PRE (true, or a list of beat ids) the music comes up to 70 % while a beat's# picture runs before its narration, and in a film while the page waits for the reader (the hold)@@ -192,8 +223,6 @@ async def main(a):frames_off = [x for m in music_off for x in m]beat_len = {bid: lengths[k] for k, (_, bid) in enumerate(beats)}beat_pre = {x['id']: x['pre'] for x in info['beats']}- # a word said while the picture holds ducks the music at once, as the page ducks it under a tapped word- saying = lambda bid, t: any(b == bid and t0 <= t < t1 for b, t0, t1 in spoken)for m in info['bgm']:song, v, duck, pos = decode(m['src']), 0.0, .3, 0.0gain = np.zeros(n); at = np.zeros(n, int)@@ -202,8 +231,8 @@ async def main(a):current = bid in m['beats'] and not frames_off[f]v = max(0.0, min(1.0, v + (1 if current else -1) / fps / m['fade'])) if m['fade'] > 0 else float(current) # 0: a cutup = info['upInPre']- want = .7 if (up and (up is True or bid in up) and t < beat_pre[bid]) or t >= waits.get(bid, 1e9) and not saying(bid, t) else .3- duck += max(-(4 if want < duck and saying(bid, t) else 1) / fps, min(1 / fps, want - duck))+ want = .7 if (up and (up is True or bid in up) and t < beat_pre[bid]) or t >= waits.get(bid, 1e9) else .3+ duck += max(-1 / fps, min(1 / fps, want - duck))if current: pos = sum(beat_len.get(b, 0) for b in m['beats'][:m['beats'].index(bid)]) + telse: pos += 1 / fpsgain[f], at[f] = v * m['gain'] * duck, round(pos * RATE) % len(song)@@ -213,10 +242,23 @@ async def main(a):put(track, i / RATE, seg, gain[f])peak = float(np.abs(track).max())if peak > 1: track *= .98 / peak # a mix that would clip, turned down as a whole- wav = audio_dir / 'track.wav'- with wave.open(str(wav), 'wb') as w:+ wav = mix = audio_dir / 'mix.wav'+ with wave.open(str(mix), 'wb') as w:w.setnchannels(2); w.setsampwidth(2); w.setframerate(RATE)w.writeframes((np.clip(track, -1, 1) * 32767).astype('<i2').tobytes())+ if a.lufs is not None: # levelled as level.py levels a clip: a gain, a limiter, measured and redone+ wav, (i0, tp0) = audio_dir / 'track.wav', lv.measure(mix)[:2]+ g, lim = a.lufs - i0, PEAK - .3+ for _ in range(5):+ subprocess.run(['ffmpeg', '-v', 'error', '-y', '-i', str(mix), '-af',+ f'volume={g:.2f}dB,alimiter=limit={10 ** (lim / 20):.4f}:level=0:latency=1', '-c:a', 'pcm_s16le', str(wav)], check=True)+ i1, tp1 = lv.measure(wav)[:2]+ if tp1 <= PEAK and abs(a.lufs - i1) <= .3: break+ if tp1 > PEAK: lim -= tp1 - PEAK + .2+ if abs(a.lufs - i1) > .3: g += a.lufs - i1 # the limiter took some of the loudness+ print(f'loudness {i0:.1f} LUFS, {tp0:.1f} dBTP as the page mixes it; levelled to {i1:.1f} LUFS, {tp1:.1f} dBTP '+ f'({g:+.1f} dB, limiter at {lim:.1f} dBFS; --lufs {a.lufs:g})'+ + ('' if abs(a.lufs - i1) <= .5 else f': WARNING {a.lufs - i1:+.1f} LU from the target, the limiter holds it back'), flush=True)# Pass 2: frames, shot by --jobs browsers at once and piped in order into the encoder with the audio track.codec, opts = encoder()print(f'encoder {codec}, {a.jobs} browsers', flush=True)@@ -245,11 +287,10 @@ async def main(a):await open_beat(w, base, i); opened[w], last[w] = i, -1# evalTo only runs forward and a tween takes its start value when first reached, so overlapping tweens# depend on the frames before: each browser steps every frame since its last shot, as one browser would- await w.evaluate('ts => { for (const t of ts) { P.t = t; evalTo(t); } }',- [g / a.fps for g in range(last[w] + 1, f + 1)])- bid = info['beats'][i]['id']- if bid in words and f / a.fps >= waits[bid]: # the words in turn, as if tapped- await w.evaluate('s => P.tapDemo?.at(s)', f / a.fps - waits[bid])+ # past a film ask's wait start the beat's clock stays at its end and the engine draws the wait (P.idleAt), so+ # the puppets breathe and blink through the hold as on the page+ await w.evaluate('([ts, wait]) => { for (const t of ts) { if (wait !== null && t > wait && P.idleAt) { P.t = wait; evalTo(wait); P.idleAt(t - wait); } else { P.t = t; evalTo(t); } } }',+ [[g / a.fps for g in range(last[w] + 1, f + 1)], waits.get(info['beats'][i]['id'])])last[w] = freturn await w.screenshot(clip=clip, type='jpeg', quality=92)@@ -283,6 +324,9 @@ async def main(a):part.unlink(missing_ok=True)sys.exit(f'failed: {errs[:3]} encoder {enc.returncode}')part.replace(video)+ if a.lufs is not None:+ i2, tp2 = lv.measure(video)[:2]+ print(f'{video}: {i2:.1f} LUFS, {tp2:.1f} dBTP after the AAC encode')print(f'{video} ({total / 60:.1f} min, {frames} frames, {len(beats)} beats{"; question beats left out" if asks else ""}; 'f'sound peak {peak:.2f}{f" turned down to 0.98 (x{.98 / peak:.2f}) so as not to clip" if peak > 1 else ""}) and {a.chapter}.srt')@@ -300,6 +344,9 @@ if __name__ == '__main__':ap.add_argument('--height', type=int, help='video height (default 1080 landscape, 1920 portrait)')ap.add_argument('--link', help='address of the interactive lesson, shown on the end card')ap.add_argument('--query', default='', help='extra page query, e.g. tags (the source and AI-illustration tags)')+ ap.add_argument('--lufs', default=-16.0, type=lambda v: None if v == 'off' else float(v),+ help="integrated loudness of the video's sound (default -16; off: as the page mixes it)")+ ap.add_argument('--to', metavar='BEAT', help='stop after this beat (its id): a first part of the film, e.g. one scene to check')ap.add_argument('--no-tags', action='store_true', help="an upright film without its source and AI tags (shown by default)")args = ap.parse_args()QUERY = args.query + '&' if args.query else ''diff --git a/.claude/skills/papermorph/scripts/level.py b/.claude/skills/papermorph/scripts/level.pyindex 2fe06dd..073f237 100644--- a/.claude/skills/papermorph/scripts/level.py+++ b/.claude/skills/papermorph/scripts/level.py@@ -22,7 +22,7 @@ from pathlib import Pathdef measure(f):"""Integrated loudness (LUFS), true peak (dBTP), duration (s) and bit rate of a clip."""- r = subprocess.run(["ffmpeg", "-hide_banner", "-nostats", "-i", str(f), "-af", "loudnorm=print_format=json",+ r = subprocess.run(["ffmpeg", "-hide_banner", "-nostats", "-i", str(f), "-vn", "-af", "loudnorm=print_format=json","-f", "null", "-"], capture_output=True, text=True, check=True)m = json.loads(re.search(r"\{[^{}]*\"input_i\"[^{}]*\}", r.stderr).group(0))p = subprocess.run(["ffprobe", "-v", "error", "-show_entries", "format=duration,bit_rate", "-of", "json", str(f)],diff --git a/.claude/skills/papermorph/scripts/lint.py b/.claude/skills/papermorph/scripts/lint.pyindex 8ba1524..da9e290 100644--- a/.claude/skills/papermorph/scripts/lint.py+++ b/.claude/skills/papermorph/scripts/lint.py@@ -15,10 +15,12 @@ Errors (exit status 1):mark m('name') is not a mark of any beatstale the narration's text differs from timings.js, or a narration [[mark]] is missing there: run tts.py againstyle style.json is not valid JSON or lacks schema, tier, book, words, look or voice- word a point-and-read thing (tapWords) has no clip: audio/<lang>/<clip>.mp3, w-<word>.mp3 by default (its word- belongs in the narration as "w-<word>": "<word>", voiced by tts.py)-Warnings: a chapter that calls tapWords() without CHAPTER.film true, or with words not written as literals- (word: 'basket'), whose clips were not checked; a beat's m('name') not among that beat's own marks (beats built by shared helpers can mislead this);+ word a listen-and-find stop (findWords) plays a clip that is missing: a thing's (clip:, else w-<word>), an+ ask's question (its clip:) and its again (r-<word> by default), the stop's end (q-done) and there (q-there)+ lines, audio/sfx/chime.mp3 after each find; or an ask's word is no thing's word. Each clip is a narration line, "w-<word>": "<word>", voiced by tts.py+Warnings: a chapter that calls findWords() without CHAPTER.film true, or whose things and asks do not write their word+ and clip as literals (word: 'bird', clip: 'q-bird'; an ask list built with .map does not), whose clips were not+ checked; a beat's m('name') not among that beat's own marks (beats built by shared helpers can mislead this);a mark in timings.js that the narration lacks (added by hand: the next tts.py or eleven.py run drops it, so apage-only time belongs in the page); no beats recognised in a chapter; no narration file to check against.--content defaults to content/<book> (content/ when that is missing and content/chNN exists: the first book's legacy@@ -43,7 +45,8 @@ PARAMS = re.compile(r'function\s*[\w$]*\s*\(([^)]*)\)|\(([^()]*)\)\s*=>|([A-Za-zMETHOD = re.compile(r'^\s*([A-Za-z_$][\w$]*)\s*\([^()]*\)\s*\{', re.M) # name(a, b) { … } in an objectDESTRUCT = re.compile(r'(?:const|let|var)\s*([\[{][^;]*?[\]}])\s*(?:=|of\b|in\b)') # const {a, b: c, d = 1} = …, for (const [x, y] of …)DKEY = re.compile(r'[A-Za-z_$][\w$]*\s*:|=[^,\]}]*') # in a pattern, a key (b: c declares c) and a default (= 1) declare nothing-WORD = re.compile(r'(?<![\w$.])(word|clip)\s*:\s*([\'"`])') # a point-and-read thing's word: 'basket', clip: 'w-basket'+FIND = re.compile(r'(?<![\w$.])(?<!function )findWords\s*\(') # a call, not the engine's definition+OBJ = re.compile(r'\{[^{}]*\}') # an object literal with no object inside: a thing { g, word: 'bird', … } or an askUSE = re.compile(r'(?<![\w$.])([A-Za-z_$][\w$]*)(?![\w$])(?!\s*:)') # a name, not a property or an object key@@ -214,28 +217,51 @@ def lint_chapter(ch, content, out):err('mark', f"m('{k}') in beat {b} is not a mark of any beat")elif b in T and k not in T[b].get('marks', {}):warn('mark', f"m('{k}') in beat {b} is not one of its marks")- # point-and-read things (tapWords): each says its clip, the word's own unless clip: names another- if any(re.search(r'(?<![\w$.])tapWords\s*\(', depth0(c)[0]) for c in own):+ # listen and find (findWords): every clip a stop can play exists, and every word asked for is a thing's+ if any(FIND.search(depth0(c)[0]) for c in own):if not re.search(r'\bfilm\s*[:=]\s*true', inline):- warn('word', 'calls tapWords() but CHAPTER.film is not true: the chapter plays as a lesson, without music or effects')- found, loose = 0, 0+ warn('word', 'calls findWords() but CHAPTER.film is not true: the chapter plays as a lesson, without music or effects')+ clips, things, asks, loose = {}, set(), set(), 0 # clip -> what plays itfor c in own:code = depth0(c)[0]- loose += len(re.findall(r'(?<![\w$.])word\s*:\s*(?![\'"`\s])', code)) # word: name, not a literal- at = [(m.start(), m.group(1), c[m.end():c.index(m.group(2), m.end())]) for m in WORD.finditer(code)]- for k, (pos, key, text) in enumerate(at):- if key != 'word':+ def lit(at, o, key): # the string literal after key: in the object o at code[at], or None+ k = re.search(rf'(?<![\w$.]){key}\s*:\s*([\'"`])', o)+ return k and c[at + k.end():c.index(k.group(1), at + k.end())]+ for m in OBJ.finditer(code): # { … word: … }: a thing (it has g:) or an ask+ o, at = m.group(0), m.start()+ if not re.search(r'(?<![\w$.])word\s*:', o):continue- found += 1- # its clip: a clip: in the same object, between the braces around the word- lo, hi = code.rfind('{', 0, pos), code.find('}', pos)- clip = next((t for p, kk, t in at if kk == 'clip' and lo < p < hi), None)- clip = clip or 'w-' + re.sub(r'[\W_]+', '-', text.lower()).strip('-') # as the engine names it- if not (ch / 'audio' / lang / f'{clip}.mp3').exists():- err('word', f'"{text}" has no audio/{lang}/{clip}.mp3: add "{clip}": "{text}" to the narration and run tts.py')- if loose or not found:- warn('word', f"calls tapWords() with {loose or 'no'} word{'s' if loose != 1 else ''} not written as word: 'literal': "- "their clips were not checked (the page warns about a missing one when the beat starts)")+ w = lit(at, o, 'word')+ thing = re.search(r'(?<![\w$.])g\s*:', o)+ if not w:+ loose += 1; continue+ slug = re.sub(r'[\W_]+', '-', w.lower()).strip('-') # as the engine names it+ if thing:+ things.add(w)+ clips.setdefault(lit(at, o, 'clip') or 'w-' + slug, f'the thing "{w}"')+ else: # an ask: its question (no default) and the short one again+ asks.add(w)+ q = lit(at, o, 'clip')+ if q: clips.setdefault(q, f'the ask for "{w}"')+ elif re.search(r'(?<![\w$.])clip\s*:', o): loose += 1+ else: err('word', f'the ask for "{w}" has no clip: (its question, e.g. clip: \'q-{slug}\')')+ clips.setdefault(lit(at, o, 'again') or 'r-' + slug, f'the ask for "{w}" (again)')+ for m in FIND.finditer(code): # the stop's own lines: findWords(things, asks, done, { end, there })+ args = slots(code, m.end() - 1)+ opts, at = (args[3], m.end() + sum(len(x) + 1 for x in args[:3])) if len(args) > 3 else ('', 0)+ for key, dflt in (('end', 'q-done'), ('there', 'q-there')):+ name = lit(at, opts, key) or dflt+ clips.setdefault(name, f'findWords {key}' + (' (default)' if name == dflt else ''))+ for name, who in clips.items():+ if not (ch / 'audio' / lang / f'{name}.mp3').exists():+ err('word', f'{who} plays audio/{lang}/{name}.mp3, which is missing: add "{name}": "<its line>" to the narration and run tts.py')+ if not (ch / 'audio' / 'sfx' / 'chime.mp3').exists():+ err('word', 'findWords plays audio/sfx/chime.mp3 after each thing found, which is missing (sfx.py makes effects)')+ for w in sorted(asks - things) if things and not loose else []:+ err('word', f'findWords asks for "{w}", but no thing in the chapter has word: \'{w}\'')+ if loose:+ warn('word', f"calls findWords() with {loose} thing{'s' if loose != 1 else ''} or ask{'s' if loose != 1 else ''} whose word or clip "+ "is not written as a literal (word: 'bird', clip: 'q-bird'): their clips were not checked, nor the asks against the things")# narration against the generated audionar = content / ch.name / f'narration.{lang}.json'if nar.exists():diff --git a/.claude/skills/papermorph/scripts/music.py b/.claude/skills/papermorph/scripts/music.pyindex 90e53d0..2d91b71 100644--- a/.claude/skills/papermorph/scripts/music.py+++ b/.claude/skills/papermorph/scripts/music.py@@ -26,8 +26,12 @@ last frame. A short fade in, then:Writes OUT as MP3 and prints the in-point, the rests it took out and the level.gaps: the bed as it sounds in the voice-free gaps (0.4 s or more where the beats' clips, placed at each beat's start plus-its `pre`, are quiet). Without --mp4 it measures the page's own track (its first music() file, at its gain, or --bed-and --gain) under the engine's 30 % ducking; with --mp4, the exported mix. Prints each gap's quietest momentary+its `pre`, are quiet). Without --mp4 it measures the bed as the engine plays it: every music() track under its own+beats at its gain (or --bed and --gain, one file under every beat), placed at the length of its earlier beats plus the+beat's clock and looping as often as the film needs, silent where MUSIC_OFF is true, under the 30 % ducking (the+crossfades and MUSIC_UP_IN_PRE lead-ins are not modelled). The film's waits for the reader are not on that timeline:+the music runs on through them, so the run names them and says the track is further on after each. With --mp4 it+measures the exported mix, on the video's timeline (export.py's `video` and `hold`). Prints each gap's quietest momentaryloudness (400 ms) against the median gap, marks a hole (8 LU or more under the median), and the median itself; thenthe ending after the last word, marked the same way (a decaying track leaves the end card silent), and, when the page'strack runs under every beat, whether it was cut for this film's length: it says "recut" after any change of length.@@ -38,7 +42,7 @@ import argparse, asyncio, json, math, pathlib, re, statistics, subprocess, sys,import level as lvfrom browsers import answers, exe-XF, TAIL, DUCK = .15, 2.0, .3+XF, TAIL, DUCK, OFF_HZ = .15, 2.0, .3, 20EVEN = "dynaudnorm=f=400:g=21:p=0.6:m=8,acompressor=threshold=-24dB:ratio=2.5:attack=40:release=400:makeup=2"@@ -51,7 +55,8 @@ def chapter_url(url, ch):async def timeline(url):- """[(beat id, P.end, pre, silent)] for every beat (silent: { dur }, no clip), the chapter's language and its first music() file, gain and beat count."""+ """[(beat id, P.end, pre, silent, MUSIC_OFF at every 1/OFF_HZ s, ask, video, hold)] for every beat (silent: { dur },+ no clip), the chapter's language, its music() tracks [(file, gain, beats)] and whether it is a film."""from playwright.async_api import async_playwrightanswers(url)async with async_playwright() as p:@@ -61,14 +66,17 @@ async def timeline(url):try: return await pg.evaluate(js)except Exception as e: sys.exit(f"{url}: the page did not load: {errs[0] if errs else e}")await pg.goto(f"{url}?beat=0&t=0")- n, lang, bgm = await ask("[BEATS.length, CHAPTER.language || 'en', typeof BGM === 'undefined' || !BGM.length ? null : [BGM[0].a.src, BGM[0].gain, BGM[0].beats.length]]")+ n, lang, bgm, film = await ask("[BEATS.length, CHAPTER.language || 'en', SND.bgm.map(m => [m.a.src, m.gain, m.beats]), !!CHAPTER.film]")beats = []for i in range(n):await pg.goto(f"{url}?beat={i}&t=0"); await pg.wait_for_timeout(300)- beats.append(tuple(await ask("[BEATS[P.i].id, P.end, BEATS[P.i].pre || 0, !!TIMINGS[BEATS[P.i].id].silent]")))+ beats.append(tuple(await ask(f"""(() => {{ const b = BEATS[P.i];+ return [b.id, P.end, b.pre || 0, !!TIMINGS[b.id].silent,+ Array.from({{length: Math.ceil(P.end * {OFF_HZ})}}, (_, f) => !!window.MUSIC_OFF?.[b.id]?.(f / {OFF_HZ})),+ !!b.ask, b.video ?? null, b.hold ?? null]; }})()""")))await b.close()if errs: print(f"page errors: {'; '.join(sorted(set(errs))[:3])}", file=sys.stderr)- return beats, lang, bgm+ return beats, lang, bgm, filmdef silences(src, db, d, ss=0.0, t=None):@@ -111,7 +119,7 @@ def spans(end, at, rests):def cut(a):if a.length is None:- beats, _, _ = asyncio.run(timeline(a.url))+ beats, _, _, _ = asyncio.run(timeline(a.url))a.length = sum(b[1] for b in beats)end, ends = (a.end, None) if a.end is not None else (last_note(a.src), sound_end(a.src))at = a.length - a.shift # where the last note falls in the cut@@ -154,13 +162,26 @@ def momentary(src, gain=1.0):def gaps(a):import numpy as np- beats, lang, bgm = asyncio.run(timeline(a.url))+ beats, lang, bgm, film = asyncio.run(timeline(a.url))+ if a.mp4: # the video's timeline, as export.py cuts it: video: false out, video: S cut there, a film's wait held+ cut = []+ for b in beats:+ bid, end, pre, silent, off, ask, video, hold = b+ if video is False or ask and not film: continue+ if isinstance(video, (int, float)): end = min(end, video)+ elif ask: end += 1.5 if hold is None else hold+ cut.append((bid, end, pre, silent, off, ask, video, hold))+ beats = cut+ elif film and (waits := [b[0] for b in beats if b[5]]):+ print(f"{', '.join(waits)} wait{'s' if len(waits) == 1 else ''} for the reader: the music runs on there at 70 %, so after "+ "a wait the track is that much further on than measured here (--mp4 measures the video, which holds or skips each wait)")L, SR, hop, w = sum(b[1] for b in beats), 16000, 800, 6400 # 400 ms windows every 50 ms+ pcm = lambda src: np.frombuffer(subprocess.run(["ffmpeg", "-v", "error", "-i", src, "-ac", "1", "-ar", str(SR), "-f", "f32le", "-"],+ capture_output=True, check=True).stdout, np.float32)voice, t0 = np.zeros(int((L + 1) * SR), np.float32), 0.0- for bid, end, pre, silent in beats:+ for bid, end, pre, silent, *_ in beats:if silent: t0 += end; continue # no clip: all of it is a gap- x = np.frombuffer(subprocess.run(["ffmpeg", "-v", "error", "-i", f"{a.url}audio/{lang}/{bid}.mp3", "-ac", "1", "-ar", str(SR),- "-f", "f32le", "-"], capture_output=True, check=True).stdout, np.float32)+ x = pcm(f"{a.url}audio/{lang}/{bid}.mp3")i = int((t0 + pre) * SR); x = x[:max(0, min(len(x), int((t0 + end) * SR) - i))]; voice[i:i + len(x)] += x; t0 += endquiet = [20 * np.log10(np.sqrt(np.mean(voice[i:i + w] ** 2)) + 1e-9) < -45 for i in range(0, len(voice) - w, hop)]runs, k = [], 0 # voice-free stretches: [first window's start, last window's end]@@ -169,12 +190,40 @@ def gaps(a):while j < len(quiet) and quiet[j]: j += 1if j - k >= 8 and (j - 1) * .05 + .4 < L - .5: runs.append((k * .05, (j - 1) * .05 + .4)) # after the last word, the music's own endingk = j + 1+ ids = [b[0] for b in beats]+ tracks = [(a.bed, a.gain if a.gain is not None else .4, ids)] if a.bed else \+ [(src, a.gain if a.gain is not None else g, tb) for src, g, tb in bgm]if a.mp4:M, what = momentary(a.mp4), f"the mix in {a.mp4}"else:- src, g = a.bed or (bgm and bgm[0]), a.gain if a.gain is not None else bgm[1] if bgm else .4- if not src: sys.exit("the page has no music(): give --bed FILE")- M, what = momentary(src, g * DUCK), f"{src.rsplit('/', 1)[-1]} at gain {g} under the {DUCK:.0%} duck" # ponytail: ducked all through, MUSIC_UP_IN_PRE lead-ins not modelled+ if not tracks: sys.exit("the page has no music(): give --bed FILE")+ # the bed as the engine plays it: each track under its own beats, at the length of its earlier beats plus the+ # clock, looping, silent where MUSIC_OFF is true; ponytail: crossfades (0.8 s) and MUSIC_UP_IN_PRE lead-ins not modelled+ BR = 44100 # the bed in stereo at the file's rate, so its loudness reads as the track's own and the video's+ bed, lens, end_of = np.zeros((int((L + 1) * BR), 2), np.float32), [], {b[0]: b[1] for b in beats}+ for src, g, tb in tracks:+ x = np.frombuffer(subprocess.run(["ffmpeg", "-v", "error", "-i", src, "-ac", "2", "-ar", str(BR), "-f", "f32le", "-"],+ capture_output=True, check=True).stdout, np.float32).reshape(-1, 2)+ lens.append(len(x) / BR); t0 = 0.0+ for bid, end, _, _, off, *_ in beats:+ if bid in tb:+ pos, n = sum(end_of.get(b, 0) for b in tb[:tb.index(bid)]), int(end * BR)+ seg = x[(int(pos * BR) + np.arange(n)) % len(x)] * g * DUCK+ mask = np.repeat(np.array(off, bool), BR // OFF_HZ)[:n]+ seg[:len(mask)][mask] = 0+ i = int(t0 * BR); bed[i:i + n] += seg[:len(bed) - i]+ t0 += end+ with tempfile.TemporaryDirectory() as d:+ wav = pathlib.Path(d) / "bed.wav"+ subprocess.run(["ffmpeg", "-v", "error", "-f", "f32le", "-ar", str(BR), "-ac", "2", "-i", "-", str(wav)], input=bed.tobytes(), check=True)+ M = momentary(wav)+ what = "; ".join(f"{src.rsplit('/', 1)[-1]} ({ln:.1f} s{', looped' if ln < sum(end_of[b] for b in tb if b in end_of) else ''}) "+ f"at gain {g} under {len(tb)} beats" for (src, g, tb), ln in zip(tracks, lens)) + \+ f", ducked to {DUCK:.0%}" + (", silent in MUSIC_OFF moments" if any(any(b[4]) for b in beats) else "")+ silenced, t0 = [], 0.0 # MUSIC_OFF moments on the timeline: a gap there is meant, not a hole+ for b in beats:+ silenced += [t0 + f / OFF_HZ for f, x in enumerate(b[4]) if x]; t0 += b[1]+ meant = lambda g0, d: any(g0 <= t <= g0 + d for t in silenced)rows = []for g0, g1 in runs:sel = [m for t, m in M if g0 + .4 <= t <= g1] # windows wholly inside the gap@@ -183,8 +232,9 @@ def gaps(a):med = statistics.median(r[2] for r in rows)print(f"film {L:.2f} s, {len(rows)} voice-free gaps; {what}")for t, d, m in rows:- print(f"gap at {t:6.2f} s for {d:4.2f} s: {m:6.1f} LUFS momentary min ({m - med:+5.1f}){' <- hole' if m <= med - 8 else ''}")- print(f"median gap {med:.1f} LUFS; {sum(m <= med - 8 for _, _, m in rows)} holes")+ print(f"gap at {t:6.2f} s for {d:4.2f} s: {m:6.1f} LUFS momentary min ({m - med:+5.1f})"+ + (" <- MUSIC_OFF (the page silences the music here)" if meant(t, d) else " <- hole" if m <= med - 8 else ""))+ print(f"median gap {med:.1f} LUFS; {sum(m <= med - 8 and not meant(t, d) for t, d, m in rows)} holes")loud = [i for i in range(0, len(voice) - w, hop) if 20 * np.log10(np.sqrt(np.mean(voice[i:i + w] ** 2)) + 1e-9) >= -45]last = (loud[-1] + w) / SR if loud else 0.0 # the end of the last wordtail = [m for t, m in M if last + .4 <= t <= L and not math.isnan(m)]@@ -192,8 +242,8 @@ def gaps(a):m = statistics.median(tail)print(f"ending: {L - last:.2f} s after the last word, {m:6.1f} LUFS momentary median ({m - med:+5.1f})"+ (" <- quiet ending: the track decays before the end (music.py cut picks its last note by loudness; or --end)" if m <= med - 8 else ""))- if not a.bed and bgm and bgm[2] == len(beats): # the page's track under every beat: was it cut for this length?- dur = lv.measure(bgm[0])[2]+ if not a.bed and len(bgm) == 1 and len(bgm[0][2]) == len(beats): # the page's one track under every beat: was it cut for this length?+ dur = lv.measure(bgm[0][0])[2]if dur > L / 2 and abs(dur - TAIL - L) > .15: # ponytail: a track under half the film is a loop, not a cutprint(f"the track is {dur:.2f} s, cut for a {dur - TAIL:.2f} s film; this one is {L:.2f} s: recut it (music.py cut)")return rows, meddiff --git a/.claude/skills/papermorph/scripts/playlog.py b/.claude/skills/papermorph/scripts/playlog.pyindex 9006e93..571a4ef 100644--- a/.claude/skills/papermorph/scripts/playlog.py+++ b/.claude/skills/papermorph/scripts/playlog.py@@ -14,8 +14,14 @@ time with its label (four a row):scene1 1.12 line Every afternoon, the old man plays chess in the park.scene1 8.41 sfx clack vol 0.50+ scene1 0.00 music theme in gain 0.40+ scene7 33.20 music theme out (MUSIC_OFF) gain 0.40+voice/sfx/bgm: an audio file started playing (its folder under audio/ names the kind; vol is the element's volume-when it started, the slider at 1). line: the caption changed (captions are switched on for the run). An effect+when it started, the slider at 1). music: a track of the engine's music() came in under the film or went out (a beat+outside its list, or a MUSIC_OFF moment), with its music() gain; the engine ducks it to 30 % under a beat, 70 % in a+MUSIC_UP_IN_PRE lead-in and while a film waits for the reader. line: the caption changed (captions are switched on for+the run). An effectlisted twice at one moment plays twice. Look at each frame: is the clack on the frame where the piece lands, theslurp where the cup is at the mouth, the line where that character's mouth moves? Effects fire only in normalplayback, never on a seek, which is why this plays the chapter instead of seeking it. Chromium; if it cannot play@@ -33,7 +39,8 @@ try { localStorage.setItem('captions', '1'); } catch {}const play0 = HTMLMediaElement.prototype.play;HTMLMediaElement.prototype.play = function () {try {- if (this.paused && !this.muted && typeof P !== 'undefined' && P.playing) { // a real start (not a resume of a playing clip, not the silent unlock)+ const engineMusic = typeof SND !== 'undefined' && SND.bgm.some(m => m.a === this); // logged below, from its state+ if (this.paused && !this.muted && !engineMusic && typeof P !== 'undefined' && P.playing) { // a real start (not a resume of a playing clip, not the silent unlock)const src = decodeURI(new URL(this.currentSrc || this.src, location.href).pathname).replace(/^.*?\/audio\//, '');__log.push({ kind: /^sfx\//.test(src) ? 'sfx' : /^bgm\//.test(src) ? 'bgm' : 'voice', what: src.replace(/^(sfx|bgm)\//, '').replace(/\.mp3$/, ''),i: P.i, t: P.t, vol: this.volume });@@ -47,6 +54,22 @@ AudioBufferSourceNode.prototype.start = function () {try { if (this._sfx && P.playing) __log.push({ kind: 'sfx', what: this._sfx, i: P.i, t: P.t, vol: this._vol }); } catch {}return start0.apply(this, arguments);};+// the engine's music (music()): its element starts once and plays on (the first, muted play() unlocks it), so each+// track is logged when it comes in under the film or goes out, a MUSIC_OFF moment included+const musicWas = new Map();+setInterval(() => {+ try {+ if (typeof SND === 'undefined' || !P.playing) return;+ const id = BEATS[P.i]?.id, off = !!window.MUSIC_OFF?.[id]?.(P.t);+ for (const m of SND.bgm) {+ const on = !!m.cur;+ if (on === (musicWas.get(m) || false)) continue;+ musicWas.set(m, on);+ const name = decodeURI(new URL(m.n, location.href).pathname).replace(/^.*\//, '').replace(/\.mp3$/, '');+ __log.push({ kind: 'music', what: `${name} ${on ? 'in' : 'out'}${!on && off ? ' (MUSIC_OFF)' : ''}`, i: P.i, t: P.t, vol: m.gain });+ }+ } catch {}+}, 40);addEventListener('DOMContentLoaded', () => {const c = document.getElementById('caption'); if (!c) return;let last = '';@@ -95,7 +118,7 @@ async def main(a):r = await pg.evaluate("(() => { const r = document.getElementById('stage').getBoundingClientRect(); return {x: r.x, y: r.y, width: r.width, height: r.height}; })()")shots.append((e, Image.open(io.BytesIO(await pg.screenshot(clip=r))).convert("RGB").resize((cw, ch))))await b.close()- lines = [f"{ids[e['i']]:10} {e['t']:6.2f} {e['kind']:5} {e['what']}" + (f" vol {e['vol']:.2f}" if e['kind'] == 'sfx' else '') for e, _ in shots]+ lines = [f"{ids[e['i']]:10} {e['t']:6.2f} {e['kind']:5} {e['what']}" + (f" vol {e['vol']:.2f}" if e['kind'] == 'sfx' else f" gain {e['vol']:.2f}" if e['kind'] == 'music' else '') for e, _ in shots]if afail: lines.append("note: sound did not play in this browser; the clock ran on wall time")(a.out / f"{a.chapter}_playlog.txt").write_text("\n".join(lines) + "\n", encoding="utf-8")print("\n".join(lines))diff --git a/.claude/skills/papermorph/scripts/still.py b/.claude/skills/papermorph/scripts/still.pyindex a6fd89a..7e9c777 100644--- a/.claude/skills/papermorph/scripts/still.py+++ b/.claude/skills/papermorph/scripts/still.py@@ -10,6 +10,9 @@ measuring; a scene's own `jit` (snowfall, a tremble) keeps working, so what is la breathing, blinking puppet that does nothing else measures about 1-1.5, real acting 2 and up (The Chess Dog,2026-10-23). Defaults: 0.03 for a lesson, 1.5 for a picture book. Strips and onion skins cannot show that nothingmoves; this can. A stretch is worth a look, not automatically wrong: a held moment can be right.+A film's ask beats (CHAPTER.film: a listen-and-find stop, a shot the reader fires) are measured like the others, up to+where the page starts waiting (P.end); what the page draws while it waits is not. A lesson's question beats are skipped,+and the run names them."""import argparse, asyncio, iofrom playwright.async_api import async_playwright@@ -41,7 +44,8 @@ async def main():b = await p.firefox.launch(firefox_user_prefs={"media.autoplay.default": 0})pg = await b.new_page(viewport={"width": 1600, "height": 960}, reduced_motion="reduce")await pg.goto(URL + "?beat=0&t=0"); await pg.wait_for_timeout(800)- ids = await pg.evaluate("BEATS.map(b => b.id)"); asks = await pg.evaluate("BEATS.map(b => !!b.ask)")+ ids = await pg.evaluate("BEATS.map(b => b.id)")+ asks = await pg.evaluate("BEATS.map(b => !!b.ask && !CHAPTER.film)") # a film's ask beat plays a scene firstfilm = await pg.evaluate(STEADY)thr = a.thr if a.thr is not None else (1.5 if film else .03)r = await pg.evaluate("(() => { const r = document.getElementById('stage').getBoundingClientRect(); return {x: r.x, y: r.y, width: r.width, height: r.height}; })()")@@ -62,6 +66,8 @@ async def main():if min(t1 - a.step, dur) - start >= a.min: runs.append((start, min(t1 - a.step, dur)))start = Noneprint(f"{bid:11s} dur {dur:5.1f} still: " + (", ".join(f"{s:.0f}-{e:.0f}s" for s, e in runs) or "-"), flush=True)+ skipped = [bid for i, bid in enumerate(ids) if asks[i] and (not a.beats or bid in a.beats)]+ if skipped: print(f"question beats skipped (a lesson's questions): {', '.join(skipped)}")await b.close()asyncio.run(main())