decklight 0.8.0 → 0.9.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 (133) hide show
  1. package/PLATFORM.md +666 -0
  2. package/README.md +224 -150
  3. package/SPEC.md +732 -886
  4. package/cli/agent-review.mjs +245 -0
  5. package/cli/agents.mjs +25 -5
  6. package/cli/associate.mjs +12 -12
  7. package/cli/audit.mjs +42 -10
  8. package/cli/banner.mjs +41 -17
  9. package/cli/bundle-audio.mjs +183 -0
  10. package/cli/bundle.mjs +383 -31
  11. package/cli/cast.mjs +7 -7
  12. package/cli/check.mjs +961 -0
  13. package/cli/clone-deck.mjs +179 -0
  14. package/cli/commands.mjs +345 -0
  15. package/cli/comments.mjs +64 -18
  16. package/cli/commit-flow.mjs +44 -19
  17. package/cli/commit-message.mjs +51 -74
  18. package/cli/commit-split.mjs +601 -0
  19. package/cli/deck-refs.mjs +59 -0
  20. package/cli/deck-routes.mjs +67 -0
  21. package/cli/deckfile.mjs +3 -5
  22. package/cli/decklight.mjs +68 -289
  23. package/cli/design-system-deps.mjs +209 -0
  24. package/cli/design-system-edit.mjs +194 -0
  25. package/cli/design-system-refs.mjs +409 -0
  26. package/cli/design-system.mjs +429 -0
  27. package/cli/doctor.mjs +115 -0
  28. package/cli/edit-git.mjs +353 -0
  29. package/cli/edit-handover.mjs +445 -0
  30. package/cli/edit-look.mjs +388 -0
  31. package/cli/edit-slides.mjs +683 -0
  32. package/cli/edit.mjs +2126 -842
  33. package/cli/enhance.mjs +483 -0
  34. package/cli/extension.mjs +10 -10
  35. package/cli/font-refs.mjs +273 -0
  36. package/cli/font.mjs +246 -0
  37. package/cli/git-tree.mjs +1 -1
  38. package/cli/git.mjs +65 -11
  39. package/cli/import.mjs +56 -10
  40. package/cli/init.mjs +400 -234
  41. package/cli/library.mjs +127 -0
  42. package/cli/loader.mjs +3 -1
  43. package/cli/marketplace.mjs +215 -21
  44. package/cli/narrate.mjs +176 -0
  45. package/cli/open-browser.mjs +63 -0
  46. package/cli/open.mjs +943 -0
  47. package/cli/pdf.mjs +41 -13
  48. package/cli/pkg.mjs +44 -2
  49. package/cli/plugin.mjs +43 -41
  50. package/cli/port-conflict.mjs +53 -23
  51. package/cli/pptx-export.mjs +71 -26
  52. package/cli/publish.mjs +8 -4
  53. package/cli/qr.mjs +1 -1
  54. package/cli/record.mjs +14 -12
  55. package/cli/remote.mjs +11 -11
  56. package/cli/restore.mjs +11 -4
  57. package/cli/review-ref.mjs +125 -0
  58. package/cli/review-remote.mjs +92 -48
  59. package/cli/review-routes.mjs +254 -0
  60. package/cli/review-store.mjs +47 -7
  61. package/cli/review-submit.mjs +47 -57
  62. package/cli/runtime-link.mjs +560 -0
  63. package/cli/serve.mjs +235 -44
  64. package/cli/setup.mjs +112 -0
  65. package/cli/sign.mjs +1 -1
  66. package/cli/skill-content.mjs +190 -33
  67. package/cli/skills.mjs +107 -24
  68. package/cli/start.mjs +110 -0
  69. package/cli/supervise.mjs +6 -6
  70. package/cli/theme-refs.mjs +515 -0
  71. package/cli/theme.mjs +181 -137
  72. package/cli/trust.mjs +83 -0
  73. package/cli/units.mjs +39 -42
  74. package/cli/update-check.mjs +1 -5
  75. package/cli/upgrade.mjs +194 -28
  76. package/cli/upstream.mjs +4 -3
  77. package/cli/util.mjs +4 -4
  78. package/cli/wizard.mjs +6 -6
  79. package/dist/build-info.json +1 -1
  80. package/dist/decklight.css +1126 -49
  81. package/dist/decklight.js +212 -115
  82. package/dist/decklight.js.map +4 -4
  83. package/docs/GLOSSARY.md +141 -0
  84. package/docs/architecture.svg +17 -17
  85. package/package.json +4 -2
  86. package/themes/README.md +9 -8
  87. package/themes/reveal-solarized.css +10 -0
  88. package/tools/args.mjs +20 -0
  89. package/tools/atomic-write.mjs +48 -0
  90. package/tools/brand-palette.mjs +717 -0
  91. package/tools/bridge.mjs +1 -1
  92. package/tools/build-groups.mjs +42 -0
  93. package/tools/color.mjs +48 -0
  94. package/tools/deck-html.mjs +396 -11
  95. package/tools/design-system-format.mjs +753 -0
  96. package/tools/elevenlabs-tts.mjs +110 -17
  97. package/tools/exec.mjs +35 -2
  98. package/tools/extension-check.mjs +31 -7
  99. package/tools/font-format.mjs +190 -0
  100. package/tools/font-stacks.mjs +24 -0
  101. package/tools/gemini-tts.mjs +3 -0
  102. package/tools/lipsync-config.mjs +103 -0
  103. package/tools/lipsync-engines.mjs +205 -2
  104. package/tools/lipsync-server.mjs +264 -41
  105. package/tools/lipsync.mjs +37 -18
  106. package/tools/local-voice.mjs +32 -42
  107. package/tools/narration-manifest.mjs +196 -0
  108. package/tools/narration-synth.mjs +416 -0
  109. package/tools/pptx.mjs +776 -19
  110. package/tools/publish-targets.mjs +1 -1
  111. package/tools/publish-voices.mjs +3 -3
  112. package/tools/recording-impact.mjs +7 -3
  113. package/tools/render-theme.mjs +33 -0
  114. package/tools/review-anchor.mjs +28 -12
  115. package/tools/semver.mjs +40 -0
  116. package/tools/sentences.mjs +180 -0
  117. package/tools/shot.mjs +14 -7
  118. package/tools/site-voices.mjs +232 -0
  119. package/tools/template-theme.mjs +1 -1
  120. package/tools/test-impact.mjs +19 -10
  121. package/tools/theme-check.mjs +30 -3
  122. package/tools/tts-cache.mjs +4 -3
  123. package/tools/tts-engines.mjs +38 -20
  124. package/tools/tts-setup.mjs +7 -7
  125. package/tools/video-options.mjs +34 -0
  126. package/tools/video.mjs +461 -48
  127. package/tools/voiceover-server.mjs +185 -104
  128. package/tools/voiceover.mjs +119 -261
  129. package/tools/zip.mjs +1 -1
  130. package/cli/dev.mjs +0 -623
  131. package/cli/present.mjs +0 -853
  132. package/cli/review.mjs +0 -361
  133. package/tools/publish-site-voices.mjs +0 -75
