Web demo: fast 2-step model only
Browse filesFiles changed (4)
- README.md+1-1
- web/app.js+7-12
- web/index.html+2-8
- web/tts.js+2-2
65 unmodified lines6667686970717265 unmodified lines- `voice`: a voice id (`tra-da-nu`, `tra-da-nu-am`, `tra-da-nam`, `tra-da-nam-tram`, `review-phim-nam`, `ke-chuyen-nam`, `ban-tin-nu`, `game-nam`, `ban-hang-nu`), a path to a reference recording, or a 192-d speaker embedding.- `cfg_weight`: text guidance. Higher is clearer; lower is looser and more natural, but makes more mistakes.- `steps`: flow-matching steps. 8 is faster and slightly rougher.- `fast=True`: use the 2-step distilled flow (`trada-tts-10m-2step.safetensors`, `onnx/cfm2.onnx`). Text guidance is built in, so `cfg_weight` is ignored. Quality is close to 16 steps (see Evaluation). The web demo uses it by default.- Long text is split into sentences automatically.- `min_syllable_ms` (default 160): every syllable lasts at least this long. Without it the model sometimes rushes long numbers until syllables get swallowed. On number-heavy text, word errors drop from 10.0% to 6.0%, while ordinary text stays the same and only 2% slower. Set it to 0 to disable.65 unmodified lines6667686970717265 unmodified lines- `voice`: a voice id (`tra-da-nu`, `tra-da-nu-am`, `tra-da-nam`, `tra-da-nam-tram`, `review-phim-nam`, `ke-chuyen-nam`, `ban-tin-nu`, `game-nam`, `ban-hang-nu`), a path to a reference recording, or a 192-d speaker embedding.- `cfg_weight`: text guidance. Higher is clearer; lower is looser and more natural, but makes more mistakes.- `steps`: flow-matching steps. 8 is faster and slightly rougher.- `fast=True`: use the 2-step distilled flow (`trada-tts-10m-2step.safetensors`, `onnx/cfm2.onnx`). Text guidance is built in, so `cfg_weight` is ignored. Quality is close to 16 steps (see Evaluation). The web demo always uses it.- Long text is split into sentences automatically.- `min_syllable_ms` (default 160): every syllable lasts at least this long. Without it the model sometimes rushes long numbers until syllables get swallowed. On number-heavy text, word errors drop from 10.0% to 6.0%, while ordinary text stays the same and only 2% slower. Set it to 0 to disable.
123456710 unmodified lines18192021222324320 unmodified lines34534634734834935035135235328 unmodified lines382383384385386387388389390391392393394import * as ort from './ort/ort.webgpu.min.mjs';import { TradaTTS, normalize, normalizePart, JOIN, isAlnum } from './tts.js?v=11220100';import { resample, kaldiFbank } from './audio.js?v=11220100';const VER = '11220100';// model repo root (config.json, onnx/, voices/): the page's parent folder, or window.TRADA_ROOT (e.g. a Hugging Face resolve URL)const ROOT = (window.TRADA_ROOT || new URL('..', import.meta.url).href).replace(/\/$/, '');10 unmodified lines['Kể chuyện', 'Chiều hôm ấy, mưa rơi lất phất trên con phố nhỏ. Bà cụ bán trà đá vẫn ngồi đó, rót cho khách quen một cốc, rồi kể chuyện ngày xưa.'],];const STORE = 'trada-tts.voices.v1', THEME = 'trada-tts.theme';const S = { tts: null, camp: null, presets: [], saved: [], sel: null, backend: 'wasm', take: null, takes: [], pending: null, selG: -1, stopAt: null, fast: true };// ---------------- iSTFT on WebGPU (WGSL; validated against torch.istft) ----------------const N = 1920, H = 480, FB = 961, MT = 2048;320 unmodified lines// ---------------- generate ----------------async function generate({ replace = false, autoplay = true } = {}) {const text = $('text').value.trim(); if (!text || !S.tts || $('go').disabled) return;const fast = S.fast && S.tts.hasFast;const v = current(), opts = { w: +$('w').value, steps: +$('steps').value, speed: +$('speed').value, seed: +$('seed').value, fast };if (!fast && !S.tts.s.cfm) $('status').textContent = 'Đang tải model 16 bước (23 MB)…';$('go').disabled = true; $('goLabel').textContent = 'Đang pha…'; $('status').classList.remove('err'); $('status').textContent = '';setFill(0); brewing(true);const t0 = performance.now();28 unmodified linesnew ResizeObserver(() => { $('hl').scrollTop = $('text').scrollTop; }).observe($('text'));textChanged();$('text').onkeydown = e => { if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') { e.preventDefault(); generate(); } };for (const [id, out, f] of [['w', 'oW', v => (+v).toFixed(2)], ['steps', 'oSteps', v => v], ['speed', 'oSpeed', v => (+v).toFixed(2) + '×']]) { $(id).oninput = () => $(out).textContent = f($(id).value); $(id).oninput(); }$('dice').onclick = () => { $('seed').value = Math.floor(Math.random() * 100000); };$('go').onclick = () => generate();const setMode = fast => { S.fast = fast; $('mFast').setAttribute('aria-checked', String(fast)); $('mStd').setAttribute('aria-checked', String(!fast));for (const id of ['setW', 'setSteps']) { $(id).classList.toggle('off', fast); $(id).querySelector('input').disabled = fast; }$('modeHint').textContent = fast ? 'Nhanh hơn khoảng 8 lần ở bước sinh âm, chất lượng tương đương.' : 'Bản gốc: 16 bước, có chỉnh độ bám chữ (CFG).'; };$('mFast').onclick = () => setMode(true); $('mStd').onclick = () => setMode(false); setMode(true);$('brkSeg').querySelectorAll('button').forEach(b => b.onclick = () => setBoundary(b.dataset.v));$('brkPlay').onclick = playBoundary;$('brkClose').onclick = () => selectBoundary(-1);123456710 unmodified lines18192021222324320 unmodified lines34534634734834935035135228 unmodified lines381382383384385386387388389import * as ort from './ort/ort.webgpu.min.mjs';import { TradaTTS, normalize, normalizePart, JOIN, isAlnum } from './tts.js?v=11220200';import { resample, kaldiFbank } from './audio.js?v=11220200';const VER = '11220200';// model repo root (config.json, onnx/, voices/): the page's parent folder, or window.TRADA_ROOT (e.g. a Hugging Face resolve URL)const ROOT = (window.TRADA_ROOT || new URL('..', import.meta.url).href).replace(/\/$/, '');10 unmodified lines['Kể chuyện', 'Chiều hôm ấy, mưa rơi lất phất trên con phố nhỏ. Bà cụ bán trà đá vẫn ngồi đó, rót cho khách quen một cốc, rồi kể chuyện ngày xưa.'],];const STORE = 'trada-tts.voices.v1', THEME = 'trada-tts.theme';const S = { tts: null, camp: null, presets: [], saved: [], sel: null, backend: 'wasm', take: null, takes: [], pending: null, selG: -1, stopAt: null };// ---------------- iSTFT on WebGPU (WGSL; validated against torch.istft) ----------------const N = 1920, H = 480, FB = 961, MT = 2048;320 unmodified lines// ---------------- generate ----------------async function generate({ replace = false, autoplay = true } = {}) {const text = $('text').value.trim(); if (!text || !S.tts || $('go').disabled) return;const fast = S.tts.hasFast; // demo always runs the 2-step distilled flow (CFG baked in)const v = current(), opts = { w: 3, steps: fast ? 2 : 16, speed: +$('speed').value, seed: +$('seed').value, fast };$('go').disabled = true; $('goLabel').textContent = 'Đang pha…'; $('status').classList.remove('err'); $('status').textContent = '';setFill(0); brewing(true);const t0 = performance.now();28 unmodified linesnew ResizeObserver(() => { $('hl').scrollTop = $('text').scrollTop; }).observe($('text'));textChanged();$('text').onkeydown = e => { if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') { e.preventDefault(); generate(); } };for (const [id, out, f] of [['speed', 'oSpeed', v => (+v).toFixed(2) + '×']]) { $(id).oninput = () => $(out).textContent = f($(id).value); $(id).oninput(); }$('dice').onclick = () => { $('seed').value = Math.floor(Math.random() * 100000); };$('go').onclick = () => generate();$('brkSeg').querySelectorAll('button').forEach(b => b.onclick = () => setBoundary(b.dataset.v));$('brkPlay').onclick = playBoundary;$('brkClose').onclick = () => selectBoundary(-1);
75 unmodified lines76777879808182212 unmodified lines29529629729829930030130230330430530630776 unmodified lines38438538638738838975 unmodified lines.chips{display:flex;gap:8px;flex-wrap:wrap;padding:0 18px 14px}.chip{border:1px solid var(--line);background:var(--bg);border-radius:999px;padding:5px 12px;font-size:13px;color:var(--ink-2);cursor:pointer}.chip:hover{border-color:var(--tea);color:var(--ink)}.settings{border-top:1px solid var(--line);padding:12px 18px;display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:16px}@media (max-width:640px){.settings{grid-template-columns:repeat(2,minmax(0,1fr))}}.set{display:flex;flex-direction:column;gap:4px;font-size:12.5px;color:var(--ink-2);min-width:0}.set .lv{display:flex;justify-content:space-between;gap:6px}212 unmodified lines</div><div class="chips" id="examples"></div><div class="settings"><div class="mode"><span class="set" style="flex-direction:row;align-items:center;gap:8px"><span>Chế độ</span></span><span class="seg2" role="radiogroup" aria-label="Chế độ sinh"><button role="radio" id="mFast" aria-checked="true">Nhanh · 2 bước</button><button role="radio" id="mStd" aria-checked="false">Chuẩn · 16 bước</button></span><span class="hint" id="modeHint">Nhanh hơn khoảng 8 lần ở bước sinh âm, chất lượng tương đương.</span></div><label class="set"><span class="lv"><span>Tốc độ</span><output id="oSpeed"></output></span><input type="range" id="speed" min="0.7" max="1.4" step="0.05" value="1"></label><label class="set" id="setW" title="Cao hơn: phát âm rõ hơn. Thấp hơn: tự nhiên hơn nhưng dễ đọc sai."><span class="lv"><span>Độ bám chữ</span><output id="oW"></output></span><input type="range" id="w" min="1" max="4" step="0.25" value="3"></label><label class="set" id="setSteps" title="Ít bước: nhanh hơn, giọng thô hơn."><span class="lv"><span>Số bước</span><output id="oSteps"></output></span><input type="range" id="steps" min="4" max="32" step="1" value="16"></label><div class="set"><label for="seed">Seed</label><div class="seed"><input type="number" id="seed" value="0" min="0"><button class="btn sq" id="dice" aria-label="Seed ngẫu nhiên">⟳</button></div></div></div><div class="foot">76 unmodified lines<span>Các giọng mẫu là giọng tổng hợp (trộn nhiều người nói), không phải giọng của một người thật.</span></footer></div><script type="module" src="app.js?v=11220100"></script></body></html>75 unmodified lines76777879808182212 unmodified lines29529629729829930030176 unmodified lines37837938038138238375 unmodified lines.chips{display:flex;gap:8px;flex-wrap:wrap;padding:0 18px 14px}.chip{border:1px solid var(--line);background:var(--bg);border-radius:999px;padding:5px 12px;font-size:13px;color:var(--ink-2);cursor:pointer}.chip:hover{border-color:var(--tea);color:var(--ink)}.settings{border-top:1px solid var(--line);padding:12px 18px;display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}@media (max-width:640px){.settings{grid-template-columns:repeat(2,minmax(0,1fr))}}.set{display:flex;flex-direction:column;gap:4px;font-size:12.5px;color:var(--ink-2);min-width:0}.set .lv{display:flex;justify-content:space-between;gap:6px}212 unmodified lines</div><div class="chips" id="examples"></div><div class="settings"><label class="set"><span class="lv"><span>Tốc độ</span><output id="oSpeed"></output></span><input type="range" id="speed" min="0.7" max="1.4" step="0.05" value="1"></label><div class="set"><label for="seed">Seed</label><div class="seed"><input type="number" id="seed" value="0" min="0"><button class="btn sq" id="dice" aria-label="Seed ngẫu nhiên">⟳</button></div></div></div><div class="foot">76 unmodified lines<span>Các giọng mẫu là giọng tổng hợp (trộn nhiều người nói), không phải giọng của một người thật.</span></footer></div><script type="module" src="app.js?v=11220200"></script></body></html>
1234567// Trà Đá TTS inference in JavaScript, backend-agnostic: pass an `ort` module (onnxruntime-web in the browser,// onnxruntime-node in tests). Mirrors trada_tts/text.py + trada_tts/infer.py.import { textNormalize } from './vi_normalize.js?v=11220100';import { fixNumbers } from './vi_fix.js?v=11220100';const TONE_MARK = { '̀': 2, '́': 3, '̉': 4, '̃': 5, '̣': 6 };const WORD_RE = /[\p{L}\p{N}_]+|[^\p{L}\p{N}_\s]/gu; // == Python re r"\w+|[^\w\s]" on NFC text1234567// Trà Đá TTS inference in JavaScript, backend-agnostic: pass an `ort` module (onnxruntime-web in the browser,// onnxruntime-node in tests). Mirrors trada_tts/text.py + trada_tts/infer.py.import { textNormalize } from './vi_normalize.js?v=11220200';import { fixNumbers } from './vi_fix.js?v=11220200';const TONE_MARK = { '̀': 2, '́': 3, '̉': 4, '̃': 5, '̣': 6 };const WORD_RE = /[\p{L}\p{N}_]+|[^\p{L}\p{N}_\s]/gu; // == Python re r"\w+|[^\w\s]" on NFC text
README.md+1-1
web/app.js+7-12
web/index.html+2-8
web/tts.js+2-2