decklight 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/NOTICE +2 -0
  2. package/PLATFORM.md +17 -0
  3. package/README.md +53 -25
  4. package/SPEC.md +1239 -67
  5. package/cli/agents.mjs +139 -15
  6. package/cli/bundle.mjs +68 -2
  7. package/cli/cast.mjs +45 -14
  8. package/cli/check-fixes.mjs +12 -4
  9. package/cli/check-watch.mjs +151 -0
  10. package/cli/check.mjs +460 -71
  11. package/cli/code-editor.mjs +287 -0
  12. package/cli/commands.mjs +13 -2
  13. package/cli/commit-message.mjs +34 -7
  14. package/cli/commit-split.mjs +123 -23
  15. package/cli/decklight.mjs +11 -1
  16. package/cli/design-system-edit.mjs +37 -1
  17. package/cli/edit-address.mjs +184 -0
  18. package/cli/edit-git.mjs +21 -4
  19. package/cli/edit-handover.mjs +136 -25
  20. package/cli/edit-look.mjs +45 -1
  21. package/cli/edit-open.mjs +143 -0
  22. package/cli/edit-slides.mjs +1043 -67
  23. package/cli/edit-translate.mjs +243 -0
  24. package/cli/edit.mjs +3182 -267
  25. package/cli/editor-support.mjs +286 -0
  26. package/cli/enhance.mjs +148 -20
  27. package/cli/find-replace.mjs +142 -0
  28. package/cli/fix-review.mjs +368 -0
  29. package/cli/init.mjs +93 -19
  30. package/cli/keep-awake.mjs +68 -0
  31. package/cli/migrate-writing.mjs +214 -0
  32. package/cli/narrate.mjs +51 -10
  33. package/cli/open.mjs +29 -9
  34. package/cli/outside-edit.mjs +257 -0
  35. package/cli/paste.mjs +92 -0
  36. package/cli/pdf.mjs +61 -2
  37. package/cli/pptx-export.mjs +3 -1
  38. package/cli/publish.mjs +24 -3
  39. package/cli/record.mjs +19 -8
  40. package/cli/rewrite.mjs +265 -0
  41. package/cli/runtime-link.mjs +218 -17
  42. package/cli/serve.mjs +7 -4
  43. package/cli/setup.mjs +2 -2
  44. package/cli/skill-content.mjs +212 -8
  45. package/cli/skills/slide-writing.md +333 -0
  46. package/cli/skills/voiceover.md +423 -0
  47. package/cli/skills.mjs +36 -13
  48. package/cli/starter-full.mjs +353 -0
  49. package/cli/supervise.mjs +14 -0
  50. package/cli/theme.mjs +3 -2
  51. package/cli/translate-core.mjs +466 -0
  52. package/cli/translate-files.mjs +149 -0
  53. package/cli/translate.mjs +458 -0
  54. package/cli/util.mjs +25 -0
  55. package/cli/vocabulary-docs.mjs +138 -0
  56. package/dist/decklight.css +2087 -91
  57. package/dist/decklight.js +367 -203
  58. package/dist/decklight.js.map +4 -4
  59. package/docs/GLOSSARY.md +9 -2
  60. package/docs/WRITING_RESEARCH.md +327 -0
  61. package/package.json +5 -3
  62. package/themes/coastal.css +3 -0
  63. package/themes/metropolis.css +2 -0
  64. package/themes/reveal-blood.css +3 -0
  65. package/themes/reveal-league.css +2 -0
  66. package/themes/reveal-moon.css +2 -0
  67. package/themes/reveal-serif.css +1 -0
  68. package/themes/reveal-sky.css +1 -0
  69. package/themes/reveal-solarized.css +4 -0
  70. package/tools/brand-palette.mjs +6 -1
  71. package/tools/build-groups.mjs +28 -8
  72. package/tools/cdp.mjs +176 -0
  73. package/tools/chart-spec.mjs +242 -0
  74. package/tools/click-match.mjs +70 -0
  75. package/tools/code-options.mjs +174 -0
  76. package/tools/conversation.mjs +49 -0
  77. package/tools/deck-family.mjs +101 -0
  78. package/tools/deck-html.mjs +212 -15
  79. package/tools/design-system-format.mjs +15 -1
  80. package/tools/diagram-shapes.mjs +221 -0
  81. package/tools/elevenlabs-tts.mjs +62 -53
  82. package/tools/face-clip.mjs +96 -0
  83. package/tools/face-layout.mjs +94 -0
  84. package/tools/gemini-tts.mjs +1 -1
  85. package/tools/invisible-in-print.mjs +27 -0
  86. package/tools/lipsync-auto.mjs +197 -0
  87. package/tools/lipsync-config.mjs +16 -0
  88. package/tools/lipsync-engines.mjs +22 -4
  89. package/tools/lipsync-server.mjs +8 -5
  90. package/tools/lipsync.mjs +122 -30
  91. package/tools/local-voice.mjs +1 -1
  92. package/tools/mouth-file.mjs +26 -0
  93. package/tools/mouth.mjs +320 -0
  94. package/tools/narration-manifest.mjs +24 -4
  95. package/tools/narration-synth.mjs +96 -76
  96. package/tools/recording-impact.mjs +16 -1
  97. package/tools/sentences.mjs +7 -1
  98. package/tools/starters.mjs +402 -0
  99. package/tools/steps.mjs +118 -0
  100. package/tools/take-check.mjs +146 -0
  101. package/tools/template-theme.mjs +3 -1
  102. package/tools/test-impact.mjs +36 -12
  103. package/tools/theme-check.mjs +196 -1
  104. package/tools/tone-cue.mjs +108 -0
  105. package/tools/tts-cache.mjs +9 -3
  106. package/tools/tts-engines.mjs +100 -11
  107. package/tools/video-cache.mjs +93 -0
  108. package/tools/video-live.mjs +349 -0
  109. package/tools/video-options.mjs +11 -0
  110. package/tools/video.mjs +772 -127
  111. package/tools/viseme-fit.mjs +27 -0
  112. package/tools/viseme-match.mjs +77 -0
  113. package/tools/vocabulary.mjs +397 -0
  114. package/tools/voice-renumber.mjs +605 -0
  115. package/tools/voiceover-server.mjs +42 -11
  116. package/tools/voiceover.mjs +48 -20
  117. package/dist/build-info.json +0 -1
