Views
No views yet
onnxruntime-web and on mobile via
onnxruntime-react-native. Built for iAny,
where it reads Khmer news aloud in the Radio feature.| File | What |
|---|---|
khmer_tts_v3.onnx | The voice to use. Tuned export: length_scale 1.15 (a touch slower/clearer), noise_scale 0.5, noise_scale_w 0.6 (less timing jitter). These are baked into the graph. |
tts_meta.json | Grapheme vocabulary + inference metadata (see below). |
config.json | Coqui-TTS training/model config. |
best_model.pth | PyTorch checkpoint (for re-export / continued training). |
khmer_tts*.onnx (others) | Earlier / alternate-speed exports, kept for comparison. |
tts_meta.json fields:1{
2 "vocab": ["…"], // grapheme -> id is the index into this array
3 "add_blank": true, // interleave the blank token between graphemes
4 "blank": "@", // the blank symbol
5 "sample_rate": 22050
6}x = int64[1, T] (grapheme ids), x_lengths = int64[1] (= T)y = float32 waveform, mono, 22050 Hzvocab; if add_blank is
true, start with the blank id and put a blank id between every grapheme.1import json, numpy as np, onnxruntime as ort, soundfile as sf
2
3meta = json.load(open("tts_meta.json"))
4id_of = {c: i for i, c in enumerate(meta["vocab"])}
5blank = id_of[meta["blank"]]
6
7def to_ids(text):
8 ids = [id_of[c] for c in text if c in id_of]
9 if meta["add_blank"]:
10 out = [blank]
11 for i in ids: out += [i, blank]
12 return out
13 return ids
14
15sess = ort.InferenceSession("khmer_tts_v3.onnx")
16ids = np.array([to_ids("សួស្ដី ពិភពលោក")], dtype=np.int64)
17xlen = np.array([ids.shape[1]], dtype=np.int64)
18y = sess.run(None, {"x": ids, "x_lengths": xlen})[0]
19sf.write("out.wav", np.asarray(y).squeeze(), meta["sample_rate"])