fix: Freigeben hielt die Datenbanksperre und legte den Dienst lahm; Stimmen-Seite als Tabelle mit passendem Modell; Probehören mit gemeinsamem Ton-Ausgang; Version 0.1.15-rc12

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GmHhg6k5Hxh8GpVW7od4Di
This commit is contained in:
2026-11-20 19:59:54 +01:00
parent 5e28b7117c
commit 98673a7fc7
5 changed files with 128 additions and 38 deletions

View File

@ -2,27 +2,35 @@
(() => {
const status = document.getElementById('probe-status');
const csrf = document.querySelector('input[name=csrf]')?.value;
// Ein einziger Ton-Ausgang für alle Proben, gleich beim ersten Klick geweckt (sonst geht der Anfang verloren
// oder die zweite Probe bleibt stumm). Vor dem Ton liegt eine kurze Stille.
let ctx = null;
const ausgang = () => {
if (!ctx || ctx.state === 'closed') ctx = new AudioContext({sampleRate: 24000});
if (ctx.state !== 'running') ctx.resume();
return ctx;
};
document.querySelectorAll('button.probe').forEach(button => button.addEventListener('click', async () => {
const select = button.parentElement.querySelector('.stimmen-modell');
const saved = button.dataset.gespeichert === '1';
const matches = o => o.dataset.art === (saved ? 'gespeichert' : 'eingebaut') || o.dataset.art === 'alle';
const model = matches(select.selectedOptions[0]) ? select.selectedOptions[0] : Array.from(select.options).find(matches);
if (!model) { status.textContent = 'Kein passendes installiertes Sprachmodell verfügbar.'; return; }
const select = button.closest('tr')?.querySelector('.stimmen-modell');
const modell = select ? select.value : button.dataset.modell;
if (!modell) { status.textContent = 'Kein passendes installiertes Sprachmodell verfügbar.'; return; }
const ton = ausgang();
button.disabled = true;
status.textContent = 'Probehören wird geladen …';
status.textContent = 'Probehören wird geladen (beim ersten Mal kann das einige Sekunden dauern) …';
try {
const response = await fetch('/ui/modelle/probe', {method: 'POST', headers: {'Content-Type': 'application/json', 'X-CSRF-Token': csrf}, credentials: 'same-origin', body: JSON.stringify({model: model.value, voice: button.dataset.stimme})});
const response = await fetch('/ui/modelle/probe', {method: 'POST', headers: {'Content-Type': 'application/json', 'X-CSRF-Token': csrf}, credentials: 'same-origin', body: JSON.stringify({model: modell, voice: button.dataset.stimme})});
if (!response.ok) throw new Error('Die Stimme konnte nicht probegehört werden.');
// PCM 24 kHz / 16 Bit / Mono, wie bei der bestehenden Vorlese-Route.
const pcm = await response.arrayBuffer();
const samples = new Int16Array(pcm);
const ctx = new AudioContext({sampleRate: 24000});
await ctx.resume();
const buffer = ctx.createBuffer(1, samples.length, 24000);
const samples = new Int16Array(pcm, 0, Math.floor(pcm.byteLength / 2));
const vorlauf = Math.round(0.3 * 24000);
const buffer = ton.createBuffer(1, vorlauf + samples.length, 24000);
const channel = buffer.getChannelData(0);
for (let i = 0; i < samples.length; i++) channel[i] = samples[i] / 32768;
const source = ctx.createBufferSource(); source.buffer = buffer; source.connect(ctx.destination);
source.onended = () => ctx.close(); source.start();
for (let i = 0; i < samples.length; i++) channel[vorlauf + i] = samples[i] / 32768;
await ton.resume();
const source = ton.createBufferSource(); source.buffer = buffer; source.connect(ton.destination);
source.onended = () => { status.textContent = ''; };
source.start(ton.currentTime + 0.05);
status.textContent = 'Probehören läuft.';
} catch (_) { status.textContent = 'Die Stimme konnte nicht probegehört werden.'; }
finally { button.disabled = false; }