Download recipe/textside/check_items.mjs from KaleComputer/kale-tts-1-tiny: direct link, hf CLI and curl.
- Browser
- Download file 2.76 kB
-
https://huggingface.co/KaleComputer/kale-tts-1-tiny/resolve/main/recipe/textside/check_items.mjs
- Command line
-
hf download hf://KaleComputer/kale-tts-1-tiny/recipe/textside/check_items.mjs
-
curl -L -o check_items.mjs https://huggingface.co/KaleComputer/kale-tts-1-tiny/resolve/main/recipe/textside/check_items.mjs
2.76 kB
| // SPDX-License-Identifier: Apache-2.0 | |
| // Copyright 2026 Kale | |
| // check_items.mjs: [{id, text}] -> per sentence the sound ids + the Ettin text side's inputs (ettin_ids, W, S, wavg, widx), through the | |
| // RELEASE front end (en-us; en-gb for d03 / d13) exactly as ../../js/kale-tts.mjs feeds them at run time. The export check reads them: | |
| // CHECK_ETTIN=<en-us out.json>,<en-gb out.json> python3 ../export/export_check.py <model.onnx> <reference.onnx> <model dir> --json out.json | |
| // usage: node check_items.mjs <en-us|en-gb> <out.json> <in.json [{id,text}]> [ettin-tokenizer.json] | |
| import { readFileSync, writeFileSync } from "node:fs"; | |
| const RD = new URL("../../", import.meta.url).pathname; // the release folder: frontend/, models/ | |
| const { G2p, G2pModel, normalizer, readTable, sentences } = await import(RD + "frontend/words/kaleTts.js"); | |
| const { EttinTokenizer, ettinInputs, wordIndex } = await import(RD + "frontend/ettin.js"); | |
| const { loadEnGB } = await import(RD + "frontend/release-loader.mjs"); | |
| const accent = process.argv[2], out = process.argv[3], inp = process.argv[4]; | |
| let fe; | |
| if (accent === "en-gb") fe = await loadEnGB(RD + "frontend/"); | |
| else { | |
| const M = RD + "frontend/words/"; const lex = readTable(readFileSync(M + "lexicon.tsv", "utf8")); readTable(readFileSync(M + "override.public.tsv", "utf8"), lex); | |
| const b = readFileSync(M + "g2p.bin"); const g2p = new G2p(lex, new G2pModel(b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength))); | |
| const { termsReplacer } = await import(RD + "frontend/terms.ts"); const terms = termsReplacer(readFileSync(M + "terms.tsv", "utf8")), norm = normalizer(lex); | |
| fe = { sentences: (t) => sentences(t, (x) => norm(terms(x))), ipa: (s) => g2p.phonemes(s) }; | |
| } | |
| const vocab = JSON.parse(readFileSync(RD + "models/kale-tts-1-tiny/tokenizer.json", "utf8")).model.vocab; vocab["ɒ"] ??= 71; | |
| const ids = (ipa) => [...ipa].map((c) => vocab[c]).filter((x) => x !== undefined); | |
| const tok = new EttinTokenizer(JSON.parse(readFileSync(process.argv[5] || (RD + "models/kale-tts-1-tiny/ettin-tokenizer.json"), "utf8"))); | |
| const line = (text) => { | |
| let prev = ""; const res = []; | |
| for (const s of fe.sentences(text)) { | |
| const a = ids(fe.ipa(s)); if (!a.length) continue; | |
| const words = s.split(/\s+/).filter(Boolean), per = words.map((w) => ids(fe.ipa(w))), e = ettinInputs(tok, s, prev); | |
| res.push({ ids: a, ettin_ids: e.ettin_ids, W: e.W, S: e.S, wavg: Array.from(e.wavg), widx: wordIndex(a, per, words.length) }); prev = s; | |
| } | |
| return res; | |
| }; | |
| const items = JSON.parse(readFileSync(inp, "utf8")); | |
| const R = items.map((b) => ({ id: b.id, sents: line(b.text) })); | |
| writeFileSync(out, JSON.stringify(R)); console.log(accent, R.length, "items", R.reduce((n, b) => n + b.sents.length, 0), "sentences"); | |