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
package/tools/lipsync-config.mjs
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
19
19
|
import { homedir } from 'node:os';
|
|
20
20
|
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
21
|
+
import { run, PROBE_MS } from './exec.mjs';
|
|
21
22
|
|
|
22
23
|
export function lipsyncConfigPath(env = process.env) {
|
|
23
24
|
const base = env.XDG_CONFIG_HOME || join(env.HOME || homedir(), '.config');
|
|
@@ -45,6 +46,21 @@ export function withPortrait(config, name, file, setup = {}) {
|
|
|
45
46
|
return next;
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
/** Whether `bin` runs here: a missing binary is ENOENT; one that runs and complains is still there. */
|
|
50
|
+
function probeBin(bin) {
|
|
51
|
+
try { run(bin, ['--version'], { stdio: 'ignore', timeout: PROBE_MS }); return true; } catch (e) { return e?.code !== 'ENOENT'; }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Why the drawn character's lip-sync cannot be made on this machine, or null.
|
|
56
|
+
* It is Rhubarb's (`lipsync --visemes`), and a video export with the character
|
|
57
|
+
* makes it before the render: the export card asks this first, so it can say
|
|
58
|
+
* so before the click rather than stop after it.
|
|
59
|
+
*/
|
|
60
|
+
export function visemesWhyNot({ config = loadLipsyncConfig() ?? {}, probe = probeBin } = {}) {
|
|
61
|
+
return probe(config.rhubarb ?? 'rhubarb') ? null : 'Rhubarb is not installed';
|
|
62
|
+
}
|
|
63
|
+
|
|
48
64
|
/** The saved setup, or null — a missing or unreadable file is "not set up", not an error. */
|
|
49
65
|
export function loadLipsyncConfig(env = process.env) {
|
|
50
66
|
try { return JSON.parse(readFileSync(lipsyncConfigPath(env), 'utf8')); }
|
|
@@ -33,10 +33,28 @@ const bufOpts = (timeout, inherit) => ({
|
|
|
33
33
|
...(inherit ? { stdio: 'inherit' } : { maxBuffer: 64 * 1024 * 1024 }),
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Rhubarb's recogniser for a language. Its default (pocketSphinx) recognises
|
|
38
|
+
* English WORDS and guides itself by the dialog text, so on French audio it
|
|
39
|
+
* hears English that is not there and the mouth follows that. `phonetic`
|
|
40
|
+
* recognises sounds and knows no language. English, and a deck that names no
|
|
41
|
+
* language, keep the default: it is the better of the two on English.
|
|
42
|
+
*/
|
|
43
|
+
export const rhubarbRecognizer = (lang) => {
|
|
44
|
+
const primary = String(lang ?? '').trim().split(/[-_]/)[0].toLowerCase();
|
|
45
|
+
return primary && primary !== 'en' ? 'phonetic' : null;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** rhubarb's argv. The dialog text guides the English recogniser, so it goes only to that one. */
|
|
49
|
+
export function rhubarbArgs({ wav, dialogFile, out, lang } = {}) {
|
|
50
|
+
const recognizer = rhubarbRecognizer(lang);
|
|
51
|
+
return ['-f', 'json', '-o', out, '--machineReadable',
|
|
52
|
+
...(recognizer ? ['-r', recognizer] : dialogFile ? ['--dialogFile', dialogFile] : []), wav];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** rhubarb: `wav` (+ optional `dialogFile`) → normalized viseme timeline. `lang` picks the recogniser. */
|
|
56
|
+
export async function runRhubarb(rhubarb, { wav, dialogFile, out, timeout, lang } = {}) {
|
|
57
|
+
await run(rhubarb, rhubarbArgs({ wav, dialogFile, out, lang }),
|
|
40
58
|
timeout ? { timeout } : {});
|
|
41
59
|
return normalizeRhubarb(JSON.parse(readFileSync(out, 'utf8')));
|
|
42
60
|
}
|
package/tools/lipsync-server.mjs
CHANGED
|
@@ -43,7 +43,7 @@ import { homedir } from 'node:os';
|
|
|
43
43
|
import { promisify } from 'node:util';
|
|
44
44
|
import { createVeo, DEFAULT_PROMPT, VEO_MODELS } from './veo.mjs';
|
|
45
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';
|
|
46
|
+
import { runRhubarb, rhubarbRecognizer, runWav2lip, runSadtalker, muteFaststart, prepareStill, faceBox, headCrop, mouthComposite, isClip, prepareClip, CLIP_MAX_SECONDS } from './lipsync-engines.mjs';
|
|
47
47
|
import { loadLipsyncConfig, saveLipsyncConfig, lipsyncConfigPath, videoSetup, SETUP_HINT, portraitsDir, withPortrait } from './lipsync-config.mjs';
|
|
48
48
|
import { corsHeaders, readBody } from './bridge.mjs';
|
|
49
49
|
import { readyLine } from '../cli/banner.mjs';
|
|
@@ -149,6 +149,9 @@ photo puts the face lower in Veo's 9:16 frame — chin off the bottom. Nudge
|
|
|
149
149
|
// so a talking head set up once starts with every `decklight <deck>`.
|
|
150
150
|
const saved = loadLipsyncConfig() ?? {};
|
|
151
151
|
const rhubarb = opt('--rhubarb', saved.rhubarb ?? 'rhubarb');
|
|
152
|
+
// the deck's language, passed by `decklight <deck>`: picks Rhubarb's recogniser
|
|
153
|
+
const lang = opt('--lang');
|
|
154
|
+
const recognizer = rhubarbRecognizer(lang);
|
|
152
155
|
const python = opt('--python', saved.python ?? 'python3');
|
|
153
156
|
const wav2lipDir = opt('--wav2lip-dir', saved.wav2lipDir);
|
|
154
157
|
const wav2lipCkpt = opt('--wav2lip-ckpt', saved.wav2lipCkpt);
|
|
@@ -248,7 +251,7 @@ photo puts the face lower in Veo's 9:16 frame — chin off the bottom. Nudge
|
|
|
248
251
|
if (!videoEngines.length) {
|
|
249
252
|
for (const p of setupNow.problems) console.log(` video: ${p}`);
|
|
250
253
|
if (!wav2lipDir && !sadtalkerDir) console.log(` video: not set up — ${SETUP_HINT}`);
|
|
251
|
-
else if (!filmWhy) console.log(' video: or
|
|
254
|
+
else if (!filmWhy) console.log(' video: or make your portrait from the deck — V → A talking head of me → Make my portrait…');
|
|
252
255
|
}
|
|
253
256
|
// Wav2Lip with no portrait yet still serves: filming one is what the deck does next
|
|
254
257
|
if (!visemeOk && !videoEngines.length && filmWhy) {
|
|
@@ -276,7 +279,7 @@ photo puts the face lower in Veo's 9:16 frame — chin off the bottom. Nudge
|
|
|
276
279
|
};
|
|
277
280
|
|
|
278
281
|
async function visemes(wav, text) {
|
|
279
|
-
const key = sha('viseme|', text, '|', wav);
|
|
282
|
+
const key = sha(recognizer ? `viseme:${recognizer}|` : 'viseme|', text, '|', wav);
|
|
280
283
|
const out = join(cacheDir, `${key}.json`);
|
|
281
284
|
if (existsSync(out)) return { body: readFileSync(out), cached: true };
|
|
282
285
|
await dedup(key, () => rhubarbQ(async () => {
|
|
@@ -288,7 +291,7 @@ photo puts the face lower in Veo's 9:16 frame — chin off the bottom. Nudge
|
|
|
288
291
|
if (text.trim()) writeFileSync(tmpTxt, text);
|
|
289
292
|
try {
|
|
290
293
|
const t0 = Date.now();
|
|
291
|
-
const tl = await runRhubarb(rhubarb, { wav: tmpWav, dialogFile: text.trim() ? tmpTxt : undefined, out: tmpOut, timeout: 120000 });
|
|
294
|
+
const tl = await runRhubarb(rhubarb, { wav: tmpWav, dialogFile: text.trim() ? tmpTxt : undefined, out: tmpOut, timeout: 120000, lang });
|
|
292
295
|
writeFileSync(out, JSON.stringify(tl));
|
|
293
296
|
console.log(` viseme: ${(wav.length / 1024).toFixed(0)} KB wav → ${tl.cues.length} cues · ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
294
297
|
} finally {
|
|
@@ -554,7 +557,7 @@ photo puts the face lower in Veo's 9:16 frame — chin off the bottom. Nudge
|
|
|
554
557
|
if (asked === null) process.exit(0);
|
|
555
558
|
server.listen(asked, '127.0.0.1', () => {
|
|
556
559
|
const what = [visemeOk && 'visemes (rhubarb)', ...videoEngines.map((e) => `video (${e})`)].filter(Boolean).join(' · ')
|
|
557
|
-
|| 'no portrait yet —
|
|
560
|
+
|| 'no portrait yet — make one from the deck (V → Make my portrait…)';
|
|
558
561
|
const ready = visemeOk || videoEngines.length > 0;
|
|
559
562
|
if (process.env.DECKLIGHT_BANNER) console.log(readyLine({ key: 'lips', text: `${what} · :${port}`, ...(ready ? { mark: 'ok' } : {}) }));
|
|
560
563
|
else console.log(`decklight lipsync bridge on http://127.0.0.1:${port} — ${what} — Ctrl-C stops`);
|
package/tools/lipsync.mjs
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Lip-sync generator for RECORDED narration: sidecar files for every
|
|
3
3
|
// slide-NN audio clip in a voiceover directory (tools/voiceover.mjs or a
|
|
4
|
-
// deck-recorded set — V →
|
|
4
|
+
// deck-recorded set — V → Save with the deck), so a deck plays back with an animated character and no
|
|
5
5
|
// bridge running. Fully offline, like everything else here.
|
|
6
6
|
//
|
|
7
7
|
// node tools/lipsync.mjs <voiceover-dir> [--visemes] [--video]
|
|
8
|
-
// [--rhubarb <bin>]
|
|
8
|
+
// [--rhubarb <bin>] [--remake slide-01,slide-02-01]
|
|
9
|
+
// [--jobs N]
|
|
9
10
|
// [--engine sadtalker|wav2lip] [--portrait <img>]
|
|
10
11
|
// [--wav2lip-dir <repo> --wav2lip-ckpt <pth>]
|
|
11
12
|
// [--sadtalker-dir <repo>] [--python python3]
|
|
12
13
|
//
|
|
13
14
|
// Outputs, next to the audio they belong to (config: narration.files dir):
|
|
14
|
-
// --visemes (default) — slide-NN.visemes.json (timeline v1, via Rhubarb
|
|
15
|
+
// --visemes (default) — slide-NN.visemes.json (timeline v1, via Rhubarb;
|
|
16
|
+
// without it, read from the voice: tools/mouth.mjs)
|
|
15
17
|
// --video — slide-NN.mp4 (muted talking head)
|
|
16
18
|
//
|
|
17
19
|
// Rhubarb wants WAV: slide-NN.wav is used when present (voiceover.mjs
|
|
@@ -29,22 +31,36 @@
|
|
|
29
31
|
//
|
|
30
32
|
// Incremental like voiceover.mjs: lipsync.json stores a hash of
|
|
31
33
|
// (audio bytes, tool, engine, portrait) per slide, persisted after every
|
|
32
|
-
// slide, so a rerun only regenerates what actually changed.
|
|
34
|
+
// slide, so a rerun only regenerates what actually changed. Each sidecar also
|
|
35
|
+
// carries `audio`, the hash of the audio it was cut from (tools/viseme-match.mjs),
|
|
36
|
+
// so a reader can tell it from one another recording left behind (#1244): a
|
|
37
|
+
// sidecar whose hash is current but which is NOT this audio's (copied in, or
|
|
38
|
+
// written by another tool) is made again rather than kept. `--remake` names the
|
|
39
|
+
// stems to make whatever the state says — what `decklight video` passes for
|
|
40
|
+
// the sidecars it found out of step with their audio.
|
|
41
|
+
//
|
|
42
|
+
// Rhubarb is slow — minutes for a long slide — so viseme-only runs cut
|
|
43
|
+
// `--jobs` files at once (default: a quarter of the cores, 1–4), and each line
|
|
44
|
+
// says how far along the run is (`[3/12]`). A run that also renders video stays
|
|
45
|
+
// one file at a time: a talking head already fills the GPU.
|
|
33
46
|
|
|
34
47
|
import { readFileSync, writeFileSync, existsSync, readdirSync, rmSync, renameSync } from 'node:fs';
|
|
35
48
|
import { createHash } from 'node:crypto';
|
|
36
49
|
import { resolve, join, basename } from 'node:path';
|
|
50
|
+
import { availableParallelism } from 'node:os';
|
|
37
51
|
import { createVeo, DEFAULT_PROMPT, VEO_MODELS } from './veo.mjs';
|
|
38
52
|
import { argReader } from './args.mjs';
|
|
39
53
|
import { runRhubarb, runWav2lip, runSadtalker, muteFaststart } from './lipsync-engines.mjs';
|
|
40
54
|
import { run, PROBE_MS, CODEC_MS } from './exec.mjs';
|
|
41
55
|
import { captioned, canonMarks } from './sentences.mjs';
|
|
42
56
|
import { loadLipsyncConfig, parsePortrait } from './lipsync-config.mjs';
|
|
57
|
+
import { audioStamp, visemeHash, visemeMismatch, wavDuration } from './viseme-match.mjs';
|
|
58
|
+
import { mouthFromFile } from './mouth-file.mjs';
|
|
43
59
|
|
|
44
60
|
const args = process.argv.slice(2);
|
|
45
61
|
const dirArg = args.find((a) => !a.startsWith('-'));
|
|
46
62
|
if (!dirArg || args.includes('--help')) {
|
|
47
|
-
console.error('usage: lipsync.mjs <voiceover-dir> [--visemes] [--video] [--rhubarb bin]\n'
|
|
63
|
+
console.error('usage: lipsync.mjs <voiceover-dir> [--visemes] [--video] [--rhubarb bin] [--lang fr]\n'
|
|
48
64
|
+ ' [--engine sadtalker|wav2lip] [--portrait img]\n'
|
|
49
65
|
+ ' [--wav2lip-dir repo --wav2lip-ckpt pth] [--sadtalker-dir repo] [--python bin]');
|
|
50
66
|
process.exit(dirArg ? 0 : 1);
|
|
@@ -55,6 +71,9 @@ const doVideo = args.includes('--video');
|
|
|
55
71
|
const doVisemes = args.includes('--visemes') || !doVideo; // visemes by default
|
|
56
72
|
const saved = loadLipsyncConfig() ?? {};
|
|
57
73
|
const rhubarb = opt('--rhubarb', saved.rhubarb ?? 'rhubarb');
|
|
74
|
+
// the language spoken in this folder (`decklight narrate --face` passes the
|
|
75
|
+
// deck's own): anything but English is heard by sound, not by English words
|
|
76
|
+
const lang = opt('--lang');
|
|
58
77
|
const wav2lipDir = opt('--wav2lip-dir', saved.wav2lipDir);
|
|
59
78
|
const wav2lipCkpt = opt('--wav2lip-ckpt', saved.wav2lipCkpt);
|
|
60
79
|
const sadtalkerDir = opt('--sadtalker-dir', saved.sadtalkerDir);
|
|
@@ -68,10 +87,23 @@ const portrait = portraitArg
|
|
|
68
87
|
? savedPortraits.find(([name]) => name === portraitArg)?.[1] ?? resolve(portraitArg)
|
|
69
88
|
: savedPortraits[0]?.[1];
|
|
70
89
|
const python = opt('--python', saved.python ?? 'python3');
|
|
90
|
+
const remake = opt('--remake') ? new Set(opt('--remake').split(',').filter(Boolean)) : null;
|
|
91
|
+
// A video export names the exact take it will play, even if a lossless
|
|
92
|
+
// intermediate with the same stem sits beside it.
|
|
93
|
+
const requestedAudio = opt('--audio-files');
|
|
94
|
+
const audioFiles = requestedAudio ? JSON.parse(requestedAudio) : null;
|
|
95
|
+
if (audioFiles && (!Array.isArray(audioFiles) || audioFiles.some((file) =>
|
|
96
|
+
typeof file !== 'string' || !/^slide-\d+(?:-\d+)?\.(wav|m4a|mp3)$/.test(file)))) {
|
|
97
|
+
console.error('--audio-files must name slide audio files in the track');
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
const audioByStem = new Map(audioFiles?.map((file) => [file.replace(/\.[^.]+$/, ''), file]));
|
|
71
101
|
// --veo: animate the portrait ONCE through Vertex (tools/veo.mjs) and give
|
|
72
102
|
// wav2lip that clip instead of the still, so the recorded narrator moves
|
|
73
103
|
// instead of staring. One billed call per portrait, cached next to the audio.
|
|
74
104
|
// A saved `veo: true` turns it on here too, and --no-veo off.
|
|
105
|
+
const jobsArg = Number(opt('--jobs', 0));
|
|
106
|
+
const jobs = doVideo ? 1 : jobsArg >= 1 ? Math.floor(jobsArg) : defaultJobs();
|
|
75
107
|
const veoOn = args.includes('--veo') || (saved.veo === true && !args.includes('--no-veo'));
|
|
76
108
|
|
|
77
109
|
const veo = veoOn ? createVeo({
|
|
@@ -84,12 +116,21 @@ const veo = veoOn ? createVeo({
|
|
|
84
116
|
cacheDir: dir,
|
|
85
117
|
}) : null;
|
|
86
118
|
|
|
119
|
+
/** A quarter of the cores, 1–4: Rhubarb threads within a file too. */
|
|
120
|
+
function defaultJobs() {
|
|
121
|
+
return Math.max(1, Math.min(4, Math.floor(availableParallelism() / 4)));
|
|
122
|
+
}
|
|
123
|
+
|
|
87
124
|
const have = (bin, flags = ['--version']) => {
|
|
88
125
|
try { run(bin, flags, { stdio: 'ignore', timeout: PROBE_MS }); return true; } catch (e) { return e?.code !== 'ENOENT'; }
|
|
89
126
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
127
|
+
// Without Rhubarb the mouth is read from the voice (tools/mouth.mjs): less
|
|
128
|
+
// exact, seconds for a whole track, and marked `source: 'builtin'`, so every
|
|
129
|
+
// reader takes it as out of date once Rhubarb is here (tools/viseme-match.mjs).
|
|
130
|
+
const rhubarbHere = !doVisemes || have(rhubarb);
|
|
131
|
+
if (!rhubarbHere) {
|
|
132
|
+
console.log(' Rhubarb is not installed: the mouth is read from the voice instead, less exactly. '
|
|
133
|
+
+ 'For Rhubarb\'s, install https://github.com/DanielSWolf/rhubarb-lip-sync, then decklight setup face --rhubarb <bin>');
|
|
93
134
|
}
|
|
94
135
|
if (doVideo) {
|
|
95
136
|
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); }
|
|
@@ -107,15 +148,24 @@ const ffmpegOk = have('ffmpeg', ['-version']);
|
|
|
107
148
|
// progressively wronger after it. Cutting one per beat is the fix, and it costs
|
|
108
149
|
// only Rhubarb passes: they are seconds each, and incremental like everything
|
|
109
150
|
// else here.
|
|
110
|
-
const stems = [...new Set(readdirSync(dir)
|
|
151
|
+
const stems = (audioFiles ? [...audioByStem.keys()] : [...new Set(readdirSync(dir)
|
|
111
152
|
.map((f) => f.match(/^(slide-\d+(?:-\d+)?)\.(wav|m4a)$/)?.[1])
|
|
112
|
-
.filter(Boolean))].sort();
|
|
153
|
+
.filter(Boolean))]).sort().filter((st) => !remake || remake.has(st));
|
|
113
154
|
const slides = stems.filter((st) => !/-\d+-\d+$/.test(st));
|
|
114
155
|
const beats = stems.filter((st) => /-\d+-\d+$/.test(st));
|
|
115
156
|
if (!stems.length) { console.error(`${dir}: no slide-NN.wav/.m4a files`); process.exit(1); }
|
|
116
157
|
console.log(`${basename(dir)}: ${slides.length} slides with audio`
|
|
117
158
|
+ (beats.length ? ` · ${beats.length} [click] beats` : ''));
|
|
118
159
|
|
|
160
|
+
// Slides you filmed while you recorded them (the manifest says `face`): their
|
|
161
|
+
// slide-NN.mp4 is your own face, and a talking head rendered over it would
|
|
162
|
+
// throw the real thing away for a likeness of it.
|
|
163
|
+
const filmed = new Set();
|
|
164
|
+
try {
|
|
165
|
+
const m = JSON.parse(readFileSync(join(dir, 'manifest.json'), 'utf8'));
|
|
166
|
+
(m.slides ?? []).forEach((e, i) => { if (e?.face) filmed.add(`slide-${String(i + 1).padStart(2, '0')}`); });
|
|
167
|
+
} catch { /* no manifest: nothing was filmed by the recorder */ }
|
|
168
|
+
|
|
119
169
|
// incremental state — its own file so voiceover.mjs reruns can't clobber it
|
|
120
170
|
const statePath = join(dir, 'lipsync.json');
|
|
121
171
|
let state = {};
|
|
@@ -127,13 +177,19 @@ const sha = (...parts) => {
|
|
|
127
177
|
return h.digest('hex').slice(0, 16);
|
|
128
178
|
};
|
|
129
179
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
180
|
+
// A sidecar on disk under a current hash is kept only if it is THIS audio's:
|
|
181
|
+
// the hash says what was made last, not what is in the file now.
|
|
182
|
+
function keepsVisemes(file, audioBytes) {
|
|
183
|
+
try {
|
|
184
|
+
return !visemeMismatch(JSON.parse(readFileSync(file, 'utf8')), { audioBytes, duration: wavDuration(audioBytes), rhubarb: rhubarbHere });
|
|
185
|
+
} catch { return false; }
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function toWav(stem, audioFile) {
|
|
189
|
+
if (audioFile.endsWith('.wav')) return { path: audioFile, tmp: false };
|
|
134
190
|
const tmp = join(dir, `${stem}.tmp.wav`);
|
|
135
|
-
if (ffmpegOk) run('ffmpeg', ['-y', '-i',
|
|
136
|
-
else run('afconvert', ['-f', 'WAVE', '-d', 'LEI16',
|
|
191
|
+
if (ffmpegOk) run('ffmpeg', ['-y', '-i', audioFile, tmp], { stdio: 'ignore', timeout: CODEC_MS, why: 'the encoder is stuck on this file — check it plays, then retry' });
|
|
192
|
+
else run('afconvert', ['-f', 'WAVE', '-d', 'LEI16', audioFile, tmp], { timeout: CODEC_MS, why: 'the encoder is stuck on this file — check it plays, then retry' });
|
|
137
193
|
return { path: tmp, tmp: true };
|
|
138
194
|
}
|
|
139
195
|
|
|
@@ -142,33 +198,56 @@ function toWav(stem) {
|
|
|
142
198
|
// GPU time is spent.
|
|
143
199
|
const face = veo && engine === 'wav2lip' ? await veo.motionFor(portrait) : portrait;
|
|
144
200
|
|
|
145
|
-
let made = 0, kept = 0;
|
|
146
|
-
|
|
201
|
+
let made = 0, kept = 0, finished = 0;
|
|
202
|
+
const unread = []; // stems whose voice could not be read (no Rhubarb, no decoder)
|
|
203
|
+
// how far along the run is, counted in files: a stem's last job finishes it
|
|
204
|
+
const of = (last) => `[${last ? ++finished : finished + 1}/${stems.length}]`;
|
|
205
|
+
async function oneStem(stem) {
|
|
147
206
|
// A beat gets visemes only. A talking head is minutes of GPU time per clip,
|
|
148
207
|
// and the player's video element mirrors the audio's transport rather than
|
|
149
208
|
// seeking a timeline — so cutting video per beat would cost a great deal to
|
|
150
209
|
// fix a smaller error than the visemes had.
|
|
151
210
|
const isBeat = /-\d+-\d+$/.test(stem);
|
|
152
|
-
const audioFile =
|
|
211
|
+
const audioFile = audioFiles ? join(dir, audioByStem.get(stem))
|
|
212
|
+
: ['wav', 'm4a'].map((e) => join(dir, `${stem}.${e}`)).find(existsSync);
|
|
153
213
|
const audioBytes = readFileSync(audioFile);
|
|
154
214
|
const txtPath = join(dir, `${stem}.txt`);
|
|
155
215
|
const text = existsSync(txtPath) ? readFileSync(txtPath, 'utf8').trim() : '';
|
|
156
216
|
const st = (state[stem] ??= {});
|
|
157
|
-
const
|
|
158
|
-
if (doVisemes)
|
|
159
|
-
if (doVideo && !isBeat)
|
|
217
|
+
const work = [];
|
|
218
|
+
if (doVisemes) work.push('visemes');
|
|
219
|
+
if (doVideo && !isBeat && filmed.has(stem)) console.log(` ${stem}: video filmed with the recording — kept`);
|
|
220
|
+
else if (doVideo && !isBeat) work.push('video');
|
|
160
221
|
|
|
161
|
-
for (const job of
|
|
222
|
+
for (const job of work) {
|
|
162
223
|
const outFile = join(dir, job === 'visemes' ? `${stem}.visemes.json` : `${stem}.mp4`);
|
|
163
224
|
const hash = job === 'visemes'
|
|
164
|
-
?
|
|
225
|
+
? visemeHash(text, audioBytes)
|
|
165
226
|
: sha('video|', engine, '|', readFileSync(face), '|', audioBytes); // `face`, so --veo re-renders
|
|
166
|
-
if (st[job] === hash && existsSync(outFile)) {
|
|
227
|
+
if (st[job] === hash && existsSync(outFile) && !remake && !audioFiles && (job !== 'visemes' || keepsVisemes(outFile, audioBytes))) {
|
|
167
228
|
kept++;
|
|
168
|
-
console.log(` ${stem}: ${job} unchanged — kept`);
|
|
229
|
+
console.log(` ${of(job === work.at(-1))} ${stem}: ${job} unchanged — kept`);
|
|
169
230
|
continue;
|
|
170
231
|
}
|
|
171
|
-
|
|
232
|
+
if (job === 'visemes' && !rhubarbHere) {
|
|
233
|
+
// read from the voice: no WAV to make, and seconds for the whole track
|
|
234
|
+
const t0 = Date.now();
|
|
235
|
+
let read;
|
|
236
|
+
try { read = mouthFromFile(audioFile); } catch (e) {
|
|
237
|
+
// one unreadable file is said and skipped, not the end of the track
|
|
238
|
+
unread.push(stem);
|
|
239
|
+
console.log(` ${of(job === work.at(-1))} ${stem}: skipped · ${e.message}`);
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
const tl = { ...read, audio: audioStamp(audioBytes) };
|
|
243
|
+
writeFileSync(outFile, JSON.stringify(tl));
|
|
244
|
+
console.log(` ${of(job === work.at(-1))} ${stem}: ${tl.cues.length} cues → ${basename(outFile)} · read from the voice · ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
245
|
+
st[job] = hash;
|
|
246
|
+
made++;
|
|
247
|
+
writeFileSync(statePath, JSON.stringify(state, null, 1));
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const wav = toWav(stem, audioFile);
|
|
172
251
|
try {
|
|
173
252
|
const t0 = Date.now();
|
|
174
253
|
if (job === 'visemes') {
|
|
@@ -177,11 +256,13 @@ for (const stem of stems) {
|
|
|
177
256
|
// the script keeps its ⟨PAUSE⟩ holds (#560); Rhubarb is told the words
|
|
178
257
|
const words = captioned(canonMarks(text));
|
|
179
258
|
if (words) { dialogFile = join(dir, `${stem}.tmp.txt`); writeFileSync(dialogFile, words); }
|
|
180
|
-
|
|
259
|
+
// stamped with the audio it was cut from, so no reader takes it for
|
|
260
|
+
// another recording's lip-sync, or another's for this one's
|
|
261
|
+
const tl = { ...await runRhubarb(rhubarb, { wav: wav.path, dialogFile, out: tmpOut, lang }), audio: audioStamp(audioBytes) };
|
|
181
262
|
writeFileSync(outFile, JSON.stringify(tl));
|
|
182
263
|
rmSync(tmpOut, { force: true });
|
|
183
264
|
rmSync(join(dir, `${stem}.tmp.txt`), { force: true });
|
|
184
|
-
console.log(` ${stem}: ${tl.cues.length} cues → ${basename(outFile)} · ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
265
|
+
console.log(` ${of(job === work.at(-1))} ${stem}: ${tl.cues.length} cues → ${basename(outFile)} · ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
185
266
|
} else {
|
|
186
267
|
const tmpMp4 = join(dir, `${stem}.tmp.mp4`);
|
|
187
268
|
if (engine === 'wav2lip') {
|
|
@@ -201,7 +282,7 @@ for (const stem of stems) {
|
|
|
201
282
|
await muteFaststart(tmpMp4, outFile);
|
|
202
283
|
rmSync(tmpMp4, { force: true });
|
|
203
284
|
} else renameSync(tmpMp4, outFile);
|
|
204
|
-
console.log(` ${stem}: ${engine} → ${basename(outFile)} · ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
285
|
+
console.log(` ${of(job === work.at(-1))} ${stem}: ${engine} → ${basename(outFile)} · ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
205
286
|
}
|
|
206
287
|
st[job] = hash;
|
|
207
288
|
made++;
|
|
@@ -212,5 +293,16 @@ for (const stem of stems) {
|
|
|
212
293
|
}
|
|
213
294
|
}
|
|
214
295
|
}
|
|
296
|
+
// a pool of `jobs` workers over the stems; the state is written by this one
|
|
297
|
+
// process, so parallel files never clobber each other's entries
|
|
298
|
+
if (jobs > 1 && stems.length > 1) console.log(` cutting up to ${jobs} files at once`);
|
|
299
|
+
const queue = [...stems];
|
|
300
|
+
await Promise.all(Array.from({ length: Math.min(jobs, stems.length) }, async () => {
|
|
301
|
+
while (queue.length) await oneStem(queue.shift());
|
|
302
|
+
}));
|
|
215
303
|
writeFileSync(statePath, JSON.stringify(state, null, 1));
|
|
216
304
|
console.log(`done → ${dir} (${made} generated${kept ? `, ${kept} unchanged` : ''})`);
|
|
305
|
+
if (unread.length) {
|
|
306
|
+
console.error(`${unread.length} file${unread.length === 1 ? '' : 's'} got no lip-sync: ${unread.join(', ')} · install ffmpeg (or Rhubarb) to read ${unread.length === 1 ? 'it' : 'them'}`);
|
|
307
|
+
process.exitCode = 1;
|
|
308
|
+
}
|
package/tools/local-voice.mjs
CHANGED
|
@@ -381,7 +381,7 @@ export function detectLocalVoice({
|
|
|
381
381
|
engine: null,
|
|
382
382
|
why: 'Android has a system voice, but only as an in-app Java API — there is no '
|
|
383
383
|
+ 'command line behind it, so nothing here can drive it',
|
|
384
|
-
suggest: 'record the narration on a desktop (decklight <deck>, then V →
|
|
384
|
+
suggest: 'record the narration on a desktop (decklight <deck>, then V → My voice → Record…) and ship the '
|
|
385
385
|
+ 'audio with the deck — a recorded track needs no bridge at all',
|
|
386
386
|
};
|
|
387
387
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// The built-in mouth (tools/mouth.mjs) of one audio file on disk, for the
|
|
5
|
+
// Node side: `decklight lipsync` writing a sidecar without Rhubarb, and
|
|
6
|
+
// `decklight video` reading one it could not have made. A WAV is read
|
|
7
|
+
// directly; anything else goes through ffmpeg, straight to the 16 kHz mono
|
|
8
|
+
// the reader works at. Node-only; the deck reads through the browser
|
|
9
|
+
// (src/core/character.js).
|
|
10
|
+
|
|
11
|
+
import { readFileSync } from 'node:fs';
|
|
12
|
+
import { spawnSync } from 'node:child_process';
|
|
13
|
+
import { basename } from 'node:path';
|
|
14
|
+
import { mouthTimeline, wavSamples } from './mouth.mjs';
|
|
15
|
+
|
|
16
|
+
/** The timeline read from `audio`'s voice; throws, saying why, when it cannot be read. */
|
|
17
|
+
export function mouthFromFile(audio) {
|
|
18
|
+
const wav = wavSamples(readFileSync(audio));
|
|
19
|
+
if (wav) return mouthTimeline(wav.samples, wav.sampleRate);
|
|
20
|
+
const r = spawnSync('ffmpeg', ['-v', 'error', '-i', audio, '-ac', '1', '-ar', '16000', '-f', 'f32le', '-'],
|
|
21
|
+
{ maxBuffer: 1 << 28 });
|
|
22
|
+
if (r.error?.code === 'ENOENT') throw new Error(`${basename(audio)} is not a WAV, and reading it needs ffmpeg, which is not installed`);
|
|
23
|
+
if (r.status !== 0 || !r.stdout?.length) throw new Error(`ffmpeg could not read ${basename(audio)}`);
|
|
24
|
+
const raw = r.stdout;
|
|
25
|
+
return mouthTimeline(new Float32Array(raw.buffer.slice(raw.byteOffset, raw.byteOffset + raw.length)), 16000);
|
|
26
|
+
}
|