File size: 2,802 Bytes
d371fbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ff4c86
d371fbe
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Lists the last STT inputs with audio players. All text is inserted with textContent.
const $ = (id) => document.getElementById(id);

function dl(rows) {
  const el = document.createElement("dl");
  for (const [k, v] of rows) {
    if (v === undefined || v === null || v === "") continue;
    const dt = document.createElement("dt");
    dt.textContent = k;
    const dd = document.createElement("dd");
    dd.textContent = typeof v === "object" ? JSON.stringify(v) : String(v);
    el.append(dt, dd);
  }
  return el;
}

function render(entry) {
  const li = document.createElement("li");
  li.className = "card";
  const head = document.createElement("div");
  head.className = "row";
  const title = document.createElement("strong");
  title.textContent = entry.transcript ? `„${entry.transcript}”` : "(brak transkryptu)";
  const when = document.createElement("span");
  when.className = "muted";
  when.textContent = `${entry.name} · ${entry.created_at}`;
  head.append(title, when);
  const audio = document.createElement("audio");
  audio.controls = true;
  audio.preload = "none";
  audio.src = `/api/debug/stt/${entry.name}.wav`;
  const d = entry.decode || {};
  const g = entry.gate || {};
  const vad = entry.vad || {};
  li.append(head, audio, dl([
    ["Czas audio [s]", `${entry.seconds} (mowa ${entry.speech_seconds}, cisza dodana z każdej strony ${entry.pad_seconds})`],
    ["Poziom / szczyt", `${entry.rms_dbfs} dBFS / ${entry.peak}`],
    ["STT [ms]", entry.stt_ms],
    ["Język / zadanie do Whispera", d.forced_language ? `${d.forced_language} / ${d.task}` : null],
    ["Tokeny dekodera", (d.decoder_prompt || []).join(" ")],
    ["Język bez wymuszenia", d.detected_language ? `${d.detected_language} (${d.detected_prob}); pl: ${d.forced_prob}` : null],
    ["avg logprob / brak mowy", d.avg_logprob !== undefined ? `${d.avg_logprob} / ${d.no_speech_prob}` : null],
    ["Bramka", g.action ? `${g.action}: ${g.reason}; usłyszano „${g.heard}”${g.matched ? `, dopasowano „${g.matched}” (${g.score})` : ""}` : null],
    ["VAD", vad],
    ["Ścieżka", entry.route],
    ["Błąd", entry.error],
  ]));
  return li;
}

async function load() {
  const list = $("entries");
  list.replaceChildren();
  try {
    const r = await fetch("/api/debug/stt", { cache: "no-store" });
    if (!r.ok) throw new Error(`HTTP ${r.status}`);
    const data = await r.json();
    $("count").textContent = `${data.entries.length} z ${data.keep} wpisów`;
    for (const e of data.entries) list.append(render(e));
    if (!data.entries.length) $("count").textContent = "Brak wpisów: powiedz coś do Kosa.";
  } catch (err) {
    $("count").textContent = `Błąd odczytu: ${err.message}`;
    $("count").className = "bad";
  }
}

$("reload").addEventListener("click", load);
load();