@@ -8,12 +8,12 @@
8
8
  // [--voice <name>] [--data-dir <dir>]
9
9
  // [--project <id>] [--location global] [--lang en-US]
10
10
  // [--tts-model gemini-2.5-pro-tts]
11
- // [--model qwen3:30b-a3b] [--no-llm] [--reuse-text]
11
+ // [--reuse-text]
12
12
  // [--keep-wav] (keep the lossless intermediates —
13
13
  // tools/lipsync.mjs consumes them)
14
14
  //
15
- // Engines (tools/tts-engines.mjs — the same three the live bridge speaks with;
16
- // the built-in macOS voices were dropped: not good enough):
15
+ // Engines (tools/tts-engines.mjs — the same six the live bridge speaks with:
16
+ // the four below, and the system voice, `say` on macOS and `sapi` on Windows):
17
17
  // piper — neural local TTS, fully offline, unlimited, free. --voice takes a
18
18
  // piper model name (default en_US-ryan-high, a natural US male):
19
19
  // uv tool install piper-tts
@@ -36,45 +36,65 @@
36
36
  // gcloud auth application-default login.
37
37
  //
38
38
  // Pipeline: extract each slide's notes (HTML asides or markdown Note: blocks,
39
- // ⟨CLICK⟩ markers removed) → optionally rewrite into flowing narration with a
40
- // LOCAL Ollama model (LLMs write text; they don't speak) → synthesize → AAC
41
- // .m4a per slide + manifest.json. --reuse-text skips the LLM pass and
42
- // re-voices the existing slide-NN.txt files, so switching voices or engines
43
- // doesn't re-roll the narration. Audio is a build artifact, not source.
39
+ // ⟨CLICK⟩ markers removed) → synthesize them as written → a file per slide in
40
+ // the track's format + manifest.json. The pipeline itself is
41
+ // tools/narration-synth.mjs, which every producer of a track shares (#555);
42
+ // this file is its command line. --reuse-text re-voices the existing slide-NN.txt files, so a
43
+ // script edited by hand, or another voice or engine, narrates the same words.
44
+ // Audio is a build artifact, not source.
45
+ //
46
+ // Nothing here writes or rewrites the words. The notes ARE the script: a
47
+ // deck's content — its notes included — is written by the author or by the
48
+ // agent they ask (A in write mode, SPEC PRESENTING), and an agent that runs on
49
+ // a local model brings that model with it. A second writer here, voicing words
50
+ // nobody had read, was the wrong place for one.
44
51
 
