talking-pixel / scripts /build-kernel.mjs
cfahlgren1's picture
cfahlgren1 HF Staff
convert talking pixel to a sveltekit app that runs pivo-1.4m tts in the browser
3ec6b9e
Raw History Blame Contribute Delete
684 Bytes
// Compile kernel/matvec.wat to a base64 module embedded in src/lib/kernel-wasm.ts.
import { readFileSync, writeFileSync } from 'node:fs';
import wabtInit from 'wabt';
const wabt = await wabtInit();
const src = readFileSync(new URL('../kernel/matvec.wat', import.meta.url), 'utf8');
const mod = wabt.parseWat('matvec.wat', src, { simd: true });
const { buffer } = mod.toBinary({});
const b64 = Buffer.from(buffer).toString('base64');
writeFileSync(new URL('../src/lib/kernel-wasm.ts', import.meta.url),
`// Generated by tools/build_kernel.mjs from kernel/matvec.wat. Do not edit.\nexport const MATVEC_WASM_BASE64 = '${b64}';\n`);
console.log('matvec.wasm', buffer.length, 'bytes');