decklight 0.8.1 → 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.
- package/PLATFORM.md +666 -0
- package/README.md +224 -150
- package/SPEC.md +732 -886
- package/cli/agent-review.mjs +245 -0
- package/cli/agents.mjs +25 -5
- package/cli/associate.mjs +12 -12
- package/cli/audit.mjs +42 -10
- package/cli/banner.mjs +41 -17
- package/cli/bundle-audio.mjs +183 -0
- package/cli/bundle.mjs +383 -31
- package/cli/cast.mjs +7 -7
- package/cli/check.mjs +961 -0
- package/cli/clone-deck.mjs +179 -0
- package/cli/commands.mjs +345 -0
- package/cli/comments.mjs +64 -18
- package/cli/commit-flow.mjs +44 -19
- package/cli/commit-message.mjs +51 -74
- package/cli/commit-split.mjs +601 -0
- package/cli/deck-refs.mjs +59 -0
- package/cli/deck-routes.mjs +67 -0
- package/cli/deckfile.mjs +3 -5
- package/cli/decklight.mjs +68 -289
- package/cli/design-system-deps.mjs +209 -0
- package/cli/design-system-edit.mjs +194 -0
- package/cli/design-system-refs.mjs +409 -0
- package/cli/design-system.mjs +429 -0
- package/cli/doctor.mjs +115 -0
- package/cli/edit-git.mjs +353 -0
- package/cli/edit-handover.mjs +445 -0
- package/cli/edit-look.mjs +388 -0
- package/cli/edit-slides.mjs +683 -0
- package/cli/edit.mjs +2126 -842
- package/cli/enhance.mjs +483 -0
- package/cli/extension.mjs +10 -10
- package/cli/font-refs.mjs +273 -0
- package/cli/font.mjs +246 -0
- package/cli/git-tree.mjs +1 -1
- package/cli/git.mjs +65 -11
- package/cli/import.mjs +56 -10
- package/cli/init.mjs +400 -234
- package/cli/library.mjs +127 -0
- package/cli/loader.mjs +3 -1
- package/cli/marketplace.mjs +215 -21
- package/cli/narrate.mjs +176 -0
- package/cli/open-browser.mjs +63 -0
- package/cli/open.mjs +943 -0
- package/cli/pdf.mjs +41 -13
- package/cli/pkg.mjs +44 -2
- package/cli/plugin.mjs +43 -41
- package/cli/port-conflict.mjs +53 -23
- package/cli/pptx-export.mjs +57 -24
- package/cli/publish.mjs +8 -4
- package/cli/qr.mjs +1 -1
- package/cli/record.mjs +14 -12
- package/cli/remote.mjs +11 -11
- package/cli/restore.mjs +11 -4
- package/cli/review-ref.mjs +125 -0
- package/cli/review-remote.mjs +92 -48
- package/cli/review-routes.mjs +254 -0
- package/cli/review-store.mjs +47 -7
- package/cli/review-submit.mjs +47 -57
- package/cli/runtime-link.mjs +560 -0
- package/cli/serve.mjs +235 -44
- package/cli/setup.mjs +112 -0
- package/cli/sign.mjs +1 -1
- package/cli/skill-content.mjs +190 -33
- package/cli/skills.mjs +107 -24
- package/cli/start.mjs +110 -0
- package/cli/supervise.mjs +6 -6
- package/cli/theme-refs.mjs +515 -0
- package/cli/theme.mjs +181 -137
- package/cli/trust.mjs +83 -0
- package/cli/units.mjs +39 -42
- package/cli/update-check.mjs +1 -5
- package/cli/upgrade.mjs +194 -28
- package/cli/upstream.mjs +4 -3
- package/cli/util.mjs +4 -4
- package/cli/wizard.mjs +6 -6
- package/dist/build-info.json +1 -1
- package/dist/decklight.css +1126 -49
- package/dist/decklight.js +212 -115
- package/dist/decklight.js.map +4 -4
- package/docs/GLOSSARY.md +141 -0
- package/docs/architecture.svg +17 -17
- package/package.json +4 -2
- package/themes/README.md +9 -8
- package/themes/reveal-solarized.css +10 -0
- package/tools/args.mjs +20 -0
- package/tools/atomic-write.mjs +48 -0
- package/tools/brand-palette.mjs +717 -0
- package/tools/bridge.mjs +1 -1
- package/tools/build-groups.mjs +42 -0
- package/tools/color.mjs +48 -0
- package/tools/deck-html.mjs +396 -11
- package/tools/design-system-format.mjs +753 -0
- package/tools/elevenlabs-tts.mjs +110 -17
- package/tools/exec.mjs +1 -1
- package/tools/extension-check.mjs +31 -7
- package/tools/font-format.mjs +190 -0
- package/tools/font-stacks.mjs +24 -0
- package/tools/gemini-tts.mjs +3 -0
- package/tools/lipsync-config.mjs +103 -0
- package/tools/lipsync-engines.mjs +205 -2
- package/tools/lipsync-server.mjs +264 -41
- package/tools/lipsync.mjs +37 -18
- package/tools/local-voice.mjs +32 -42
- package/tools/narration-manifest.mjs +196 -0
- package/tools/narration-synth.mjs +416 -0
- package/tools/pptx.mjs +776 -19
- package/tools/publish-targets.mjs +1 -1
- package/tools/publish-voices.mjs +3 -3
- package/tools/recording-impact.mjs +7 -3
- package/tools/render-theme.mjs +33 -0
- package/tools/review-anchor.mjs +28 -12
- package/tools/semver.mjs +40 -0
- package/tools/sentences.mjs +180 -0
- package/tools/shot.mjs +14 -7
- package/tools/site-voices.mjs +232 -0
- package/tools/template-theme.mjs +1 -1
- package/tools/test-impact.mjs +17 -10
- package/tools/theme-check.mjs +30 -3
- package/tools/tts-cache.mjs +4 -3
- package/tools/tts-engines.mjs +38 -20
- package/tools/tts-setup.mjs +7 -7
- package/tools/video-options.mjs +34 -0
- package/tools/video.mjs +461 -48
- package/tools/voiceover-server.mjs +185 -104
- package/tools/voiceover.mjs +119 -261
- package/tools/zip.mjs +1 -1
- package/cli/dev.mjs +0 -623
- package/cli/present.mjs +0 -853
- package/cli/review.mjs +0 -361
- package/tools/publish-site-voices.mjs +0 -75
package/tools/lipsync-server.mjs
CHANGED
|
@@ -12,9 +12,11 @@
|
|
|
12
12
|
// → viseme timeline JSON v1 (tools/visemes.mjs)
|
|
13
13
|
// POST /video?engine=wav2lip&portrait=<name> (body: audio/wav)
|
|
14
14
|
// → video/mp4 (muted talking head)
|
|
15
|
+
// GET /portrait?name=<name> → image/jpeg: the still the clips are made from
|
|
16
|
+
// (scaled, cropped square around the head) — shown under the video
|
|
15
17
|
//
|
|
16
18
|
// decklight lipsync [--port 8789] [--rhubarb <bin>]
|
|
17
|
-
// [--portrait <name=img.png>]… (first one is 'default')
|
|
19
|
+
// [--portrait <name=img.png|clip.mp4>]… (first one is 'default')
|
|
18
20
|
// [--wav2lip-dir <repo> --wav2lip-ckpt <pth>]
|
|
19
21
|
// [--sadtalker-dir <repo>] [--python <bin>]
|
|
20
22
|
// [--cache-dir ~/.cache/decklight/lipsync]
|
|
@@ -32,21 +34,33 @@
|
|
|
32
34
|
|
|
33
35
|
import { createServer } from 'node:http';
|
|
34
36
|
import { createInterface } from 'node:readline/promises';
|
|
35
|
-
import { canBind, resolvePortConflict } from '../cli/port-conflict.mjs';
|
|
37
|
+
import { canBind, resolvePortConflict, describePortOutcome } from '../cli/port-conflict.mjs';
|
|
36
38
|
import { createHash } from 'node:crypto';
|
|
37
39
|
import { execFile } from 'node:child_process';
|
|
38
|
-
import { mkdirSync, existsSync, readFileSync, writeFileSync, rmSync, statSync, copyFileSync } from 'node:fs';
|
|
40
|
+
import { mkdirSync, existsSync, readFileSync, writeFileSync, rmSync, statSync, copyFileSync, renameSync } from 'node:fs';
|
|
39
41
|
import { join, resolve, basename } from 'node:path';
|
|
40
42
|
import { homedir } from 'node:os';
|
|
41
43
|
import { promisify } from 'node:util';
|
|
42
44
|
import { createVeo, DEFAULT_PROMPT, VEO_MODELS } from './veo.mjs';
|
|
43
|
-
import { argReader, isMain } from './args.mjs';
|
|
44
|
-
import { runRhubarb, runWav2lip, runSadtalker, muteFaststart } from './lipsync-engines.mjs';
|
|
45
|
+
import { argReader, isMain, parsePort, badPort } from './args.mjs';
|
|
46
|
+
import { runRhubarb, runWav2lip, runSadtalker, muteFaststart, prepareStill, faceBox, headCrop, mouthComposite, isClip, prepareClip, CLIP_MAX_SECONDS } from './lipsync-engines.mjs';
|
|
47
|
+
import { loadLipsyncConfig, saveLipsyncConfig, lipsyncConfigPath, videoSetup, SETUP_HINT, portraitsDir, withPortrait } from './lipsync-config.mjs';
|
|
45
48
|
import { corsHeaders, readBody } from './bridge.mjs';
|
|
46
49
|
import { readyLine } from '../cli/banner.mjs';
|
|
47
50
|
|
|
48
51
|
const run = promisify(execFile);
|
|
49
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Whether the bridge's own housekeeping lines are printed: its cache, how a
|
|
55
|
+
* portrait was prepared. Always when it runs on its own; under the banner of
|
|
56
|
+
* `decklight <deck>` only with DECKLIGHT_DEBUG, since they are not a fact a
|
|
57
|
+
* presenter acts on.
|
|
58
|
+
*/
|
|
59
|
+
const chatty = () => !process.env.DECKLIGHT_BANNER || !!process.env.DECKLIGHT_DEBUG;
|
|
60
|
+
|
|
61
|
+
/** The largest film the deck may send — ten seconds of 1080p is well under it. */
|
|
62
|
+
const FILM_MAX = 200 * 1024 * 1024;
|
|
63
|
+
|
|
50
64
|
// width-limited job queue: rhubarb gets 2 lanes, the GPU exactly 1 — a burst
|
|
51
65
|
// of lookahead prefetches must never launch parallel model runs
|
|
52
66
|
function makeQueue(width) {
|
|
@@ -90,22 +104,32 @@ export async function lipsyncMain(args) {
|
|
|
90
104
|
// production, decisive under test: V8 writes a process's coverage only when
|
|
91
105
|
// it exits through process.exit, so a bridge the suite stops with SIGKILL —
|
|
92
106
|
// or an unhandled SIGTERM — reports NOTHING of the handler it ran. The edit
|
|
93
|
-
// and
|
|
107
|
+
// and no-trust mode already do this; voiceover-server does now too.
|
|
94
108
|
process.on('SIGTERM', () => process.exit(0));
|
|
95
109
|
if (args.includes('--help')) {
|
|
96
110
|
console.log(`usage: decklight lipsync [--port 8789] [--rhubarb <bin>]
|
|
97
|
-
[--portrait <name=img.png>]...
|
|
111
|
+
[--portrait <name=img.png|clip.mp4>]... portraits offered for video mode (first = default)
|
|
98
112
|
[--wav2lip-dir <repo> --wav2lip-ckpt <checkpoint.pth>]
|
|
99
113
|
[--sadtalker-dir <repo>] [--python python3]
|
|
100
114
|
[--cache-dir ~/.cache/decklight/lipsync]
|
|
115
|
+
[--save] remember these (lipsync.json) — the deck then opens with no flags
|
|
101
116
|
[--veo] [--veo-project <id>] [--veo-model veo-3.1-lite-generate-001]
|
|
102
117
|
[--veo-seconds 4|6|8] [--veo-prompt "..."] [--veo-location us-central1]
|
|
103
118
|
[--veo-face-y 0.12] where the square crop starts, as a fraction of height
|
|
104
119
|
|
|
105
120
|
Viseme timelines need rhubarb on PATH (or --rhubarb):
|
|
106
121
|
https://github.com/DanielSWolf/rhubarb-lip-sync
|
|
107
|
-
Talking-head video needs a local Wav2Lip and/or SadTalker checkout,
|
|
108
|
-
and at least one --portrait
|
|
122
|
+
Talking-head video needs a local Wav2Lip and/or SadTalker checkout, its
|
|
123
|
+
Python, and at least one --portrait (a head-and-shoulders photo; a large one is
|
|
124
|
+
scaled down for the face detector). Everything runs offline on this machine.
|
|
125
|
+
A portrait can be FILMED instead (.mp4 .mov .m4v .webm .mkv): 5-10 s of you
|
|
126
|
+
facing the camera, mouth relaxed, blinking, not talking. Its first ${CLIP_MAX_SECONDS} s are
|
|
127
|
+
played forward then back, so the head never snaps back; hold the head still
|
|
128
|
+
and only the mouth is redrawn over the film.
|
|
129
|
+
Set it up once and --save it:
|
|
130
|
+
${SETUP_HINT}
|
|
131
|
+
Wav2Lip redraws the face at 96 px, so only the MOUTH is taken from it and laid
|
|
132
|
+
over the sharp photo.
|
|
109
133
|
|
|
110
134
|
--veo is the exception, and the only thing here that leaves the machine: it
|
|
111
135
|
animates each portrait ONCE through Veo on Vertex AI (head turns, blinks,
|
|
@@ -119,28 +143,65 @@ photo puts the face lower in Veo's 9:16 frame — chin off the bottom. Nudge
|
|
|
119
143
|
return;
|
|
120
144
|
}
|
|
121
145
|
const { opt, opts } = argReader(args);
|
|
122
|
-
const port =
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
const
|
|
146
|
+
const port = parsePort(opt('--port', 8789));
|
|
147
|
+
if (port === null) { console.error(`decklight lipsync: ${badPort('--port', opt('--port'))}`); process.exitCode = 1; return; }
|
|
148
|
+
// Flags win; what `--save` remembered fills the rest (tools/lipsync-config.mjs),
|
|
149
|
+
// so a talking head set up once starts with every `decklight <deck>`.
|
|
150
|
+
const saved = loadLipsyncConfig() ?? {};
|
|
151
|
+
const rhubarb = opt('--rhubarb', saved.rhubarb ?? 'rhubarb');
|
|
152
|
+
const python = opt('--python', saved.python ?? 'python3');
|
|
153
|
+
const wav2lipDir = opt('--wav2lip-dir', saved.wav2lipDir);
|
|
154
|
+
const wav2lipCkpt = opt('--wav2lip-ckpt', saved.wav2lipCkpt);
|
|
155
|
+
const sadtalkerDir = opt('--sadtalker-dir', saved.sadtalkerDir);
|
|
156
|
+
const portraitSpecs = opts('--portrait').length ? opts('--portrait') : (saved.portraits ?? []);
|
|
157
|
+
if (args.includes('--save')) {
|
|
158
|
+
const abs = (p) => (p ? resolve(p) : undefined);
|
|
159
|
+
const next = {
|
|
160
|
+
...saved,
|
|
161
|
+
...(wav2lipDir ? { wav2lipDir: abs(wav2lipDir) } : {}),
|
|
162
|
+
...(wav2lipCkpt ? { wav2lipCkpt: abs(wav2lipCkpt) } : {}),
|
|
163
|
+
...(sadtalkerDir ? { sadtalkerDir: abs(sadtalkerDir) } : {}),
|
|
164
|
+
...(python !== 'python3' ? { python: python.includes('/') ? abs(python) : python } : {}),
|
|
165
|
+
...(portraitSpecs.length ? { portraits: portraitSpecs.map((sp) => {
|
|
166
|
+
const at = sp.indexOf('=');
|
|
167
|
+
return at > 0 ? `${sp.slice(0, at)}=${abs(sp.slice(at + 1))}` : abs(sp);
|
|
168
|
+
}) } : {}),
|
|
169
|
+
// the rest of what used to be a flag on `decklight <deck>` each run
|
|
170
|
+
...(opt('--cache-dir') ? { cacheDir: abs(opt('--cache-dir')) } : {}),
|
|
171
|
+
...(opt('--rhubarb') ? { rhubarb: opt('--rhubarb') } : {}),
|
|
172
|
+
// Veo animates the portrait through Vertex, BILLED once per portrait
|
|
173
|
+
// and cached: remembered only when --veo is asked for here, explicitly
|
|
174
|
+
...(args.includes('--veo') ? { veo: true } : {}),
|
|
175
|
+
...(args.includes('--no-veo') ? { veo: false } : {}),
|
|
176
|
+
...Object.fromEntries([['--veo-project', 'veoProject'], ['--veo-model', 'veoModel'], ['--veo-seconds', 'veoSeconds'],
|
|
177
|
+
['--veo-prompt', 'veoPrompt'], ['--veo-location', 'veoLocation'], ['--veo-face-y', 'veoFaceY']]
|
|
178
|
+
.filter(([f]) => opt(f) !== undefined).map(([f, k]) => [k, /seconds|face-y/.test(f) ? Number(opt(f)) : opt(f)])),
|
|
179
|
+
};
|
|
180
|
+
const { engines, problems } = videoSetup(next);
|
|
181
|
+
console.log(`saved to ${saveLipsyncConfig(next)} — decklight <deck> starts the lip-sync bridge with it from now on`);
|
|
182
|
+
console.log(engines.length ? ` neural video: ${engines.join(', ')} ready` : ' neural video: not ready yet');
|
|
183
|
+
for (const p of problems) console.log(` ${p}`);
|
|
184
|
+
// saving is the whole job: `open` starts the bridge with it (and a second
|
|
185
|
+
// bridge here would only fight the one the edit server runs for the port)
|
|
186
|
+
process.exitCode = problems.length && !engines.length ? 1 : 0;
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const cacheDir = resolve(opt('--cache-dir', saved.cacheDir ?? join(homedir(), '.cache', 'decklight', 'lipsync')));
|
|
129
190
|
mkdirSync(cacheDir, { recursive: true });
|
|
130
191
|
|
|
131
192
|
// Veo: the portrait's MOTION, bought once (tools/veo.mjs). Only wav2lip can
|
|
132
193
|
// use it — SadTalker animates the head itself and wants a still.
|
|
133
|
-
const veoOn = args.includes('--veo');
|
|
194
|
+
const veoOn = args.includes('--veo') || (saved.veo === true && !args.includes('--no-veo'));
|
|
134
195
|
let veo = null;
|
|
135
196
|
if (veoOn) {
|
|
136
197
|
try {
|
|
137
198
|
veo = createVeo({
|
|
138
|
-
project: opt('--veo-project', process.env.GOOGLE_CLOUD_PROJECT),
|
|
139
|
-
location: opt('--veo-location', 'us-central1'),
|
|
140
|
-
model: opt('--veo-model', VEO_MODELS[0]),
|
|
141
|
-
seconds: Number(opt('--veo-seconds', 8)),
|
|
142
|
-
prompt: opt('--veo-prompt', DEFAULT_PROMPT),
|
|
143
|
-
faceY: Number(opt('--veo-face-y', 0.12)),
|
|
199
|
+
project: opt('--veo-project', saved.veoProject ?? process.env.GOOGLE_CLOUD_PROJECT),
|
|
200
|
+
location: opt('--veo-location', saved.veoLocation ?? 'us-central1'),
|
|
201
|
+
model: opt('--veo-model', saved.veoModel ?? VEO_MODELS[0]),
|
|
202
|
+
seconds: Number(opt('--veo-seconds', saved.veoSeconds ?? 8)),
|
|
203
|
+
prompt: opt('--veo-prompt', saved.veoPrompt ?? DEFAULT_PROMPT),
|
|
204
|
+
faceY: Number(opt('--veo-face-y', saved.veoFaceY ?? 0.12)),
|
|
144
205
|
cacheDir,
|
|
145
206
|
});
|
|
146
207
|
} catch (e) {
|
|
@@ -153,7 +214,7 @@ photo puts the face lower in Veo's 9:16 frame — chin off the bottom. Nudge
|
|
|
153
214
|
|
|
154
215
|
// portraits: --portrait alice=face.png (or a bare path — named by basename)
|
|
155
216
|
const portraits = new Map();
|
|
156
|
-
for (const p of
|
|
217
|
+
for (const p of portraitSpecs) {
|
|
157
218
|
if (!p) continue;
|
|
158
219
|
const eq = p.indexOf('=');
|
|
159
220
|
const name = eq > 0 ? p.slice(0, eq) : basename(p).replace(/\.[^.]+$/, '');
|
|
@@ -168,13 +229,32 @@ photo puts the face lower in Veo's 9:16 frame — chin off the bottom. Nudge
|
|
|
168
229
|
};
|
|
169
230
|
const visemeOk = await has(rhubarb);
|
|
170
231
|
const ffmpegOk = await has('ffmpeg', ['-version']);
|
|
232
|
+
const wav2lipReady = !!(wav2lipDir && wav2lipCkpt && existsSync(join(wav2lipDir, 'inference.py')) && existsSync(wav2lipCkpt));
|
|
233
|
+
const sadtalkerReady = !!(sadtalkerDir && existsSync(join(sadtalkerDir, 'inference.py')));
|
|
234
|
+
// grows when a portrait is filmed from the deck (POST /portrait)
|
|
171
235
|
const videoEngines = [];
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
236
|
+
const enginesNow = () => {
|
|
237
|
+
if (!portraits.size) return;
|
|
238
|
+
if (wav2lipReady && !videoEngines.includes('wav2lip')) videoEngines.push('wav2lip');
|
|
239
|
+
if (sadtalkerReady && !videoEngines.includes('sadtalker')) videoEngines.push('sadtalker');
|
|
240
|
+
};
|
|
241
|
+
enginesNow();
|
|
242
|
+
// Filming yourself from the deck needs Wav2Lip's face detector and ffmpeg
|
|
243
|
+
// here — not a portrait: filming is how the first one gets made.
|
|
244
|
+
const filmWhy = !wav2lipReady ? (videoSetup({ wav2lipDir, wav2lipCkpt, python }).problems[0] ?? `Wav2Lip is not set up — ${SETUP_HINT}`)
|
|
245
|
+
: !ffmpegOk ? 'ffmpeg is not installed on this machine' : null;
|
|
246
|
+
// What stands in the way of video, in the same words doctor and the deck use
|
|
247
|
+
const setupNow = videoSetup({ wav2lipDir, wav2lipCkpt, sadtalkerDir, python, portraits: portraitSpecs });
|
|
248
|
+
if (!videoEngines.length) {
|
|
249
|
+
for (const p of setupNow.problems) console.log(` video: ${p}`);
|
|
250
|
+
if (!wav2lipDir && !sadtalkerDir) console.log(` video: not set up — ${SETUP_HINT}`);
|
|
251
|
+
else if (!filmWhy) console.log(' video: or film yourself from the deck — V → Character → Film yourself');
|
|
252
|
+
}
|
|
253
|
+
// Wav2Lip with no portrait yet still serves: filming one is what the deck does next
|
|
254
|
+
if (!visemeOk && !videoEngines.length && filmWhy) {
|
|
175
255
|
console.error(`neither engine is usable:
|
|
176
256
|
visemes — rhubarb not found (install it, or pass --rhubarb <bin>)
|
|
177
|
-
video — needs
|
|
257
|
+
video — needs Wav2Lip or SadTalker and a portrait, set up once: ${SETUP_HINT}`);
|
|
178
258
|
process.exitCode = 1;
|
|
179
259
|
return;
|
|
180
260
|
}
|
|
@@ -218,6 +298,47 @@ photo puts the face lower in Veo's 9:16 frame — chin off the bottom. Nudge
|
|
|
218
298
|
return { body: readFileSync(out), cached: false };
|
|
219
299
|
}
|
|
220
300
|
|
|
301
|
+
/**
|
|
302
|
+
* A portrait as the clips are made from it: scaled down for the face
|
|
303
|
+
* detector, its face box found once, cropped square around the head — and
|
|
304
|
+
* what the deck shows UNDER the video (GET /portrait), so the photo and the
|
|
305
|
+
* clips line up exactly. Cached per portrait; `box` is null without Wav2Lip.
|
|
306
|
+
* A FILMED portrait (a video) becomes a forward-and-back loop the same way
|
|
307
|
+
* (`prepareClip`): `loop` is what Wav2Lip is given, `file` its first frame,
|
|
308
|
+
* and `box` is only kept when the head held still enough to use it.
|
|
309
|
+
*/
|
|
310
|
+
const prepared = new Map();
|
|
311
|
+
function stillFor(name) {
|
|
312
|
+
const still = portraits.get(name);
|
|
313
|
+
if (!still) return Promise.reject(new Error(`unknown portrait '${name}'`));
|
|
314
|
+
// keyed by FILE: 'default' and its own name are one portrait, prepared once
|
|
315
|
+
if (!prepared.has(still)) {
|
|
316
|
+
prepared.set(still, (async () => {
|
|
317
|
+
if (isClip(still)) {
|
|
318
|
+
// without ffmpeg or Wav2Lip's detector the film goes in as it is:
|
|
319
|
+
// Wav2Lip finds the face per frame, and the loop jumps at its end
|
|
320
|
+
if (!ffmpegOk || !wav2lipDir) return { file: null, loop: still, box: null };
|
|
321
|
+
const t0 = Date.now();
|
|
322
|
+
const c = await prepareClip(python, { dir: wav2lipDir, clip: still, cacheDir });
|
|
323
|
+
if (chatty()) console.log(` portrait ${name}: filmed · ${c.seconds.toFixed(1)}s, played there and back · face in ${c.faces} frames · `
|
|
324
|
+
+ (c.steady ? 'head steady — only the mouth is redrawn'
|
|
325
|
+
: 'head moves — the whole face is redrawn (softer); film with the head still for a sharper one')
|
|
326
|
+
+ ` · ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
327
|
+
return { file: c.still, loop: c.loop, box: c.steady ? c.box : null };
|
|
328
|
+
}
|
|
329
|
+
const small = await prepareStill(still, cacheDir).catch(() => still);
|
|
330
|
+
const found = wav2lipDir ? await faceBox(python, { dir: wav2lipDir, still: small, cacheDir }).catch(() => null) : null;
|
|
331
|
+
const head = found && ffmpegOk ? await headCrop(small, found, cacheDir).catch(() => null) : null;
|
|
332
|
+
return { file: head?.file ?? small, box: head?.box ?? found };
|
|
333
|
+
})());
|
|
334
|
+
prepared.get(still).catch((e) => {
|
|
335
|
+
console.error(` portrait ${name}: ${String(e.message ?? e).slice(0, 200)}`);
|
|
336
|
+
prepared.delete(still);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
return prepared.get(still);
|
|
340
|
+
}
|
|
341
|
+
|
|
221
342
|
async function video(wav, engine, portraitName) {
|
|
222
343
|
if (!videoEngines.includes(engine)) throw new Error(`engine '${engine}' not available`);
|
|
223
344
|
const still = portraits.get(portraitName);
|
|
@@ -227,10 +348,19 @@ photo puts the face lower in Veo's 9:16 frame — chin off the bottom. Nudge
|
|
|
227
348
|
// the new mouth. Bought once per portrait and cached (tools/veo.mjs), so
|
|
228
349
|
// this awaits a network call only the very first time. SadTalker is left
|
|
229
350
|
// alone — it makes its own head motion and needs the still.
|
|
230
|
-
|
|
351
|
+
// A filmed portrait already moves: Veo is not asked to animate a film.
|
|
352
|
+
const filmed = isClip(still);
|
|
353
|
+
const moving = veo && engine === 'wav2lip' && !filmed;
|
|
354
|
+
// a phone photo is too big for the face detector, and the head should fill
|
|
355
|
+
// the round overlay: scaled, face found, cropped — once per portrait
|
|
356
|
+
const ready = moving ? null : await stillFor(portraitName);
|
|
357
|
+
const small = ready?.file ?? still;
|
|
358
|
+
if (filmed && engine !== 'wav2lip' && !ready?.file) throw new Error(`${engine} needs a still — no frame could be taken from ${still} (is ffmpeg installed?)`);
|
|
359
|
+
const face = moving ? await veo.motionFor(still) : filmed && engine === 'wav2lip' ? ready.loop : small;
|
|
231
360
|
// the key reads `face`, so a veo clip and a still can never share a cache
|
|
232
|
-
// entry — flip --veo off and yesterday's clips are still there, untouched
|
|
233
|
-
|
|
361
|
+
// entry — flip --veo off and yesterday's clips are still there, untouched.
|
|
362
|
+
// `mouth-v1`: clips from before the mouth-only composite are not reused.
|
|
363
|
+
const key = sha('video|head-v2|', engine, '|', readFileSync(face), '|', wav);
|
|
234
364
|
const out = join(cacheDir, `${key}.mp4`);
|
|
235
365
|
if (existsSync(out)) return { body: readFileSync(out), cached: true };
|
|
236
366
|
await dedup(key, () => gpuQ(async () => {
|
|
@@ -249,12 +379,28 @@ photo puts the face lower in Veo's 9:16 frame — chin off the bottom. Nudge
|
|
|
249
379
|
// big to run face detection on GPU" — which it will do on an 8 GB card
|
|
250
380
|
// that a desktop is already using half of. Batch small instead: the
|
|
251
381
|
// clip is short, and the GPU queue is serial anyway.
|
|
252
|
-
|
|
253
|
-
|
|
382
|
+
// A still's face is found ONCE (cached), handed to Wav2Lip as --box so
|
|
383
|
+
// it skips detection per clip — and it places the mouth-only
|
|
384
|
+
// composite below. A motion clip moves, so neither applies to it.
|
|
385
|
+
// the head-cropped still and its face box (stillFor) — handed to
|
|
386
|
+
// Wav2Lip as --box so it skips detection per clip
|
|
387
|
+
// A filmed portrait whose head held still gets the same: one box for
|
|
388
|
+
// every frame, and the mouth laid over the film (frame-aligned).
|
|
389
|
+
const src = face;
|
|
390
|
+
const box = moving ? null : ready?.box ?? null;
|
|
391
|
+
const raw = box ? join(cacheDir, `${key}.tmp.raw.mp4`) : tmpMp4;
|
|
392
|
+
await runWav2lip(python, { dir: wav2lipDir, checkpoint: wav2lipCkpt, face: src,
|
|
393
|
+
wav: tmpWav, out: raw, smallBatches: moving || (filmed && !box), box, timeout: 600000 });
|
|
394
|
+
// Wav2Lip redraws the whole face at 96 px; keep the photo sharp and
|
|
395
|
+
// take only the mouth from it (lipsync-engines.mjs `mouthComposite`)
|
|
396
|
+
if (box && ffmpegOk) {
|
|
397
|
+
try { await mouthComposite(src, raw, box, tmpMp4); }
|
|
398
|
+
finally { rmSync(raw, { force: true }); }
|
|
399
|
+
} else if (box) renameSync(raw, tmpMp4);
|
|
254
400
|
} else {
|
|
255
401
|
// SadTalker writes <timestamp>/….mp4 into result_dir — runSadtalker
|
|
256
402
|
// takes the newest and moves it to tmpMp4.
|
|
257
|
-
await runSadtalker(python, { dir: sadtalkerDir, still:
|
|
403
|
+
await runSadtalker(python, { dir: sadtalkerDir, still: small,
|
|
258
404
|
wav: tmpWav, out: tmpMp4, resultDir: tmpDir, timeout: 1800000 });
|
|
259
405
|
}
|
|
260
406
|
// strip the audio track (playback is muted — narrAudio is the voice)
|
|
@@ -280,11 +426,69 @@ photo puts the face lower in Veo's 9:16 frame — chin off the bottom. Nudge
|
|
|
280
426
|
return res.end(JSON.stringify({
|
|
281
427
|
ok: true,
|
|
282
428
|
engines: { viseme: visemeOk, video: videoEngines },
|
|
429
|
+
// why there is no video, in the words doctor uses — the deck says it
|
|
430
|
+
...(videoEngines.length ? {} : { videoWhy: setupNow.problems[0] ?? 'no Wav2Lip or SadTalker set up' }),
|
|
283
431
|
// what the head is driven from: a veo motion clip, or the still photo
|
|
284
432
|
motion: veo ? { engine: 'veo', model: veo.model, seconds: veo.seconds } : null,
|
|
433
|
+
// whether the deck may film a portrait here (POST /portrait), and why not
|
|
434
|
+
film: !filmWhy, ...(filmWhy ? { filmWhy } : {}),
|
|
285
435
|
portraits: [...portraits.keys()],
|
|
286
436
|
}));
|
|
287
437
|
}
|
|
438
|
+
// the portrait the clips are made from, for the deck to show UNDER the
|
|
439
|
+
// video — so the medallion is the photo, not black, while a clip renders
|
|
440
|
+
if (req.method === 'GET' && url.pathname === '/portrait') {
|
|
441
|
+
try {
|
|
442
|
+
const { file } = await stillFor(url.searchParams.get('name') || 'default');
|
|
443
|
+
if (!file) throw new Error('no still for a film without ffmpeg');
|
|
444
|
+
res.writeHead(200, { ...CORS, 'content-type': 'image/jpeg', 'cache-control': 'max-age=3600' });
|
|
445
|
+
return res.end(readFileSync(file));
|
|
446
|
+
} catch (e) {
|
|
447
|
+
res.writeHead(404, { ...CORS, 'content-type': 'text/plain' });
|
|
448
|
+
return res.end(String(e.message ?? e));
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
// A portrait filmed in the deck: prepared like any film, kept beside
|
|
452
|
+
// lipsync.json, remembered there, and offered at once — no restart.
|
|
453
|
+
if (req.method === 'POST' && url.pathname === '/portrait') {
|
|
454
|
+
const answer = (code, body) => { res.writeHead(code, { ...CORS, 'content-type': 'application/json' }); res.end(JSON.stringify(body)); };
|
|
455
|
+
const name = url.searchParams.get('name') || 'filmed';
|
|
456
|
+
if (!/^[A-Za-z0-9_-]{1,40}$/.test(name) || name === 'default') return answer(400, { error: `a portrait name is letters, digits, - and _ (not '${name}')` });
|
|
457
|
+
if (filmWhy) return answer(409, { error: filmWhy });
|
|
458
|
+
const type = String(req.headers['content-type'] ?? '');
|
|
459
|
+
const ext = /mp4/.test(type) ? '.mp4' : /webm/.test(type) ? '.webm' : /quicktime/.test(type) ? '.mov' : null;
|
|
460
|
+
if (!ext) return answer(415, { error: `a film is video/mp4, video/webm or video/quicktime, not '${type || 'nothing'}'` });
|
|
461
|
+
const tmp = join(cacheDir, `upload-${process.pid}-${Date.now()}${ext}`);
|
|
462
|
+
try {
|
|
463
|
+
const body = await readBody(req, { max: FILM_MAX });
|
|
464
|
+
if (body.length < 1024) return answer(400, { error: 'no film in the request' });
|
|
465
|
+
writeFileSync(tmp, body);
|
|
466
|
+
const t0 = Date.now();
|
|
467
|
+
const c = await prepareClip(python, { dir: wav2lipDir, clip: tmp, cacheDir });
|
|
468
|
+
const dir = portraitsDir();
|
|
469
|
+
mkdirSync(dir, { recursive: true });
|
|
470
|
+
const file = join(dir, `${name}${ext}`);
|
|
471
|
+
// a retake in another container must not leave the old take behind
|
|
472
|
+
for (const old of ['.mp4', '.webm', '.mov']) if (old !== ext) rmSync(join(dir, `${name}${old}`), { force: true });
|
|
473
|
+
copyFileSync(tmp, file);
|
|
474
|
+
prepared.delete(file); // a retake: same path, new film
|
|
475
|
+
if (!portraits.size) portraits.set('default', file);
|
|
476
|
+
portraits.set(name, file);
|
|
477
|
+
enginesNow();
|
|
478
|
+
const saved = saveLipsyncConfig(withPortrait(loadLipsyncConfig(), name, file,
|
|
479
|
+
{ wav2lipDir: resolve(wav2lipDir), wav2lipCkpt: resolve(wav2lipCkpt), python: python.includes('/') ? resolve(python) : python }));
|
|
480
|
+
console.log(` portrait ${name}: filmed in the deck · ${c.seconds.toFixed(1)}s · face in ${c.faces} frames · `
|
|
481
|
+
+ `${c.steady ? 'head steady' : 'head moves'} · ${((Date.now() - t0) / 1000).toFixed(1)}s → ${file}`);
|
|
482
|
+
return answer(200, { ok: true, name, file, saved, seconds: c.seconds, steady: c.steady, faces: c.faces });
|
|
483
|
+
} catch (e) {
|
|
484
|
+
const msg = String(e.message ?? e);
|
|
485
|
+
console.error(` portrait ${name}: ${msg.slice(0, 200)}`);
|
|
486
|
+
return answer(e.code === 'E2BIG' ? 413 : /no face found/.test(msg) ? 422 : 500,
|
|
487
|
+
{ error: e.code === 'E2BIG' ? `a film is at most ${FILM_MAX / 1024 / 1024} MB` : msg.replace(tmp, 'the film') });
|
|
488
|
+
} finally {
|
|
489
|
+
rmSync(tmp, { force: true });
|
|
490
|
+
}
|
|
491
|
+
}
|
|
288
492
|
if (req.method === 'POST' && (url.pathname === '/viseme' || url.pathname === '/video')) {
|
|
289
493
|
try {
|
|
290
494
|
const wav = await readBody(req);
|
|
@@ -316,7 +520,7 @@ photo puts the face lower in Veo's 9:16 frame — chin off the bottom. Nudge
|
|
|
316
520
|
// it, so they were the one place the deck could still look broken.
|
|
317
521
|
//
|
|
318
522
|
// On a TTY it names the occupant and offers a choice; anywhere else — and
|
|
319
|
-
//
|
|
523
|
+
// `open` spawns these with a piped stdin, so that is the usual case — it
|
|
320
524
|
// moves to the next free port and says so. The player finds the bridge by
|
|
321
525
|
// probing, so a moved port costs nothing.
|
|
322
526
|
// `canBind`, NOT `isPortOpen`: this file's own note says why, and getting it
|
|
@@ -334,25 +538,44 @@ photo puts the face lower in Veo's 9:16 frame — chin off the bottom. Nudge
|
|
|
334
538
|
kind: 'bridge',
|
|
335
539
|
ask: process.stdin.isTTY && process.stdout.isTTY ? askLine : undefined,
|
|
336
540
|
log: console.log,
|
|
541
|
+
// Under `open`, how it ended is this bridge's row on the banner: ✓ when
|
|
542
|
+
// one is already there and serves the deck, ✗ when the port is somebody
|
|
543
|
+
// else's and the bridge may not move. Standalone, the lines as before.
|
|
544
|
+
outcome: process.env.DECKLIGHT_BANNER
|
|
545
|
+
? (o) => console.log(readyLine({ key: 'lips', text: describePortOutcome({ ...o, kind: 'bridge' }), mark: o.ending === 'reuse' ? 'ok' : 'fail' }))
|
|
546
|
+
: null,
|
|
337
547
|
})
|
|
338
548
|
: port;
|
|
339
549
|
// null is "stand down" — either a bridge is already serving this port, or
|
|
340
550
|
// somebody else holds it and this one cannot move (the deck only ever calls
|
|
341
|
-
// the one number). Exiting is the honest outcome:
|
|
551
|
+
// the one number). Exiting is the honest outcome: `open` prints "carrying on
|
|
342
552
|
// without it" and the deck degrades where you can see it, instead of a
|
|
343
553
|
// bridge running somewhere nothing will ever knock.
|
|
344
554
|
if (asked === null) process.exit(0);
|
|
345
555
|
server.listen(asked, '127.0.0.1', () => {
|
|
346
|
-
const what = [visemeOk && 'visemes (rhubarb)', ...videoEngines.map((e) => `video (${e})`)].filter(Boolean).join(' · ')
|
|
347
|
-
|
|
556
|
+
const what = [visemeOk && 'visemes (rhubarb)', ...videoEngines.map((e) => `video (${e})`)].filter(Boolean).join(' · ')
|
|
557
|
+
|| 'no portrait yet — film one from the deck (V → Character)';
|
|
558
|
+
const ready = visemeOk || videoEngines.length > 0;
|
|
559
|
+
if (process.env.DECKLIGHT_BANNER) console.log(readyLine({ key: 'lips', text: `${what} · :${port}`, ...(ready ? { mark: 'ok' } : {}) }));
|
|
348
560
|
else console.log(`decklight lipsync bridge on http://127.0.0.1:${port} — ${what} — Ctrl-C stops`);
|
|
349
|
-
if (veo) {
|
|
561
|
+
if (chatty() && veo) {
|
|
350
562
|
console.log(`veo: ${veo.model} · ${veo.seconds}s — each portrait is animated ONCE (billed), `
|
|
351
563
|
+ 'then wav2lip re-syncs that clip locally for every sentence');
|
|
352
564
|
}
|
|
353
|
-
console.log(`cache: ${cacheDir}`);
|
|
565
|
+
if (chatty()) console.log(`cache: ${cacheDir}`);
|
|
566
|
+
// A filmed portrait takes a minute to prepare (a face found in every
|
|
567
|
+
// second of it): start now, not on the first sentence of the talk.
|
|
568
|
+
if (videoEngines.length) {
|
|
569
|
+
const seen = new Set();
|
|
570
|
+
// by the name it was given, not the 'default' alias it also answers to
|
|
571
|
+
for (const [name, file] of [...portraits].reverse()) {
|
|
572
|
+
if (!seen.has(file)) { seen.add(file); stillFor(name).catch(() => {}); }
|
|
573
|
+
}
|
|
574
|
+
}
|
|
354
575
|
});
|
|
355
576
|
return server;
|
|
356
577
|
}
|
|
357
578
|
|
|
358
|
-
if (isMain(import.meta.url))
|
|
579
|
+
if (isMain(import.meta.url)) {
|
|
580
|
+
lipsyncMain(process.argv.slice(2)).catch((e) => { console.error(`decklight lipsync: ${e.message}`); process.exitCode = 1; });
|
|
581
|
+
}
|
package/tools/lipsync.mjs
CHANGED
|
@@ -21,6 +21,12 @@
|
|
|
21
21
|
// default engine — per-slide clips are long enough that its natural head
|
|
22
22
|
// motion beats Wav2Lip's static pose (live mode is the reverse).
|
|
23
23
|
//
|
|
24
|
+
// `decklight narrate <deck> --face [--video]` is the command in front of this
|
|
25
|
+
// (cli/narrate.mjs): it finds the deck's narration folders and runs this once
|
|
26
|
+
// per folder. What `decklight setup face` saved (tools/lipsync-config.mjs)
|
|
27
|
+
// fills every flag not given: rhubarb, python, the engine checkouts, the
|
|
28
|
+
// first portrait, and Veo. Flags win, as they do for the live bridge.
|
|
29
|
+
//
|
|
24
30
|
// Incremental like voiceover.mjs: lipsync.json stores a hash of
|
|
25
31
|
// (audio bytes, tool, engine, portrait) per slide, persisted after every
|
|
26
32
|
// slide, so a rerun only regenerates what actually changed.
|
|
@@ -32,6 +38,8 @@ import { createVeo, DEFAULT_PROMPT, VEO_MODELS } from './veo.mjs';
|
|
|
32
38
|
import { argReader } from './args.mjs';
|
|
33
39
|
import { runRhubarb, runWav2lip, runSadtalker, muteFaststart } from './lipsync-engines.mjs';
|
|
34
40
|
import { run, PROBE_MS, CODEC_MS } from './exec.mjs';
|
|
41
|
+
import { captioned, canonMarks } from './sentences.mjs';
|
|
42
|
+
import { loadLipsyncConfig, parsePortrait } from './lipsync-config.mjs';
|
|
35
43
|
|
|
36
44
|
const args = process.argv.slice(2);
|
|
37
45
|
const dirArg = args.find((a) => !a.startsWith('-'));
|
|
@@ -45,25 +53,34 @@ const dir = resolve(dirArg);
|
|
|
45
53
|
const { opt } = argReader(args);
|
|
46
54
|
const doVideo = args.includes('--video');
|
|
47
55
|
const doVisemes = args.includes('--visemes') || !doVideo; // visemes by default
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
const
|
|
56
|
+
const saved = loadLipsyncConfig() ?? {};
|
|
57
|
+
const rhubarb = opt('--rhubarb', saved.rhubarb ?? 'rhubarb');
|
|
58
|
+
const wav2lipDir = opt('--wav2lip-dir', saved.wav2lipDir);
|
|
59
|
+
const wav2lipCkpt = opt('--wav2lip-ckpt', saved.wav2lipCkpt);
|
|
60
|
+
const sadtalkerDir = opt('--sadtalker-dir', saved.sadtalkerDir);
|
|
61
|
+
// SadTalker by default (see above), unless the machine was set up for Wav2Lip only
|
|
62
|
+
const engine = opt('--engine', !sadtalkerDir && wav2lipDir && wav2lipCkpt ? 'wav2lip' : 'sadtalker');
|
|
63
|
+
// --portrait is a file, or the name of a portrait `setup face` saved; none
|
|
64
|
+
// given, the first saved one, which the live bridge also calls 'default'
|
|
65
|
+
const savedPortraits = (saved.portraits ?? []).map(parsePortrait);
|
|
66
|
+
const portraitArg = opt('--portrait');
|
|
67
|
+
const portrait = portraitArg
|
|
68
|
+
? savedPortraits.find(([name]) => name === portraitArg)?.[1] ?? resolve(portraitArg)
|
|
69
|
+
: savedPortraits[0]?.[1];
|
|
70
|
+
const python = opt('--python', saved.python ?? 'python3');
|
|
55
71
|
// --veo: animate the portrait ONCE through Vertex (tools/veo.mjs) and give
|
|
56
72
|
// wav2lip that clip instead of the still, so the recorded narrator moves
|
|
57
73
|
// instead of staring. One billed call per portrait, cached next to the audio.
|
|
58
|
-
|
|
74
|
+
// A saved `veo: true` turns it on here too, and --no-veo off.
|
|
75
|
+
const veoOn = args.includes('--veo') || (saved.veo === true && !args.includes('--no-veo'));
|
|
59
76
|
|
|
60
77
|
const veo = veoOn ? createVeo({
|
|
61
|
-
project: opt('--veo-project', process.env.GOOGLE_CLOUD_PROJECT),
|
|
62
|
-
location: opt('--veo-location', 'us-central1'),
|
|
63
|
-
model: opt('--veo-model', VEO_MODELS[0]),
|
|
64
|
-
seconds: Number(opt('--veo-seconds', 8)),
|
|
65
|
-
prompt: opt('--veo-prompt', DEFAULT_PROMPT),
|
|
66
|
-
faceY: Number(opt('--veo-face-y', 0.12)),
|
|
78
|
+
project: opt('--veo-project', saved.veoProject ?? process.env.GOOGLE_CLOUD_PROJECT),
|
|
79
|
+
location: opt('--veo-location', saved.veoLocation ?? 'us-central1'),
|
|
80
|
+
model: opt('--veo-model', saved.veoModel ?? VEO_MODELS[0]),
|
|
81
|
+
seconds: Number(opt('--veo-seconds', saved.veoSeconds ?? 8)),
|
|
82
|
+
prompt: opt('--veo-prompt', saved.veoPrompt ?? DEFAULT_PROMPT),
|
|
83
|
+
faceY: Number(opt('--veo-face-y', saved.veoFaceY ?? 0.12)),
|
|
67
84
|
cacheDir: dir,
|
|
68
85
|
}) : null;
|
|
69
86
|
|
|
@@ -71,11 +88,11 @@ const have = (bin, flags = ['--version']) => {
|
|
|
71
88
|
try { run(bin, flags, { stdio: 'ignore', timeout: PROBE_MS }); return true; } catch (e) { return e?.code !== 'ENOENT'; }
|
|
72
89
|
};
|
|
73
90
|
if (doVisemes && !have(rhubarb)) {
|
|
74
|
-
console.error(`rhubarb not found — install https://github.com/DanielSWolf/rhubarb-lip-sync
|
|
91
|
+
console.error(`rhubarb not found — install https://github.com/DanielSWolf/rhubarb-lip-sync, then decklight setup face --rhubarb <bin>`);
|
|
75
92
|
process.exit(1);
|
|
76
93
|
}
|
|
77
94
|
if (doVideo) {
|
|
78
|
-
if (!portrait || !existsSync(portrait)) { console.error('--video needs --portrait <image>'); process.exit(1); }
|
|
95
|
+
if (!portrait || !existsSync(portrait)) { console.error(portrait ? `portrait not found: ${portrait}` : '--video needs a portrait: --portrait <image>, or decklight setup face --portrait me=<image>'); process.exit(1); }
|
|
79
96
|
if (engine === 'wav2lip' && !(wav2lipDir && wav2lipCkpt)) { console.error('--engine wav2lip needs --wav2lip-dir and --wav2lip-ckpt'); process.exit(1); }
|
|
80
97
|
if (engine === 'sadtalker' && !sadtalkerDir) { console.error('--engine sadtalker needs --sadtalker-dir'); process.exit(1); }
|
|
81
98
|
}
|
|
@@ -97,7 +114,7 @@ const slides = stems.filter((st) => !/-\d+-\d+$/.test(st));
|
|
|
97
114
|
const beats = stems.filter((st) => /-\d+-\d+$/.test(st));
|
|
98
115
|
if (!stems.length) { console.error(`${dir}: no slide-NN.wav/.m4a files`); process.exit(1); }
|
|
99
116
|
console.log(`${basename(dir)}: ${slides.length} slides with audio`
|
|
100
|
-
+ (beats.length ? ` · ${beats.length}
|
|
117
|
+
+ (beats.length ? ` · ${beats.length} [click] beats` : ''));
|
|
101
118
|
|
|
102
119
|
// incremental state — its own file so voiceover.mjs reruns can't clobber it
|
|
103
120
|
const statePath = join(dir, 'lipsync.json');
|
|
@@ -157,7 +174,9 @@ for (const stem of stems) {
|
|
|
157
174
|
if (job === 'visemes') {
|
|
158
175
|
const tmpOut = join(dir, `${stem}.tmp.visemes.json`);
|
|
159
176
|
let dialogFile;
|
|
160
|
-
|
|
177
|
+
// the script keeps its ⟨PAUSE⟩ holds (#560); Rhubarb is told the words
|
|
178
|
+
const words = captioned(canonMarks(text));
|
|
179
|
+
if (words) { dialogFile = join(dir, `${stem}.tmp.txt`); writeFileSync(dialogFile, words); }
|
|
161
180
|
const tl = await runRhubarb(rhubarb, { wav: wav.path, dialogFile, out: tmpOut });
|
|
162
181
|
writeFileSync(outFile, JSON.stringify(tl));
|
|
163
182
|
rmSync(tmpOut, { force: true });
|