45
- import { readFileSync, writeFileSync, mkdirSync, rmSync, existsSync } from 'node:fs';
46
- import { createHash } from 'node:crypto';
47
- import { execFileSync } from 'node:child_process';
52
+ import { readFileSync, existsSync } from 'node:fs';
48
53
  import { resolve, join, basename } from 'node:path';
49
54
  import { homedir } from 'node:os';
50
55
  import { createEngine } from './tts-engines.mjs';
51
- import { clipKey, createTtsCache, extFor } from './tts-cache.mjs';
56
+ import { createTtsCache } from './tts-cache.mjs';
52
57
  import { argReader } from './args.mjs';
53
- import { sectionBodies, NOTES_ASIDE, cleanNotes, notesSegments, isHiddenSection } from './deck-html.mjs';
54
- import { run, PROBE_MS, CODEC_MS } from './exec.mjs';
58
+ import { sectionBodies } from './deck-html.mjs';
59
+ import { parseSlideRange } from './video.mjs';
60
+ import { synthesizeSlides, readTrack, trackFormat, planLine, TRACK_FORMATS, DEFAULT_FORMAT } from './narration-synth.mjs';
55
61
 
56
62
  const args = process.argv.slice(2);
57
63
 
58
- const HELP = `decklight voiceover — batch-synthesize a deck's narration into a folder
64
+ const HELP = `decklight narrate — batch-synthesize a deck's narration into a folder
59
65
 
60
66
  Usage:
61
- decklight voiceover <deck.html> [-o <dir>] [--engine piper|chirp|gemini|elevenlabs]
62
- [--voice <name>] [--no-llm] [--reuse-text] [--keep-wav]
63
- [--no-cache]
67
+ decklight narrate <deck.html> [-o <dir>] [--engine piper|chirp|gemini|elevenlabs]
68
+ [--voice <name>] [--format m4a|wav|mp3] [--reuse-text] [--keep-wav]
69
+ [--slides a-b] [--no-cache]
64
70
 
65
- The headless counterpart of the deck's V \u2192 Record this deck\u2026: it reads each slide's speaker
66
- notes and writes one slide-NN.m4a per slide (plus a file per \u27e8CLICK\u27e9 beat)
71
+ The headless counterpart of the deck's V → Record this deck…: it reads each slide's speaker
72
+ notes and writes one slide-NN file per slide (plus a file per [click] beat)
67
73
  and a manifest.json into <dir>, so a deck can point at it with
68
- narration: { files: [{ label, dir, segments: true }] }.
74
+ narration: { files: '<dir>', segments: true } (m4a, the default)
75
+ narration: { files: '<dir>', ext: 'wav', segments: true } (--format wav)
76
+ — the same one-track form decklight narrate --mic and the deck's recorder print.
77
+ Several tracks to pick between are a list of the same fields, each labelled:
78
+ narration: { files: [{ label: 'Anna', dir: 'voices/anna', segments: true }, …] }
79
+
80
+ A folder that already holds a track is REFRESHED as that track: its engine,
81
+ voice, style and format are the defaults, so voicing one stale slide of a track
82
+ the deck's recorder made writes wav in the same voice, beside the rest. A flag
83
+ overrides any of them; a --slides run in another voice is refused, since a
84
+ track has one voice.
69
85
 
70
86
  -o <dir> output folder (default: <deck>/voiceover)
71
87
  --engine piper (local, free, default) · chirp · gemini · elevenlabs
72
88
  --voice the engine's voice name (piper: a model name; elevenlabs: omit
73
89
  for the first of YOUR voices)
