Download runtime/web/index.html from islomov/gapi-uz-gapiring-v1: direct link, hf CLI and curl.
- Browser
- Download file 7.6 kB
-
https://huggingface.co/islomov/gapi-uz-gapiring-v1/resolve/main/runtime/web/index.html
- Command line
-
hf download hf://islomov/gapi-uz-gapiring-v1/runtime/web/index.html
-
curl -L -o index.html https://huggingface.co/islomov/gapi-uz-gapiring-v1/resolve/main/runtime/web/index.html
7.6 kB
| <html lang="ru"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| <title>Gapiring Edge v1</title> | |
| <style> | |
| :root{--bg:#f7f7f5;--card:#fff;--fg:#1d1d1b;--mut:#6b6b66;--line:#e2e1dc;--acc:#2f5bd3} | |
| @media (prefers-color-scheme:dark){:root:not([data-theme="light"]){--bg:#161615;--card:#1f1f1d;--fg:#ecebe6;--mut:#a3a29c;--line:#34332f;--acc:#8aa8ff}} | |
| :root[data-theme="dark"]{--bg:#161615;--card:#1f1f1d;--fg:#ecebe6;--mut:#a3a29c;--line:#34332f;--acc:#8aa8ff} | |
| *{box-sizing:border-box}body{background:var(--bg);color:var(--fg);font:16px/1.5 system-ui,sans-serif;margin:0;padding:20px 16px} | |
| main{max-width:640px;margin:0 auto}h1{font-size:21px;margin:0 0 6px}.mut{color:var(--mut);font-size:14px} | |
| .card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:14px;margin:12px 0} | |
| label{display:block;font-size:13px;color:var(--mut);margin:8px 0 3px}select,textarea,button{font:inherit;width:100%;border:1px solid var(--line);border-radius:8px;padding:9px;background:var(--bg);color:var(--fg)} | |
| textarea{min-height:96px;resize:vertical}.row{display:grid;grid-template-columns:1fr 1fr;gap:10px} | |
| button{background:var(--acc);color:#fff;border:0;margin-top:12px;font-weight:600}button:disabled{opacity:.5} | |
| progress{width:100%}#stats{font-variant-numeric:tabular-nums}</style> | |
| <script src="https://cdn.jsdelivr.net/npm/onnxruntime-web@1.23.2/dist/ort.min.js"></script></head> | |
| <body><main><h1>Gapiring Edge v1 прямо в браузере</h1> | |
| <p class="mut">Узбекская модель Gapiring Edge v1 (6 слоёв, int8, 117 МБ) работает на этом устройстве через WebAssembly: сервер только отдаёт файлы, | |
| синтез идёт в телефоне. Первая загрузка — 117 МБ. Числа пишите словами: обработка текста агента (фронтенд) сюда не перенесена.</p> | |
| <div class="card"><button id="load">Загрузить модель (117 МБ)</button><progress id="prog" value="0" max="1" hidden></progress><div id="lstat" class="mut"></div></div> | |
| <div class="card"><label for="text">Текст</label><textarea id="text">Assalomu alaykum! Namunaning sun'iy intellekt yordamchisiman, sizga qanday yordam bera olaman?</textarea> | |
| <div class="row"><div><label for="voice">Голос</label><select id="voice"><option value="f1">Ж1 (женский)</option><option value="m1">М1 (мужской)</option></select></div> | |
| <div><label for="role">Роль</label><select id="role"></select></div></div> | |
| <label for="style">Манера</label><select id="style"></select> | |
| <button id="go" disabled>Озвучить</button><div id="stats" class="mut"></div><a id="dl" hidden download="gapiring.wav">Скачать WAV</a></div> | |
| </main><script type="module"> | |
| import { PocketTTS } from "./pocket_tts.js"; | |
| const ROLES = { assistant: ["ИИ-ассистент, живой", "③"], assistant_formal: ["ИИ-ассистент, официальный", "④"], operator: ["Оператор", "①"], emotional: ["Эмоциональный режим", "②"] }; | |
| const STYLES = ["calm","friendly","joking","grateful","curious","confused","hurried","irritated","angry","worried","upset","sceptical","tired","elderly","neutral","warm","cheerful","empathetic","dictation","persuasive","brisk","soothing"]; | |
| const CHAR = Object.fromEntries(STYLES.map((s, i) => [s, String.fromCodePoint(0x2464 + i)])); | |
| const RU = {calm:"спокойно",friendly:"дружелюбно",joking:"шутливо",grateful:"благодарно",curious:"с интересом",confused:"растерянно",hurried:"торопливо",irritated:"раздражённо",angry:"сердито",worried:"встревоженно",upset:"расстроенно",sceptical:"скептично",tired:"устало",elderly:"по-стариковски",neutral:"нейтрально",warm:"тепло",cheerful:"бодро",empathetic:"сочувственно",dictation:"под диктовку",persuasive:"убеждающе",brisk:"коротко и по делу",soothing:"успокаивающе"}; | |
| const PAIRS = { assistant: ["warm","neutral","calm","cheerful","empathetic","soothing","dictation"], | |
| assistant_formal: ["neutral","warm","calm","cheerful","empathetic","soothing","dictation"], | |
| operator: ["warm","neutral","calm","cheerful","empathetic","dictation","persuasive","brisk"], | |
| emotional: ["angry","upset","irritated","worried","tired","sceptical","confused","hurried","joking","grateful","curious","friendly","calm","elderly"] }; | |
| const $ = (id) => document.getElementById(id); | |
| for (const [k, [ru]] of Object.entries(ROLES)) $("role").add(new Option(ru, k)); | |
| const fillStyles = () => { $("style").innerHTML = ""; for (const s of PAIRS[$("role").value]) $("style").add(new Option(RU[s], s)); }; | |
| $("role").onchange = fillStyles; fillStyles(); | |
| const tts = new PocketTTS(); | |
| $("load").onclick = async () => { | |
| $("load").disabled = true; $("prog").hidden = false; | |
| const t0 = performance.now(); | |
| try { | |
| await tts.load("./", (n, got, total) => { $("prog").max = 117e6; $("prog").value = got; $("lstat").textContent = `${n}: ${(got / 1e6).toFixed(0)} МБ`; }); | |
| $("lstat").textContent = `Модель загружена за ${((performance.now() - t0) / 1000).toFixed(1)} с; потоков WebAssembly: ${ort.env.wasm.numThreads}`; | |
| $("go").disabled = false; | |
| } catch (e) { $("lstat").textContent = "Ошибка: " + e; $("load").disabled = false; } | |
| }; | |
| let ctx = null; | |
| $("go").onclick = async () => { | |
| $("go").disabled = true; | |
| ctx = ctx || new AudioContext({ sampleRate: 24000 }); | |
| await ctx.resume(); | |
| let at = ctx.currentTime + 0.05; | |
| const role = $("role").value, tags = ROLES[role][1] + CHAR[$("style").value]; | |
| $("stats").textContent = "Синтез…"; | |
| const chunks = []; | |
| const r = await tts.speak($("text").value, tags, $("voice").value, (audio) => { | |
| chunks.push(audio); | |
| const buf = ctx.createBuffer(1, audio.length, 24000); buf.copyToChannel(audio, 0); | |
| const src = ctx.createBufferSource(); src.buffer = buf; src.connect(ctx.destination); | |
| at = Math.max(at, ctx.currentTime); src.start(at); at += buf.duration; | |
| }, { seed: (Date.now() % 100000) + 1 }); | |
| $("stats").textContent = `Первый звук через ${r.firstMs.toFixed(0)} мс · ${r.seconds.toFixed(1)} с речи · синтез ${r.rtf < 1 ? "в " + (1 / r.rtf).toFixed(1) + " раза быстрее" : "в " + r.rtf.toFixed(1) + " раза медленнее"} реального времени`; | |
| const all = new Float32Array(chunks.reduce((n, c) => n + c.length, 0)); let o = 0; for (const c of chunks) { all.set(c, o); o += c.length; } | |
| window.__lastAudio = all; window.__lastStats = r; | |
| $("dl").href = URL.createObjectURL(wav(all, 24000)); $("dl").hidden = false; | |
| $("go").disabled = false; | |
| }; | |
| function wav(x, rate) { // 16-bit PCM WAV | |
| const b = new DataView(new ArrayBuffer(44 + x.length * 2)), w = (o, s) => [...s].forEach((c, i) => b.setUint8(o + i, c.charCodeAt(0))); | |
| w(0, "RIFF"); b.setUint32(4, 36 + x.length * 2, true); w(8, "WAVEfmt "); b.setUint32(16, 16, true); b.setUint16(20, 1, true); b.setUint16(22, 1, true); | |
| b.setUint32(24, rate, true); b.setUint32(28, rate * 2, true); b.setUint16(32, 2, true); b.setUint16(34, 16, true); w(36, "data"); b.setUint32(40, x.length * 2, true); | |
| for (let i = 0; i < x.length; i++) b.setInt16(44 + i * 2, Math.max(-1, Math.min(1, x[i])) * 32767, true); | |
| return new Blob([b], { type: "audio/wav" }); | |
| } | |
| </script></body></html> | |