Spaces:
Running
Running
v0.2.1: pauses at punctuation and clear p sounds
Browse filesFiles changed (3)
- g2p.js+31-3
- index.html+2-1
- worker.js+8-3
316 unmodified lines3173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513243523533543555 unmodified lines361362363336337364365366367368316 unmodified lines }); }
// Turn layout and brackets into punctuation the model can pause on. function pauseMarks(s) { const low = (ch) => ch !== "" && ch.toLowerCase() === ch && ch.toUpperCase() !== ch; s = s.replaceAll("\r\n", "\n").replaceAll("\r", "\n").trim(); s = s.replace(/(?:^|(?<=\n))[ \t]*[-*•+–—][ \t]+/g, "•"); if (s.startsWith("•")) s = s.slice(1); s = s.replace(/([^\s•])([ \t]*\n[\s•]*)([^\s•])/g, (_, prev, brk, nxt) => { if (".,;:?!—…".includes(prev)) return prev + " " + nxt; return prev + (low(nxt) && brk.split("\n").length === 2 && !brk.includes("•") ? " " : ". ") + nxt; }); s = s.replace(/•/g, " "); s = s.replace(/(?<![A-Za-zÀ-ỹ])[vV]\.\s?[vV]\.?(?![A-Za-zÀ-ỹ])/g, "vân vân"); s = s.replace(/(?:…|\.{2,})(\s*)(\S?)/g, (_, _w, n) => (n ? (low(n) ? ", " : ". ") + n : ".")); s = s.replace(/(?<![A-Za-zÀ-ỹ])([A-ZĐ])\.(?=\s?[A-ZĐ])/g, "$1 "); s = s.replace(/(?<=\s)[-–—](?=\s)/g, "—"); s = s.replace(/(?<![\p{L}\p{N}_.,/–—-])([0-9]+(?:[.,][0-9]+)*)\s?[-–]\s?([0-9]+(?:[.,][0-9]+)*)(?![\p{L}\p{N}_/–—-]|[.,][0-9])/gu, (m, a, b) => Number(a.replaceAll(".", "").replaceAll(",", ".")) < Number(b.replaceAll(".", "").replaceAll(",", ".")) ? `${a} đến ${b}` : m); s = s.replace(/\s*[(\[{]\s*/g, ", "); s = s.replace(/\s*[)\]}]/g, ","); s = s.replace(/\s+([,.;:?!])/g, "$1"); s = s.replace(/,(?:\s*,)+/g, ","); s = s.replace(/,\s*([.;:?!—])/g, "$1"); s = s.replace(/([.;:?!—])\s*,/g, "$1"); s = s.replace(/,(?=[^\s\d])/g, ", "); return s.replace(/^[,\s]+/, ""); }
function normalizeText(text) { let s = text.normalize("NFC") .replace(/[\u00d0\u0189]/g, "Đ").replace(/[\u00f0\u0256]/g, "đ") .replace(/[\u00ad\u200b-\u200d\u2060\ufeff]/g, "") ; .replaceAll("…", ".").replaceAll("–", "—") s = pauseMarks(s).replaceAll("–", "—") .replaceAll("“", "").replaceAll("”", "").replaceAll('"', ""); s = s.replace(/(ngày\s+)?\b(\d{1,2})\/(\d{1,2})\/(\d{4})\b/gi, (_, p, d, mo, y) => `${p || "ngày "}${numberToWords(Number(d))} tháng ${numberToWords(Number(mo))} năm ${numberToWords(Number(y))}`);5 unmodified lines } return `${numberToWords(whole)} phần trăm`; }); s = s.replace(/\b(\d+(?:\.\d{3})*)\s?(?:đ|VND|VNĐ)(?![A-Za-zÀ-ỹà-ỹ])/g, (_, w) => `${numberToWords(Number(w.replaceAll(".", "")))} đồng`); s = s.replace(/(?<![\d.,])(\d+(?:\.\d{3})*)(?:,(\d+))?\s?(?:đ|VND|VNĐ)(?![A-Za-zÀ-ỹà-ỹ])/g, (_, w, f) => `${numberToWords(Number(w.replaceAll(".", "")))}${f ? " phẩy " + fracWords(f) : ""} đồng`); s = s.replace(/\b(\d+(?:\.\d{3})*),(\d+)\b/g, (_, w, f) => `${numberToWords(Number(w.replaceAll(".", "")))} phẩy ${fracWords(f)}`); s = s.replace(/\b\d{1,3}(?:\.\d{3})+\b|\b\d+\b/g, (m) => {50 unmodified lines51525354545556571 unmodified line5960616263646550 unmodified lines</head><body><div class="wrap"> <h1>TinyVoca-Vi <span class="badge">v0.2 · 4.77M params</span> <span class="badge">3 Voices</span> <span class="badge">24 kHz</span> <span class="badge">WASM 1-Thread · 100% Offline</span></h1> <h1>TinyVoca-Vi <span class="badge">v0.2.1 · 4.77M params</span> <span class="badge">3 Voices</span> <span class="badge">24 kHz</span> <span class="badge">WASM 1-Thread · 100% Offline</span></h1> <p class="sub">Northern Vietnamese neural TTS (3 female voices in 1 ONNX file, voicing-gated pitch-locked HN-Vocos) running directly in your browser via ONNX Runtime Web + ~12 KB (gzipped) rule-based G2P. No server, no Python.</p>
<div class="card">1 unmodified line <div><span id="dot" class="dot"></span><span id="statusText">Starting worker...</span></div> <div style="display:flex;align-items:center;gap:10px;flex-wrap:wrap;"> <select id="modelSelect" style="background:#10141c;color:var(--text);border:1px solid var(--border);border-radius:6px;padding:4px 8px;font-size:13px;"> <option value="./assets/tiny-voca-vi-v0.2.1.onnx">v0.2.1 (better pauses and p sounds · 14.3 MB)</option> <option value="./assets/tiny-voca-vi-v0.2.onnx">v0.2 HN-Vocos (3 voices · echo-free · 14.3 MB)</option> <option value="./assets/tiny-voca-vi.onnx">v0.1 Vocos-1M (Mai Anh only · 13.8 MB)</option> <option value="./assets/tiny-voca-vi-512.onnx">v0.1 512-pt Vocos (Mai Anh only · 10.5 MB)</option>1 unmodified line23455678910111112131415168 unmodified lines1841851861861871881891901911921931941951 unmodified lineconst ORT_CDN = "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.1/dist/";importScripts(ORT_CDN + "ort.wasm.min.js", "./g2p.js");
const MODEL_URL = "./assets/tiny-voca-vi-v0.2.onnx";const MODEL_URL = "./assets/tiny-voca-vi-v0.2.1.onnx";const HF_FALLBACK_MAP = { "./assets/tiny-voca-vi-v0.2.1.onnx": "https://huggingface.co/datmt24/tiny-voca-vi/resolve/main/onnx/tiny-voca-vi-v0.2.1-hnvocos-fp16.onnx", "./assets/tiny-voca-vi-v0.2.onnx": "https://huggingface.co/datmt24/tiny-voca-vi/resolve/main/onnx/tiny-voca-vi-v0.2-hnvocos-fp16.onnx", "./assets/tiny-voca-vi.onnx": "https://huggingface.co/datmt24/tiny-voca-vi/resolve/main/onnx/tiny-voca-vi-v0.1-1024-fp16.onnx", "./assets/tiny-voca-vi-512.onnx": "https://huggingface.co/datmt24/tiny-voca-vi/resolve/main/onnx/tiny-voca-vi-v0.1-512-fp16.onnx",};const CACHE_NAME = "tiny-voca-vi-v0.2.1";const CACHE_NAME = "tiny-voca-vi-v0.2.1-p";const SAMPLE_RATE = 24000;
let session = null;168 unmodified lines for (let i = 0; i < utts.length; i++) { if (currentRunId !== id) return; // cancelled const utt = utts[i]; const { audio, inferMs } = await runChunk(utt, { voiceId, speed, pitchShift, pause }); const { audio: speech, inferMs } = await runChunk(utt, { voiceId, speed, pitchShift, pause }); if (currentRunId !== id) return; // Gap after a sentence (chunks already end with ~100 ms of silence) const gapSec = i + 1 < utts.length && /[.!?]$/.test(chunks[i]) ? 0.25 * pause / speed : 0; const audio = new Float32Array(speech.length + Math.round(gapSec * SAMPLE_RATE)); audio.set(speech);
const audioSec = audio.length / SAMPLE_RATE; totalInferMs += inferMs;g2p.js+31-3
index.html+2-1
worker.js+8-3