decklight 0.9.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.
- package/NOTICE +2 -0
- package/PLATFORM.md +61 -3
- package/README.md +58 -28
- package/SPEC.md +1326 -85
- package/cli/agent-review.mjs +5 -4
- package/cli/agents.mjs +148 -18
- package/cli/bundle-audio.mjs +10 -3
- package/cli/bundle-module.mjs +95 -0
- package/cli/bundle.mjs +125 -7
- package/cli/cast.mjs +86 -19
- package/cli/check-fixes.mjs +194 -0
- package/cli/check-watch.mjs +151 -0
- package/cli/check.mjs +491 -75
- package/cli/code-editor.mjs +287 -0
- package/cli/commands.mjs +13 -2
- package/cli/commit-flow.mjs +7 -3
- package/cli/commit-message.mjs +35 -8
- package/cli/commit-split.mjs +125 -25
- package/cli/deck-refs.mjs +8 -3
- package/cli/decklight.mjs +11 -1
- package/cli/design-system-edit.mjs +37 -1
- package/cli/design-system-refs.mjs +263 -6
- package/cli/design-system.mjs +82 -14
- package/cli/edit-address.mjs +184 -0
- package/cli/edit-git.mjs +23 -6
- package/cli/edit-handover.mjs +257 -40
- package/cli/edit-look.mjs +293 -6
- package/cli/edit-open.mjs +143 -0
- package/cli/edit-slides.mjs +1043 -67
- package/cli/edit-translate.mjs +243 -0
- package/cli/edit.mjs +3680 -319
- package/cli/editor-support.mjs +286 -0
- package/cli/enhance.mjs +157 -27
- package/cli/find-replace.mjs +142 -0
- package/cli/fix-review.mjs +368 -0
- package/cli/git.mjs +13 -0
- package/cli/init.mjs +101 -22
- package/cli/keep-awake.mjs +68 -0
- package/cli/marketplace-autocheck.mjs +200 -0
- package/cli/marketplace.mjs +250 -13
- package/cli/migrate-writing.mjs +214 -0
- package/cli/narrate.mjs +121 -5
- package/cli/open.mjs +53 -15
- package/cli/outside-edit.mjs +257 -0
- package/cli/paste.mjs +92 -0
- package/cli/pdf.mjs +88 -10
- package/cli/pptx-export.mjs +10 -5
- package/cli/publish.mjs +24 -3
- package/cli/record.mjs +86 -15
- package/cli/remote.mjs +32 -6
- package/cli/rewrite.mjs +265 -0
- package/cli/runtime-link.mjs +218 -17
- package/cli/serve.mjs +9 -6
- package/cli/setup.mjs +2 -2
- package/cli/skill-content.mjs +251 -10
- package/cli/skills/slide-writing.md +333 -0
- package/cli/skills/voiceover.md +423 -0
- package/cli/skills.mjs +282 -15
- package/cli/starter-full.mjs +353 -0
- package/cli/supervise.mjs +14 -0
- package/cli/theme-refs.mjs +14 -2
- package/cli/theme.mjs +3 -2
- package/cli/translate-core.mjs +466 -0
- package/cli/translate-files.mjs +149 -0
- package/cli/translate.mjs +458 -0
- package/cli/units.mjs +75 -7
- package/cli/util.mjs +25 -0
- package/cli/vocabulary-docs.mjs +138 -0
- package/dist/decklight.css +2506 -113
- package/dist/decklight.js +385 -175
- package/dist/decklight.js.map +4 -4
- package/docs/GLOSSARY.md +9 -2
- package/docs/WRITING_RESEARCH.md +327 -0
- package/package.json +5 -3
- package/themes/coastal.css +3 -0
- package/themes/metropolis.css +2 -0
- package/themes/reveal-blood.css +3 -0
- package/themes/reveal-league.css +2 -0
- package/themes/reveal-moon.css +2 -0
- package/themes/reveal-serif.css +1 -0
- package/themes/reveal-sky.css +1 -0
- package/themes/reveal-solarized.css +4 -0
- package/tools/brand-palette.mjs +6 -1
- package/tools/build-groups.mjs +28 -8
- package/tools/cdp.mjs +176 -0
- package/tools/chart-spec.mjs +242 -0
- package/tools/click-match.mjs +70 -0
- package/tools/code-options.mjs +174 -0
- package/tools/conversation.mjs +49 -0
- package/tools/deck-family.mjs +101 -0
- package/tools/deck-html.mjs +212 -15
- package/tools/design-system-format.mjs +40 -1
- package/tools/design-system-migrations.mjs +207 -0
- package/tools/diagram-shapes.mjs +221 -0
- package/tools/elevenlabs-tts.mjs +62 -53
- package/tools/exec.mjs +10 -2
- package/tools/face-clip.mjs +96 -0
- package/tools/face-layout.mjs +94 -0
- package/tools/gemini-tts.mjs +1 -1
- package/tools/invisible-in-print.mjs +27 -0
- package/tools/lipsync-auto.mjs +197 -0
- package/tools/lipsync-config.mjs +16 -0
- package/tools/lipsync-engines.mjs +22 -4
- package/tools/lipsync-server.mjs +8 -5
- package/tools/lipsync.mjs +122 -30
- package/tools/local-voice.mjs +1 -1
- package/tools/mouth-file.mjs +26 -0
- package/tools/mouth.mjs +320 -0
- package/tools/narration-manifest.mjs +100 -6
- package/tools/narration-synth.mjs +96 -76
- package/tools/recording-impact.mjs +16 -1
- package/tools/sentences.mjs +7 -1
- package/tools/site-clip.mjs +114 -0
- package/tools/starters.mjs +402 -0
- package/tools/steps.mjs +118 -0
- package/tools/take-check.mjs +146 -0
- package/tools/template-theme.mjs +3 -1
- package/tools/test-impact.mjs +36 -12
- package/tools/theme-check.mjs +196 -1
- package/tools/tone-cue.mjs +108 -0
- package/tools/tts-cache.mjs +9 -3
- package/tools/tts-engines.mjs +100 -11
- package/tools/video-cache.mjs +93 -0
- package/tools/video-live.mjs +349 -0
- package/tools/video-options.mjs +11 -0
- package/tools/video.mjs +825 -117
- package/tools/viseme-fit.mjs +27 -0
- package/tools/viseme-match.mjs +77 -0
- package/tools/vocabulary.mjs +397 -0
- package/tools/voice-renumber.mjs +605 -0
- package/tools/voiceover-server.mjs +42 -11
- package/tools/voiceover.mjs +48 -20
- 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
|
-
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
217
|
-
//
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
|
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
|
-
//
|
|
280
|
-
//
|
|
281
|
-
|
|
282
|
-
//
|
|
283
|
-
//
|
|
284
|
-
//
|
|
285
|
-
|
|
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:
|
|
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
|
-
//
|
|
305
|
-
|
|
306
|
-
|
|
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) =>
|
|
331
|
+
const save = (entries) => writeFileAtomic(join(dir, 'manifest.json'), JSON.stringify(manifestOf(entries), null, 1));
|
|
323
332
|
|
|
324
|
-
|
|
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) {
|
|
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(
|
|
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() :
|
|
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
|
-
|
|
353
|
-
&& (was.hash === hash || was.hash === clipHash(text) || (
|
|
354
|
-
|| (
|
|
355
|
-
|
|
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
|
|
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);
|
package/tools/sentences.mjs
CHANGED
|
@@ -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(
|
|
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;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// The narration clip on decklight.io: one showcase slide, narrated by the
|
|
5
|
+
// site's own voice track with captions on, its builds stepping with the voice.
|
|
6
|
+
// It is a RECORDING of the live deck, not a `decklight video` render: a render
|
|
7
|
+
// is one still per build step, so the strokes drawing in and the caption bar
|
|
8
|
+
// following the voice would never be in it.
|
|
9
|
+
//
|
|
10
|
+
// node tools/site-voices.mjs pull the voice track → site/voices/ (once)
|
|
11
|
+
// node tools/site-clip.mjs re-record site/img/narration.{webm,mp4,jpg}
|
|
12
|
+
//
|
|
13
|
+
// It bundles the showcase the way the site deploy does, with the voice track's
|
|
14
|
+
// per-beat clips switched on (segments), serves it on 127.0.0.1, plays the
|
|
15
|
+
// slide in Chrome (Playwright) and keeps the stretch from the first build to
|
|
16
|
+
// the last one plus a short hold, muted, as VP9 WebM, an H.264 MP4 for older
|
|
17
|
+
// Safari, and a poster frame. Re-run it when the slide or its notes change.
|
|
18
|
+
// Needs Playwright, Chrome and ffmpeg; never runs in CI.
|
|
19
|
+
|
|
20
|
+
import fs from 'node:fs';
|
|
21
|
+
import http from 'node:http';
|
|
22
|
+
import os from 'node:os';
|
|
23
|
+
import path from 'node:path';
|
|
24
|
+
import { execFileSync } from 'node:child_process';
|
|
25
|
+
import { fileURLToPath } from 'node:url';
|
|
26
|
+
|
|
27
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
28
|
+
const args = process.argv.slice(2);
|
|
29
|
+
const opt = (name, fallback) => { const i = args.indexOf(name); return i === -1 ? fallback : args[i + 1]; };
|
|
30
|
+
const SLIDE = Number(opt('--slide', 7));
|
|
31
|
+
const OUT = path.resolve(ROOT, opt('--out', 'site/img/narration'));
|
|
32
|
+
const HOLD_MS = Number(opt('--hold', 2500));
|
|
33
|
+
const LIMIT_MS = 90_000;
|
|
34
|
+
|
|
35
|
+
const cfg = JSON.parse(fs.readFileSync(path.join(ROOT, 'site/voices.json'), 'utf8'));
|
|
36
|
+
const voices = path.join(ROOT, cfg.dir);
|
|
37
|
+
if (!fs.existsSync(path.join(voices, path.basename(cfg.voices[0].dir), 'manifest.json'))) {
|
|
38
|
+
console.error(`no voice track in ${cfg.dir}/ — run: node tools/site-voices.mjs pull`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ── the showcase, bundled with its voice, as the deploy does ─────────────────
|
|
43
|
+
const work = fs.mkdtempSync(path.join(os.tmpdir(), 'decklight-site-clip-'));
|
|
44
|
+
const site = path.join(work, 'site');
|
|
45
|
+
fs.mkdirSync(site);
|
|
46
|
+
fs.cpSync(voices, path.join(site, 'voices'), { recursive: true });
|
|
47
|
+
execFileSync(process.execPath, [path.join(ROOT, 'cli/decklight.mjs'), 'bundle', path.join(ROOT, cfg.deck),
|
|
48
|
+
'--themes', 'all', '-o', path.join(site, 'showcase.html')], { stdio: 'ignore' });
|
|
49
|
+
{
|
|
50
|
+
// segments: the per-beat clips drive the builds, one beat per [click]
|
|
51
|
+
const files = cfg.voices.map((v) => `{ label: ${JSON.stringify(v.label)}, dir: ${JSON.stringify(v.dir)}, segments: true }`).join(', ');
|
|
52
|
+
const p = path.join(site, 'showcase.html');
|
|
53
|
+
const html = fs.readFileSync(p, 'utf8');
|
|
54
|
+
const out = html.replace('Decklight.init({', `Decklight.init({\n narration: { files: [${files}] },`);
|
|
55
|
+
if (out === html) throw new Error('init config anchor not found in the bundled showcase');
|
|
56
|
+
fs.writeFileSync(p, out);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const TYPES = { '.html': 'text/html', '.m4a': 'audio/mp4', '.json': 'application/json', '.txt': 'text/plain' };
|
|
60
|
+
const server = http.createServer((req, res) => {
|
|
61
|
+
const rel = decodeURIComponent(new URL(req.url, 'http://x').pathname);
|
|
62
|
+
const file = path.join(site, rel);
|
|
63
|
+
if (!file.startsWith(site) || !fs.existsSync(file) || !fs.statSync(file).isFile()) { res.writeHead(404).end(); return; }
|
|
64
|
+
res.writeHead(200, { 'content-type': TYPES[path.extname(file)] ?? 'application/octet-stream' });
|
|
65
|
+
fs.createReadStream(file).pipe(res);
|
|
66
|
+
});
|
|
67
|
+
await new Promise((r) => server.listen(0, '127.0.0.1', r));
|
|
68
|
+
const base = `http://127.0.0.1:${server.address().port}`;
|
|
69
|
+
|
|
70
|
+
// ── play the slide and record it ─────────────────────────────────────────────
|
|
71
|
+
const { chromium } = await import('playwright');
|
|
72
|
+
const browser = await chromium.launch({ channel: 'chrome', args: ['--autoplay-policy=no-user-gesture-required'] });
|
|
73
|
+
const videoDir = path.join(work, 'video');
|
|
74
|
+
const ctx = await browser.newContext({ viewport: { width: 1280, height: 720 }, recordVideo: { dir: videoDir, size: { width: 1280, height: 720 } } });
|
|
75
|
+
const recordingFrom = Date.now();
|
|
76
|
+
const page = await ctx.newPage();
|
|
77
|
+
// ?embedded hides the controls and saves nothing; &captions shows the caption bar
|
|
78
|
+
await page.goto(`${base}/showcase.html?embedded&captions&voiceover#/${SLIDE}/0`, { waitUntil: 'networkidle' });
|
|
79
|
+
await page.evaluate(() => {
|
|
80
|
+
// the engine dispatches on the deck's root, and the event does not bubble
|
|
81
|
+
window.__steps = [];
|
|
82
|
+
document.querySelector('.decklight').addEventListener('decklight:build',
|
|
83
|
+
(e) => window.__steps.push({ at: Date.now(), index: e.detail.index, total: e.detail.total }));
|
|
84
|
+
});
|
|
85
|
+
await page.waitForTimeout(500);
|
|
86
|
+
await page.keyboard.press('Shift'); // the gesture ?voiceover waits for, without moving the deck
|
|
87
|
+
const deadline = Date.now() + LIMIT_MS;
|
|
88
|
+
let steps = [];
|
|
89
|
+
while (Date.now() < deadline) {
|
|
90
|
+
steps = await page.evaluate(() => window.__steps);
|
|
91
|
+
if (steps.length && steps.at(-1).index >= steps.at(-1).total) break;
|
|
92
|
+
await page.waitForTimeout(250);
|
|
93
|
+
}
|
|
94
|
+
if (!steps.length) throw new Error(`slide ${SLIDE} never stepped: is the voice track playing?`);
|
|
95
|
+
await page.waitForTimeout(HOLD_MS);
|
|
96
|
+
const video = await page.video().path();
|
|
97
|
+
await ctx.close();
|
|
98
|
+
await browser.close();
|
|
99
|
+
server.close();
|
|
100
|
+
|
|
101
|
+
// ── cut from just before the first build to the hold after the last ──────────
|
|
102
|
+
const from = Math.max(0, (steps[0].at - recordingFrom) / 1000 - 0.8);
|
|
103
|
+
const to = (steps.at(-1).at - recordingFrom + HOLD_MS) / 1000;
|
|
104
|
+
const ff = (...a) => execFileSync('ffmpeg', ['-loglevel', 'error', '-y', ...a], { stdio: 'inherit' });
|
|
105
|
+
const cut = ['-ss', from.toFixed(2), '-to', to.toFixed(2), '-i', video, '-vf', 'scale=960:-2', '-an'];
|
|
106
|
+
fs.mkdirSync(path.dirname(OUT), { recursive: true });
|
|
107
|
+
ff(...cut, '-c:v', 'libvpx-vp9', '-crf', '34', '-b:v', '0', '-row-mt', '1', `${OUT}.webm`);
|
|
108
|
+
ff(...cut, '-c:v', 'libx264', '-crf', '26', '-preset', 'slow', '-pix_fmt', 'yuv420p', '-movflags', '+faststart', `${OUT}.mp4`);
|
|
109
|
+
ff('-sseof', '-0.3', '-i', `${OUT}.mp4`, '-frames:v', '1', '-q:v', '4', `${OUT}.jpg`);
|
|
110
|
+
fs.rmSync(work, { recursive: true, force: true });
|
|
111
|
+
|
|
112
|
+
const kb = (f) => `${Math.round(fs.statSync(f).size / 1024)} KB`;
|
|
113
|
+
console.log(`slide ${SLIDE}: ${steps.length} builds, ${(to - from).toFixed(1)}s`
|
|
114
|
+
+ ` → ${path.relative(ROOT, OUT)}.webm (${kb(`${OUT}.webm`)}), .mp4 (${kb(`${OUT}.mp4`)}), .jpg (${kb(`${OUT}.jpg`)})`);
|