@biunow/agent-biutalk 0.0.0-stage → 1.1.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/bin/server.js +355 -0
- package/engine/AGENTS.md +1414 -0
- package/engine/CLAUDE.md +1 -0
- package/engine/LICENSE +21 -0
- package/engine/README.md +216 -0
- package/engine/bin/explainroo.js +19 -0
- package/engine/dev/audio-lab.mjs +268 -0
- package/engine/docs/media/contact-sheet.jpg +0 -0
- package/engine/docs/media/dns-poster.jpg +0 -0
- package/engine/docs/media/intro-poster.jpg +0 -0
- package/engine/docs/media/logo-dark.png +0 -0
- package/engine/docs/media/logo-light.png +0 -0
- package/engine/docs/media/looks-dark.webp +0 -0
- package/engine/docs/media/looks-light.webp +0 -0
- package/engine/docs/media/product-demo.webp +0 -0
- package/engine/docs/media/rebase-poster.jpg +0 -0
- package/engine/docs/media/sizes-dark.webp +0 -0
- package/engine/docs/media/sizes-light.webp +0 -0
- package/engine/engine/audio/dsp.js +69 -0
- package/engine/engine/audio/instruments.js +147 -0
- package/engine/engine/audio/music.js +576 -0
- package/engine/engine/audio/pcm.js +93 -0
- package/engine/engine/audio/rng.js +40 -0
- package/engine/engine/audio/sfx.js +287 -0
- package/engine/engine/audio/soundtrack.js +201 -0
- package/engine/engine/audio/synth.js +721 -0
- package/engine/engine/audio/theory.js +105 -0
- package/engine/engine/audio/wav.js +47 -0
- package/engine/engine/captions.js +131 -0
- package/engine/engine/clips.js +107 -0
- package/engine/engine/code.js +179 -0
- package/engine/engine/director.js +475 -0
- package/engine/engine/frame.html +135 -0
- package/engine/engine/icons/LICENSE-lucide.txt +43 -0
- package/engine/engine/icons/lucide-tags.json +1 -0
- package/engine/engine/icons/lucide.json +1 -0
- package/engine/engine/layout.js +69 -0
- package/engine/engine/pathdata.js +234 -0
- package/engine/engine/pen.js +240 -0
- package/engine/engine/player.html +67 -0
- package/engine/engine/player.js +219 -0
- package/engine/engine/readability.js +9 -0
- package/engine/engine/runtime.js +690 -0
- package/engine/engine/stage.js +2247 -0
- package/engine/engine/studio.html +216 -0
- package/engine/engine/text.js +81 -0
- package/engine/engine/themes.js +360 -0
- package/engine/engine/transitions.js +161 -0
- package/engine/engine/ui.js +1042 -0
- package/engine/engine/upload.js +32 -0
- package/engine/engine/util.js +204 -0
- package/engine/examples/callbacks-to-async-await/code-versions.js +34 -0
- package/engine/examples/callbacks-to-async-await/scenes.js +106 -0
- package/engine/examples/callbacks-to-async-await/script.md +22 -0
- package/engine/examples/callbacks-to-async-await/video.json +16 -0
- package/engine/examples/circle-area/scenes.js +228 -0
- package/engine/examples/circle-area/script.md +37 -0
- package/engine/examples/circle-area/video.json +14 -0
- package/engine/examples/explainroo-intro/scenes.js +133 -0
- package/engine/examples/explainroo-intro/script.md +27 -0
- package/engine/examples/explainroo-intro/video.json +8 -0
- package/engine/examples/how-dns-works/scenes.js +130 -0
- package/engine/examples/how-dns-works/script.md +28 -0
- package/engine/examples/how-dns-works/video.json +8 -0
- package/engine/examples/leap-years/scenes.js +156 -0
- package/engine/examples/leap-years/script.md +25 -0
- package/engine/examples/leap-years/video.json +16 -0
- package/engine/examples/leap-years-ja/scenes.js +194 -0
- package/engine/examples/leap-years-ja/script.md +32 -0
- package/engine/examples/leap-years-ja/video.json +17 -0
- package/engine/examples/merge-vs-rebase/scenes.js +129 -0
- package/engine/examples/merge-vs-rebase/script.md +22 -0
- package/engine/examples/merge-vs-rebase/video.json +8 -0
- package/engine/examples/password-storage-zh/scenes.js +185 -0
- package/engine/examples/password-storage-zh/script.md +25 -0
- package/engine/examples/password-storage-zh/video.json +19 -0
- package/engine/examples/sqlite-demo/README.md +19 -0
- package/engine/examples/sqlite-demo/scenes.js +423 -0
- package/engine/examples/sqlite-demo/script.md +35 -0
- package/engine/examples/sqlite-demo/video.json +17 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-400.woff2 +0 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-500.woff2 +0 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-600.woff2 +0 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-700.woff2 +0 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-OFL.txt +93 -0
- package/engine/examples/unspar-demo/assets/unspar-logo.svg +23 -0
- package/engine/examples/unspar-demo/scenes.js +367 -0
- package/engine/examples/unspar-demo/script.md +25 -0
- package/engine/examples/unspar-demo/video.json +21 -0
- package/engine/examples/why-is-the-sky-blue-es/scenes.js +160 -0
- package/engine/examples/why-is-the-sky-blue-es/script.md +22 -0
- package/engine/examples/why-is-the-sky-blue-es/video.json +15 -0
- package/engine/fonts/ArchitectsDaughter-400-latin-ext.woff2 +0 -0
- package/engine/fonts/ArchitectsDaughter-400-latin.woff2 +0 -0
- package/engine/fonts/CabinSketch-400-latin.woff2 +0 -0
- package/engine/fonts/CabinSketch-700-latin.woff2 +0 -0
- package/engine/fonts/InstrumentSerif-400-italic-latin-ext.woff2 +0 -0
- package/engine/fonts/InstrumentSerif-400-italic-latin.woff2 +0 -0
- package/engine/fonts/InstrumentSerif-400-normal-latin-ext.woff2 +0 -0
- package/engine/fonts/InstrumentSerif-400-normal-latin.woff2 +0 -0
- package/engine/fonts/Inter-400-latin-ext.woff2 +0 -0
- package/engine/fonts/Inter-400-latin.woff2 +0 -0
- package/engine/fonts/JetBrainsMono-400-latin-ext.woff2 +0 -0
- package/engine/fonts/JetBrainsMono-400-latin.woff2 +0 -0
- package/engine/fonts/Kalam-400-latin-ext.woff2 +0 -0
- package/engine/fonts/Kalam-400-latin.woff2 +0 -0
- package/engine/fonts/Kalam-700-latin-ext.woff2 +0 -0
- package/engine/fonts/Kalam-700-latin.woff2 +0 -0
- package/engine/fonts/NotoSansDevanagari-400.ttf +0 -0
- package/engine/fonts/NotoSansDevanagari-700.ttf +0 -0
- package/engine/fonts/PatrickHand-400-latin-ext.woff2 +0 -0
- package/engine/fonts/PatrickHand-400-latin.woff2 +0 -0
- package/engine/fonts/PlusJakartaSans-600-latin-ext.woff2 +0 -0
- package/engine/fonts/PlusJakartaSans-600-latin.woff2 +0 -0
- package/engine/fonts/SpaceGrotesk-500-latin-ext.woff2 +0 -0
- package/engine/fonts/SpaceGrotesk-500-latin.woff2 +0 -0
- package/engine/fonts/fonts.json +216 -0
- package/engine/fonts/licenses/ArchitectsDaughter-OFL.txt +93 -0
- package/engine/fonts/licenses/CabinSketch-OFL.txt +93 -0
- package/engine/fonts/licenses/InstrumentSerif-OFL.txt +93 -0
- package/engine/fonts/licenses/Inter-OFL.txt +93 -0
- package/engine/fonts/licenses/JetBrainsMono-OFL.txt +93 -0
- package/engine/fonts/licenses/Kalam-OFL.txt +93 -0
- package/engine/fonts/licenses/NotoSansDevanagari-OFL.txt +118 -0
- package/engine/fonts/licenses/PatrickHand-OFL.txt +93 -0
- package/engine/fonts/licenses/PlusJakartaSans-OFL.txt +93 -0
- package/engine/fonts/licenses/SpaceGrotesk-OFL.txt +93 -0
- package/engine/package-lock.json +1201 -0
- package/engine/package.json +67 -0
- package/engine/scripts/build-icons.mjs +74 -0
- package/engine/scripts/fetch-fonts.mjs +68 -0
- package/engine/skills/explainroo/SKILL.md +51 -0
- package/engine/src/align.js +357 -0
- package/engine/src/browser.js +121 -0
- package/engine/src/capture.js +315 -0
- package/engine/src/chapters.js +32 -0
- package/engine/src/cli.js +421 -0
- package/engine/src/clips.js +19 -0
- package/engine/src/elevenlabs.js +90 -0
- package/engine/src/env.js +16 -0
- package/engine/src/export.js +187 -0
- package/engine/src/ffmpeg.js +103 -0
- package/engine/src/fonts.js +86 -0
- package/engine/src/g2p.py +76 -0
- package/engine/src/images.js +151 -0
- package/engine/src/licenses/misaki-Apache-2.0.txt +201 -0
- package/engine/src/math.js +83 -0
- package/engine/src/models.js +161 -0
- package/engine/src/phonemes.js +162 -0
- package/engine/src/pipeline.js +63 -0
- package/engine/src/project.js +331 -0
- package/engine/src/qa.js +186 -0
- package/engine/src/recordings.js +89 -0
- package/engine/src/render.js +156 -0
- package/engine/src/script.js +266 -0
- package/engine/src/server.js +288 -0
- package/engine/src/subtitles.js +78 -0
- package/engine/src/timeline.js +55 -0
- package/engine/src/voice.js +240 -0
- package/engine/src/wav.js +98 -0
- package/engine/templates/starter/scenes.js +31 -0
- package/engine/templates/starter/script.md +14 -0
- package/engine/test/align.test.js +108 -0
- package/engine/test/brand.test.js +41 -0
- package/engine/test/browser.test.js +89 -0
- package/engine/test/camera-browser.test.js +225 -0
- package/engine/test/caption-phrases.test.js +35 -0
- package/engine/test/capture-browser.test.js +90 -0
- package/engine/test/capture-fixture.js +46 -0
- package/engine/test/capture.test.js +62 -0
- package/engine/test/chapters.test.js +41 -0
- package/engine/test/cjk-browser.test.js +101 -0
- package/engine/test/cjk.test.js +232 -0
- package/engine/test/cli-exit.test.js +25 -0
- package/engine/test/cli.test.js +116 -0
- package/engine/test/clips-browser.test.js +125 -0
- package/engine/test/clips.test.js +67 -0
- package/engine/test/code-morph-browser.test.js +99 -0
- package/engine/test/code-morph.test.js +110 -0
- package/engine/test/contrast-browser.test.js +63 -0
- package/engine/test/contrast.test.js +80 -0
- package/engine/test/director.test.js +316 -0
- package/engine/test/engine-pure.test.js +29 -0
- package/engine/test/export-browser.test.js +224 -0
- package/engine/test/export.test.js +96 -0
- package/engine/test/fixtures/capture.html +55 -0
- package/engine/test/formats-pace.test.js +104 -0
- package/engine/test/languages-browser.test.js +78 -0
- package/engine/test/languages.test.js +140 -0
- package/engine/test/looks-browser.test.js +109 -0
- package/engine/test/looks-preview.test.js +57 -0
- package/engine/test/looks.test.js +130 -0
- package/engine/test/math-browser.test.js +114 -0
- package/engine/test/math.test.js +54 -0
- package/engine/test/multi-size-browser.test.js +133 -0
- package/engine/test/multi-size.test.js +116 -0
- package/engine/test/phonemes.test.js +92 -0
- package/engine/test/readability-browser.test.js +36 -0
- package/engine/test/readability.test.js +20 -0
- package/engine/test/render-options.test.js +52 -0
- package/engine/test/script.test.js +67 -0
- package/engine/test/server.test.js +256 -0
- package/engine/test/stills-browser.test.js +70 -0
- package/engine/test/subtitles.test.js +83 -0
- package/engine/test/timeline.test.js +31 -0
- package/engine/test/transparent-browser.test.js +123 -0
- package/engine/test/ui-kit.test.js +96 -0
- package/engine/test/upload-browser.test.js +55 -0
- package/engine/test/voice-providers.test.js +338 -0
- package/lib/host.mjs +480 -0
- package/manifest.json +54 -0
- package/package.json +8 -4
- package/skills/biutalk/SKILL.md +21 -0
- package/studio/app.js +209 -0
- package/studio/assert-panel-permit.mjs +67 -0
- package/studio/composer.css +354 -0
- package/studio/composer.js +169 -0
- package/studio/index.html +82 -0
- package/studio/looks/blueprint.svg +21 -0
- package/studio/looks/chalk.svg +15 -0
- package/studio/looks/clean.svg +20 -0
- package/studio/looks/editorial.svg +18 -0
- package/studio/looks/midnight.svg +17 -0
- package/studio/looks/paper.svg +11 -0
- package/studio/select-menu.js +268 -0
- package/studio/styles.css +4 -0
- package/README.md +0 -3
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { spawnSync } from 'node:child_process';
|
|
7
|
+
import { findChrome } from '../src/browser.js';
|
|
8
|
+
import { loadProject } from '../src/project.js';
|
|
9
|
+
import { withEngine } from '../src/pipeline.js';
|
|
10
|
+
import { render } from '../src/render.js';
|
|
11
|
+
import { stills, verify } from '../src/qa.js';
|
|
12
|
+
import { ffmpegPath, ffmpegVersion, probe } from '../src/ffmpeg.js';
|
|
13
|
+
|
|
14
|
+
let chrome;
|
|
15
|
+
try { chrome = findChrome(); } catch {}
|
|
16
|
+
const skip = !chrome || !ffmpegVersion();
|
|
17
|
+
|
|
18
|
+
function pixels(file, decoder = []) {
|
|
19
|
+
const r = spawnSync(ffmpegPath(), ['-v', 'error', ...decoder, '-i', file, '-frames:v', '1', '-f', 'rawvideo', '-pix_fmt', 'rgba', '-threads', '1', '-'], { maxBuffer: 1024 * 1024 });
|
|
20
|
+
assert.equal(r.status, 0, r.stderr.toString());
|
|
21
|
+
return r.stdout;
|
|
22
|
+
}
|
|
23
|
+
const alphaAt = (data, x, y, w = 320) => data[(y * w + x) * 4 + 3];
|
|
24
|
+
|
|
25
|
+
function projectFiles(dir) {
|
|
26
|
+
fs.writeFileSync(path.join(dir, 'video.json'), JSON.stringify({ theme: 'clean', size: '320x180', fps: 24, captions: false, watermark: false, music: false, sfx: false, end: 0 }));
|
|
27
|
+
fs.writeFileSync(path.join(dir, 'script.md'), '## box {min=2 chapter="Box"}\n');
|
|
28
|
+
fs.writeFileSync(path.join(dir, 'scenes.js'), `export default { box(s) {
|
|
29
|
+
s.box('', { x: 160, y: 90, w: 80, h: 60, fill: '#245cff', border: false, at: 0, enter: 'none' });
|
|
30
|
+
} };`);
|
|
31
|
+
return loadProject(dir);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
test('transparent WebM and MOV retain alpha, audio, chapters and opaque covers', { skip }, async () => {
|
|
35
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-alpha-'));
|
|
36
|
+
try {
|
|
37
|
+
const project = projectFiles(dir);
|
|
38
|
+
for (const format of ['webm', 'mov']) {
|
|
39
|
+
const r = await render(project, { format, transparent: true, workers: 2 });
|
|
40
|
+
assert.equal(r.out, path.join(dir, `out/video.${format}`));
|
|
41
|
+
assert.equal(r.duration, 2);
|
|
42
|
+
assert.equal(r.chapters, path.join(dir, 'out/video.chapters.txt'));
|
|
43
|
+
assert.equal(r.cover, path.join(dir, 'out/video.cover.jpg'));
|
|
44
|
+
const info = await probe(r.out);
|
|
45
|
+
const video = info.streams.find((s) => s.codec_type === 'video');
|
|
46
|
+
const audio = info.streams.find((s) => s.codec_type === 'audio');
|
|
47
|
+
assert.equal(audio.codec_name, format === 'webm' ? 'opus' : 'pcm_s16le');
|
|
48
|
+
// ffprobe's native VP9 decoder hides the alpha plane. libvpx exposes it.
|
|
49
|
+
if (format === 'webm') {
|
|
50
|
+
assert.equal(video.codec_name, 'vp9');
|
|
51
|
+
assert.equal(video.tags.alpha_mode ?? video.tags.ALPHA_MODE, '1');
|
|
52
|
+
const decoded = spawnSync(ffmpegPath(), ['-c:v', 'libvpx-vp9', '-i', r.out, '-frames:v', '1', '-f', 'null', '-'], { encoding: 'utf8' });
|
|
53
|
+
assert.equal(decoded.status, 0, decoded.stderr);
|
|
54
|
+
assert.match(decoded.stderr, /yuva420p/);
|
|
55
|
+
} else {
|
|
56
|
+
assert.equal(video.codec_name, 'prores');
|
|
57
|
+
assert.equal(video.codec_tag_string, 'ap4h');
|
|
58
|
+
assert.match(video.pix_fmt, /^yuva444p/);
|
|
59
|
+
}
|
|
60
|
+
const chapters = spawnSync(process.env.EXPLAINROO_FFPROBE || 'ffprobe', ['-v', 'error', '-show_chapters', '-of', 'json', r.out], { encoding: 'utf8' });
|
|
61
|
+
assert.equal(chapters.status, 0, chapters.stderr);
|
|
62
|
+
assert.equal(JSON.parse(chapters.stdout).chapters[0].tags.title, 'Box');
|
|
63
|
+
const data = pixels(r.out, format === 'webm' ? ['-c:v', 'libvpx-vp9'] : []);
|
|
64
|
+
assert.equal(alphaAt(data, 0, 0), 0);
|
|
65
|
+
assert.equal(alphaAt(data, 160, 90), 255);
|
|
66
|
+
assert.equal(alphaAt(pixels(r.cover), 0, 0), 255);
|
|
67
|
+
const report = await verify(project, { file: r.out });
|
|
68
|
+
assert.deepEqual(report.blackSegments, []);
|
|
69
|
+
assert.ok(report.issues.some((i) => /skipped because the video has alpha/.test(i.message)));
|
|
70
|
+
assert.ok(!report.issues.some((i) => i.level === 'error'));
|
|
71
|
+
}
|
|
72
|
+
const [still] = await stills(project, ['box@1'], { transparent: true });
|
|
73
|
+
const data = pixels(still.file);
|
|
74
|
+
assert.equal(alphaAt(data, 0, 0), 0);
|
|
75
|
+
assert.equal(alphaAt(data, 160, 90), 255);
|
|
76
|
+
for (const format of ['webm', 'mov']) {
|
|
77
|
+
const r = await render(project, { format, draft: true, workers: 1 });
|
|
78
|
+
assert.equal(r.out, path.join(dir, `out/draft.${format}`));
|
|
79
|
+
assert.equal(alphaAt(pixels(r.out), 0, 0, 160), 255);
|
|
80
|
+
}
|
|
81
|
+
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('every transparent transition keeps empty pixels clear and clears old frames', { skip: !chrome }, async () => {
|
|
85
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-transitions-'));
|
|
86
|
+
try {
|
|
87
|
+
const project = projectFiles(dir);
|
|
88
|
+
const names = ['fade', 'slide', 'wipe', 'zoom', 'brush', 'cut'];
|
|
89
|
+
const timeline = { duration: 14, frames: 336, fps: 24, width: 320, height: 180, transitionSeconds: 0.7,
|
|
90
|
+
scenes: ['none', ...names].map((transition, index) => ({ id: 'box', index, start: index * 2, dur: 2, words: [], marks: {}, voice: null, transition })) };
|
|
91
|
+
await withEngine(project, timeline, { transparent: true }, async (page) => {
|
|
92
|
+
const results = await page.evaluate(async () => {
|
|
93
|
+
const { boot } = await import('/engine/runtime.js');
|
|
94
|
+
const { engine } = await boot({ canvas: document.createElement('canvas'), transparent: true });
|
|
95
|
+
engine.scenesModule.box = (s) => {
|
|
96
|
+
s.ctx.fillStyle = '#245cff';
|
|
97
|
+
s.ctx.fillRect(s.scene.index % 2 ? 160 : 80, 60, 80, 60);
|
|
98
|
+
};
|
|
99
|
+
const sample = (T) => {
|
|
100
|
+
engine.renderFrame(T);
|
|
101
|
+
const ctx = engine.ctx;
|
|
102
|
+
return [0, 100, 180].map((x) => ctx.getImageData(x, x ? 90 : 0, 1, 1).data[3]);
|
|
103
|
+
};
|
|
104
|
+
return engine.timeline.scenes.slice(1).map((sc) => ({
|
|
105
|
+
name: sc.transition, middle: sample(sc.start + 0.35), end: sample(sc.start + 0.8), repeat: sample(sc.start + 0.35),
|
|
106
|
+
}));
|
|
107
|
+
});
|
|
108
|
+
for (const [i, r] of results.entries()) {
|
|
109
|
+
assert.equal(r.middle[0], 0, r.name);
|
|
110
|
+
assert.equal(r.end[0], 0, r.name);
|
|
111
|
+
assert.deepEqual(r.repeat, r.middle, r.name);
|
|
112
|
+
const outgoing = i % 2 ? 2 : 1;
|
|
113
|
+
const incoming = i % 2 ? 1 : 2;
|
|
114
|
+
assert.equal(r.end[outgoing], 0, r.name);
|
|
115
|
+
assert.equal(r.end[incoming], 255, r.name);
|
|
116
|
+
if (r.name !== 'cut') {
|
|
117
|
+
assert.ok(Math.abs(r.middle[outgoing] - 128) <= 1, JSON.stringify(r));
|
|
118
|
+
assert.ok(Math.abs(r.middle[incoming] - 128) <= 1, JSON.stringify(r));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
|
123
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { Stage } from '../engine/stage.js';
|
|
4
|
+
import { UI } from '../engine/ui.js';
|
|
5
|
+
import { getTheme } from '../engine/themes.js';
|
|
6
|
+
|
|
7
|
+
Stage.UI = UI;
|
|
8
|
+
|
|
9
|
+
// Just enough of the browser's DOMMatrix and DOMPoint for the stage's text log.
|
|
10
|
+
globalThis.DOMPoint ??= class {
|
|
11
|
+
constructor(x = 0, y = 0) {
|
|
12
|
+
this.x = x;
|
|
13
|
+
this.y = y;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
globalThis.DOMMatrix ??= class {
|
|
17
|
+
constructor([a, b, c, d, e, f]) {
|
|
18
|
+
Object.assign(this, { a, b, c, d, e, f });
|
|
19
|
+
}
|
|
20
|
+
transformPoint(p) {
|
|
21
|
+
return new DOMPoint(this.a * p.x + this.c * p.y + this.e, this.b * p.x + this.d * p.y + this.f);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// A canvas that records what gets drawn.
|
|
26
|
+
function fakeCanvas() {
|
|
27
|
+
const drawn = [];
|
|
28
|
+
const ctx = new Proxy(
|
|
29
|
+
{ font: '', fillStyle: '#000', globalAlpha: 1 },
|
|
30
|
+
{
|
|
31
|
+
get(target, key) {
|
|
32
|
+
if (key in target) return target[key];
|
|
33
|
+
if (key === 'drawn') return drawn;
|
|
34
|
+
if (key === 'measureText') return (t) => ({ width: String(t).length * 10 });
|
|
35
|
+
if (key === 'getTransform') return () => ({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, transformPoint: (p) => p });
|
|
36
|
+
if (['fill', 'stroke', 'fillText', 'drawImage', 'fillRect'].includes(key)) return (...args) => drawn.push([key, ...args]);
|
|
37
|
+
return () => {};
|
|
38
|
+
},
|
|
39
|
+
set(target, key, value) {
|
|
40
|
+
target[key] = value;
|
|
41
|
+
return true;
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
return ctx;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function stageAt(t, texts) {
|
|
49
|
+
const theme = getTheme('clean');
|
|
50
|
+
const engine = {
|
|
51
|
+
theme,
|
|
52
|
+
pen: { draw() {} },
|
|
53
|
+
W: 1920,
|
|
54
|
+
H: 1080,
|
|
55
|
+
safeArea: { x: 0, y: 0, w: 1920, h: 1080, bottom: 1080 },
|
|
56
|
+
config: { brand: null },
|
|
57
|
+
timeline: { pace: 1, duration: 10, frames: 300, fps: 30, width: 1920, height: 1080, scenes: [] },
|
|
58
|
+
fps: 30,
|
|
59
|
+
scale: 1,
|
|
60
|
+
recorder: null,
|
|
61
|
+
textLog: texts,
|
|
62
|
+
};
|
|
63
|
+
const scene = { start: 0, dur: 10, id: 'demo', index: 0, words: [], marks: {}, voice: null, lead: 0 };
|
|
64
|
+
return new Stage(engine, fakeCanvas(), scene, t);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
test('s.ui draws nothing while its s.group is hidden, before and after', () => {
|
|
68
|
+
const drawnAt = (t) => {
|
|
69
|
+
const texts = [];
|
|
70
|
+
const s = stageAt(t, texts);
|
|
71
|
+
s.group({ at: 2, out: 4, x: 500, y: 300 }, () => {
|
|
72
|
+
s.ui.card(0, 0, 400, 200);
|
|
73
|
+
s.ui.text('Inside the group', 20, 40);
|
|
74
|
+
s.ui.button('Save', 20, 120, 160, 50);
|
|
75
|
+
});
|
|
76
|
+
return { drawn: s.ctx.drawn.length, texts: texts.length };
|
|
77
|
+
};
|
|
78
|
+
assert.deepEqual(drawnAt(0), { drawn: 0, texts: 0 });
|
|
79
|
+
assert.deepEqual(drawnAt(1), { drawn: 0, texts: 0 });
|
|
80
|
+
const visible = drawnAt(3);
|
|
81
|
+
assert.ok(visible.drawn > 0, 'the group draws while it is visible');
|
|
82
|
+
assert.ok(visible.texts >= 2, 'check sees the text while it is visible');
|
|
83
|
+
assert.deepEqual(drawnAt(5), { drawn: 0, texts: 0 });
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('a hidden s.ui group still records its sounds', () => {
|
|
87
|
+
const texts = [];
|
|
88
|
+
const s = stageAt(0, texts);
|
|
89
|
+
const events = [];
|
|
90
|
+
s.engine.recorder = { push: (e) => events.push(e) };
|
|
91
|
+
s.group({ at: 2, x: 0, y: 0 }, () => {
|
|
92
|
+
s.ui.panel(0, 0, 100, 100, { at: 2.5, sfx: 'pop' });
|
|
93
|
+
});
|
|
94
|
+
assert.ok(events.some((e) => e.sfx === 'pop' && Math.abs(e.at - 2.5) < 1e-9));
|
|
95
|
+
assert.equal(s.ctx.drawn.length, 0);
|
|
96
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { findChrome } from '../src/browser.js';
|
|
8
|
+
import { loadProject } from '../src/project.js';
|
|
9
|
+
import { withEngine } from '../src/pipeline.js';
|
|
10
|
+
|
|
11
|
+
// Regression test for long renders failing with ERR_STRING_TOO_LONG while the
|
|
12
|
+
// soundtrack was uploaded: an ArrayBuffer request body is copied into the
|
|
13
|
+
// DevTools event that Playwright reads as one string. The upload must arrive
|
|
14
|
+
// intact, in bounded pieces, without its bytes travelling through the driver.
|
|
15
|
+
let chrome;
|
|
16
|
+
try { chrome = findChrome(); } catch {}
|
|
17
|
+
test('engine uploads go up in bounded pieces that never pass through the driver', { skip: !chrome }, async () => {
|
|
18
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-upload-'));
|
|
19
|
+
try {
|
|
20
|
+
fs.writeFileSync(path.join(dir, 'video.json'), JSON.stringify({ theme: 'clean', captions: false, music: false, sfx: false }));
|
|
21
|
+
fs.writeFileSync(path.join(dir, 'script.md'), '## demo\nA sound.');
|
|
22
|
+
fs.writeFileSync(path.join(dir, 'scenes.js'), 'export default { demo(s) { s.text("demo", { at: 0 }); } };');
|
|
23
|
+
const project = loadProject(dir);
|
|
24
|
+
const timeline = { pace: 1, duration: 1, frames: 30, fps: 30, width: 1920, height: 1080, transitionSeconds: 0,
|
|
25
|
+
scenes: [{ id: 'demo', index: 0, start: 0, dur: 1, words: [], marks: {}, voice: null, lead: 0, transition: 'none' }] };
|
|
26
|
+
await withEngine(project, timeline, { scale: 0.25 }, async (page) => {
|
|
27
|
+
const puts = [];
|
|
28
|
+
page.on('request', (r) => {
|
|
29
|
+
if (r.method() === 'PUT') puts.push({ url: r.url(), driverBytes: r.postDataBuffer()?.length ?? 0 });
|
|
30
|
+
});
|
|
31
|
+
// 5 MB of pseudo-random bytes as an ArrayBuffer, like an encoded WAV, in 1 MB pieces
|
|
32
|
+
const size = 5 * 1024 * 1024 + 123;
|
|
33
|
+
const digest = await page.evaluate(async ({ size }) => {
|
|
34
|
+
const { upload } = await import('/engine/upload.js');
|
|
35
|
+
const bytes = new Uint8Array(size);
|
|
36
|
+
let x = 2463534242;
|
|
37
|
+
for (let i = 0; i < size; i++) { x ^= x << 13; x ^= x >>> 17; x ^= x << 5; bytes[i] = x & 255; }
|
|
38
|
+
await upload('build/big.bin', bytes.buffer, { chunkBytes: 1024 * 1024 });
|
|
39
|
+
const hash = await crypto.subtle.digest('SHA-256', bytes);
|
|
40
|
+
return [...new Uint8Array(hash)].map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
41
|
+
}, { size });
|
|
42
|
+
const written = fs.readFileSync(path.join(dir, 'build', 'big.bin'));
|
|
43
|
+
assert.equal(written.length, size);
|
|
44
|
+
assert.equal(crypto.createHash('sha256').update(written).digest('hex'), digest);
|
|
45
|
+
assert.equal(puts.length, 6);
|
|
46
|
+
assert.deepEqual(puts.map((p) => Number(new URL(p.url).searchParams.get('offset'))), [0, 1, 2, 3, 4, 5].map((k) => k * 1024 * 1024));
|
|
47
|
+
assert.equal(new URL(puts.at(-1).url).searchParams.get('last'), '1');
|
|
48
|
+
const ids = new Set(puts.map((p) => new URL(p.url).searchParams.get('upload')));
|
|
49
|
+
assert.equal(ids.size, 1);
|
|
50
|
+
assert.match([...ids][0], /^[0-9a-f]{32}$/);
|
|
51
|
+
assert.ok(puts.every((p) => p.driverBytes === 0), 'request bodies must not be copied into the driver protocol');
|
|
52
|
+
assert.deepEqual(fs.readdirSync(path.join(dir, 'build')).filter((n) => n.endsWith('.part')), []);
|
|
53
|
+
});
|
|
54
|
+
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
|
55
|
+
});
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { normalizeConfig, loadProject, ProjectError } from '../src/project.js';
|
|
7
|
+
import { parseScript, speechChunks } from '../src/script.js';
|
|
8
|
+
import { findEnv, readEnvFile } from '../src/env.js';
|
|
9
|
+
import { findKey } from '../src/images.js';
|
|
10
|
+
import { elevenSpeech, elevenSpeed, decodePCM, elevenVoices, elevenUsage } from '../src/elevenlabs.js';
|
|
11
|
+
import { recordingCuts, recordingFiles, decodeRecording, saveRecording } from '../src/recordings.js';
|
|
12
|
+
import { sceneHash } from '../src/voice.js';
|
|
13
|
+
import { readWav, writeWav } from '../src/wav.js';
|
|
14
|
+
import { loudness } from '../src/ffmpeg.js';
|
|
15
|
+
import { main } from '../src/cli.js';
|
|
16
|
+
|
|
17
|
+
function temp(t) {
|
|
18
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-voices-'));
|
|
19
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
20
|
+
return dir;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function project(t, voice = { provider: 'elevenlabs', id: 'test-voice' }) {
|
|
24
|
+
const dir = temp(t);
|
|
25
|
+
fs.mkdirSync(path.join(dir, 'assets'));
|
|
26
|
+
fs.writeFileSync(path.join(dir, 'video.json'), JSON.stringify({ voice }));
|
|
27
|
+
fs.writeFileSync(path.join(dir, 'script.md'), '# Test\n## first\nHello.\n## silent\n## second\nGoodbye.');
|
|
28
|
+
fs.writeFileSync(path.join(dir, 'scenes.js'), 'export default { first() {}, silent() {}, second() {} };');
|
|
29
|
+
return loadProject(dir);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function setEnv(t, name, value) {
|
|
33
|
+
const previous = process.env[name];
|
|
34
|
+
process.env[name] = value;
|
|
35
|
+
t.after(() => {
|
|
36
|
+
if (previous === undefined) delete process.env[name];
|
|
37
|
+
else process.env[name] = previous;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function mockAPI(t, fn) {
|
|
42
|
+
t.mock.method(globalThis, 'fetch', fn);
|
|
43
|
+
setEnv(t, 'ELEVENLABS_API_KEY', 'secret-test-key');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
test('voice config accepts strings and all providers, with provider speed defaults', () => {
|
|
47
|
+
assert.equal(normalizeConfig({}).voice, 'af_heart');
|
|
48
|
+
assert.equal(normalizeConfig({ voice: 'am_michael' }).speed, 0.9);
|
|
49
|
+
assert.equal(normalizeConfig({ voice: { provider: 'kokoro', id: 'af_heart' } }).voice, 'af_heart');
|
|
50
|
+
assert.equal(normalizeConfig({ voice: { provider: 'kokoro', id: 'af_heart' } }).speed, 0.9);
|
|
51
|
+
const cfg = normalizeConfig({ voice: { provider: 'elevenlabs', id: 'voice' }, pace: 1.6 });
|
|
52
|
+
assert.deepEqual(cfg.voice, { provider: 'elevenlabs', id: 'voice', model: 'eleven_multilingual_v2' });
|
|
53
|
+
assert.equal(cfg.speed, 1);
|
|
54
|
+
assert.equal(normalizeConfig({ voice: { provider: 'elevenlabs', id: 'voice', model: 'eleven_flash_v2_5' }, speed: 0.8 }).speed, 0.8);
|
|
55
|
+
for (const src of ['assets/narration.wav', 'assets/narration/', 'assets/take.m4a']) {
|
|
56
|
+
assert.equal(normalizeConfig({ voice: { provider: 'recording', src } }).speed, 1);
|
|
57
|
+
assert.equal(normalizeConfig({ voice: { provider: 'recording', src }, speed: 1.2 }).speed, 1.2);
|
|
58
|
+
}
|
|
59
|
+
assert.throws(() => normalizeConfig({ speed: 1.6, pace: 1.6 }), /too fast/);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('voice config rejects bad providers, missing ids, unknown keys and unsafe paths', () => {
|
|
63
|
+
for (const voice of [null, [], 1, {}, { provider: 'bad' }, { provider: 'toString' }, { provider: ['kokoro'], id: 'af_heart' },
|
|
64
|
+
{ provider: 'kokoro' }, { provider: 'kokoro', id: 'bad' }, { provider: 'kokoro', id: 'toString' },
|
|
65
|
+
{ provider: 'kokoro', id: 'af_heart', model: 'x' }, { provider: 'elevenlabs' },
|
|
66
|
+
{ provider: 'elevenlabs', id: '' }, { provider: 'elevenlabs', id: 'v', model: 4 },
|
|
67
|
+
{ provider: 'elevenlabs', id: 'v', key: 'secret' }, { provider: 'recording' },
|
|
68
|
+
{ provider: 'recording', src: '../take.wav' }, { provider: 'recording', src: 'assets/../take.wav' },
|
|
69
|
+
{ provider: 'recording', src: 'assets/..\\take.wav' }, { provider: 'recording', src: 'assets/a.wav', id: 'x' }]) {
|
|
70
|
+
assert.throws(() => normalizeConfig({ voice }), ProjectError);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('shared env reader keeps environment, project, root precedence and quoted exports', (t) => {
|
|
75
|
+
const dir = temp(t);
|
|
76
|
+
const root = temp(t);
|
|
77
|
+
const name = 'EXPLAINROO_TEST_KEY';
|
|
78
|
+
const file = path.join(dir, '.env');
|
|
79
|
+
setEnv(t, name, 'environment');
|
|
80
|
+
fs.writeFileSync(path.join(root, '.env'), `${name}=root\n`);
|
|
81
|
+
fs.writeFileSync(file, `UNRELATED=x\n export ${name} = "project" \nOPENROUTER_API_KEY='image-key'\n`);
|
|
82
|
+
assert.equal(readEnvFile(file, name), 'project');
|
|
83
|
+
assert.equal(findEnv(name, dir, root), 'environment');
|
|
84
|
+
process.env[name] = '';
|
|
85
|
+
assert.equal(findEnv(name, dir, root), 'project');
|
|
86
|
+
setEnv(t, 'OPENROUTER_API_KEY', '');
|
|
87
|
+
assert.equal(findKey(dir), 'image-key');
|
|
88
|
+
fs.writeFileSync(file, `${name}=''\n`);
|
|
89
|
+
assert.equal(findEnv(name, dir, root), 'root');
|
|
90
|
+
fs.rmSync(file);
|
|
91
|
+
assert.equal(readEnvFile(file, name), null);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('ElevenLabs requests PCM, neighbouring text, speed, and logs usage without secrets', async (t) => {
|
|
95
|
+
const p = project(t);
|
|
96
|
+
p.config.speed = 1.1;
|
|
97
|
+
p.config.pace = 1.3;
|
|
98
|
+
const pcm = Buffer.alloc(6);
|
|
99
|
+
pcm.writeInt16LE(-32768, 0);
|
|
100
|
+
pcm.writeInt16LE(0, 2);
|
|
101
|
+
pcm.writeInt16LE(16384, 4);
|
|
102
|
+
mockAPI(t, async (url, opts) => {
|
|
103
|
+
assert.equal(url, 'https://api.elevenlabs.io/v1/text-to-speech/test-voice?output_format=pcm_24000');
|
|
104
|
+
assert.equal(opts.method, 'POST');
|
|
105
|
+
assert.equal(opts.headers['xi-api-key'], 'secret-test-key');
|
|
106
|
+
assert.deepEqual(JSON.parse(opts.body), { text: 'Hello.', model_id: 'eleven_multilingual_v2', voice_settings: { speed: 1.2 }, previous_text: 'Before.', next_text: 'After.' });
|
|
107
|
+
return new Response(pcm);
|
|
108
|
+
});
|
|
109
|
+
const audio = await elevenSpeech(p, 'first', 'Hello.', { previous: 'Before.', next: 'After.' });
|
|
110
|
+
assert.equal(audio.sampling_rate, 24000);
|
|
111
|
+
assert.deepEqual([...audio.audio], [-1, 0, 0.5]);
|
|
112
|
+
const usage = elevenUsage(p);
|
|
113
|
+
assert.equal(usage.length, 1);
|
|
114
|
+
assert.deepEqual(Object.keys(usage[0]), ['time', 'scene', 'characters', 'model', 'voice_id']);
|
|
115
|
+
assert.equal(usage[0].scene, 'first');
|
|
116
|
+
assert.equal(usage[0].characters, 6);
|
|
117
|
+
assert.equal(usage[0].voice_id, 'test-voice');
|
|
118
|
+
assert.equal(usage[0].model, 'eleven_multilingual_v2');
|
|
119
|
+
assert.ok(Number.isFinite(Date.parse(usage[0].time)));
|
|
120
|
+
assert.ok(!JSON.stringify(usage).includes('secret-test-key'));
|
|
121
|
+
assert.throws(() => decodePCM(Buffer.alloc(1)), /unreadable audio/);
|
|
122
|
+
assert.throws(() => decodePCM(Buffer.alloc(0)), /unreadable audio/);
|
|
123
|
+
assert.equal(elevenSpeed(0.42), 0.7);
|
|
124
|
+
assert.equal(elevenSpeed(2.56), 1.2);
|
|
125
|
+
assert.equal(elevenSpeed(1), 1);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('ElevenLabs keeps the saved voice settings at normal speed', async (t) => {
|
|
129
|
+
const p = project(t);
|
|
130
|
+
p.config.speed = 1;
|
|
131
|
+
p.config.pace = 1;
|
|
132
|
+
mockAPI(t, async (url, opts) => {
|
|
133
|
+
assert.equal(JSON.parse(opts.body).voice_settings, undefined);
|
|
134
|
+
return new Response(Buffer.alloc(2));
|
|
135
|
+
});
|
|
136
|
+
await elevenSpeech(p, 'first', 'Hello.');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('ElevenLabs omits unsupported continuity for v3 and reports unreadable downloads safely', async (t) => {
|
|
140
|
+
const p = project(t, { provider: 'elevenlabs', id: 'test-voice', model: 'eleven_v3' });
|
|
141
|
+
mockAPI(t, async (url, opts) => {
|
|
142
|
+
const body = JSON.parse(opts.body);
|
|
143
|
+
assert.equal(body.model_id, 'eleven_v3');
|
|
144
|
+
assert.equal(body.previous_text, undefined);
|
|
145
|
+
assert.equal(body.next_text, undefined);
|
|
146
|
+
return new Response(Buffer.alloc(2));
|
|
147
|
+
});
|
|
148
|
+
await elevenSpeech(p, 'first', 'Hello.', { previous: 'Before.', next: 'After.' });
|
|
149
|
+
globalThis.fetch = async () => ({ ok: true, arrayBuffer: async () => { throw new Error('secret-test-key'); } });
|
|
150
|
+
await assert.rejects(() => elevenSpeech(p, 'first', 'Hello.'), (e) => {
|
|
151
|
+
assert.match(e.message, /download failed/);
|
|
152
|
+
assert.ok(!e.message.includes('secret-test-key'));
|
|
153
|
+
return true;
|
|
154
|
+
});
|
|
155
|
+
assert.equal(elevenUsage(p).length, 2);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('ElevenLabs gives friendly errors without echoing the key or server body', async (t) => {
|
|
159
|
+
const p = project(t);
|
|
160
|
+
mockAPI(t, async () => { throw new Error('secret-test-key'); });
|
|
161
|
+
const error = async (pattern) => assert.rejects(() => elevenSpeech(p, 'first', 'Hello.'), (e) => {
|
|
162
|
+
assert.match(e.message, pattern);
|
|
163
|
+
assert.ok(!e.message.includes('secret-test-key'));
|
|
164
|
+
return true;
|
|
165
|
+
});
|
|
166
|
+
await error(/connection/);
|
|
167
|
+
for (const [http, status, pattern] of [[401, 'invalid_api_key', /rejected/], [403, '', /permissions/],
|
|
168
|
+
[404, 'voice_not_found', /voice id/], [400, 'voice_not_found', /voice id/], [401, 'quota_exceeded', /no characters/],
|
|
169
|
+
[402, '', /no characters/], [422, '', /voice.model/]]) {
|
|
170
|
+
globalThis.fetch = async () => new Response(JSON.stringify({ detail: { status, message: 'secret-test-key' } }), { status: http });
|
|
171
|
+
await error(pattern);
|
|
172
|
+
}
|
|
173
|
+
assert.deepEqual(elevenUsage(p), []);
|
|
174
|
+
process.env.ELEVENLABS_API_KEY = '';
|
|
175
|
+
await error(/Ask the user.*elevenlabs.io.*\.env/);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('ElevenLabs retries 429 and server failures, but stops after three attempts', async (t) => {
|
|
179
|
+
const p = project(t);
|
|
180
|
+
let calls = 0;
|
|
181
|
+
mockAPI(t, async () => {
|
|
182
|
+
calls++;
|
|
183
|
+
return calls < 3 ? new Response('{}', { status: calls === 1 ? 429 : 503 }) : new Response(Buffer.alloc(2));
|
|
184
|
+
});
|
|
185
|
+
await elevenSpeech(p, 'first', 'Hello.');
|
|
186
|
+
assert.equal(calls, 3);
|
|
187
|
+
assert.equal(elevenUsage(p).length, 1);
|
|
188
|
+
calls = 0;
|
|
189
|
+
globalThis.fetch = async () => { calls++; return new Response('secret-test-key', { status: 500 }); };
|
|
190
|
+
await assert.rejects(() => elevenSpeech(p, 'first', 'Hello.'), /busy/);
|
|
191
|
+
assert.equal(calls, 3);
|
|
192
|
+
assert.equal(elevenUsage(p).length, 1);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('ElevenLabs voice list paginates and CLI prints names, ids and labels with JSON support', async (t) => {
|
|
196
|
+
const dir = temp(t);
|
|
197
|
+
let calls = 0;
|
|
198
|
+
mockAPI(t, async (url) => {
|
|
199
|
+
calls++;
|
|
200
|
+
assert.equal(url.pathname, '/v2/voices');
|
|
201
|
+
assert.equal(url.searchParams.get('page_size'), '100');
|
|
202
|
+
const page2 = url.searchParams.has('next_page_token');
|
|
203
|
+
if (page2) assert.equal(url.searchParams.get('next_page_token'), 'next');
|
|
204
|
+
return Response.json({ voices: [{ name: page2 ? 'Bob' : 'Alice', voice_id: page2 ? 'b' : 'a', labels: { accent: 'American' } }], has_more: !page2, next_page_token: page2 ? null : 'next' });
|
|
205
|
+
});
|
|
206
|
+
assert.deepEqual(await elevenVoices(dir), [{ name: 'Alice', id: 'a', labels: { accent: 'American' } }, { name: 'Bob', id: 'b', labels: { accent: 'American' } }]);
|
|
207
|
+
assert.equal(calls, 2);
|
|
208
|
+
let output = '';
|
|
209
|
+
t.mock.method(process.stdout, 'write', (s) => { output += s; return true; });
|
|
210
|
+
assert.equal(await main(['voices', '--elevenlabs', dir, '--json']), 0);
|
|
211
|
+
assert.equal(JSON.parse(output).voices[1].id, 'b');
|
|
212
|
+
output = '';
|
|
213
|
+
assert.equal(await main(['voices', dir, '--elevenlabs']), 0);
|
|
214
|
+
assert.match(output, /Alice a accent: American/);
|
|
215
|
+
output = '';
|
|
216
|
+
await main(['voices']);
|
|
217
|
+
assert.match(output, /af_heart/);
|
|
218
|
+
assert.match(output, /voices --elevenlabs.*recording/);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('cached CLI voice output reports recording mismatches and ElevenLabs speed limits', async (t) => {
|
|
222
|
+
const p = project(t, { provider: 'recording', src: 'assets/take.wav' });
|
|
223
|
+
writeWav(path.join(p.dir, 'assets/take.wav'), new Float32Array(24000), 24000);
|
|
224
|
+
const recordings = recordingFiles(p);
|
|
225
|
+
fs.mkdirSync(p.paths.voice, { recursive: true });
|
|
226
|
+
const cache = (recording) => {
|
|
227
|
+
for (const scene of p.script.scenes) {
|
|
228
|
+
const chunks = speechChunks(scene.units, p.config);
|
|
229
|
+
const hash = sceneHash(scene, chunks, p.config, recording && chunks.length
|
|
230
|
+
? { content: recordings.files[scene.id].hash, scenes: p.script.scenes.map((s) => s.spoken) } : null);
|
|
231
|
+
const info = { hash, id: scene.id, duration: chunks.length ? 1 : 0, words: [], marks: {}, chunks: [], transcript: 'Different words.', matchRate: chunks.length ? 0 : 1, unmatched: chunks.length ? [scene.spoken] : [] };
|
|
232
|
+
fs.writeFileSync(path.join(p.paths.voice, scene.id + '.json'), JSON.stringify(info));
|
|
233
|
+
if (chunks.length) writeWav(path.join(p.paths.voice, scene.id + '.wav'), new Float32Array(24000), 24000);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
cache(true);
|
|
237
|
+
let output = '';
|
|
238
|
+
t.mock.method(process.stdout, 'write', (s) => { output += s; return true; });
|
|
239
|
+
assert.equal(await main(['voice', p.dir, '--json']), 0);
|
|
240
|
+
assert.match(JSON.parse(output).scenes[0].message, /recording does not match.*actually said/);
|
|
241
|
+
fs.writeFileSync(path.join(p.dir, 'video.json'), JSON.stringify({ voice: { provider: 'elevenlabs', id: 'v' }, pace: 1.3 }));
|
|
242
|
+
p.config = loadProject(p.dir).config;
|
|
243
|
+
cache(false);
|
|
244
|
+
output = '';
|
|
245
|
+
assert.equal(await main(['voice', p.dir, '--json']), 0);
|
|
246
|
+
assert.equal(JSON.parse(output).speed, 1.2);
|
|
247
|
+
assert.equal(JSON.parse(output).requested_speed, 1.3);
|
|
248
|
+
assert.equal(JSON.parse(output).characters, 0);
|
|
249
|
+
output = '';
|
|
250
|
+
assert.equal(await main(['voice', p.dir]), 0);
|
|
251
|
+
assert.equal((output.match(/outside 0.7 to 1.2/g) || []).length, 1);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('single-take cuts retain internal pauses and margins, skip silent scenes and avoid overlap', () => {
|
|
255
|
+
const scenes = parseScript('## first\n[#hello] Hello [pause 9] {world|world}.\n## silent\n## second\nGoodbye now.').scenes;
|
|
256
|
+
const heard = [{ text: 'Hello', start: 1, end: 1.5 }, { text: 'world', start: 3, end: 3.5 },
|
|
257
|
+
{ text: 'Goodbye', start: 5, end: 5.5 }, { text: 'now', start: 6, end: 6.5 }];
|
|
258
|
+
const cuts = recordingCuts(scenes, heard, 8);
|
|
259
|
+
assert.equal(cuts.length, 2);
|
|
260
|
+
assert.equal(cuts[0].scene.id, 'first');
|
|
261
|
+
assert.equal(cuts[0].start, 0.85);
|
|
262
|
+
assert.equal(cuts[0].end, 3.65);
|
|
263
|
+
assert.deepEqual(cuts[0].words, [{ start: 1, end: 1.5, matched: true }, { start: 3, end: 3.5, matched: true }]);
|
|
264
|
+
assert.equal(cuts[1].start, 4.85);
|
|
265
|
+
assert.equal(cuts[1].end, 6.65);
|
|
266
|
+
heard[2].start = 3.6;
|
|
267
|
+
const close = recordingCuts(scenes, heard, 6.5);
|
|
268
|
+
assert.equal(close[0].end, 3.55);
|
|
269
|
+
assert.equal(close[1].start, 3.55);
|
|
270
|
+
assert.equal(close[1].end, 6.5);
|
|
271
|
+
assert.deepEqual(recordingCuts(scenes.filter((s) => s.id === 'silent'), [], 8), []);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test('recording folders report all missing scenes, validate files and stay inside assets', (t) => {
|
|
275
|
+
const p = project(t, { provider: 'recording', src: 'assets/narration/' });
|
|
276
|
+
const folder = path.join(p.dir, 'assets/narration');
|
|
277
|
+
fs.mkdirSync(folder);
|
|
278
|
+
assert.throws(() => recordingFiles(p), /missing scene recordings.*first, second/);
|
|
279
|
+
fs.writeFileSync(path.join(folder, 'first.mp3'), 'first');
|
|
280
|
+
fs.writeFileSync(path.join(folder, 'second.M4A'), 'second');
|
|
281
|
+
const files = recordingFiles(p);
|
|
282
|
+
assert.equal(files.folder, true);
|
|
283
|
+
assert.deepEqual(Object.keys(files.files), ['first', 'second']);
|
|
284
|
+
fs.writeFileSync(path.join(folder, 'first.mp3'), 'replaced');
|
|
285
|
+
const changed = recordingFiles(p);
|
|
286
|
+
assert.notEqual(changed.files.first.hash, files.files.first.hash);
|
|
287
|
+
assert.equal(changed.files.second.hash, files.files.second.hash);
|
|
288
|
+
fs.rmSync(path.join(folder, 'first.mp3'));
|
|
289
|
+
const outside = path.join(temp(t), 'outside.wav');
|
|
290
|
+
fs.writeFileSync(outside, 'outside');
|
|
291
|
+
fs.symlinkSync(outside, path.join(folder, 'first.wav'));
|
|
292
|
+
assert.throws(() => recordingFiles(p), /including symlinks/);
|
|
293
|
+
p.config.voice.src = 'assets/no.wav';
|
|
294
|
+
assert.throws(() => recordingFiles(p), /missing/);
|
|
295
|
+
p.config.voice.src = 'assets/bad.txt';
|
|
296
|
+
fs.writeFileSync(path.join(p.dir, 'assets/bad.txt'), 'not audio');
|
|
297
|
+
assert.throws(() => recordingFiles(p), /wav, mp3/);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test('scene cache includes audio settings and recording contents, ignores recording gaps', () => {
|
|
301
|
+
const scene = parseScript('## first\n[#a] Hello. Goodbye.').scenes[0];
|
|
302
|
+
const cfg = normalizeConfig({});
|
|
303
|
+
const chunks = speechChunks(scene.units);
|
|
304
|
+
const hash = sceneHash(scene, chunks, cfg);
|
|
305
|
+
assert.notEqual(hash, sceneHash(scene, chunks, { ...cfg, voice: 'am_michael' }));
|
|
306
|
+
assert.notEqual(hash, sceneHash(scene, chunks, { ...cfg, speed: 1 }));
|
|
307
|
+
const eleven = normalizeConfig({ voice: { provider: 'elevenlabs', id: 'v' } });
|
|
308
|
+
assert.notEqual(sceneHash(scene, chunks, eleven), sceneHash(scene, chunks, { ...eleven, voice: { ...eleven.voice, model: 'another' } }));
|
|
309
|
+
const recording = normalizeConfig({ voice: { provider: 'recording', src: 'assets/take.wav' } });
|
|
310
|
+
const recHash = sceneHash(scene, chunks, recording, { content: 'abc' });
|
|
311
|
+
assert.notEqual(recHash, sceneHash(scene, chunks, recording, { content: 'def' }));
|
|
312
|
+
assert.equal(recHash, sceneHash(scene, speechChunks(scene.units, { sentenceGap: 9 }), recording, { content: 'abc' }));
|
|
313
|
+
assert.notEqual(recHash, sceneHash(scene, chunks, { ...recording, pace: 1.2 }, { content: 'abc' }));
|
|
314
|
+
const paused = parseScript('## first\n[#a] Hello. [pause 9] Goodbye.').scenes[0];
|
|
315
|
+
assert.equal(recHash, sceneHash(paused, speechChunks(paused.units), recording, { content: 'abc' }));
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test('recordings preserve sample rate up to 48 kHz, apply tempo and normalize loudness', async (t) => {
|
|
319
|
+
const dir = temp(t);
|
|
320
|
+
const file = path.join(dir, 'tone.wav');
|
|
321
|
+
const sr = 24000;
|
|
322
|
+
const samples = Float32Array.from({ length: sr * 4 }, (_, i) => 0.02 * Math.sin(2 * Math.PI * 440 * i / sr));
|
|
323
|
+
writeWav(file, samples, sr);
|
|
324
|
+
const decoded = await decodeRecording(file, dir, 1.25);
|
|
325
|
+
assert.equal(decoded.sampleRate, sr);
|
|
326
|
+
assert.ok(Math.abs(decoded.samples.length / sr - 3.2) < 0.05);
|
|
327
|
+
const out = path.join(dir, 'out.wav');
|
|
328
|
+
await saveRecording(out, decoded.samples, decoded.sampleRate);
|
|
329
|
+
assert.equal(readWav(out).sampleRate, sr);
|
|
330
|
+
assert.ok(Math.abs((await loudness(out)).integrated - -22.3) < 0.5);
|
|
331
|
+
const high = path.join(dir, 'high.wav');
|
|
332
|
+
writeWav(high, new Float32Array(96000), 96000);
|
|
333
|
+
assert.equal((await decodeRecording(high, dir, 1)).sampleRate, 48000);
|
|
334
|
+
const silent = path.join(dir, 'silent.wav');
|
|
335
|
+
await saveRecording(silent, new Float32Array(sr), sr);
|
|
336
|
+
assert.equal(readWav(silent).samples.length, sr);
|
|
337
|
+
assert.deepEqual(fs.readdirSync(dir).filter((n) => n.startsWith('recording-')), []);
|
|
338
|
+
});
|