@@ -27,12 +27,14 @@
27
27
  */
28
28
 
29
29
  import { readFileSync, writeFileSync, mkdirSync, rmSync, existsSync } from 'node:fs';
30
- import { createHash } from 'node:crypto';
31
30
  import { join, extname } from 'node:path';
32
31
  import { clipKey, extFor } from './tts-cache.mjs';
32
+ import { resolveTtsVoice } from './tts-engines.mjs';
33
+ import { checkedSynth, takeLine } from './take-check.mjs';
33
34
  import { cleanNotes, notesSegments } from './deck-html.mjs';
34
- import { slideNotes, priorSlideTexts, manifestHash, markerPauses } from './narration-manifest.mjs';
35
+ import { slideNotes, priorSlideTexts, manifestHash, markerPauses, entryMatches, withTrackVoice } from './narration-manifest.mjs';
35
36
  import { PAUSE_MARK, speechRuns, hasWords, canonMarks, writtenMarks, forEngine, voicedPauses } from './sentences.mjs';
37
+ import { writeFileAtomic } from './atomic-write.mjs';
36
38
  import { run as runBounded, PROBE_MS, CODEC_MS } from './exec.mjs';
37
39
 
38
40
  /** The formats a track can be in — what a manifest's `file` names end with. */
@@ -42,7 +44,7 @@ export const TRACK_FORMATS = ['wav', 'm4a', 'mp3'];
42
44
  export const DEFAULT_FORMAT = 'm4a';
43
45
 
