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/mouth.mjs
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// The 2D character's mouth, read from the voice itself (PRESENTING_VOICE,
|
|
5
|
+
// Character). No Rhubarb, no bridge, no model: a few measurements of the
|
|
6
|
+
// sound, 100 times a second, and rules modelled on Rhubarb's for turning them
|
|
7
|
+
// into its nine mouth shapes. It does not recognise speech, so it cannot tell
|
|
8
|
+
// an "m" from a "t" the way Rhubarb can; it can tell silence from a hum, a
|
|
9
|
+
// hiss from a vowel, and a dark vowel ("oo", "oh") from a bright one ("ah",
|
|
10
|
+
// "ee"), which is most of what a cartoon mouth shows.
|
|
11
|
+
//
|
|
12
|
+
// Pure and DOM-free: it takes samples and returns a timeline in the shape
|
|
13
|
+
// tools/lipsync.mjs writes (`{ v: 1, kind: 'visemes', duration, cues:
|
|
14
|
+
// [{ t, v }] }`), so the deck, the bundle and the video renderer read it
|
|
15
|
+
// exactly as they read Rhubarb's.
|
|
16
|
+
//
|
|
17
|
+
// The shapes (Rhubarb's names):
|
|
18
|
+
// A closed (m, b, p) B slightly open, teeth (most consonants, "ee")
|
|
19
|
+
// C open ("eh", "a") D wide open ("ah")
|
|
20
|
+
// E slightly rounded ("or") F puckered ("oo", "w")
|
|
21
|
+
// G teeth on lip (f, v) H tongue (l) X rest
|
|
22
|
+
|
|
23
|
+
const HOP_S = 0.01; // one measurement every 10 ms
|
|
24
|
+
const WIN_S = 0.03; // over 30 ms of sound
|
|
25
|
+
const MIN_CUE_S = 0.06; // no shape shorter than this (Rhubarb holds ~2 frames at 24 fps)
|
|
26
|
+
const REST_S = 0.18; // a silence this long rests the mouth; shorter, it closes
|
|
27
|
+
|
|
28
|
+
/** In-place radix-2 FFT of `re`/`im` (length a power of two). */
|
|
29
|
+
function fft(re, im) {
|
|
30
|
+
const n = re.length;
|
|
31
|
+
for (let i = 1, j = 0; i < n; i++) {
|
|
32
|
+
let bit = n >> 1;
|
|
33
|
+
for (; j & bit; bit >>= 1) j ^= bit;
|
|
34
|
+
j ^= bit;
|
|
35
|
+
if (i < j) { [re[i], re[j]] = [re[j], re[i]]; [im[i], im[j]] = [im[j], im[i]]; }
|
|
36
|
+
}
|
|
37
|
+
for (let len = 2; len <= n; len <<= 1) {
|
|
38
|
+
const ang = -2 * Math.PI / len;
|
|
39
|
+
const wr = Math.cos(ang), wi = Math.sin(ang);
|
|
40
|
+
for (let i = 0; i < n; i += len) {
|
|
41
|
+
let cr = 1, ci = 0;
|
|
42
|
+
for (let k = 0; k < len / 2; k++) {
|
|
43
|
+
const a = i + k, b = a + len / 2;
|
|
44
|
+
const tr = re[b] * cr - im[b] * ci, ti = re[b] * ci + im[b] * cr;
|
|
45
|
+
re[b] = re[a] - tr; im[b] = im[a] - ti;
|
|
46
|
+
re[a] += tr; im[a] += ti;
|
|
47
|
+
const nr = cr * wr - ci * wi; ci = cr * wi + ci * wr; cr = nr;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The vocal tract's two lowest resonances (formants) in one frame, from its
|
|
55
|
+
* LPC envelope: F1 rises as the mouth opens, F2 rises as the tongue moves
|
|
56
|
+
* forward and falls as the lips round. Peaks of the envelope, read on a grid
|
|
57
|
+
* (no polynomial roots): the first above 250 Hz is F1, the next F2.
|
|
58
|
+
*/
|
|
59
|
+
const LPC_ORDER = 14;
|
|
60
|
+
function lpc(frame) {
|
|
61
|
+
const p = LPC_ORDER;
|
|
62
|
+
const r = new Float64Array(p + 1);
|
|
63
|
+
for (let k = 0; k <= p; k++) { let s = 0; for (let i = k; i < frame.length; i++) s += frame[i] * frame[i - k]; r[k] = s; }
|
|
64
|
+
if (r[0] <= 0) return null;
|
|
65
|
+
r[0] *= 1.0001; // a touch of white noise: keeps the recursion stable on pure tones
|
|
66
|
+
const a = new Float64Array(p + 1); a[0] = 1;
|
|
67
|
+
let err = r[0];
|
|
68
|
+
for (let i = 1; i <= p; i++) {
|
|
69
|
+
let acc = r[i];
|
|
70
|
+
for (let j = 1; j < i; j++) acc += a[j] * r[i - j];
|
|
71
|
+
const k = -acc / err;
|
|
72
|
+
const prev = a.slice();
|
|
73
|
+
for (let j = 1; j < i; j++) a[j] = prev[j] + k * prev[i - j];
|
|
74
|
+
a[i] = k;
|
|
75
|
+
err *= 1 - k * k;
|
|
76
|
+
if (err <= 0) return null;
|
|
77
|
+
}
|
|
78
|
+
return a;
|
|
79
|
+
}
|
|
80
|
+
const GRID = 200, GRID_TOP = 4000; // 20 Hz steps to 4 kHz
|
|
81
|
+
function formants(a, sampleRate, trig) {
|
|
82
|
+
const env = new Float64Array(GRID);
|
|
83
|
+
for (let g = 0; g < GRID; g++) {
|
|
84
|
+
let re = 0, im = 0;
|
|
85
|
+
for (let k = 0; k < a.length; k++) { re += a[k] * trig.cos[g][k]; im -= a[k] * trig.sin[g][k]; }
|
|
86
|
+
env[g] = 1 / (re * re + im * im);
|
|
87
|
+
}
|
|
88
|
+
// the strongest peak where each formant lives: F1 from 250 Hz to 1.1 kHz,
|
|
89
|
+
// F2 from 200 Hz above F1 to 3 kHz. The first peak would be a harmonic as
|
|
90
|
+
// often as a formant on a high voice.
|
|
91
|
+
const strongest = (lo, hi) => {
|
|
92
|
+
let best = null;
|
|
93
|
+
for (let g = 1; g < GRID - 1; g++) {
|
|
94
|
+
const hz = g * GRID_TOP / GRID;
|
|
95
|
+
if (hz < lo || hz > hi || !(env[g] > env[g - 1] && env[g] >= env[g + 1])) continue;
|
|
96
|
+
if (best == null || env[g] > env[best]) best = g;
|
|
97
|
+
}
|
|
98
|
+
return best == null ? null : best * GRID_TOP / GRID;
|
|
99
|
+
};
|
|
100
|
+
const f1 = strongest(250, 1100);
|
|
101
|
+
return { f1, f2: f1 == null ? null : strongest(f1 + 200, 3000) };
|
|
102
|
+
}
|
|
103
|
+
function trigFor(sampleRate) {
|
|
104
|
+
const cos = [], sin = [];
|
|
105
|
+
for (let g = 0; g < GRID; g++) {
|
|
106
|
+
const w = 2 * Math.PI * (g * GRID_TOP / GRID) / sampleRate;
|
|
107
|
+
cos.push(Float64Array.from({ length: LPC_ORDER + 1 }, (_, k) => Math.cos(w * k)));
|
|
108
|
+
sin.push(Float64Array.from({ length: LPC_ORDER + 1 }, (_, k) => Math.sin(w * k)));
|
|
109
|
+
}
|
|
110
|
+
return { cos, sin };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* What the voice is doing, frame by frame: loudness (dB), how much of its
|
|
115
|
+
* energy is hiss (above 3.5 kHz), how much is low (below 900 Hz, where an open
|
|
116
|
+
* vowel's first formant sits), and how much is in the middle (900 Hz to
|
|
117
|
+
* 2.5 kHz, where a front vowel's second formant sits).
|
|
118
|
+
*/
|
|
119
|
+
export function measure(samples, sampleRate) {
|
|
120
|
+
const hop = Math.max(1, Math.round(HOP_S * sampleRate));
|
|
121
|
+
const win = Math.round(WIN_S * sampleRate);
|
|
122
|
+
let n = 1; while (n < win) n <<= 1;
|
|
123
|
+
const re = new Float64Array(n), im = new Float64Array(n);
|
|
124
|
+
const hann = Float64Array.from({ length: win }, (_, i) => 0.5 - 0.5 * Math.cos(2 * Math.PI * i / (win - 1)));
|
|
125
|
+
const bin = (hz) => Math.min(n / 2, Math.round(hz * n / sampleRate));
|
|
126
|
+
const [b150, b900, b2500, b3500, b8000] = [150, 900, 2500, 3500, 8000].map(bin);
|
|
127
|
+
const frames = [];
|
|
128
|
+
const trig = trigFor(sampleRate);
|
|
129
|
+
const pre = new Float64Array(win);
|
|
130
|
+
for (let at = 0; at + win <= samples.length; at += hop) {
|
|
131
|
+
let sq = 0;
|
|
132
|
+
for (let i = 0; i < win; i++) {
|
|
133
|
+
const s = samples[at + i]; sq += s * s; re[i] = s * hann[i]; im[i] = 0;
|
|
134
|
+
pre[i] = (s - 0.97 * (at + i > 0 ? samples[at + i - 1] : 0)) * hann[i];
|
|
135
|
+
}
|
|
136
|
+
const a = lpc(pre);
|
|
137
|
+
const { f1, f2 } = a ? formants(a, sampleRate, trig) : { f1: null, f2: null };
|
|
138
|
+
for (let i = win; i < n; i++) { re[i] = 0; im[i] = 0; }
|
|
139
|
+
fft(re, im);
|
|
140
|
+
const band = (lo, hi) => { let e = 0; for (let k = lo; k < hi; k++) e += re[k] * re[k] + im[k] * im[k]; return e; };
|
|
141
|
+
const low = band(b150, b900), mid = band(b900, b2500), high = band(b3500, b8000);
|
|
142
|
+
const all = low + mid + band(b2500, b3500) + high + 1e-12;
|
|
143
|
+
frames.push({
|
|
144
|
+
t: at / sampleRate,
|
|
145
|
+
db: 10 * Math.log10(sq / win + 1e-12),
|
|
146
|
+
low: low / all, mid: mid / all, hiss: high / all, f1, f2,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return frames;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** The clip's speaking level: loud speech, not its peak (one shout does not set the scale). */
|
|
153
|
+
function speechLevel(frames) {
|
|
154
|
+
const dbs = frames.map((f) => f.db).sort((a, b) => a - b);
|
|
155
|
+
return dbs.length ? dbs[Math.floor(dbs.length * 0.9)] : 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* One frame's mouth. `rel` is dB below the speaking level; `open` and `front`
|
|
160
|
+
* are F1 and F2 placed within this voice's own range (0 its lowest, 1 its
|
|
161
|
+
* highest), since a man's "ah" and a woman's "ee" can share an F1 in hertz.
|
|
162
|
+
*/
|
|
163
|
+
export function shapeOf({ rel, hiss, open, front }) {
|
|
164
|
+
if (rel < -35) return 'X'; // silence (closures are decided later)
|
|
165
|
+
if (hiss > 0.3 && rel < -4) return 'B'; // s, sh, t, k, ch: teeth
|
|
166
|
+
if (rel < -22) return 'A'; // a quiet hum between sounds: lips together (m, n, b)
|
|
167
|
+
if (open == null || front == null) return 'C'; // voiced, formants unread: plainly open
|
|
168
|
+
if (open > 0.62) return front > 0.6 ? 'C' : 'D'; // open: "a" in cat, or "ah"
|
|
169
|
+
if (open > 0.35) return front < 0.3 ? 'E' : 'C'; // half open: "aw", "or", else "eh"
|
|
170
|
+
return front > 0.55 ? 'B' : front < 0.3 ? 'F' : 'E'; // closed: "ee", "oo", or between ("er")
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** `x` placed between this voice's 10th and 90th percentiles of `xs`. */
|
|
174
|
+
function placer(xs) {
|
|
175
|
+
const v = xs.filter((x) => x != null).sort((a, b) => a - b);
|
|
176
|
+
if (v.length < 5) return () => null;
|
|
177
|
+
const lo = v[Math.floor(v.length * 0.1)], hi = v[Math.floor(v.length * 0.9)];
|
|
178
|
+
return (x) => (x == null || hi <= lo ? null : Math.min(1, Math.max(0, (x - lo) / (hi - lo))));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The voice at 16 kHz, where the formant reading is tuned (its LPC order
|
|
183
|
+
* suits a 16 kHz band; a browser decodes at 44.1 or 48 kHz). Averaged over
|
|
184
|
+
* each step before it is picked, so nothing above 8 kHz folds back down.
|
|
185
|
+
*/
|
|
186
|
+
const RATE = 16000;
|
|
187
|
+
export function at16k(samples, sampleRate) {
|
|
188
|
+
if (sampleRate <= RATE) return { samples, sampleRate };
|
|
189
|
+
const step = sampleRate / RATE;
|
|
190
|
+
const out = new Float32Array(Math.floor(samples.length / step));
|
|
191
|
+
for (let i = 0; i < out.length; i++) {
|
|
192
|
+
const a = Math.floor(i * step), b = Math.max(a + 1, Math.floor((i + 1) * step));
|
|
193
|
+
let sum = 0; for (let j = a; j < b; j++) sum += samples[j];
|
|
194
|
+
out[i] = sum / (b - a);
|
|
195
|
+
}
|
|
196
|
+
return { samples: out, sampleRate: RATE };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* A WAV's voice as mono samples (-1..1) and its rate, or null for anything
|
|
201
|
+
* this does not read (not a WAV, a compressed one, a format it does not know):
|
|
202
|
+
* the caller decodes those some other way. Integer PCM at 8, 16, 24 or 32
|
|
203
|
+
* bits and 32-bit float, channels averaged. Pure, so the deck and Node read a
|
|
204
|
+
* recording the same way without a decoder: a headless browser's media stack
|
|
205
|
+
* and a machine without ffmpeg both stopped the mouth before this.
|
|
206
|
+
*/
|
|
207
|
+
export function wavSamples(bytes) {
|
|
208
|
+
const u8 = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
209
|
+
const d = new DataView(u8.buffer, u8.byteOffset, u8.byteLength);
|
|
210
|
+
const tag = (at) => String.fromCharCode(u8[at], u8[at + 1], u8[at + 2], u8[at + 3]);
|
|
211
|
+
if (u8.length < 12 || tag(0) !== 'RIFF' || tag(8) !== 'WAVE') return null;
|
|
212
|
+
let fmt = null;
|
|
213
|
+
for (let at = 12; at + 8 <= u8.length;) {
|
|
214
|
+
const id = tag(at), body = at + 8;
|
|
215
|
+
let size = d.getUint32(at + 4, true);
|
|
216
|
+
if (id === 'fmt ' && size >= 16) {
|
|
217
|
+
let format = d.getUint16(body, true);
|
|
218
|
+
// WAVE_FORMAT_EXTENSIBLE names the real format in its sub-format GUID
|
|
219
|
+
if (format === 0xfffe && size >= 26) format = d.getUint16(body + 24, true);
|
|
220
|
+
fmt = { format, channels: d.getUint16(body + 2, true), rate: d.getUint32(body + 4, true), bits: d.getUint16(body + 14, true) };
|
|
221
|
+
} else if (id === 'data') {
|
|
222
|
+
if (!fmt || !fmt.channels || !fmt.rate) return null;
|
|
223
|
+
// a streamed WAV says 0 or 0xFFFFFFFF: its data runs to the end
|
|
224
|
+
if (!size || body + size > u8.length) size = u8.length - body;
|
|
225
|
+
const { format, channels, rate, bits } = fmt, width = bits / 8;
|
|
226
|
+
const read = format === 3 && bits === 32 ? (o) => d.getFloat32(o, true)
|
|
227
|
+
: format !== 1 ? null
|
|
228
|
+
: bits === 8 ? (o) => (d.getUint8(o) - 128) / 128
|
|
229
|
+
: bits === 16 ? (o) => d.getInt16(o, true) / 32768
|
|
230
|
+
: bits === 24 ? (o) => ((d.getUint8(o) | (d.getUint8(o + 1) << 8) | (d.getInt8(o + 2) << 16))) / 8388608
|
|
231
|
+
: bits === 32 ? (o) => d.getInt32(o, true) / 2147483648
|
|
232
|
+
: null;
|
|
233
|
+
if (!read) return null;
|
|
234
|
+
const n = Math.floor(size / (width * channels));
|
|
235
|
+
const samples = new Float32Array(n);
|
|
236
|
+
for (let i = 0, o = body; i < n; i++) {
|
|
237
|
+
let sum = 0;
|
|
238
|
+
for (let c = 0; c < channels; c++, o += width) sum += read(o);
|
|
239
|
+
samples[i] = sum / channels;
|
|
240
|
+
}
|
|
241
|
+
return { samples, sampleRate: rate };
|
|
242
|
+
}
|
|
243
|
+
at = body + size + (size & 1);
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* The timeline for `samples` (mono, -1..1) at `sampleRate`: one shape per
|
|
250
|
+
* frame, smoothed the way a mouth moves. A short silence between sounds is
|
|
251
|
+
* lips closing, not resting; a shape held for less than a couple of frames is
|
|
252
|
+
* folded into its longer neighbour; the mouth starts and ends at rest.
|
|
253
|
+
*/
|
|
254
|
+
export function mouthTimeline(input, inputRate) {
|
|
255
|
+
const duration = input.length / inputRate;
|
|
256
|
+
const { samples, sampleRate } = at16k(input, inputRate);
|
|
257
|
+
const frames = measure(samples, sampleRate);
|
|
258
|
+
const level = speechLevel(frames);
|
|
259
|
+
// the voice's own range, read from where it is clearly voicing
|
|
260
|
+
const voiced = frames.filter((f) => f.db - level > -15 && f.hiss < 0.2);
|
|
261
|
+
const openOf = placer(voiced.map((f) => f.f1));
|
|
262
|
+
const frontOf = placer(voiced.map((f) => f.f2));
|
|
263
|
+
// and an absolute floor: in a clip of silence, the silence is not its speaking level
|
|
264
|
+
const FLOOR_DB = -60;
|
|
265
|
+
let shapes = frames.map((f) => (f.db < FLOOR_DB ? 'X'
|
|
266
|
+
: shapeOf({ rel: f.db - level, hiss: f.hiss, open: openOf(f.f1), front: frontOf(f.f2) })));
|
|
267
|
+
// a three-frame majority: one odd frame is a measurement, not a mouth
|
|
268
|
+
shapes = shapes.map((s, i) => {
|
|
269
|
+
const a = shapes[i - 1], b = shapes[i + 1];
|
|
270
|
+
return a && a === b && s !== a ? a : s;
|
|
271
|
+
});
|
|
272
|
+
// runs of one shape
|
|
273
|
+
let runs = [];
|
|
274
|
+
for (let i = 0; i < shapes.length; i++) {
|
|
275
|
+
const t = frames[i].t;
|
|
276
|
+
if (runs.length && runs[runs.length - 1].v === shapes[i]) runs[runs.length - 1].end = t + HOP_S;
|
|
277
|
+
else runs.push({ v: shapes[i], start: t, end: t + HOP_S });
|
|
278
|
+
}
|
|
279
|
+
// a short silence inside speech closes the lips (the stop of a p, b, t, k)
|
|
280
|
+
runs = runs.map((r, i) => (r.v === 'X' && i > 0 && i < runs.length - 1 && r.end - r.start < REST_S ? { ...r, v: 'A' } : r));
|
|
281
|
+
// too short to see: folded into the longer neighbour, until none is left
|
|
282
|
+
for (let changed = true; changed;) {
|
|
283
|
+
changed = false;
|
|
284
|
+
for (let i = 0; i < runs.length; i++) {
|
|
285
|
+
const r = runs[i];
|
|
286
|
+
if (r.end - r.start >= MIN_CUE_S || runs.length === 1) continue;
|
|
287
|
+
const prev = runs[i - 1], next = runs[i + 1];
|
|
288
|
+
const into = !prev ? next : !next ? prev : (prev.end - prev.start >= next.end - next.start ? prev : next);
|
|
289
|
+
into.start = Math.min(into.start, r.start);
|
|
290
|
+
into.end = Math.max(into.end, r.end);
|
|
291
|
+
runs.splice(i, 1);
|
|
292
|
+
changed = true;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
for (let i = 1; i < runs.length; i++) {
|
|
296
|
+
if (runs[i].v === runs[i - 1].v) { runs[i - 1].end = runs[i].end; runs.splice(i, 1); i--; changed = true; }
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const r3 = (x) => Math.round(x * 1000) / 1000;
|
|
300
|
+
const cues = runs.map((r) => ({ t: r3(r.start), v: r.v }));
|
|
301
|
+
if (!cues.length || cues[0].t > 0) cues.unshift({ t: 0, v: 'X' });
|
|
302
|
+
if (cues[cues.length - 1].v !== 'X') cues.push({ t: r3(Math.min(duration, runs[runs.length - 1]?.end ?? duration)), v: 'X' });
|
|
303
|
+
return { v: 1, kind: 'visemes', duration: r3(duration), source: 'builtin', cues };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* The loudness-only mouth the deck falls back to today, as a timeline: what
|
|
308
|
+
* the prototype is compared with. Four shapes from the frame's level.
|
|
309
|
+
*/
|
|
310
|
+
export function loudnessTimeline(input, inputRate) {
|
|
311
|
+
const { samples, sampleRate } = at16k(input, inputRate);
|
|
312
|
+
const frames = measure(samples, sampleRate);
|
|
313
|
+
const cues = [];
|
|
314
|
+
for (const f of frames) {
|
|
315
|
+
const rms = Math.sqrt(10 ** (f.db / 10));
|
|
316
|
+
const v = rms < 0.02 ? 'X' : rms < 0.06 ? 'B' : rms < 0.12 ? 'C' : 'D';
|
|
317
|
+
if (!cues.length || cues[cues.length - 1].v !== v) cues.push({ t: Math.round(f.t * 1000) / 1000, v });
|
|
318
|
+
}
|
|
319
|
+
return { v: 1, kind: 'visemes', duration: Math.round(samples.length / sampleRate * 1000) / 1000, source: 'loudness', cues };
|
|
320
|
+
}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { createHash } from 'node:crypto';
|
|
20
20
|
import { cacheKey } from './tts-cache.mjs';
|
|
21
21
|
import { readsAudioTags } from './elevenlabs-tts.mjs';
|
|
22
|
-
import { sectionBodies, NOTES_ASIDE, cleanNotes, readNotes, isHiddenSection } from './deck-html.mjs';
|
|
22
|
+
import { sectionBodies, NOTES_ASIDE, cleanNotes, readNotes, isHiddenSection, notesSegments } from './deck-html.mjs';
|
|
23
23
|
import { deckConfig } from '../cli/runtime-link.mjs';
|
|
24
24
|
import { PAUSE_MARK } from './sentences.mjs';
|
|
25
25
|
|
|
@@ -114,7 +114,7 @@ export function markerPauses(html) {
|
|
|
114
114
|
* `format` is the audio's extension, wav unless a header says otherwise —
|
|
115
115
|
* ElevenLabs alone can be told to speak mp3.
|
|
116
116
|
*/
|
|
117
|
-
export function manifestKey({ engine, model, voice, style, format } = {}, text) {
|
|
117
|
+
export function manifestKey({ engine, model, voice, voiceId, style, format, lang } = {}, text) {
|
|
118
118
|
const e = engine ?? '';
|
|
119
119
|
const fixed = e === 'piper';
|
|
120
120
|
const defaultVoice = e === 'say' || e === 'sapi';
|
|
@@ -123,9 +123,11 @@ export function manifestKey({ engine, model, voice, style, format } = {}, text)
|
|
|
123
123
|
engine: e,
|
|
124
124
|
model: fixed || defaultVoice ? undefined : (model ?? undefined),
|
|
125
125
|
format: format ?? 'wav',
|
|
126
|
-
voice: fixed ? model :
|
|
126
|
+
voice: fixed ? model : (voiceId ?? voice ?? (defaultVoice ? model : undefined)),
|
|
127
127
|
style: stylable ? style : undefined,
|
|
128
128
|
text,
|
|
129
|
+
// the language the engine was told, when the header records one
|
|
130
|
+
lang: lang || undefined,
|
|
129
131
|
});
|
|
130
132
|
}
|
|
131
133
|
|
|
@@ -140,9 +142,24 @@ export const manifestHash = (header, text) => manifestKey(header, text).slice(0,
|
|
|
140
142
|
export const legacyHash = ({ engine, voice, style } = {}, text) => createHash('sha256')
|
|
141
143
|
.update(`${engine}|${voice}|${style}|${text}`).digest('hex').slice(0, 16);
|
|
142
144
|
|
|
145
|
+
/** Record a voice identity without changing what the existing hashes vouch for. */
|
|
146
|
+
export function withTrackVoice(manifest, { voice, voiceId }) {
|
|
147
|
+
const before = manifest.voiceId ?? manifest.voice;
|
|
148
|
+
const changed = before !== (voiceId ?? voice);
|
|
149
|
+
return {
|
|
150
|
+
...manifest, voice, ...(voiceId ? { voiceId } : {}),
|
|
151
|
+
slides: changed ? manifest.slides.map((entry) => (entry?.hash && !Object.hasOwn(entry, 'hashVoice')
|
|
152
|
+
? { ...entry, hashVoice: before ?? null } : entry)) : manifest.slides,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
143
156
|
/** Does this manifest slide entry vouch for `text`, under its header? */
|
|
144
157
|
export function entryMatches(header, entry, text) {
|
|
145
158
|
if (!entry?.hash) return true; // a hand-recorded take carries no hash to disagree
|
|
159
|
+
if (Object.hasOwn(entry, 'hashVoice')) {
|
|
160
|
+
// A legacy take can keep its original notes hash after the voice is identified.
|
|
161
|
+
header = { ...header, voice: entry.hashVoice, voiceId: undefined };
|
|
162
|
+
}
|
|
146
163
|
if (entry.hash === manifestHash(header, text)) return true;
|
|
147
164
|
return header?.model === undefined && entry.hash === legacyHash(header, text);
|
|
148
165
|
}
|
|
@@ -170,6 +187,77 @@ export function staleSlides(manifest, texts, range = null, prior = null) {
|
|
|
170
187
|
return out;
|
|
171
188
|
}
|
|
172
189
|
|
|
190
|
+
/**
|
|
191
|
+
* Each slide's beats as a reader is shown them: the ⟨CLICK⟩ segments with
|
|
192
|
+
* words, ⟨PAUSE⟩ kept, or the whole slide as one beat when it is not
|
|
193
|
+
* segmented; [] for a slide with nothing to say. Index i is slide i+1.
|
|
194
|
+
*
|
|
195
|
+
* What your own voice's manifest records per slide (#850). A hash says THAT
|
|
196
|
+
* the notes moved; this says how: a recorded beat is cut where you pressed →,
|
|
197
|
+
* so moving a ⟨CLICK⟩ changes nothing you hear, and the one fix is to read
|
|
198
|
+
* those beats again. A synthesized track is re-voiced from the notes, so
|
|
199
|
+
* its hash is all it needs.
|
|
200
|
+
*/
|
|
201
|
+
export const slideBeats = (html) => slideNotes(html).map((raw) => {
|
|
202
|
+
if (!raw) return [];
|
|
203
|
+
const segs = notesSegments(raw, { marks: true });
|
|
204
|
+
if (segs) return segs;
|
|
205
|
+
const text = cleanNotes(raw, { marks: true });
|
|
206
|
+
return text ? [text] : [];
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* How a slide recorded in your own voice differs from its notes now: null in
|
|
211
|
+
* step; `{ why: 'text' }` when the words moved; `{ why: 'clicks', was, now }`
|
|
212
|
+
* when the words are the same and only the ⟨CLICK⟩ split moved (`was`/`now`
|
|
213
|
+
* the beat counts). `undefined` when the entry carries no record of what was
|
|
214
|
+
* read (anything recorded before #850): unknown, which is never a verdict.
|
|
215
|
+
*/
|
|
216
|
+
export function scriptDrift(entry, beats) {
|
|
217
|
+
if (!Array.isArray(entry?.beats)) return undefined;
|
|
218
|
+
const was = entry.beats.map(String);
|
|
219
|
+
const now = (beats ?? []).map(String);
|
|
220
|
+
if (was.length === now.length && was.every((b, k) => b === now[k])) return null;
|
|
221
|
+
const words = (list) => list.join(' ').replace(/\s+/g, ' ').trim();
|
|
222
|
+
if (words(was) === words(now)) return { why: 'clicks', was: was.length, now: now.length };
|
|
223
|
+
return { why: 'text' };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Every slide of `manifest` out of step with the deck: `drift` lists
|
|
228
|
+
* `{ slide, why, was?, now? }`, from the beats a take of your own voice
|
|
229
|
+
* recorded, else from the notes hash; `unknown` counts the slides that carry
|
|
230
|
+
* neither (recorded by hand before either existed), which are left alone.
|
|
231
|
+
*/
|
|
232
|
+
export function trackDrift(manifest, html) {
|
|
233
|
+
const out = { drift: [], unknown: 0 };
|
|
234
|
+
const beats = slideBeats(html);
|
|
235
|
+
const texts = slideTexts(html);
|
|
236
|
+
const prior = priorSlideTexts(html);
|
|
237
|
+
const slides = manifest?.slides ?? [];
|
|
238
|
+
for (let i = 0; i < slides.length; i++) {
|
|
239
|
+
const entry = slides[i];
|
|
240
|
+
if (!entry) continue;
|
|
241
|
+
const d = scriptDrift(entry, beats[i]);
|
|
242
|
+
if (d) { out.drift.push({ slide: i + 1, ...d }); continue; }
|
|
243
|
+
if (d === null) continue;
|
|
244
|
+
if (!entry.hash) { out.unknown++; continue; }
|
|
245
|
+
if (entryMatches(manifest, entry, texts[i] ?? '')) continue;
|
|
246
|
+
if (manifest.recorder === 'deck' && prior[i] && entryMatches(manifest, entry, prior[i])) continue;
|
|
247
|
+
out.drift.push({ slide: i + 1, why: 'text' });
|
|
248
|
+
}
|
|
249
|
+
return out;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* What a re-record of `slides` takes, as a line to paste: your own voice at
|
|
254
|
+
* the microphone, or the track's engine from the notes.
|
|
255
|
+
*/
|
|
256
|
+
export function rerecordLine(deck, dir, slides, { mine = false } = {}) {
|
|
257
|
+
const range = slides.length === 1 ? String(slides[0]) : `${Math.min(...slides)}-${Math.max(...slides)}`;
|
|
258
|
+
return `decklight narrate ${deck}${mine ? ' --mic' : ''} --slides ${range} --dir ${dir}`;
|
|
259
|
+
}
|
|
260
|
+
|
|
173
261
|
/**
|
|
174
262
|
* The manifest the deck recorder writes, after each slide of a take (#535):
|
|
175
263
|
* `recorded` maps slide number → its beat file numbers; every slide inside
|
|
@@ -177,7 +265,7 @@ export function staleSlides(manifest, texts, range = null, prior = null) {
|
|
|
177
265
|
* `prev`'s entry — a ranged re-record is a surgical redo, the same promise
|
|
178
266
|
* `voiceover --slides` makes. Files are wav: the recorder stitches WAV.
|
|
179
267
|
*/
|
|
180
|
-
export function recorderManifest({ prev, header, texts, range, recorded }) {
|
|
268
|
+
export function recorderManifest({ prev, header, texts, range, recorded, recorder = 'deck', beats = null }) {
|
|
181
269
|
const total = Math.max(texts.length, prev?.slides?.length ?? 0);
|
|
182
270
|
const slides = [];
|
|
183
271
|
for (let i = 0; i < total; i++) {
|
|
@@ -189,8 +277,14 @@ export function recorderManifest({ prev, header, texts, range, recorded }) {
|
|
|
189
277
|
const entry = { file: `slide-${nn}.wav`, hash: manifestHash(header, texts[i] ?? '') };
|
|
190
278
|
const segs = (take.segments ?? []).filter((k) => Number.isInteger(k) && k > 0);
|
|
191
279
|
if (segs.length) entry.segments = segs.map((k) => ({ file: `slide-${nn}-${String(k).padStart(2, '0')}.wav` }));
|
|
280
|
+
// your own voice: the beats as you read them, which is what tells a moved
|
|
281
|
+
// ⟨CLICK⟩ from changed words (scriptDrift)
|
|
282
|
+
if (beats) entry.beats = beats[i] ?? [];
|
|
283
|
+
// …and filmed with it: slide-NN.mp4 (and one per beat) is your face, which
|
|
284
|
+
// `decklight lipsync` must not render over and `decklight video` shows
|
|
285
|
+
if (take.face) entry.face = true;
|
|
192
286
|
slides.push(entry);
|
|
193
287
|
}
|
|
194
|
-
const { engine, model, voice, style } = header;
|
|
195
|
-
return { engine, model, voice, style,
|
|
288
|
+
const { engine, model, voice, voiceId, style, format } = header;
|
|
289
|
+
return { engine, model, voice, ...(voiceId ? { voiceId } : {}), style, ...(format ? { format } : {}), recorder, slides };
|
|
196
290
|
}
|