74
- --no-llm skip the local-LLM notes rewrite; voice the notes as written
75
- --reuse-text re-voice the existing slide-NN.txt without re-rolling the text
76
- — switch voices or engines without a new narration pass
77
- --keep-wav keep the lossless WAVs (tools/lipsync.mjs consumes them)
90
+ --format m4a (default for a new track) · wav · mp3 (an existing track
91
+ keeps its own)
92
+ --reuse-text re-voice the existing slide-NN.txt (edit one to change what is
93
+ said) — switch voices or engines on the same script
94
+ --keep-wav keep the lossless WAVs of an m4a/mp3 track (tools/lipsync.mjs
95
+ consumes them)
96
+ --slides a-b voice only this range (1-based, inclusive; "7" for one slide)
97
+ — every other slide's files and manifest entry are left alone
78
98
  --no-cache re-synthesize every slide, ignoring the shared clip cache
79
99
 
80
100
  Synthesis is cached on disk (~/.cache/decklight/tts) under a key made of
@@ -86,260 +106,98 @@ Cloud engines need --project or $GOOGLE_CLOUD_PROJECT and application-default
86
106
  credentials; elevenlabs needs $ELEVENLABS_API_KEY. Audio is a build artifact.`;
87
107
 
88
108
  if (args.includes('--help') || args.includes('-h')) { console.log(HELP); process.exit(0); }
89
- const deckPath = args.find((a) => !a.startsWith('-'));
90
- if (!deckPath) { console.error('decklight voiceover: name the deck to voice\n\n' + HELP); process.exit(1); }
109
+ // Every option voiceover takes, and nothing else. It used to accept anything
110
+ // that started with a dash and ignore whatever it did not read, so a removed or
111
+ // mistyped flag was dropped without a word and the run went ahead doing
112
+ // something else. The value options are listed apart because the token after
113
+ // one is its VALUE, not the deck — which is also how `-o out deck.html` used to
114
+ // take `out` for the deck.
115
+ const VALUE_OPTIONS = new Set(['-o', '--engine', '--voice', '--style', '--data-dir', '--project',
116
+ '--location', '--lang', '--tts-model', '--tts-format', '--slides', '--format']);
117
+ const SWITCHES = new Set(['--reuse-text', '--keep-wav', '--no-cache']);
118
+ let deckPath;
119
+ for (let i = 0; i < args.length; i++) {
120
+ const a = args[i];
121
+ if (VALUE_OPTIONS.has(a)) { i++; continue; }
122
+ if (SWITCHES.has(a)) continue;
123
+ if (a.startsWith('-')) {
124
+ console.error(`decklight narrate: unknown option ${a} — see decklight narrate --help`);
125
+ process.exit(1);
126
+ }
127
+ deckPath ??= a;
128
+ }
129
+ if (!deckPath) { console.error('decklight narrate: name the deck to voice\n\n' + HELP); process.exit(1); }
91
130
  const { opt } = argReader(args);
131
+ // before the engine and encoder probes: a mistyped deck or a range past its end
132
+ // is not a missing ffmpeg
133
+ if (!existsSync(deckPath)) { console.error(`decklight narrate: no deck at ${deckPath}`); process.exit(1); }
134
+ const html = readFileSync(deckPath, 'utf8');
135
+ let range;
136
+ try { range = parseSlideRange(opt('--slides'), sectionBodies(html).length); } catch (e) {
137
+ console.error(`decklight narrate: ${e.message}`);
138
+ process.exit(1);
139
+ }
92
140
  const outDir = resolve(opt('-o', join(resolve(deckPath, '..'), 'voiceover')));
93
- const engine = opt('--engine', 'piper');
141
+
142
+ // The track already in the folder, if any, and what it was voiced with: the
143
+ // defaults for everything a flag does not say. Refreshing a track is voicing it
144
+ // AS that track — the voice its other slides speak in, the format its files
145
+ // are in — not re-voicing it in whatever this command defaults to (#555).
146
+ const prev = readTrack(outDir);
147
+ const engine = opt('--engine', prev?.engine ?? 'piper');
148
+ const track = prev?.engine === engine ? prev : null; // its header speaks for THIS engine only
94
149
  // elevenlabs has no default name worth guessing: the roster is the account's,
95
150
  // and undefined means "the first of yours", which is what you came for
96
- const voice = opt('--voice', engine === 'piper' ? 'en_US-ryan-high'
151
+ const voice = opt('--voice', track ? track.voice : engine === 'piper' ? 'en_US-ryan-high'
97
152
  : engine === 'elevenlabs' ? undefined : 'Alnilam');
98
- const style = opt('--style',
153
+ const style = opt('--style', track?.style ??
99
154
  'Read in a warm, welcoming tone, like a friendly battle-hardened senior ' +
100
155
  'engineer who is still curious about new technology.');
156
+ // the model is identity only where the engine has more than one per voice
157
+ const model = opt('--tts-model', track?.model != null && (engine === 'elevenlabs' || engine === 'gemini') ? track.model : undefined);
158
+ const format = opt('--format', trackFormat(prev) ?? DEFAULT_FORMAT);
159
+ if (!TRACK_FORMATS.includes(format)) {
160
+ console.error(`decklight narrate: --format is ${TRACK_FORMATS.join(', ')}, not ${format}`);
161
+ process.exit(1);
162
+ }
101
163
  const dataDir = resolve(opt('--data-dir', join(homedir(), '.local', 'share', 'piper')));
102
164
  const project = opt('--project', process.env.GOOGLE_CLOUD_PROJECT);
103
- const model = opt('--model', 'qwen3:30b-a3b');
104
- const useLlm = !args.includes('--no-llm');
105
- const reuseText = args.includes('--reuse-text');
106
- const keepWav = args.includes('--keep-wav');
107
- const useCache = !args.includes('--no-cache');
108
165
 
109
- // one factory, three engines — the same ones the live bridge speaks with
166
+ // one factory, every engine — the same ones the live bridge speaks with
110
167
  let tts;
111
168
  try {
112
169
  tts = createEngine({
113
- engine, project, voice, dataDir,
114
- model: opt('--tts-model'), location: opt('--location'), lang: opt('--lang'),
115
- format: opt('--tts-format'),
170
+ engine, project, voice, dataDir, model,
171
+ location: opt('--location'), lang: opt('--lang'), format: opt('--tts-format'),
116
172
  });
117
173
  } catch (e) {
118
174
  console.error(e.message);
119
175
  process.exit(1);
120
176
  }
121
177
 
122
- // WAV → AAC. ffmpeg everywhere; afconvert is Core Audio, so it only exists on
123
- // macOS — probing in that order keeps this working off a Mac (as tools/lipsync.mjs
124
- // already does), and both engines' output goes through here.
125
- const have = (bin, flags = ['-version']) => {
126
- try { run(bin, flags, { stdio: 'ignore', timeout: PROBE_MS }); return true; } catch (e) { return e?.code !== 'ENOENT'; }
127
- };
128
- const encoder = have('ffmpeg') ? 'ffmpeg' : have('afconvert') ? 'afconvert' : null;
129
- if (!encoder) {
130
- console.error('no AAC encoder — install ffmpeg (apt install ffmpeg / brew install ffmpeg)');
131
- process.exit(1);
132
- }
133
- const toAac = (wav, m4a) => run(encoder, encoder === 'ffmpeg'
134
- ? ['-y', '-i', wav, '-c:a', 'aac', '-b:a', '128k', m4a]
135
- : ['-f', 'm4af', '-d', 'aac', wav, m4a], { stdio: 'ignore', timeout: CODEC_MS, why: 'the encoder is stuck on this file — check it plays, then retry' });
136
-
137
- // ── extract per-slide narration text ─────────────────────────────────────────
138
- const html = readFileSync(deckPath, 'utf8');
139
- const sections = sectionBodies(html);
140
- const raw = sections.map((sec) => {
141
- if (isHiddenSection(sec)) return ''; // no file for a hidden slide; the numbering stays
142
- const aside = sec.match(NOTES_ASIDE);
143
- if (aside) return aside[1];
144
- const md = sec.match(/^Note:\s*$([\s\S]*?)(?=^Rehearse:\s*$|<\/script>)/m);
145
- return md ? md[1] : '';
146
- });
147
- const slides = raw.map(cleanNotes);
148
- /**
149
- * A slide's ⟨CLICK⟩ segments, or null when there is only one.
150
- *
151
- * These are the author's own build cues, and the sync rule they carry already
152
- * ships: src/core/narration.js speaks segment k over build step k in live
153
- * playback, and captions, rehearse mode and the notes editor all read the same
154
- * segmentation. Recording them separately is what lets a rendered mp4 mirror
155
- * that (SPEC PRESENTING). An empty segment is dropped rather than synthesised
156
- * as silence — a ⟨CLICK⟩ at the very start or end of a note is punctuation,
157
- * not a beat.
158
- */
159
- // Segmenting needs ffmpeg specifically: the per-slide file is CONCATENATED from
160
- // the segments, and afconvert (Core Audio, macOS-only) has no concat demuxer.
161
- // Without it the slide is synthesised whole, exactly as before.
162
- const canSegment = encoder === 'ffmpeg';
163
- const segmented = raw.map((r) => (canSegment ? notesSegments(r) : null));
164
- if (!canSegment && raw.some((r) => notesSegments(r))) {
165
- console.log(' note: ⟨CLICK⟩ segments need ffmpeg to concatenate — narrating each slide whole');
166
- }
167
- console.log(`${basename(deckPath)}: ${slides.length} slides, ${slides.filter(Boolean).length} with notes`);
168
-
169
- // ── optional narration pass through a local model ────────────────────────────
170
- function narrate(text, slideNo) {
171
- if (!useLlm || !text) return text;
172
- const prompt =
173
- 'Rewrite these presentation speaker notes as a single flowing voice-over ' +
174
- 'narration paragraph. Natural spoken English, roughly the same length, no ' +
175
- 'headings, no stage directions, no markdown, plain text only. Notes: ' +
176
- text + ' /no_think';
177
- try {
178
- const out = execFileSync('ollama', ['run', model, prompt], { encoding: 'utf8', timeout: 180000 });
179
- const cleaned = out.replace(/<think>[\s\S]*?<\/think>/g, '').trim();
180
- return cleaned || text;
181
- } catch (e) {
182
- console.warn(` slide ${slideNo}: ollama failed (${String(e).slice(0, 60)}) — using raw notes`);
183
- return text;
184
- }
185
- }
186
-
187
- // ── synthesize ────────────────────────────────────────────────────────────────
188
- // TWO layers of reuse, and they answer different questions.
189
- //
190
- // The MANIFEST answers "is this folder already correct?" — a hash per slide,
191
- // so a rerun re-synthesizes only the slides whose narration actually changed
192
- // and leaves the rest of the .m4a files alone.
193
- //
194
- // The CLIP CACHE (tools/tts-cache.mjs) answers "has anyone, ever, paid for
195
- // these exact words?" — it is keyed by content rather than by folder, so it
196
- // survives a different -o, a deleted manifest, and above all the process
197
- // boundary: the live bridge fills the same cache while you preview the deck,
198
- // and this run collects it. An ElevenLabs deck used to be billed twice for
199
- // that, once in the browser and once here.
200
- //
201
- // Both keys carry the same fields, and the reason is one bug rather than two:
202
- // anything that changes the AUDIO must change the key. `model` is in them
203
- // because `--tts-model eleven_v3` is a different voice performance of the same
204
- // words, and a hash without it skipped the slide and kept the old take. STYLE
205
- // is in them only when the engine can act on it — every engine but gemini and
206
- // ElevenLabs v3 ignores the instruction entirely, and letting a style the
207
- // engine never read change the hash would miss the bridge's own clip for no
208
- // audible reason.
209
- mkdirSync(outDir, { recursive: true });
210
- let totalCost = 0;
211
- const audioExt = extFor(tts.synth.mimeType ?? 'audio/wav');
212
- const clips = createTtsCache({ enabled: useCache });
213
- clips.prune();
214
- // `--voice` omitted on ElevenLabs means "the first of your voices", and the
215
- // deck's picker offers that same roster in that same order — so the name is
216
- // resolved HERE, for the key. Left undefined it would hash differently from
217
- // the identical sentence the bridge just synthesized, and the cross-process
218
- // reuse this cache exists for would silently never hit.
219
- let keyVoice = voice;
220
- if (!keyVoice && tts.listVoices) {
221
- try { keyVoice = (await tts.listVoices())[0]?.name; } catch { /* keep it undefined */ }
222
- }
223
-
224
- /** `tts.synth`, but a sentence anyone has already paid for is free. */
225
- async function synth(text) {
226
- const key = clipKey(tts, { voice: keyVoice, style, text });
227
- const hit = clips.read(key, audioExt);
228
- if (hit) return { wav: hit, usage: { chars: 0, cost: 0 }, cached: true };
229
- const out = await tts.synth(text, { voice, style });
230
- clips.write(key, out.wav, audioExt);
231
- return { ...out, cached: false };
232
- }
233
- // The manifest hash is the CLIP KEY, shortened: one definition of "the same
234
- // audio", so the folder-level skip and the content-level cache can never
235
- // disagree about whether a slide changed.
236
- const slideHash = (text) => clipKey(tts, { voice: keyVoice, style, text }).slice(0, 16);
237
- // ONE-TIME MIGRATION. The hash above gained `model` and lost the style no
238
- // engine reads, so every folder recorded before this change hashes differently
239
- // — and a folder that hashes differently is re-synthesized in full. That audio
240
- // is not stale; it is exactly what today's key describes, and re-rolling it
241
- // would hand an ElevenLabs user a bill for clips already on their disk.
242
- //
243
- // So a slide matching the OLD formula is accepted once and re-stamped. The
244
- // gate is `prev.model === undefined`: only a manifest written before this
245
- // change lacks that field, so the allowance cannot be claimed twice, and a
246
- // later `--tts-model` switch is a genuine miss again. The one case it lets
247
- // through is changing the model in the SAME run as the upgrade — narrow, and
248
- // `--no-cache` is the way out of it.
249
- const legacyHash = (text) => createHash('sha256')
250
- .update(`${engine}|${voice}|${style}|${text}`).digest('hex').slice(0, 16);
251
- const preDatesModel = (m) => m && m.model === undefined
252
- && m.engine === engine && m.voice === voice && m.style === style;
253
- let prev = null;
178
+ // `· N to voice` closes the line because the edit server reads it: an export
179
+ // that voices its slides first counts them off against this number.
180
+ console.log(planLine(basename(deckPath), html, range, !!opt('--slides')));
181
+ const reuseTextFrom = args.includes('--reuse-text')
182
+ // falls back to the deck's default voiceover/ scripts so a second take
183
+ // (other engine/voice) narrates the SAME text, not a re-roll
184
+ ? [outDir, join(resolve(deckPath, '..'), 'voiceover')]
185
+ : [];
254
186
  try {
255
- const m = JSON.parse(readFileSync(join(outDir, 'manifest.json'), 'utf8'));
256
- if (m && Array.isArray(m.slides)) prev = m;
257
- } catch { /* no previous manifest, or the old array format: regenerate all */ }
258
- let skipped = 0;
259
- const manifest = [];
260
- for (let i = 0; i < slides.length; i++) {
261
- const n = String(i + 1).padStart(2, '0');
262
- if (!slides[i]) { manifest.push(null); continue; }
263
- const txt = join(outDir, `slide-${n}.txt`);
264
- // --reuse-text falls back to the deck's default voiceover/ scripts so a
265
- // second take (other engine/voice) narrates the SAME text, not a re-roll
266
- const prior = [txt, join(resolve(deckPath, '..'), 'voiceover', `slide-${n}.txt`)]
267
- .find((f) => reuseText && existsSync(f));
268
- const text = prior ? readFileSync(prior, 'utf8').trim() : narrate(slides[i], i + 1);
269
- const wav = join(outDir, `slide-${n}.wav`);
270
- const m4a = join(outDir, `slide-${n}.m4a`);
271
- writeFileSync(txt, text);
272
- const hash = slideHash(text);
273
- manifest.push({ file: `slide-${n}.m4a`, hash });
274
- const stamped = prev?.slides?.[i]?.hash;
275
- if ((stamped === hash || (preDatesModel(prev) && stamped === legacyHash(text))) && existsSync(m4a)) {
276
- // Carry the segments across, or an unchanged slide loses its build sync on
277
- // the next rerun: the audio is still on disk and the manifest is the only
278
- // thing that knows it is there.
279
- const kept = prev.slides[i].segments;
280
- if (kept?.every((sg) => existsSync(join(outDir, sg.file)))) manifest[i].segments = kept;
281
- skipped++;
282
- console.log(` slide ${n}: unchanged — kept${manifest[i].segments ? ` (${manifest[i].segments.length} segments)` : ''}`);
283
- continue;
284
- }
285
- // A segmented slide is synthesised segment by segment, and the per-slide file
286
- // is CONCATENATED from those — one synthesis, both shapes. TTS is billed per
287
- // character; asking for the same words twice to get the same audio cut two
288
- // ways would be a bill nobody agreed to. --reuse-text takes the whole-slide
289
- // path, since its prior text is one script rather than segments.
290
- const segs = prior ? null : segmented[i];
291
- let usage = { cost: 0 };
292
- let cachedBeats = 0;
293
- if (segs) {
294
- const parts = [];
295
- for (let k = 0; k < segs.length; k++) {
296
- const kk = String(k + 1).padStart(2, '0');
297
- const sWav = join(outDir, `slide-${n}-${kk}.wav`);
298
- const sM4a = join(outDir, `slide-${n}-${kk}.m4a`);
299
- const out = await synth(segs[k]);
300
- if (out.cached) cachedBeats++;
301
- writeFileSync(sWav, out.wav);
302
- // The beat's own words, beside its own audio — tools/lipsync.mjs hands
303
- // this to Rhubarb as the dialog hint, and a hint for the whole slide
304
- // would be worse than none against one beat of it.
305
- writeFileSync(join(outDir, `slide-${n}-${kk}.txt`), segs[k]);
306
- usage = { cost: usage.cost + (out.usage?.cost ?? 0) };
307
- toAac(sWav, sM4a);
308
- if (!keepWav) rmSync(sWav);
309
- parts.push({ file: `slide-${n}-${kk}.m4a`, path: sM4a });
310
- }
311
- const list = join(outDir, `slide-${n}.concat`);
312
- writeFileSync(list, `${parts.map((p) => `file '${p.path.replaceAll("'", "'\\''")}'`).join('\n')}\n`);
313
- run('ffmpeg', ['-y', '-f', 'concat', '-safe', '0', '-i', list, '-c', 'copy', m4a],
314
- { stdio: 'ignore' });
315
- rmSync(list, { force: true });
316
- manifest[i].segments = parts.map((p) => ({ file: p.file }));
317
- } else {
318
- const out = await synth(text);
319
- if (out.cached) cachedBeats++;
320
- writeFileSync(wav, out.wav);
321
- usage = out.usage ?? { cost: 0 };
322
- toAac(wav, m4a);
323
- if (!keepWav) rmSync(wav);
324
- }
325
- totalCost += usage.cost ?? 0;
326
- const costNote = usage.cost ? ` · ~$${usage.cost.toFixed(4)}` : '';
327
- // "cached" is worth a word: on a paid engine it is the difference between a
328
- // rerun that costs nothing and one that quietly re-bills the whole deck
329
- const cacheNote = cachedBeats
330
- ? ` · ${segs ? `${cachedBeats}/${segs.length} ` : ''}cached`
331
- : '';
332
- console.log(` slide ${n}: ${text.length} chars → ${basename(m4a)}`
333
- + `${segs ? ` (${segs.length} ⟨CLICK⟩ segments)` : ''}${cacheNote}${costNote}`);
334
- // crash-safe: persist progress after every slide so an interrupted run
335
- // resumes incrementally instead of re-synthesizing everything
336
- writeFileSync(join(outDir, 'manifest.json'),
337
- JSON.stringify({ engine, model: tts.model ?? null, voice, style, slides: manifest }, null, 1));
187
+ const cache = createTtsCache({ enabled: !args.includes('--no-cache') });
188
+ cache.prune();
189
+ const { skipped, cost } = await synthesizeSlides({
190
+ html, dir: outDir, tts, voice, style, format,
191
+ range: opt('--slides') ? range : null, prev, cache, reuseTextFrom,
192
+ keepWav: args.includes('--keep-wav'),
193
+ });
194
+ console.log(`done → ${outDir}${skipped ? ` (${skipped} unchanged, skipped)` : ''}`
195
+ + (cost ? ` · estimated cost ~$${cost.toFixed(4)}` : ''));
196
+ } catch (e) {
197
+ console.error(`decklight narrate: ${e.message}`);
198
+ process.exitCode = 1;
199
+ } finally {
200
+ // piper is held resident (§ createPiper) — without this the tool prints
201
+ // `done` and then hangs on the live child process
202
+ tts.synth.close?.();
338
203
  }
339
- writeFileSync(join(outDir, 'manifest.json'),
340
- JSON.stringify({ engine, model: tts.model ?? null, voice, style, slides: manifest }, null, 1));
341
- // piper is held resident (§ createPiper) — without this the tool prints `done`
342
- // and then hangs on the live child process
343
- tts.synth.close?.();
344
- console.log(`done → ${outDir}${skipped ? ` (${skipped} unchanged, skipped)` : ''}`
345
- + (totalCost ? ` · estimated cost ~$${totalCost.toFixed(4)}` : ''));
package/tools/zip.mjs CHANGED
@@ -15,7 +15,7 @@
15
15
  // than a wrong answer if it ever shows up.
16
16
  //
17
17
  // And deliberately bounded: everything this reads is something someone SENT —
18
- // a `.pptx` on import, a `.decklight` container that `present` must unzip
18
+ // a `.pptx` on import, a `.decklight` container that `--no-trust` must unzip
19
19
  // BEFORE it can even find the signature — so a few-KB archive that inflates to
20
20
  // gigabytes (a zip bomb) would detonate ahead of every trust decision. Two
21
21
  // caps, both far above anything Office or `bundle --deck` writes, and the