44
46
  /** The manifest header's own keys — everything else in a header is carried. */
45
- const HEADER_KEYS = ['engine', 'model', 'voice', 'style', 'format', 'slides'];
47
+ const HEADER_KEYS = ['engine', 'model', 'voice', 'voiceId', 'style', 'format', 'lang', 'slides'];
46
48
 
47
49
  /**
48
50
  * The format an existing track is in: the extension its slide files carry,
@@ -74,11 +76,13 @@ export function readTrack(dir) {
74
76
  * it was never voiced under. Refused rather than resolved: the fix is to voice
75
77
  * the whole track, or to put the other voice in its own folder.
76
78
  */
77
- export function voiceDrift(prev, { engine, model, voice }, { modelIsVoice = true } = {}) {
79
+ export function voiceDrift(prev, { engine, model, voice, voiceId }, { modelIsVoice = true } = {}) {
78
80
  if (!prev?.slides?.some(Boolean)) return null;
79
81
  const was = [];
80
82
  if (prev.engine != null && prev.engine !== engine) was.push(`engine ${prev.engine}`);
81
- if (prev.voice != null && voice != null && prev.voice !== voice) was.push(`voice ${prev.voice}`);
83
+ const differentVoice = prev.voiceId && voiceId
84
+ ? prev.voiceId !== voiceId : prev.voice != null && voice != null && prev.voice !== voice;
85
+ if (differentVoice) was.push(`voice ${prev.voice ?? prev.voiceId}`);
82
86
  // a header written before `model` was recorded has none to disagree with;
83
87
  // and for say/sapi the "model" is only the voice a bridge booted with — the
84
88
  // voice that spoke is `voice` — so it has nothing to say about identity
@@ -159,9 +163,9 @@ export function findEncoder(run = runBounded) {
159
163
  * hash still matches and whose file is on disk is kept, whoever made it.
160
164
  */
161
165
  export async function synthesizeSlides({
162
- html, dir, tts, voice, style, format = DEFAULT_FORMAT, range = null, prev = null,
166
+ html, dir, tts, voice, voiceId, style, format = DEFAULT_FORMAT, range = null, prev = null,
163
167
  cache, reuseTextFrom = [], keepWav = false, log = console.log,
164
- run = runBounded, encoder = undefined,
168
+ run = runBounded, encoder = undefined, force = false,
165
169
  }) {
166
170
  if (!TRACK_FORMATS.includes(format)) throw new Error(`a track is ${TRACK_FORMATS.join(', ')} — not ${format}`);
167
171
  const raw = slideNotes(html);
@@ -171,13 +175,26 @@ export async function synthesizeSlides({
171
175
  const slides = raw.map((r) => (r ? cleanNotes(r, { marks: true }) : ''));
172
176
  const holds = markerPauses(html);
173
177
  const span = range ?? { from: 1, to: slides.length };
174
- if (range && prev) {
175
- const drift = voiceDrift(prev, { engine: tts.name, model: tts.model ?? null, voice }, { modelIsVoice: !tts.modelIsDefaultVoice });
176
- if (drift) {
177
- throw new Error(`${dir} is voiced in ${drift} — voicing slides ${span.from}–${span.to} in another would leave the `
178
- + 'track in two voices; voice the whole track, or give the other voice its own folder (-o)');
179
- }
178
+ const existing = prev?.slides?.some(Boolean) && prev.engine === tts.name;
179
+ if (existing && !voice && !voiceId && !prev.voice && !prev.voiceId) {
180
+ throw new Error(`${dir} has no recorded voice — set it in the voice panel or pass --voice`);
181
+ }
182
+ const picked = await resolveTtsVoice(tts, voice || voiceId
183
+ ? { voice, voiceId } : { voice: existing ? prev.voice : null, voiceId: existing ? prev.voiceId : null });
184
+ const identity = { voice: picked.name, voiceId: picked.id };
185
+ const drift = voiceDrift(prev, {
186
+ engine: tts.name, model: tts.model ?? null, ...identity,
187
+ // Before IDs were stored, the saved name could be an engine alias.
188
+ voice: existing && (!voice || voice === prev.voice) ? prev.voice ?? identity.voice : identity.voice,
189
+ }, {
190
+ modelIsVoice: !tts.modelIsDefaultVoice,
191
+ });
192
+ if (range && drift) {
193
+ throw new Error(`${dir} is voiced in ${drift} — voicing slides ${span.from}–${span.to} in another would leave the `
194
+ + 'track in two voices; voice the whole track, or give the other voice its own folder (-o)');
180
195
  }
196
+ const sameVoice = !drift && existing;
197
+ const priorTrack = sameVoice && (range || prev.voice || prev.voiceId) ? withTrackVoice(prev, identity) : null;
181
198
 
182
199
  const synthExt = extFor(tts.synth.mimeType ?? 'audio/wav');
183
200
  // An encoder is needed only to change what the engine spoke into something
@@ -200,6 +217,10 @@ export async function synthesizeSlides({
200
217
  }
201
218
  /** `audio` (in `from`, the synthesis format by default) into `dst` in the track's, or a plain write. */
202
219
  const encode = (audio, dst, from = synthExt) => {
220
+ // New audio takes its old lip-sync with it (#1244): a sidecar cut from the
221
+ // last take would have the character mouth that take. `decklight video`
222
+ // remakes what is missing; `decklight narrate <deck> --face` does too.
223
+ rmSync(dst.replace(/\.\w+$/, '.visemes.json'), { force: true });
203
224
  if (format === from) { writeFileSync(dst, audio); return; }
204
225
  const src = `${dst}.${from}`;
205
226
  writeFileSync(src, audio);
@@ -213,21 +234,25 @@ export async function synthesizeSlides({
213
234
  rmSync(src, { force: true });
214
235
  };
215
236
 
216
- // `--voice` omitted on ElevenLabs means "the first of your voices", and the
217
- // deck's picker offers that roster in that order — so the name is resolved
218
- // HERE, for the key. Left undefined it would hash differently from the
219
- // identical sentence the bridge just synthesized, and the cross-process
220
- // reuse the cache exists for would silently never hit.
221
- let keyVoice = voice;
222
- if (!keyVoice && tts.listVoices) {
223
- try { keyVoice = (await tts.listVoices())[0]?.name; } catch { /* keep it undefined */ }
224
- }
225
- /** `tts.synth`, but a sentence anyone has already paid for is free. */
226
- const synth = async (text) => {
237
+ const keyVoice = picked.id ?? picked.request;
238
+ // Every take that was sampled again because its length did not fit its
239
+ // text (#1005), as `slide N: …` lines: the run ends with them, a list of
240
+ // what is worth a listen.
241
+ const retried = [];
242
+ /**
243
+ * `tts.synth`, but a sentence anyone has already paid for is free, and a
244
+ * take whose length does not fit its text is sampled once more first.
245
+ */
246
+ const synth = async (text, where) => {
227
247
  const key = clipKey(tts, { voice: keyVoice, style, text });
228
248
  const hit = cache.read(key, synthExt);
229
249
  if (hit) return { wav: hit, usage: { chars: 0, cost: 0 }, cached: true };
230
- const out = await tts.synth(text, { voice, style });
250
+ const out = await checkedSynth(tts, text, { voice: picked.request, style });
251
+ if (out.take) {
252
+ const line = `${where}: ${takeLine(text, out.take)}`;
253
+ retried.push(line);
254
+ log(` retried ${line}`);
255
+ }
231
256
  cache.write(key, out.wav, synthExt);
232
257
  return { ...out, cached: false };
233
258
  };
@@ -244,9 +269,9 @@ export async function synthesizeSlides({
244
269
  * (ElevenLabs v3/v4) holds each ⟨PAUSE⟩ itself: it is sent as `[pause]`,
245
270
  * in one clip, and nothing is joined.
246
271
  */
247
- const voiceText = async (text, hold) => {
272
+ const voiceText = async (text, hold, where) => {
248
273
  text = tts.audioTags ? voicedPauses(text) : forEngine(tts, text);
249
- if (!text.includes(PAUSE_MARK)) return { ...(await synth(text)), ext: synthExt };
274
+ if (!text.includes(PAUSE_MARK)) return { ...(await synth(text, where)), ext: synthExt };
250
275
  const { lead: bare, runs: all } = speechRuns(text);
251
276
  let lead = bare;
252
277
  const runs = [];
@@ -256,7 +281,7 @@ export async function synthesizeSlides({
256
281
  else lead += r.pause;
257
282
  }
258
283
  const outs = [];
259
- for (const r of runs) outs.push(await synth(r.text));
284
+ for (const r of runs) outs.push(await synth(r.text, where));
260
285
  let clips = outs.map((o) => o.wav);
261
286
  if (synthExt !== 'wav') {
262
287
  clips = clips.map((clip, j) => {
@@ -276,40 +301,24 @@ export async function synthesizeSlides({
276
301
  usage: { cost: outs.reduce((sum, o) => sum + (o.usage?.cost ?? 0), 0) },
277
302
  };
278
303
  };
279
- // The header names every input the slide hash is taken over, and the hash
280
- // is taken FROM it — `manifestHash`, the function `decklight video` checks
281
- // with (#557). Stamped from the engine instead, a default-voice ElevenLabs
282
- // track hashed under the resolved voice beside a header with none, and the
283
- // check could never reproduce it: a re-voiced slide stayed stale forever.
284
- //
285
- // A track that already has audio keeps its own terms. Its `voice: null` is
286
- // the default voice, which is what an unasked-for voice resolves to, and its
287
- // format (absent: wav) is what its other slides were stamped under —
288
- // resolving either would turn every slide outside a range stale against a
289
- // header they were never checked under. A fresh track, or one whose header
290
- // never named a voice, gets the resolved one; with it, the hash is the clip
291
- // key shortened, as before.
292
- const inherits = prev?.slides?.some(Boolean) && prev.engine === tts.name;
293
- const headerVoice = voice ?? (inherits && prev.voice === null ? null : keyVoice) ?? null;
294
- const headerFormat = inherits ? prev.format : synthExt === 'wav' ? undefined : synthExt;
304
+ // Match the hash to the header the freshness checker will read. An existing
305
+ // track keeps its synthesis format, which is the format its hashes include.
306
+ const headerFormat = existing ? prev.format : synthExt === 'wav' ? undefined : synthExt;
307
+ // The language the engine is told (tts.lang), kept like the format: a track
308
+ // recorded before a deck's language reached the voice keeps a header
309
+ // without one, or its untouched slides would all read as stale.
310
+ const headerLang = existing ? prev.lang : tts.lang;
295
311
  const header = {
296
- engine: tts.name, model: tts.model ?? null, voice: headerVoice, style,
312
+ engine: tts.name, model: tts.model ?? null, voice: identity.voice, style,
313
+ ...(identity.voiceId ? { voiceId: identity.voiceId } : {}),
297
314
  ...(headerFormat ? { format: headerFormat } : {}),
315
+ ...(headerLang ? { lang: headerLang } : {}),
298
316
  };
299
317
  const slideHash = (text) => manifestHash(header, text);
300
- // What this core stamped before #557 — the clip key, under a header that
301
- // did not always name its voice or format. Still these words in this voice,
302
- // so a slide carrying it is kept and re-stamped rather than paid for again.
303
318
  const clipHash = (text) => clipKey(tts, { voice: keyVoice, style, text }).slice(0, 16);
304
- // ONE-TIME MIGRATION. The hash gained `model` and lost the style no engine
305
- // reads, so a folder recorded before that hashes differently — and would be
306
- // re-synthesized in full, handing an ElevenLabs user a bill for clips already
307
- // on disk. A slide matching the OLD formula is accepted once and re-stamped;
308
- // only a header without `model` can claim it, so it cannot be claimed twice.
309
- const legacyHash = (text) => createHash('sha256')
310
- .update(`${header.engine}|${voice}|${style}|${text}`).digest('hex').slice(0, 16);
311
- const preDatesModel = prev && prev.model === undefined
312
- && prev.engine === header.engine && prev.voice === voice && prev.style === style;
319
+ // Before the header stored voice IDs, some takes used the voice name's clip key.
320
+ const nameHash = (text) => clipKey(tts, { voice: picked.name, style, text }).slice(0, 16);
321
+ const sameStyle = sameVoice && manifestHash(prev, '') === manifestHash({ ...prev, style }, '');
313
322
  // A slide the DECK's recorder voiced was stamped over the file's old reading
314
323
  // of the notes, before entities were decoded; it spoke the decoded words all
315
324
  // along, so a stamp matching that reading still vouches for them.
@@ -319,29 +328,23 @@ export async function synthesizeSlides({
319
328
  // the track's, and a refresh of it keeps it.
320
329
  const extras = Object.fromEntries(Object.entries(prev ?? {}).filter(([k]) => !HEADER_KEYS.includes(k)));
321
330
  const manifestOf = (entries) => ({ ...extras, ...header, slides: entries });
322
- const save = (entries) => writeFileSync(join(dir, 'manifest.json'), JSON.stringify(manifestOf(entries), null, 1));
331
+ const save = (entries) => writeFileAtomic(join(dir, 'manifest.json'), JSON.stringify(manifestOf(entries), null, 1));
323
332
 
324
- mkdirSync(dir, { recursive: true });
325
- let skipped = 0;
326
- let cost = 0;
327
- const entries = [];
328
- for (let i = 0; i < slides.length; i++) {
333
+ const plan = slides.map((slide, i) => {
329
334
  const n = String(i + 1).padStart(2, '0');
330
335
  // Outside the range the track's own entry stands, segments and all: a
331
336
  // ranged run is a surgical redo, the promise `decklight narrate --mic --slides`
332
337
  // makes, and the video rendered from this folder still finds the rest.
333
- if (i + 1 < span.from || i + 1 > span.to) { entries.push(prev?.slides?.[i] ?? null); continue; }
338
+ if (i + 1 < span.from || i + 1 > span.to) return { entry: priorTrack?.slides?.[i] ?? null };
334
339
  // no words — or nothing but ⟨PAUSE⟩ and audio tags: direction with nothing to direct
335
- if (!hasWords(slides[i])) { entries.push(null); continue; }
340
+ if (!hasWords(slide)) return { entry: null };
336
341
  const txt = join(dir, `slide-${n}.txt`);
337
342
  // reused text: a second take (another engine or voice) narrates the SAME
338
343
  // words, not a re-roll
339
344
  const prior = reuseTextFrom.map((d) => join(d, `slide-${n}.txt`)).find((f) => existsSync(f));
340
- const text = prior ? canonMarks(readFileSync(prior, 'utf8')).replace(/\s+/g, ' ').trim() : slides[i];
345
+ const text = prior ? canonMarks(readFileSync(prior, 'utf8')).replace(/\s+/g, ' ').trim() : slide;
341
346
  const file = `slide-${n}.${format}`;
342
- writeFileSync(txt, writtenMarks(text)); // read back through canonMarks: the hash is of `text`
343
347
  const hash = slideHash(text);
344
- entries.push({ file, hash });
345
348
 
346
349
  // Unchanged: the audio on disk is still these words in this voice. The
347
350
  // file checked is the one the ENTRY names — a slide another producer wrote
@@ -349,11 +352,27 @@ export async function synthesizeSlides({
349
352
  // A file in another format is not kept: a track is one format, and a run
350
353
  // asked for another (`--format`) is converting it.
351
354
  const was = prev?.slides?.[i];
352
- if (was?.file && extname(was.file) === `.${format}`
353
- && (was.hash === hash || was.hash === clipHash(text) || (preDatesModel && was.hash === legacyHash(text))
354
- || (oldReading[i] && was.hash === slideHash(oldReading[i])))
355
- && existsSync(join(dir, was.file))) {
355
+ const kept = !force && was?.file && extname(was.file) === `.${format}`
356
+ && (was.hash === hash || was.hash === clipHash(text) || (sameVoice && was.hash === nameHash(text))
357
+ || (sameVoice && sameStyle && was.hash && (prev.voice || prev.voiceId)
358
+ && (entryMatches(prev, was, text) || (oldReading[i] && entryMatches(prev, was, oldReading[i])))))
359
+ && existsSync(join(dir, was.file));
360
+ return { n, txt, prior, text, file, hash, was, kept };
361
+ });
362
+ log(` voice work: ${plan.filter((slide) => slide.txt && !slide.kept).length} slides to synthesize`);
363
+
364
+ mkdirSync(dir, { recursive: true });
365
+ let skipped = 0;
366
+ let cost = 0;
367
+ const entries = plan.map((slide, i) => (slide.txt ? priorTrack?.slides?.[i] ?? null : slide.entry));
368
+ for (const [i, slide] of plan.entries()) {
369
+ const { n, txt, prior, text, file, hash, was, kept } = slide;
370
+ if (!txt) continue;
371
+ writeFileSync(txt, writtenMarks(text)); // read back through canonMarks: the hash is of `text`
372
+ entries[i] = { file, hash };
373
+ if (kept) {
356
374
  entries[i] = { ...was, hash };
375
+ delete entries[i].hashVoice;
357
376
  // Carry the segments across only while they are still on disk — the
358
377
  // manifest is the one thing that knows they are there.
359
378
  if (!was.segments?.every((sg) => existsSync(join(dir, sg.file)))) delete entries[i].segments;
@@ -373,7 +392,7 @@ export async function synthesizeSlides({
373
392
  for (let k = 0; k < segs.length; k++) {
374
393
  const kk = String(k + 1).padStart(2, '0');
375
394
  const beat = `slide-${n}-${kk}.${format}`;
376
- const out = await voiceText(segs[k], holds[i]);
395
+ const out = await voiceText(segs[k], holds[i], `slide ${i + 1} beat ${k + 1}`);
377
396
  if (out.cached) cachedBeats++;
378
397
  // the beat's own words beside its audio — tools/lipsync.mjs hands this
379
398
  // to Rhubarb as the dialog hint for that beat
@@ -384,11 +403,12 @@ export async function synthesizeSlides({
384
403
  }
385
404
  const list = join(dir, `slide-${n}.concat`);
386
405
  writeFileSync(list, `${parts.map((p) => `file '${join(dir, p).replaceAll("'", "'\\''")}'`).join('\n')}\n`);
406
+ rmSync(join(dir, `slide-${n}.visemes.json`), { force: true }); // the slide's audio is new too
387
407
  run('ffmpeg', ['-y', '-f', 'concat', '-safe', '0', '-i', list, '-c', 'copy', join(dir, file)], { stdio: 'ignore' });
388
408
  rmSync(list, { force: true });
389
409
  entries[i].segments = parts.map((p) => ({ file: p }));
390
410
  } else {
391
- const out = await voiceText(text, holds[i]);
411
+ const out = await voiceText(text, holds[i], `slide ${i + 1}`);
392
412
  if (out.cached) cachedBeats++;
393
413
  slideCost = out.usage?.cost ?? 0;
394
414
  encode(out.wav, join(dir, file), out.ext);
@@ -402,10 +422,10 @@ export async function synthesizeSlides({
402
422
  save(entries); // crash-safe: an interrupted run resumes from here
403
423
  }
404
424
  save(entries);
405
- return { manifest: manifestOf(entries), skipped, cost };
425
+ return { manifest: manifestOf(entries), skipped, cost, retried };
406
426
  }
407
427
 
408
- /** The plan line `decklight narrate` prints — the edit server reads its `· N to voice`. */
428
+ /** The notes and range summary `decklight narrate` prints. */
409
429
  export function planLine(name, html, range, ranged) {
410
430
  const texts = slideNotes(html).map((r) => (r ? cleanNotes(r) : ''));
411
431
  const span = range ?? { from: 1, to: texts.length };
@@ -47,8 +47,11 @@ function notesPerSlide(html) {
47
47
  * entry has no local dir and is not one). `recordedSlides(dir)` → the 1-based
48
48
  * slide numbers with audio in that dir, `[]` for a dir with none. Both are
49
49
  * injected so this stays testable without a filesystem or the init walkers.
50
+ * `renumber`, a Map dir → (old slide → new slide | null), names the tracks
51
+ * whose files were renumbered with the edit: those are read slide by slide
52
+ * against where each recording went, never as reshaped.
50
53
  */
51
- export function recordingImpact(before, after, { dirsOf, recordedSlides }) {
54
+ export function recordingImpact(before, after, { dirsOf, recordedSlides, renumber = null }) {
52
55
  const beforeDirs = dirsOf(before);
53
56
  const afterDirs = new Set(dirsOf(after));
54
57
  const nb = notesPerSlide(before);
@@ -61,6 +64,18 @@ export function recordingImpact(before, after, { dirsOf, recordedSlides }) {
61
64
  const recorded = recordedSlides(dir);
62
65
  if (!recorded.length) continue; // nothing on disk → nothing to lose
63
66
  if (!afterDirs.has(dir)) { orphaned.push({ dir, slides: recorded.length }); continue; }
67
+ // its recordings followed their slides (#920): each is read against the
68
+ // slide it is on now, and a count that changed is no longer a shift
69
+ const follow = renumber?.get?.(String(dir).replace(/^\.\//, '').replace(/\/+$/, ''));
70
+ if (follow) {
71
+ const slides = [];
72
+ for (const k of recorded) {
73
+ const n = follow(k);
74
+ if (n != null && n <= na.length && nb[k - 1] !== na[n - 1]) slides.push(n);
75
+ }
76
+ if (slides.length) stale.push({ dir, slides: slides.sort((x, y) => x - y) });
77
+ continue;
78
+ }
64
79
  // still configured — did the slides move or change under it?
65
80
  if (nb.length !== na.length) { reshaped.push({ dir, before: nb.length, after: na.length }); continue; }
66
81
  const has = new Set(recorded);
@@ -15,9 +15,15 @@
15
15
  * clip that is only a laugh, or, on an engine that cannot act on tags, a clip
16
16
  * of nothing.
17
17
  */
18
+ // A sentence ends at `.`, `!`, `?` or `…`, or at their full-width forms
19
+ // (`。!?`, which Chinese and Japanese write with no space after), and takes
20
+ // with it whatever closes around it: an English quote or bracket, a French
21
+ // guillemet (`« Non. »`, the space before it included), a CJK bracket.
22
+ const SENTENCE = /[^.!?…。!?]+[.!?…。!?]+(?:[”’"')\]」』)]|[   ]?»)*|[^.!?…。!?]+$/g;
23
+
18
24
  export function splitSentences(text) {
19
25
  const out = [];
20
- for (let s of ((text ?? '').match(/[^.!?…]+[.!?…]+[”’"')\]]*|[^.!?…]+$/g) ?? []).map((x) => x.trim()).filter(Boolean)) {
26
+ for (let s of ((text ?? '').match(SENTENCE) ?? []).map((x) => x.trim()).filter(Boolean)) {
21
27
  // a `[pause]` a voice holds itself (`voicedPauses`) belongs to the words
22
28
  // BEFORE it, as a ⟨PAUSE⟩ does — and so does any tag ahead of it
23
29
  const held = out.length ? LEADING_PAUSE.exec(s) : null;