NERDDISCO's picture
kale-tts-1
f21d6eb
Raw History Blame Contribute Delete
1.85 kB
// onnxruntime-node + our JS API (release-draft/js/kale-tts.mjs): text in -> WAV, then the shared bench. usage: node test.mjs <nano|tiny> [threads] [voice: name or id, default kenzie]
import { writeFileSync, mkdirSync } from "node:fs";
const RD = new URL("../../", import.meta.url).pathname, [, , size = "nano", threads = "4", voice = "kenzie"] = process.argv;
// ---- snippet ----------------------------------------------------------------------------------------------------------------
import * as ort from "onnxruntime-node";
const { KaleTTS, toWav } = await import(RD + "js/kale-tts.mjs");
const t0 = performance.now();
const tts = await KaleTTS.load(`kale-tts-1-${size}`, { ort, threads: Number(threads) });
const load_s = (performance.now() - t0) / 1000;
const { audio, sampleRate } = await tts.speak("A volcano is a place where very hot, melted rock comes up out of the ground. Most volcanoes are hidden under the sea!", { voice });
mkdirSync("out", { recursive: true }); writeFileSync(`out/${size}.wav`, toWav(audio, sampleRate));
// -----------------------------------------------------------------------------------------------------------------------------
if (tts.ettinTok) { console.log(JSON.stringify({ runtime: "onnxruntime-node", model: `kale-tts-1-${size}`, voice, text_audio_s: +(audio.length / 24000).toFixed(2), bench: "ids-only bench lines are for nano (tiny also needs Ettin word inputs per sentence)" })); process.exit(0); }
const { bench } = await import(RD + "runtimes/_bench/bench.mjs"); const v = await tts._loadVoice(voice);
console.log(JSON.stringify({ runtime: "onnxruntime-node", model: `kale-tts-1-${size}`, ort_node: ort.env.versions.node, node: process.version, threads: +threads,
load_s: +load_s.toFixed(2), text_audio_s: +(audio.length / 24000).toFixed(2), ...(await bench((ids) => tts._render(v, ids))) }));