Download runtimes/python/frontend_cli.mjs from KaleComputer/kale-tts-1-tiny: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/KaleComputer/kale-tts-1-tiny/resolve/main/runtimes/python/frontend_cli.mjs
- Command line
-
hf download hf://KaleComputer/kale-tts-1-tiny/runtimes/python/frontend_cli.mjs
-
curl -L -o frontend_cli.mjs https://huggingface.co/KaleComputer/kale-tts-1-tiny/resolve/main/runtimes/python/frontend_cli.mjs
1.29 kB
| // the release text front end (js/kale-tts.mjs -> frontend/) as a line-in/line-out helper for non-JS runtimes. | |
| // stdin: one JSON per line {"text": "...", "accent": "en-us"}; stdout: one JSON per line {"sentences": [{"text", "ipa", "ids"}]} | |
| // ids are Kokoro-table ids (tokenizer.json) without the 0 pads. needs only node >= 18, no npm packages. | |
| import { createInterface } from "node:readline"; import { readFileSync } from "node:fs"; | |
| const RD = new URL("../../", import.meta.url).pathname; | |
| const { KaleTTS } = await import(RD + "js/kale-tts.mjs"); | |
| const vocab = JSON.parse(readFileSync(RD + "models/kale-tts-1-nano/tokenizer.json", "utf8")).model.vocab; | |
| const fe = Object.assign(Object.create(KaleTTS.prototype), { feBase: RD + "frontend/", _fe: {} }); | |
| for await (const line of createInterface({ input: process.stdin })) { | |
| if (!line.trim()) continue; | |
| try { | |
| const { text, accent = "en-us" } = JSON.parse(line); const f = await fe._frontEnd(accent); | |
| const sentences = f.sentences(text).map((s) => { const ipa = f.ipa(s); return { text: s, ipa, ids: [...ipa].map((c) => vocab[c]).filter((x) => x !== undefined) }; }); | |
| process.stdout.write(JSON.stringify({ sentences }) + "\n"); | |
| } catch (e) { process.stdout.write(JSON.stringify({ error: String(e?.message ?? e) }) + "\n"); } | |
| } | |