apptor-tiny-tts-at / web /index.html
apptor's picture
G2P: English words common in German text
645650a verified
Raw History Blame Contribute Delete
19.3 kB
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>apptor-tiny-tts</title>
<meta name="description" content="Eine kleine deutsche Stimme, die auch (etwas) österreichisch kann. Läuft komplett im Browser, Apache 2.0.">
<meta property="og:title" content="apptor-tiny-tts: vom Fischbrötchen zum Schnitzel">
<meta property="og:description" content="Kleine deutsche Stimme mit Akzent-Regler, hochdeutsch oder österreichisch. Läuft komplett im Browser, Apache 2.0.">
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='8' fill='%23c8102e'/%3E%3Crect y='11' width='32' height='10' fill='%23fff'/%3E%3C/svg%3E">
<style>
:root {
--ink: #1d232b; --muted: #5b6672; --card: #ffffffee; --line: #d9dee4; --accent: #c8102e; --accent-ink: #fff;
--bg-a: #2f7aa0; --bg-b: #d8eef6; --shadow: 0 10px 30px #0002; --track: #e7ebef;
font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
:root { --ink: #eef2f5; --muted: #a6b1bc; --card: #1b2229ee; --line: #34404b; --shadow: 0 10px 30px #0006; --track: #2b343d; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
min-height: 100vh; color: var(--ink);
background: linear-gradient(160deg, var(--bg-a), var(--bg-b)); background-attachment: fixed;
transition: background 0.6s;
}
main { max-width: 760px; margin: 0 auto; padding: 28px 16px 40px; }
header { text-align: center; color: #fff; text-shadow: 0 2px 8px #0004; }
header h1 { font-size: clamp(2.2rem, 7vw, 3.6rem); margin: 0; letter-spacing: -0.02em; transition: transform 0.25s; }
header p { margin: 6px 0 0; font-size: 1.05rem; opacity: 0.95; }
.ver { display: inline-block; margin-top: 10px; padding: 3px 12px; border-radius: 999px; background: #fff3; border: 1px solid #fff8;
font-size: 0.8rem; font-weight: 600; text-shadow: none; }
.card { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 20px; margin-top: 18px; backdrop-filter: blur(6px); }
.food { position: relative; height: 190px; display: flex; align-items: center; justify-content: center; }
.food svg { position: absolute; width: min(260px, 70vw); height: 180px; transition: opacity 0.35s, transform 0.35s; }
.dish { text-align: center; font-weight: 600; margin: 2px 0 10px; min-height: 1.4em; }
.slider-wrap { padding: 4px 4px 0; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; }
.stops { position: relative; height: 1.9em; font-size: 0.85rem; color: var(--muted); margin-top: 2px; }
.stops button { position: absolute; top: 0; white-space: nowrap; }
.stops button { background: none; border: 0; color: inherit; font: inherit; cursor: pointer; padding: 4px 2px; }
.stops button:hover { color: var(--ink); text-decoration: underline; }
.value { text-align: center; color: var(--muted); font-size: 0.9rem; margin-top: 4px; }
textarea { width: 100%; min-height: 200px; resize: vertical; border: 1px solid var(--line); border-radius: 12px; padding: 12px;
font: inherit; font-size: 1.05rem; background: transparent; color: var(--ink); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--ink); padding: 9px 16px; font: inherit; cursor: pointer; }
.seg button[aria-pressed=true] { background: var(--ink); color: var(--card); }
.speak { margin-left: auto; border: 0; border-radius: 999px; padding: 11px 26px; font: inherit; font-weight: 700; font-size: 1.05rem;
background: var(--accent); color: var(--accent-ink); cursor: pointer; box-shadow: 0 4px 14px #c8102e55; }
.speak:disabled { opacity: 0.5; cursor: wait; box-shadow: none; }
.examples { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.examples button { border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 999px; padding: 6px 12px;
font: inherit; font-size: 0.85rem; cursor: pointer; }
.examples button:hover { color: var(--ink); border-color: var(--ink); }
.source { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.status { font-size: 0.88rem; color: var(--muted); margin-top: 12px; min-height: 1.2em; }
.bar { height: 6px; background: var(--track); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
label.check { display: inline-flex; gap: 6px; align-items: center; font-size: 0.9rem; color: var(--muted); }
.info { font-size: 0.92rem; line-height: 1.55; color: var(--muted); }
.info h2 { color: var(--ink); font-size: 1.05rem; margin: 0 0 6px; }
.info p + h2 { margin-top: 16px; }
.info p { margin: 0 0 10px; }
.info a { color: var(--accent); }
.use { margin: 0 0 12px; padding-left: 18px; }
.use li { margin-bottom: 8px; }
.use b { color: var(--ink); }
.links { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 12px; }
.btn { display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: 8px 18px; text-decoration: none;
font-weight: 600; color: var(--ink) !important; }
.btn:hover { border-color: var(--ink); }
.small { font-size: 0.82rem; }
footer { text-align: center; color: #1d232bcc; font-size: 0.9rem; margin-top: 22px; }
footer a { color: #1d232b; font-weight: 600; }
.wobble { animation: wob 0.5s; }
@keyframes wob { 30% { transform: rotate(-3deg) scale(1.04); } 60% { transform: rotate(2deg); } }
@media (max-width: 520px) { .speak { margin-left: 0; width: 100%; } }
</style>
</head>
<body>
<main>
<header>
<h1 id="greet">Servus!</h1>
<p>Eine kleine deutsche Stimme, die auch (etwas) österreichisch kann. Direkt in deinem Browser.</p>
<span class="ver">Version 0.1 · frühe Vorschau</span>
</header>
<section class="card" aria-label="Akzent">
<div class="food" id="food" aria-hidden="true">
<!-- Fischbrötchen -->
<svg viewBox="0 0 260 180" data-i="0">
<ellipse cx="130" cy="150" rx="110" ry="14" fill="#0002"/>
<path d="M30 112 Q130 150 230 112 L224 128 Q130 168 36 128Z" fill="#d79a4a"/>
<path d="M44 98 Q70 84 100 92 Q130 80 160 92 Q190 82 216 98 L214 110 Q130 124 46 110Z" fill="#7dbb4a"/>
<path d="M8 96 Q40 70 120 78 Q200 72 236 92 L252 78 L248 104 L252 126 L234 108 Q190 118 120 112 Q40 116 8 96Z" fill="#c9cfd6"/>
<path d="M30 92 Q120 84 230 96" stroke="#8d97a3" stroke-width="3" fill="none"/>
<circle cx="32" cy="92" r="4" fill="#24303a"/>
<circle cx="96" cy="104" r="9" fill="none" stroke="#b07ac0" stroke-width="4"/>
<circle cx="160" cy="104" r="9" fill="none" stroke="#b07ac0" stroke-width="4"/>
<path d="M34 92 Q130 30 226 92 Q130 70 34 92Z" fill="#e2ad5f"/>
<path d="M70 66 l6 -4 M110 52 l6 -3 M150 54 l6 3 M188 66 l6 4" stroke="#fff8" stroke-width="3" stroke-linecap="round"/>
</svg>
<!-- Wiener Schnitzel -->
<svg viewBox="0 0 260 180" data-i="1">
<ellipse cx="130" cy="98" rx="122" ry="72" fill="#f5f2ec" stroke="#d8d2c6" stroke-width="3"/>
<path d="M34 98 Q30 52 92 46 Q130 30 178 48 Q232 56 226 102 Q232 146 170 150 Q130 164 86 150 Q28 146 34 98Z" fill="#d9952f"/>
<path d="M50 96 Q48 62 96 58 Q130 46 172 60 Q214 66 210 100 Q214 134 166 138 Q130 150 92 138 Q50 134 50 96Z" fill="#e8ad46"/>
<g fill="#b97821"><circle cx="80" cy="80" r="3"/><circle cx="120" cy="66" r="3"/><circle cx="160" cy="84" r="3"/><circle cx="104" cy="112" r="3"/><circle cx="150" cy="120" r="3"/><circle cx="186" cy="104" r="3"/><circle cx="70" cy="118" r="3"/></g>
<path d="M168 40 a26 26 0 0 1 44 22 Z" fill="#f4e04d" stroke="#d9c22c" stroke-width="3"/>
<path d="M172 44 L200 58 M186 38 L198 58" stroke="#fff7" stroke-width="2"/>
<path d="M46 52 q10 -14 22 -4 q8 -12 18 0" stroke="#3f8f3a" stroke-width="5" fill="none" stroke-linecap="round"/>
</svg>
</div>
<p class="dish" id="dish">Wiener Schnitzel</p>
<div class="slider-wrap">
<label for="accent" class="value" style="display:block">Akzentstärke: <b id="accent-val">1,0</b></label>
<input id="accent" type="range" min="0" max="1.6" step="0.05" value="1" aria-describedby="dish">
<div class="stops">
<button data-v="0" style="left:0">Hochdeutsch</button><button data-v="1.6" style="right:0">Österreichisch</button>
</div>
</div>
</section>
<section class="card" aria-label="Sprechen">
<label for="text" class="value" style="display:block;text-align:left;margin:0 0 6px">Was soll ich sagen?</label>
<textarea id="text" rows="8">Da streiten sich die Leut herum
oft um den Wert des Glücks,
der eine heißt den andern dumm,
am End weiß keiner nix.
Da ist der allerärmste Mann
dem andern viel zu reich,
das Schicksal setzt den Hobel an
und hobelt alles gleich.</textarea>
<div class="source">Ferdinand Raimund, „Hobellied“ (1834). Oder schreib einfach etwas Eigenes.</div>
<div class="row">
<div class="seg" role="group" aria-label="Stimme">
<button data-voice="M2" aria-pressed="true">Mann</button><button data-voice="F2" aria-pressed="false">Frau</button>
</div>
<label class="check"><input type="checkbox" id="vocos" checked disabled> Klangfilter</label>
<button class="speak" id="speak" disabled>Lade …</button>
</div>
<div class="status" id="status">Lade die Modelle (einmalig, danach im Browser gespeichert) …</div>
<div class="bar"><i id="bar"></i></div>
</section>
<section class="card info">
<h2>Warum österreichisch?</h2>
<p>Sprachausgaben klingen fast immer bundesdeutsch. apptor-tiny-tts soll eine Alternative sein, und zwar dort, wo große
Modelle keinen Platz haben: im Browser, am Handy, in kleinen Apps. Der Akzent ist noch dezent und sitzt nicht in jedem
Wort: besser als nichts, aber noch nicht ganz österreichisch. Das hier ist Version 0.1, trainiert auf einer einzigen Grafikkarte mit freien Aufnahmen von Freiwilligen
aus <a href="https://commonvoice.mozilla.org/de" rel="noopener">Mozilla Common Voice</a>. Die beiden Stimmen sind
synthetisch; das Modell hat den Tonfall gelernt, nicht die Stimmen der Sprecherinnen und Sprecher.</p>
<p>Was hier passiert: Beim ersten Besuch lädt dein Browser einmalig rund 50 MB (Aussprache, Stimme, Klangfilter) und
rechnet danach alles selbst. Dein Text verlässt das Gerät nicht.</p>
</section>
<section class="card info">
<h2>Selbst verwenden</h2>
<ul class="use">
<li><b>Im Web.</b> Diese Seite ist das ganze Paket: ein paar Dateien, kein Build, keine Abhängigkeiten. Den Ordner von
Hugging Face auf den eigenen Webserver legen, und die Stimme läuft auch dort.</li>
<li><b>In Python.</b> Dieselben Modelle als ONNX, dazu ein kleines Skript. Es braucht nur onnxruntime, kein eSpeak, keine GPU.</li>
<li><b>Als ganzer Sprachassistent.</b> <a href="https://github.com/ViktorsGitUser/flash-voice" rel="noopener">flash-voice</a>
auf GitHub verbindet Hören, Entscheiden und Sprechen; apptor-tiny-tts ist dort die deutsche Stimme.</li>
</ul>
<div class="links">
<a class="btn" href="https://huggingface.co/apptor/apptor-tiny-tts-at" rel="noopener">Hugging Face</a>
<a class="btn" href="https://github.com/ViktorsGitUser/flash-voice" rel="noopener">GitHub</a>
</div>
<p class="small">Apache 2.0. Gebaut auf <a href="https://github.com/n4ze3m/tiny-voca" rel="noopener">tiny-voca</a> von Nazeem,
Klangfilter <a href="https://github.com/gemelo-ai/vocos" rel="noopener">Vocos</a> (MIT), Laufzeit
<a href="https://onnxruntime.ai" rel="noopener">ONNX Runtime Web</a> (MIT).</p>
</section>
<footer>
<a href="https://apptor.at" rel="noopener">apptor.at</a> ·
Feedback gern auf <a href="https://x.com/apptor_at" rel="noopener">X @apptor_at</a>
</footer>
</main>
<script type="module">
import * as ort from "./ort/ort.wasm.min.mjs";
import {G2P, makeFrontEnd, Voice} from "./apptor-tts.js?v=4";
ort.env.wasm.wasmPaths = new URL("./ort/", location.href).href;
ort.env.wasm.numThreads = self.crossOriginIsolated ? Math.min(4, navigator.hardwareConcurrency || 2) : 1;
ort.env.wasm.proxy = true; // run the models in a Web Worker, so the page stays responsive while it computes
const $ = id => document.getElementById(id);
const STOPS = [
{v: 0, hi: "Moin!", dish: "Fischbrötchen", bg: ["#2f7aa0", "#d8eef6"]},
{v: 1.0, hi: "Servus!", dish: "Wiener Schnitzel", bg: ["#c8102e", "#f6e9ea"]},
];
const svgs = [...document.querySelectorAll("#food svg")];
let voiceName = "M2", voice = null, playing = null, ctx = null, spoken = false;
function mix(a, b, t) {
const p = h => [1, 3, 5].map(i => parseInt(h.slice(i, i + 2), 16));
const x = p(a), y = p(b);
return "#" + x.map((v, i) => Math.round(v + (y[i] - v) * t).toString(16).padStart(2, "0")).join("");
}
function showAccent(v) {
$("accent-val").textContent = v.toFixed(2).replace(/0$/, "").replace(".", ",");
let i = 0;
while (i < STOPS.length - 2 && v > STOPS[i + 1].v) i++;
const a = STOPS[i], b = STOPS[i + 1], t = Math.max(0, Math.min(1, (v - a.v) / (b.v - a.v)));
svgs.forEach((s, k) => {
const o = k === i ? 1 - t : k === i + 1 ? t : 0;
s.style.opacity = o; s.style.transform = `scale(${0.8 + 0.2 * o}) rotate(${(1 - o) * (k > i ? 8 : -8)}deg)`;
});
const near = t < 0.5 ? a : b;
if ($("greet").textContent !== near.hi) { $("greet").textContent = near.hi; $("greet").classList.remove("wobble"); void $("greet").offsetWidth; $("greet").classList.add("wobble"); }
$("dish").textContent = near.dish;
document.body.style.setProperty("--bg-a", mix(a.bg[0], b.bg[0], t));
document.body.style.setProperty("--bg-b", mix(a.bg[1], b.bg[1], t));
}
$("accent").addEventListener("input", e => showAccent(Number(e.target.value)));
$("accent").addEventListener("change", () => { if (spoken) speak(); });
document.querySelectorAll(".stops button").forEach(b => b.addEventListener("click", () => {
$("accent").value = b.dataset.v; showAccent(Number(b.dataset.v)); if (spoken) speak();
}));
document.querySelectorAll(".seg button").forEach(b => b.addEventListener("click", () => {
voiceName = b.dataset.voice;
document.querySelectorAll(".seg button").forEach(x => x.setAttribute("aria-pressed", String(x === b)));
if (spoken) speak();
}));
showAccent(1.0);
// ---- loading with progress, kept in the Cache Storage for the next visit
const CACHE = "apptor-tiny-tts-v1";
async function fetchBytes(url, onProgress) {
let cache = null;
try { cache = await caches.open(CACHE); const hit = await cache.match(url); if (hit) { const b = await hit.arrayBuffer(); onProgress(b.byteLength, b.byteLength); return new Uint8Array(b); } } catch {}
const r = await fetch(url);
if (!r.ok) throw new Error(`${url}: ${r.status}`);
const total = Number(r.headers.get("content-length")) || 0, reader = r.body.getReader(), parts = [];
let got = 0;
for (;;) { const {done, value} = await reader.read(); if (done) break; parts.push(value); got += value.length; onProgress(got, total); }
const out = new Uint8Array(got); let o = 0; for (const p of parts) { out.set(p, o); o += p.length; }
try { await cache?.put(url, new Response(out.slice(), {headers: {"content-type": "application/octet-stream"}})); } catch {}
return out;
}
const SIZES = {"models/apptor-g2p-de.onnx": 12.4, "models/apptor-tiny-tts-at.onnx": 21.4, "models/apptor-vocos-de.int8.onnx": 16.7};
const done = {};
function progress(url, got, total) {
done[url] = got / 1e6;
const all = Object.values(SIZES).reduce((a, b) => a + b, 0), have = Object.values(done).reduce((a, b) => a + b, 0);
$("bar").style.width = `${Math.min(100, 100 * have / all)}%`;
$("status").textContent = `Lade die Modelle: ${have.toFixed(0)} von ${all.toFixed(0)} MB (einmalig, danach im Browser gespeichert)`;
}
const json = async u => (await fetch(u)).json();
const opts = {executionProviders: ["wasm"], graphOptimizationLevel: "all"};
async function load() {
const [F, exceptions, austrian, g2pMeta, ttsMeta] = await Promise.all(["frontend-de.json", "exceptions-de.json?v=2", "austrian-de.json", "models/apptor-g2p-de.json", "models/apptor-tiny-tts-at.json"].map(json));
const [g2pBytes, ttsBytes] = await Promise.all(["models/apptor-g2p-de.onnx", "models/apptor-tiny-tts-at.onnx"].map(u => fetchBytes(u, (g, t) => progress(u, g, t))));
const g2p = new G2P(ort, await ort.InferenceSession.create(g2pBytes, opts), g2pMeta, exceptions, austrian);
voice = new Voice(ort, await ort.InferenceSession.create(ttsBytes, opts), ttsMeta, makeFrontEnd(F, g2p));
$("speak").disabled = false; $("speak").textContent = "Sprechen";
$("status").textContent = "Bereit. Der Klangfilter lädt noch im Hintergrund.";
const u = "models/apptor-vocos-de.int8.onnx";
const vb = await fetchBytes(u, (g, t) => progress(u, g, t));
voice.setVocos(await ort.InferenceSession.create(vb, opts));
$("vocos").disabled = false;
$("status").textContent = "Bereit. Alles ist geladen und bleibt im Browser gespeichert.";
}
load().catch(e => { $("status").textContent = "Das Laden hat nicht geklappt: " + e.message; console.error(e); });
let busy = false, again = false, sources = [];
function stopAudio() { for (const x of sources) { try { x.stop(); } catch {} } sources = []; }
async function speak() {
if (!voice) return;
if (busy) { again = true; return; } // the running job stops after its current sentence, then this starts
busy = true; spoken = true;
$("speak").disabled = true; $("speak").textContent = "Rechne …";
const keep = voice.vocos;
try {
ctx ??= new (window.AudioContext || window.webkitAudioContext)();
await ctx.resume();
stopAudio();
if (!$("vocos").checked) voice.vocos = null;
const sr = voice.meta.sample_rate, t = performance.now();
let at = 0, first = 0;
const audio = await voice.speak($("text").value, {voice: voiceName, accent: Number($("accent").value), cancelled: () => again,
onChunk: (a, i) => { // play each sentence as soon as it is ready
const buf = ctx.createBuffer(1, a.length, sr);
buf.copyToChannel(a, 0);
const src = ctx.createBufferSource(); src.buffer = buf; src.connect(ctx.destination);
if (i === 0) { first = performance.now() - t; at = ctx.currentTime + 0.05; } else at += 0.12;
at = Math.max(at, ctx.currentTime + 0.02);
src.start(at); at += buf.duration; sources.push(src);
}});
if (again) return;
if (!audio.length) throw new Error("kein Text zum Sprechen");
const ms = performance.now() - t;
$("status").textContent = `${(audio.length / sr).toFixed(1)} s Sprache, auf deinem Gerät gerechnet: erster Satz nach ${(first / 1000).toFixed(2)} s, alles nach ${(ms / 1000).toFixed(2)} s.`;
} catch (e) {
$("status").textContent = "Fehler: " + e.message; console.error(e);
} finally {
voice.vocos = keep;
busy = false; $("speak").disabled = false; $("speak").textContent = "Sprechen";
if (again) { again = false; speak(); }
}
}
$("speak").addEventListener("click", speak);
</script>
</body>
</html>