← snapshot
1667 bytes
/**
* Proves whisper reaches a real browser session: the page decodes audio,
* runs it through the app's own WAV encoder, uploads it through the Next
* proxy to jac-serve, and renders the transcript whisper.cpp returned.
*
* The microphone itself is not exercised — headless Chromium blocks capture,
* which is why the app has watchdogs for exactly that case. Everything from
* the samples onward is real.
*/
import { chromium } from "@playwright/test";
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1100, height: 950 }, colorScheme: "dark" });
const errs = [];
page.on("pageerror", (e) => errs.push(e.message));
page.on("console", (m) => { if (m.type() === "error") errs.push(m.text()); });
await page.goto("http://localhost:3000/lab/voice", { waitUntil: "networkidle" });
await page.waitForTimeout(1200);
const status = await page.evaluate(() => document.body.innerText);
console.log("whisper reported configured:", status.includes("Audio is transcribed here"));
await page.locator("button", { hasText: "Self-test without the mic" }).click();
await page.waitForFunction(
() => {
const el = document.querySelector('[data-selftest="1"]');
return el && !el.textContent.includes("running");
},
{ timeout: 90000 },
);
const out = await page.locator('[data-selftest="1"]').textContent();
console.log("browser got back:", JSON.stringify(out?.trim()));
console.log("round trip ok :", /thundering herd/i.test(out ?? ""));
await page.screenshot({ path: "tour/lab/voice.png", fullPage: true });
console.log("errors:", errs.length ? [...new Set(errs)].slice(0, 3) : "none");
await browser.close();