mirror of
https://github.com/bitbaum/heidi.git
synced 2026-12-04 05:17:27 +01:00
The listening lab, built on the media that already exist. A learner follows
YouTube channels they watch anyway (a link, a video link or the @handle, or
one of the register's rows with what is spoken beside it); Heidi reads each
channel's public Atom feed — no API key — hourly on the box and inline when
the page opens, lists what is new since the last visit, and sends a Web Push
to the browsers that asked. Following rings for the next video, never the
back catalogue, and nothing here reminds anyone to practise.
One video is the lab's exercise in HEIDI.md's order: a gist question before
the first listen, three to five detail questions in the bridge after it,
each wrong answer answered with the line that was said and a button that
plays that second (IFrame API seek), then the transcript, tap a line to hear
it. A count with its denominator, no score. What was answered stays in the
browser (heidi.videos.v1) and feeds the streak.
The transcript is the platform's captions, in a language the pack accepts
(lib/channels/accepted.ts: the target, then sibling/roof bridges; never a
gloss language; automatic captions only where the pack trusts the
recogniser), and its source is printed every time: the publisher's,
automatic («bei Mundart oft falsch») or pasted. YouTube refuses data-centre
addresses the caption tracks often enough that the refusal is a first-class
state: the screen then shows the three steps to copy the transcript from
YouTube's own panel, and parsePasted reads that format, SRT and WebVTT.
Questions are written by the model from the transcript once per video, on
the first follower's request (never in the sweep — no background job spends
the free pool), refused unless every detail question cites a real line, and
shared with every follower.
Schema: channels, channel_videos, channel_follows, push_subscriptions
(drizzle/0008). Routes: /api/channels, /api/videos/[id]/{transcript,
questions}, /api/cron/channels (bearer CRON_SECRET), /api/push/*. Pages:
/channels, /channels/[video], a dashboard panel, a settings section, an
invitation on /listen. Seven dictionaries, privacy flows, HEIDI.md,
CHANGELOG. The box's hourly timer row is in loki's install-app-crons.sh;
CRON_SECRET and VAPID_* in .env.example.
Claude-Session: https://claude.ai/code/session_01RKRxpcVWoZwtg6Gfr9m6Rb
Co-authored-by: Claude <noreply@anthropic.com>
98 lines
4.8 KiB
TypeScript
98 lines
4.8 KiB
TypeScript
import { test, describe } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { clock, decodeTranscript, excerpt, mergeFragments, parseClock, parsePasted } from "./transcript.ts";
|
|
|
|
describe("a pasted transcript", () => {
|
|
test("the platform's panel copy: a time on one line, the words on the next", () => {
|
|
const lines = parsePasted(["0:00", "Guten Morgen und herzlich willkommen.", "0:04", "Heute geht es um Orangensaft.", "1:02:03", "Das war es für heute."].join("\n"));
|
|
assert.ok(lines);
|
|
assert.equal(lines.length, 3);
|
|
assert.deepEqual(lines[0], { start: 0, end: 4, text: "Guten Morgen und herzlich willkommen." });
|
|
assert.equal(lines[1].start, 4);
|
|
assert.equal(lines[2].start, 3723);
|
|
assert.ok(lines[2].end > lines[2].start, "the last line is given a length");
|
|
});
|
|
|
|
test("the same, with the time and the words on one line, bracketed or not", () => {
|
|
const a = parsePasted("[0:00] Eins zwei drei.\n[0:03] Vier fünf sechs.\n[0:06] Sieben acht neun.");
|
|
const b = parsePasted("0:00 Eins zwei drei.\n0:03 Vier fünf sechs.\n0:06 Sieben acht neun.");
|
|
assert.ok(a && b);
|
|
assert.deepEqual(a.map((l) => l.text), ["Eins zwei drei.", "Vier fünf sechs.", "Sieben acht neun."]);
|
|
assert.deepEqual(a, b);
|
|
});
|
|
|
|
test("WebVTT and SRT cues, with their own end times and wrapped text", () => {
|
|
const vtt = ["WEBVTT", "", "00:00:01.000 --> 00:00:03.500", "Erste Zeile.", "", "00:00:04.000 --> 00:00:06.000", "Zweite Zeile,", "die umbricht.", "", "00:00:07.000 --> 00:00:08.000", "Dritte."].join("\n");
|
|
const lines = parsePasted(vtt);
|
|
assert.ok(lines);
|
|
assert.deepEqual(lines[0], { start: 1, end: 3.5, text: "Erste Zeile." });
|
|
assert.equal(lines[1].text, "Zweite Zeile, die umbricht.");
|
|
const srt = ["1", "00:00:01,000 --> 00:00:03,000", "Eins.", "", "2", "00:00:04,000 --> 00:00:05,000", "Zwei.", "", "3", "00:00:06,000 --> 00:00:07,000", "Drei."].join("\n");
|
|
assert.equal(parsePasted(srt)?.length, 3);
|
|
});
|
|
|
|
test("prose with no times is not a transcript", () => {
|
|
assert.equal(parsePasted("Ein Absatz ohne Zeiten.\nNoch einer.\nUnd noch einer."), null);
|
|
assert.equal(parsePasted(""), null);
|
|
assert.equal(parsePasted("0:00\nNur eine Zeile."), null, "fewer than three lines is a caption, not a transcript");
|
|
});
|
|
|
|
test("clock readings", () => {
|
|
assert.equal(parseClock("0:05"), 5);
|
|
assert.equal(parseClock("12:34"), 754);
|
|
assert.equal(parseClock("1:02:03"), 3723);
|
|
assert.equal(parseClock("00:00:01.250"), 1.25);
|
|
assert.equal(parseClock("00:00:01,5"), 1.5);
|
|
assert.equal(parseClock("1:75"), null);
|
|
assert.equal(parseClock("abc"), null);
|
|
assert.equal(clock(3723), "1:02:03");
|
|
assert.equal(clock(65), "1:05");
|
|
assert.equal(clock(5), "0:05");
|
|
});
|
|
});
|
|
|
|
describe("fragments", () => {
|
|
test("are joined until a sentence ends, a pause falls or the line gets long", () => {
|
|
const merged = mergeFragments([
|
|
{ start: 0, end: 1, text: "und dann hat" },
|
|
{ start: 1, end: 2, text: "er gesagt, dass" },
|
|
{ start: 2, end: 3, text: "es reicht." },
|
|
{ start: 3.2, end: 4, text: "Danach" },
|
|
{ start: 9, end: 10, text: "ging er." },
|
|
]);
|
|
assert.deepEqual(merged.map((l) => l.text), ["und dann hat er gesagt, dass es reicht.", "Danach", "ging er."]);
|
|
assert.deepEqual(merged[0], { start: 0, end: 3, text: "und dann hat er gesagt, dass es reicht." });
|
|
});
|
|
|
|
test("stage directions and blanks are dropped", () => {
|
|
assert.deepEqual(
|
|
mergeFragments([
|
|
{ start: 0, end: 1, text: "[Musik]" },
|
|
{ start: 1, end: 2, text: " " },
|
|
{ start: 2, end: 3, text: "Hallo." },
|
|
]),
|
|
[{ start: 2, end: 3, text: "Hallo." }],
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("the stored shape", () => {
|
|
test("is checked rather than trusted", () => {
|
|
const good = { lines: [{ start: 0, end: 1, text: "a" }, { start: 1, end: 2, text: "b" }, { start: 2, end: 3, text: "c" }], source: "auto", lang: "de" };
|
|
assert.deepEqual(decodeTranscript(good), good);
|
|
assert.equal(decodeTranscript({ ...good, source: "wiki" }), null);
|
|
assert.equal(decodeTranscript({ ...good, lines: good.lines.slice(0, 2) }), null);
|
|
assert.equal(decodeTranscript("nonsense"), null);
|
|
assert.equal(decodeTranscript({ ...good, lines: [...good.lines, { start: "x" }] })?.lines.length, 3, "a bad line is dropped, not fatal");
|
|
});
|
|
|
|
test("the excerpt a question set is written from is whole lines up to a budget", () => {
|
|
const lines = Array.from({ length: 10 }, (_, i) => ({ start: i, end: i + 1, text: "x".repeat(100) }));
|
|
const cut = excerpt(lines, 450);
|
|
assert.equal(cut.lines.length, 4);
|
|
assert.equal(cut.truncated, true);
|
|
assert.equal(excerpt(lines, 5000).truncated, false);
|
|
assert.equal(excerpt([{ start: 0, end: 1, text: "x".repeat(500) }], 100).lines.length, 1, "the first line always fits");
|
|
});
|
|
});
|