decklight 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +2 -0
- package/PLATFORM.md +17 -0
- package/README.md +53 -25
- package/SPEC.md +1239 -67
- package/cli/agents.mjs +139 -15
- package/cli/bundle.mjs +68 -2
- package/cli/cast.mjs +45 -14
- package/cli/check-fixes.mjs +12 -4
- package/cli/check-watch.mjs +151 -0
- package/cli/check.mjs +460 -71
- package/cli/code-editor.mjs +287 -0
- package/cli/commands.mjs +13 -2
- package/cli/commit-message.mjs +34 -7
- package/cli/commit-split.mjs +123 -23
- package/cli/decklight.mjs +11 -1
- package/cli/design-system-edit.mjs +37 -1
- package/cli/edit-address.mjs +184 -0
- package/cli/edit-git.mjs +21 -4
- package/cli/edit-handover.mjs +136 -25
- package/cli/edit-look.mjs +45 -1
- 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 +3182 -267
- package/cli/editor-support.mjs +286 -0
- package/cli/enhance.mjs +148 -20
- package/cli/find-replace.mjs +142 -0
- package/cli/fix-review.mjs +368 -0
- package/cli/init.mjs +93 -19
- package/cli/keep-awake.mjs +68 -0
- package/cli/migrate-writing.mjs +214 -0
- package/cli/narrate.mjs +51 -10
- package/cli/open.mjs +29 -9
- package/cli/outside-edit.mjs +257 -0
- package/cli/paste.mjs +92 -0
- package/cli/pdf.mjs +61 -2
- package/cli/pptx-export.mjs +3 -1
- package/cli/publish.mjs +24 -3
- package/cli/record.mjs +19 -8
- package/cli/rewrite.mjs +265 -0
- package/cli/runtime-link.mjs +218 -17
- package/cli/serve.mjs +7 -4
- package/cli/setup.mjs +2 -2
- package/cli/skill-content.mjs +212 -8
- package/cli/skills/slide-writing.md +333 -0
- package/cli/skills/voiceover.md +423 -0
- package/cli/skills.mjs +36 -13
- package/cli/starter-full.mjs +353 -0
- package/cli/supervise.mjs +14 -0
- 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/util.mjs +25 -0
- package/cli/vocabulary-docs.mjs +138 -0
- package/dist/decklight.css +2087 -91
- package/dist/decklight.js +367 -203
- 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 +15 -1
- package/tools/diagram-shapes.mjs +221 -0
- package/tools/elevenlabs-tts.mjs +62 -53
- 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 +24 -4
- package/tools/narration-synth.mjs +96 -76
- package/tools/recording-impact.mjs +16 -1
- package/tools/sentences.mjs +7 -1
- 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 +772 -127
- 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
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Lip-sync that follows the audio (#1244, SPEC CHARACTER).
|
|
6
|
+
*
|
|
7
|
+
* A deck with a 2D character (`narration.character.mode: 'viseme'`) plays a
|
|
8
|
+
* `slide-NN[-KK].visemes.json` beside each audio file. Whatever writes that
|
|
9
|
+
* audio — `decklight narrate`, the export's re-voicing of stale slides, the
|
|
10
|
+
* deck's own "Generate an AI recording" — calls THIS afterwards, so the
|
|
11
|
+
* sidecars are cut from the audio that is now on disk instead of waiting for
|
|
12
|
+
* someone to remember `decklight narrate <deck> --face`.
|
|
13
|
+
*
|
|
14
|
+
* Two halves:
|
|
15
|
+
* - `lipsyncStatus(dir)`: which stems' sidecars are missing or belong to
|
|
16
|
+
* another recording (tools/viseme-match.mjs: the `audio` stamp, then the
|
|
17
|
+
* lipsync.json hash, then the length). The voice card shows it.
|
|
18
|
+
* - `makeLipsync(dir, stems)`: tools/lipsync.mjs on just those stems, in
|
|
19
|
+
* parallel (`--jobs`), its `[k/N]` progress passed on line by line.
|
|
20
|
+
*
|
|
21
|
+
* Without Rhubarb the sidecars are still made, read from the voice
|
|
22
|
+
* (tools/mouth.mjs, marked `source: 'builtin'`), and the caller says ONCE how
|
|
23
|
+
* to get Rhubarb's (`RHUBARB_HINT`). Once Rhubarb is here those count as out
|
|
24
|
+
* of date (tools/viseme-match.mjs), so the next run replaces them.
|
|
25
|
+
*
|
|
26
|
+
* A slide filmed with your face (the manifest's `face`, and its .mp4 beside
|
|
27
|
+
* the audio) plays the film, not the character, so it is never counted or cut.
|
|
28
|
+
*
|
|
29
|
+
* Node-only.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { spawn } from 'node:child_process';
|
|
33
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
34
|
+
import { join, basename } from 'node:path';
|
|
35
|
+
import { fileURLToPath } from 'node:url';
|
|
36
|
+
import { run, PROBE_MS } from './exec.mjs';
|
|
37
|
+
import { loadLipsyncConfig } from './lipsync-config.mjs';
|
|
38
|
+
import { visemeMismatch, wavDuration } from './viseme-match.mjs';
|
|
39
|
+
import { deckConfigSource } from '../cli/runtime-link.mjs';
|
|
40
|
+
|
|
41
|
+
const LIPSYNC = fileURLToPath(new URL('./lipsync.mjs', import.meta.url));
|
|
42
|
+
|
|
43
|
+
/** Said once, when audio was written and its lip-sync could not be. */
|
|
44
|
+
export const RHUBARB_HINT = 'lip-sync read from the voice: Rhubarb is not installed, which makes it more exact. '
|
|
45
|
+
+ 'Install it from https://github.com/DanielSWolf/rhubarb-lip-sync and run decklight setup face --rhubarb <bin>; '
|
|
46
|
+
+ 'then decklight narrate <deck> --face (or the voice card\'s "Update lip-sync") remakes it';
|
|
47
|
+
|
|
48
|
+
/** The deck's configured character mode: 'viseme', 'video', 'off', or null when it names none. */
|
|
49
|
+
export function characterMode(html) {
|
|
50
|
+
try { return deckConfigSource(html).config?.narration?.character?.mode ?? null; } catch { return null; }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The Rhubarb this machine would run: what `decklight setup face` saved, else the one on PATH. */
|
|
54
|
+
export function rhubarbBin(env = process.env) {
|
|
55
|
+
return loadLipsyncConfig(env)?.rhubarb ?? 'rhubarb';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Whether Rhubarb runs here. */
|
|
59
|
+
export function haveRhubarb(bin = rhubarbBin(), probe = run) {
|
|
60
|
+
try { probe(bin, ['--version'], { stdio: 'ignore', timeout: PROBE_MS }); return true; } catch (e) { return e?.code !== 'ENOENT'; }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// asked at most every 30 s: the voice card polls the status, and installing
|
|
64
|
+
// Rhubarb mid-session should still be noticed
|
|
65
|
+
let rhubarbSeen = null;
|
|
66
|
+
function rhubarbNow() {
|
|
67
|
+
if (!rhubarbSeen || Date.now() - rhubarbSeen.at > 30_000) rhubarbSeen = { at: Date.now(), have: haveRhubarb() };
|
|
68
|
+
return rhubarbSeen.have;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The stems of slides filmed with your face: they play the film, never the character. */
|
|
72
|
+
function filmedStems(dir, stems) {
|
|
73
|
+
let m;
|
|
74
|
+
try { m = JSON.parse(readFileSync(join(dir, 'manifest.json'), 'utf8')); } catch { return new Set(); }
|
|
75
|
+
const filmed = new Set((m?.slides ?? []).map((e, i) => (e?.face === true ? String(i + 1).padStart(2, '0') : null)).filter(Boolean));
|
|
76
|
+
return new Set(stems.filter((st) => filmed.has(st.slice(6, 8)) && existsSync(join(dir, `${st}.mp4`))));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// file → [stat key, verdict]: a track of 150 WAVs is read once, not on every
|
|
80
|
+
// open of the voice card
|
|
81
|
+
const memo = new Map();
|
|
82
|
+
const statKey = (f) => { try { const s = statSync(f); return `${s.size}:${s.mtimeMs}`; } catch { return 'none'; } };
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The lip-sync of the track in `dir`: `{ stems, stale }` — every stem with
|
|
86
|
+
* audio the character plays, and those whose sidecar is missing or is not
|
|
87
|
+
* this audio's, each `{ stem, why }`.
|
|
88
|
+
*/
|
|
89
|
+
export function lipsyncStatus(dir, { rhubarb = rhubarbNow() } = {}) {
|
|
90
|
+
let names;
|
|
91
|
+
try { names = readdirSync(dir); } catch { return { stems: [], stale: [] }; }
|
|
92
|
+
const audioOf = new Map();
|
|
93
|
+
for (const f of names) {
|
|
94
|
+
const m = /^(slide-\d+(?:-\d+)?)\.(wav|m4a)$/.exec(f);
|
|
95
|
+
// wav first: it is what lipsync.mjs cuts from, and what the deck plays
|
|
96
|
+
if (m && (!audioOf.has(m[1]) || m[2] === 'wav')) audioOf.set(m[1], join(dir, f));
|
|
97
|
+
}
|
|
98
|
+
const all = [...audioOf.keys()].sort();
|
|
99
|
+
const filmed = filmedStems(dir, all);
|
|
100
|
+
const stems = all.filter((st) => !filmed.has(st));
|
|
101
|
+
let state = {};
|
|
102
|
+
try { state = JSON.parse(readFileSync(join(dir, 'lipsync.json'), 'utf8')); } catch { /* none kept */ }
|
|
103
|
+
const stale = [];
|
|
104
|
+
for (const stem of stems) {
|
|
105
|
+
const audio = audioOf.get(stem);
|
|
106
|
+
const side = join(dir, `${stem}.visemes.json`);
|
|
107
|
+
const txt = join(dir, `${stem}.txt`);
|
|
108
|
+
const key = [statKey(audio), statKey(side), statKey(txt), state[stem]?.visemes ?? '', rhubarb].join('|');
|
|
109
|
+
const hit = memo.get(side);
|
|
110
|
+
let why;
|
|
111
|
+
if (hit?.[0] === key) why = hit[1];
|
|
112
|
+
else {
|
|
113
|
+
why = null;
|
|
114
|
+
if (!existsSync(side)) why = 'it is missing';
|
|
115
|
+
else {
|
|
116
|
+
let tl = null;
|
|
117
|
+
try { tl = JSON.parse(readFileSync(side, 'utf8')); } catch { /* unreadable */ }
|
|
118
|
+
if (!Array.isArray(tl?.cues)) why = 'it is not a viseme timeline';
|
|
119
|
+
else {
|
|
120
|
+
const bytes = readFileSync(audio);
|
|
121
|
+
why = visemeMismatch(tl, {
|
|
122
|
+
audioBytes: bytes,
|
|
123
|
+
stateHash: state[stem]?.visemes ?? null,
|
|
124
|
+
text: existsSync(txt) ? readFileSync(txt, 'utf8').trim() : '',
|
|
125
|
+
duration: audio.endsWith('.wav') ? wavDuration(bytes) : null,
|
|
126
|
+
rhubarb,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
memo.set(side, [key, why]);
|
|
131
|
+
}
|
|
132
|
+
if (why) stale.push({ stem, why });
|
|
133
|
+
}
|
|
134
|
+
return { stems, stale };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* tools/lipsync.mjs on `stems` of `dir` (all that need it when omitted), in
|
|
139
|
+
* parallel. Each progress line goes to `log`. Resolves `{ ok, made, why }`;
|
|
140
|
+
* never rejects. `spawnImpl` is for tests.
|
|
141
|
+
*/
|
|
142
|
+
export function makeLipsync(dir, stems = null, { log = console.log, jobs = null, spawnImpl = spawn, env = process.env } = {}) {
|
|
143
|
+
const list = stems ?? lipsyncStatus(dir).stale.map((s) => s.stem);
|
|
144
|
+
if (!list.length) return Promise.resolve({ ok: true, made: 0, why: null });
|
|
145
|
+
const args = [LIPSYNC, dir, '--visemes', '--remake', list.join(',')];
|
|
146
|
+
if (jobs) args.push('--jobs', String(jobs));
|
|
147
|
+
return new Promise((done) => {
|
|
148
|
+
let child;
|
|
149
|
+
try { child = spawnImpl(process.execPath, args, { stdio: ['ignore', 'pipe', 'pipe'], env }); } catch (e) {
|
|
150
|
+
done({ ok: false, made: 0, why: e.message });
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
let made = 0;
|
|
154
|
+
let err = '';
|
|
155
|
+
let buf = '';
|
|
156
|
+
child.stdout?.setEncoding?.('utf8');
|
|
157
|
+
child.stdout?.on('data', (chunk) => {
|
|
158
|
+
buf += chunk;
|
|
159
|
+
let nl;
|
|
160
|
+
while ((nl = buf.indexOf('\n')) !== -1) {
|
|
161
|
+
const line = buf.slice(0, nl).trimEnd();
|
|
162
|
+
buf = buf.slice(nl + 1);
|
|
163
|
+
if (/cues →/.test(line)) made++;
|
|
164
|
+
// the per-file lines and the pool size; the tool's own header and
|
|
165
|
+
// summary say what the caller says better
|
|
166
|
+
if (/^\s+(\[\d+\/\d+\]|cutting up to)/.test(line)) log(` lip-sync: ${line.trim()}`);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
child.stderr?.on('data', (chunk) => { err += chunk; });
|
|
170
|
+
child.on('error', (e) => done({ ok: false, made, why: e.message }));
|
|
171
|
+
child.on('close', (code) => done(code === 0
|
|
172
|
+
? { ok: true, made, why: null }
|
|
173
|
+
: { ok: false, made, why: String(err).trim().split('\n').pop() || `lipsync exited ${code}` }));
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* After audio was written into `dir` for the deck `html`: cut its lip-sync
|
|
179
|
+
* when the deck has a 2D character. New audio deleted its old sidecar
|
|
180
|
+
* (synthesizeSlides' `encode`), so what the run wrote is among the stale
|
|
181
|
+
* stems, and any other stale sidecar of the folder comes along: one run of
|
|
182
|
+
* Rhubarb is the cheapest place to fix it. Says what it did, or once why it
|
|
183
|
+
* did nothing. Resolves `{ ran, made, why }`.
|
|
184
|
+
*/
|
|
185
|
+
export async function lipsyncAfterVoicing({ html, dir, log = console.log, have = haveRhubarb, make = makeLipsync }) {
|
|
186
|
+
if (characterMode(html) !== 'viseme') return { ran: false, made: 0, why: null };
|
|
187
|
+
const rhubarb = have();
|
|
188
|
+
const stems = lipsyncStatus(dir, { rhubarb }).stale.map((s) => s.stem);
|
|
189
|
+
if (!stems.length) return { ran: false, made: 0, why: null };
|
|
190
|
+
if (!rhubarb) log(` ${RHUBARB_HINT}`);
|
|
191
|
+
log(` lip-sync: cutting ${stems.length} file${stems.length === 1 ? '' : 's'} for the 2D character in ${basename(dir)}/`
|
|
192
|
+
+ `${rhubarb ? ' with Rhubarb' : ', read from the voice'}…`);
|
|
193
|
+
const r = await make(dir, stems, { log });
|
|
194
|
+
if (!r.ok) log(` lip-sync: not made — ${r.why}; decklight narrate <deck> --face tries again`);
|
|
195
|
+
else log(` lip-sync: ${r.made} file${r.made === 1 ? '' : 's'} made`);
|
|
196
|
+
return { ran: true, made: r.made, why: r.ok ? null : r.why };
|
|
197
|
+
}
|
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
|
+
}
|