Skip to content

Text to vertical video in 100+ styles: AI codes each scene (HTML/SVG/WebGL), renders a 9:16 MP4 with music and English/Vietnamese voice. MCP, CLI and REST for AI agents.

1.6 KB
Raw Blame
#!/usr/bin/env node
// Sinh file nghe thử: engine/audio/samples/sfx-all.wav (mọi sfx nối nhau, cách 0,5s) + sfx-all.txt (mốc từng tiếng)
// và music-<style>.wav (8s mỗi kiểu).   node engine/audio/samples.mjs [--seed 1]
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { SFX_LIST, synthSfx } from './sfx.mjs';
import { MUSIC_STYLES, writeMusic } from './music.mjs';
import { writeWav, mixInto, ns, SR, peak } from './dsp.mjs';

const OUT = path.join(path.dirname(fileURLToPath(import.meta.url)), 'samples');
fs.mkdirSync(OUT, { recursive: true });
const seed = Number(process.argv[process.argv.indexOf('--seed') + 1]) || 1;

const clips = SFX_LIST.map((s) => ({ ...s, buf: synthSfx(s.name) }));
const total = clips.reduce((a, c) => a + c.buf[0].length / SR + 0.5, 0.5);
const L = new Float32Array(ns(total)), R = new Float32Array(ns(total));
let t = 0.5; const idx = [];
for (const c of clips) {
  mixInto(L, c.buf[0], t, 0.7); mixInto(R, c.buf[1], t, 0.7); // −3 dB: chừa chỗ cho đỉnh giữa mẫu (true peak)
  idx.push(`${t.toFixed(2).padStart(6)}s  ${c.name.padEnd(15)} ${c.desc}`);
  t += c.buf[0].length / SR + 0.5;
}
writeWav(path.join(OUT, 'sfx-all.wav'), [L, R]);
fs.writeFileSync(path.join(OUT, 'sfx-all.txt'), idx.join('\n') + '\n');
console.log(`sfx-all.wav  ${clips.length} tiếng, ${total.toFixed(1)}s, đỉnh ${(20 * Math.log10(peak(L, R))).toFixed(1)} dBFS`);
for (const s of MUSIC_STYLES) { writeMusic(s, path.join(OUT, `music-${s}.wav`), 8, seed); console.log(`music-${s}.wav`); }
console.log('→ ' + OUT);