Explainer videos and product demos made by your AI agent. Free and open source: a local voice (Kokoro), word timing (Whisper) and a canvas renderer turn a script into a narrated MP4.
JavaScript ai-agentsanimationcanvasclaude-codecodexexplainer-videoffmpegjavascriptkokoroproduct-demotext-to-speechvideo-generationwhisper
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
import { fileURLToPath } from 'node:url';
import { findChrome } from '../src/browser.js';
import { capture } from '../src/capture.js';
import { normalizeConfig } from '../src/project.js';
import { captureFixture } from './capture-fixture.js';
let chrome;
try { chrome = findChrome(); } catch {}
const bin = fileURLToPath(new URL('../bin/explainroo.js', import.meta.url));
const run = promisify(execFile);
const dimensions = (file) => {
const png = fs.readFileSync(file);
return [png.readUInt32BE(16), png.readUInt32BE(20)];
};
test('capture saves a local site, its loaded fonts and desktop and phone screenshots', { skip: !chrome }, async () => {
const site = await captureFixture();
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-capture-'));
try {
const config = '{"title":"Existing project"}\n';
fs.writeFileSync(path.join(dir, 'video.json'), config);
fs.mkdirSync(path.join(dir, 'assets'));
fs.writeFileSync(path.join(dir, 'assets', 'keep.txt'), 'Keep this file');
const result = await capture(dir, `${site.url}/redirect`, { mobile: true, googleHostCheck: (host) => host === '127.0.0.1' });
const root = path.join(dir, 'assets/capture/127.0.0.1');
assert.deepEqual(JSON.parse(fs.readFileSync(path.join(root, 'capture.json'))), result);
assert.equal(result.url, `${site.url}/`);
assert.equal(result.title, 'Fixture Studio');
assert.equal(result.description, 'A local page for capture tests.');
assert.equal(result.themeColor, '#245cff');
assert.equal(result.colors.accent, '#245cff');
assert.equal(result.colors.background, '#f8f6f1');
assert.equal(result.colors.text, '#202020');
assert.equal(result.colors.heading, '#163469');
assert.equal(result.colors.link, '#245cff');
assert.ok(result.colors.other.length <= 6);
assert.equal(result.fonts.body, 'Fixture Sans');
assert.deepEqual(result.fonts.headings, ['Fixture Sans']);
assert.deepEqual(result.fonts.buttons, ['Fixture Sans']);
assert.equal(result.suggestion.fonts.length, 1);
assert.equal(result.suggestion.fonts[0].weight, 400);
assert.equal(site.requests.includes('/unused.woff2'), false);
assert.deepEqual(fs.readFileSync(path.join(dir, result.suggestion.fonts[0].src)), fs.readFileSync(path.join(site.dir, 'fixture.woff2')));
assert.deepEqual(result.text.h1, ['Build a clear product demo']);
assert.deepEqual(result.text.h2, ['Your brand on every screen', 'Capture once, use the files']);
assert.deepEqual(result.text.navigation, ['Features', 'Plans']);
assert.deepEqual(result.text.buttons, ['Start a project', 'See examples', 'Create project']);
assert.deepEqual(result.text.labels, ['Project name']);
assert.deepEqual(result.text.placeholders, ['My first demo']);
assert.equal(result.brand.logo, 'assets/capture/127.0.0.1/logo.svg');
assert.equal(result.logo.picked, result.brand.logo);
assert.deepEqual(result.logo.candidates.map((c) => path.basename(c.file)), ['logo.svg', 'logo-2.svg', 'logo-3.png']);
assert.match(fs.readFileSync(path.join(root, 'logo.svg'), 'utf8'), /xmlns="http:\/\/www.w3.org\/2000\/svg"/);
assert.match(fs.readFileSync(path.join(root, 'logo.svg'), 'utf8'), /fill: rgb\(36, 92, 255\)/);
assert.doesNotMatch(fs.readFileSync(path.join(root, 'logo.svg'), 'utf8'), /currentColor/i);
assert.deepEqual(dimensions(path.join(root, 'page.png')), [2880, 1800]);
assert.deepEqual(dimensions(path.join(root, 'full.png')), [2880, 16000]);
assert.deepEqual(dimensions(path.join(root, 'mobile.png')), [780, 1688]);
assert.deepEqual(dimensions(path.join(root, 'mobile-full.png')), [780, 16000]);
assert.ok(result.files.every((file) => fs.existsSync(path.join(dir, file))));
assert.deepEqual(normalizeConfig(result.suggestion).brand, result.brand);
assert.equal(fs.readFileSync(path.join(dir, 'video.json'), 'utf8'), config);
assert.equal(fs.readFileSync(path.join(dir, 'assets', 'keep.txt'), 'utf8'), 'Keep this file');
await assert.rejects(capture(dir, `${site.url}/missing`), /page did not load/);
assert.ok(fs.existsSync(path.join(root, 'mobile.png')));
fs.writeFileSync(path.join(root, 'stale.txt'), 'old capture');
const cli = await run(process.execPath, [bin, 'capture', dir, site.url, '--json'], { timeout: 60000 });
const json = JSON.parse(cli.stdout);
assert.equal(json.colors.accent, '#245cff');
assert.equal(json.suggestion.fonts.length, 0);
assert.match(json.notes.join(' '), /Fixture Sans: get the font files and check the license/);
assert.equal(fs.existsSync(path.join(root, 'stale.txt')), false);
assert.equal(fs.existsSync(path.join(root, 'mobile.png')), false);
const human = await run(process.execPath, [bin, 'capture', '--mobile', site.url], { cwd: dir, timeout: 60000 });
assert.match(human.stdout, /accent: #245cff/);
assert.match(human.stdout, /logo: assets\/capture\/127.0.0.1\/logo.svg/);
assert.match(human.stdout, /Paste into video.json:/);
assert.ok(fs.existsSync(path.join(root, 'mobile.png')));
} finally {
await site.close();
fs.rmSync(dir, { recursive: true, force: true });
}
});