diff --git a/.github/skills/cracktro/SKILL.md b/.github/skills/cracktro/SKILL.md index 925752ccb34..914402f3c38 100644 --- a/.github/skills/cracktro/SKILL.md +++ b/.github/skills/cracktro/SKILL.md @@ -88,7 +88,7 @@ A PR that adds or changes a slide must show it: upload a 16:9 `.stage` capture ( - `docs/public/cracktro/fonts/`: Monaspace Neon plus its OFL licence. Mona Sans comes from `docs/public/fonts/`. - `docs/public/cracktro/wizard.js`: `window.CracktroWizard`, a choose-your-own-adventure dialog replaying githubnext/gh-aw-wizard (W, dock button via `create({ wizard })`), loaded with `wizard-data.js` before `deck.js`. `wizard-data.js` is generated by `refresh/wizard.mjs` (`refresh/wizard.md`); never edit it by hand. -- `cracktro/captions.js`: kiosk closed captions (C), generated by the docs build and dev server (`docs/src/lib/cracktro/`) from the `slides.md` Captions fields; not in `docs/public/`. +- `cracktro/captions.js`: kiosk closed captions (C), also read aloud by the voice (V, browser `speechSynthesis`; button disabled where unsupported), generated by the docs build and dev server (`docs/src/lib/cracktro/`) from the `slides.md` Captions fields; not in `docs/public/`. - `docs/tests/talk.spec.ts`: Playwright tests of the deck, runtime, parser and built JSON-LD against `slides.md`. - `docs/src/lib/cracktro/`: `slides.js` parses `slides.md` and renders JSON-LD; `integration.js` (Astro) applies it. - `docs/README.md` "Interactive talk": user-facing description (keys, public-content rules). diff --git a/.github/skills/cracktro/slides.md b/.github/skills/cracktro/slides.md index 9ca558bcca0..368e0e7154d 100644 --- a/.github/skills/cracktro/slides.md +++ b/.github/skills/cracktro/slides.md @@ -32,7 +32,7 @@ sandbox, firewall, read-only token - **Notes** (optional): `illustrative` when the speaker notes must match `/illustrative|synthetic|simulated/i`; omit the field otherwise. - **Summary**: one public sentence with the slide's executive takeaway. Start band headers with `Band header ():`. Describe the durable point, not measured counts or dates that age. No URLs, handles or slide numbers. - **Keywords**: comma-separated public search terms a viewer might type for this slide: synonyms, acronyms, feature and option names, pattern names. Prefer terms absent from the Heading and Summary; each must be accurate for the slide. No URLs, handles or slide numbers. -- **Captions**: the kiosk closed captions (C): a short two-speaker TV news conversation retelling the Summary, one `- ` list item per turn, at least two turns, alternating speakers (each turn a sentence or two). Public, plain text: no URLs, handles, slide numbers, real people or mascot names. +- **Captions**: the kiosk closed captions (C), also spoken by the voice (V): a short two-speaker TV news conversation retelling the Summary, one `- ` list item per turn, at least two turns, alternating speakers (each turn a sentence or two). Public, plain text: no URLs, handles, slide numbers, real people or mascot names. A field's lines join with spaces, so long text may wrap. `docs/src/lib/cracktro/slides.js` parses this file and fails, with the line number, on a malformed slide title, an invalid Id, an unknown, repeated, missing or out-of-order field, an empty Heading, Summary, keyword or caption turn, fewer than two caption turns, an unknown Notes value or a duplicate. The docs build injects every slide into the talk page's JSON-LD (`hasPart`: position, name, description, keywords, `#` URL); the deck's fuzzy search (`/`) reads keywords from there, and `docs/tests/talk.spec.ts` checks the deck's ids, headings and that metadata against this list. The build and dev server also generate `cracktro/captions.js` (`window.CracktroCaptions`) from the Captions fields; it is never committed, so the plain `python3 -m http.server` preview has no captions and kiosk CC falls back to each slide's notes. diff --git a/docs/README.md b/docs/README.md index ce7153b803b..59b90106001 100644 --- a/docs/README.md +++ b/docs/README.md @@ -108,7 +108,10 @@ button or leaving fullscreen stops kiosk mode. Kiosk mode starts with closed cap CC button in the kiosk dock) turns them off or on, and the choice holds for later kiosk runs. Like a muted TV in a bar or airport, a short two-speaker news conversation about each slide rolls in as captions at the bottom of the screen, and each slide stays up until its conversation ends. C starts kiosk mode if needed, and captions end with it; while it runs, Escape stops it before it -hides notes. A manual move restarts the countdown, and an open +hides notes. V (or the voice button beside CC in the kiosk dock) reads the same conversation aloud +with the browser's built-in speech synthesis, alternating two voices (or two pitches), and holds each slide until +its last line is spoken (at most 60 s past the slide's dwell); voice is off by default, starts kiosk mode if needed, ends with it, and the choice holds for +later kiosk runs. Where the browser has no speech synthesis the voice button is disabled. A manual move restarts the countdown, and an open dialog holds the current slide. The slide map button (or G) opens a full-screen grid of every slide under its band's title, each pattern's examples beside it, with the current slide focused and the tiles fanning in from it; arrows move between tiles and Enter or a click jumps there. The search button next to the sound toggle (or `/`, diff --git a/docs/public/cracktro/runtime.d.ts b/docs/public/cracktro/runtime.d.ts index a0115b2defd..5519a77f39d 100644 --- a/docs/public/cracktro/runtime.d.ts +++ b/docs/public/cracktro/runtime.d.ts @@ -111,6 +111,8 @@ declare namespace CracktroDeck { kiosk(on?: boolean): boolean; /** Start (`true`), stop (`false`) or toggle closed captioning (CC); starting it starts kiosk mode, stopping kiosk mode stops it. Returns whether it is on. */ captions(on?: boolean): boolean; + /** Start (`true`), stop (`false`) or toggle the voice (V): browser speech synthesis reads the caption lines aloud; starting it starts kiosk mode, stopping kiosk mode stops it. Always `false` where the browser lacks speech synthesis. Returns whether it is on. */ + voice(on?: boolean): boolean; } interface API { diff --git a/docs/public/cracktro/runtime.js b/docs/public/cracktro/runtime.js index a25a37d8df6..e453b6ce2c1 100644 --- a/docs/public/cracktro/runtime.js +++ b/docs/public/cracktro/runtime.js @@ -85,8 +85,8 @@ body.light .dots button { background: #1f232833; } body.light .dots button.hd { background: transparent; box-shadow: inset 0 0 0 2px #1f232859; } body.light .dots button.on { background: #1f2328; box-shadow: none; } - body.light .snd, body.light .fzb, body.light .smb, body.light .ntb, body.light .ksb, body.light .ccb, body.light .wzb, body.light .arrows button { border-color: #9ea7b3; background: #e6eaefcc; color: #424a53; } - body.light .snd:hover, body.light .fzb:hover, body.light .smb:hover, body.light .ntb:hover, body.light .ksb:hover, body.light .ccb:hover, body.light .wzb:hover, body.light .arrows button:hover { color: #1f2328; border-color: #818b98; } + body.light .snd, body.light .fzb, body.light .smb, body.light .ntb, body.light .ksb, body.light .ccb, body.light .vcb, body.light .wzb, body.light .arrows button { border-color: #9ea7b3; background: #e6eaefcc; color: #424a53; } + body.light .snd:hover, body.light .fzb:hover, body.light .smb:hover, body.light .ntb:hover, body.light .ksb:hover, body.light .ccb:hover, body.light .vcb:hover, body.light .wzb:hover, body.light .arrows button:hover { color: #1f2328; border-color: #818b98; } /* research prototype badge on every gh cao slide (top right, clear of the chrome) */ .proto { position: absolute; right: 110px; top: 76px; display: flex; align-items: center; gap: 14px; padding: 12px 22px; border: 2px dashed #e3b341; border-radius: 999px; background: #0d1117cc; font: 600 20px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: #e3b341; z-index: 5; } .proto i { width: 12px; height: 12px; border-radius: 50%; background: #e3b341; box-shadow: 0 0 12px #e3b341; animation: proto-blink 1.6s ease-in-out infinite; } @@ -174,10 +174,10 @@ body.compact-nav.nav-idle :is(.arrows, .vnb, .snd, .fzb, .smb, .ntb, .ksb, .wzb, .tourp) { opacity: .4; } body.compact-nav.nav-idle :is(.arrows:has(:focus-visible), .vnb:focus-visible, .snd:focus-visible, .fzb:focus-visible, .smb:focus-visible, .ntb:focus-visible, .ksb:focus-visible, .wzb:focus-visible, .tourp:has(:focus-visible)) { opacity: 1; } @media (prefers-reduced-motion: reduce) { body.compact-nav :is(.arrows, .vnb, .snd, .fzb, .smb, .ntb, .ksb, .wzb, .tourp) { transition: none; } } - .snd, .fzb, .smb, .ntb, .ksb, .ccb, .wzb { position: fixed; right: calc(24px + var(--sr)); bottom: calc(10px + var(--sb)); width: 34px; height: 34px; padding: 6px; border: 1px solid #3d444d; border-radius: 8px; + .snd, .fzb, .smb, .ntb, .ksb, .ccb, .vcb, .wzb { position: fixed; right: calc(24px + var(--sr)); bottom: calc(10px + var(--sb)); width: 34px; height: 34px; padding: 6px; border: 1px solid #3d444d; border-radius: 8px; background: #151b23cc; color: #9198a1; cursor: pointer; z-index: 5; transition: color .2s, border-color .2s, background .2s; } - .snd:hover, .fzb:hover, .smb:hover, .ntb:hover, .ksb:hover, .ccb:hover, .wzb:hover { color: #f0f6fc; border-color: #9198a1; } - .snd svg, .fzb svg, .smb svg, .ntb svg, .ksb svg, .ccb svg, .wzb svg { width: 100%; height: 100%; display: block; } + .snd:hover, .fzb:hover, .smb:hover, .ntb:hover, .ksb:hover, .ccb:hover, .vcb:hover, .wzb:hover { color: #f0f6fc; border-color: #9198a1; } + .snd svg, .fzb svg, .smb svg, .ntb svg, .ksb svg, .ccb svg, .vcb svg, .wzb svg { width: 100%; height: 100%; display: block; } .fzb { right: calc(64px + var(--sr)); } .smb { right: calc(104px + var(--sr)); } .ntb { right: calc(144px + var(--sr)); } @@ -202,6 +202,14 @@ body.kiosk.nav-idle .ccb:not(:focus-visible) { opacity: 0; } body.light.kiosk .ccb { color: #1f2328; border-color: #1f2328; } .ccb[aria-pressed="true"] { box-shadow: inset 0 -3px currentColor; } + /* voice (V): kiosk mode reads each slide's caption lines aloud with the browser's own speech synthesis; the button + sits beside CC in the kiosk dock and stays disabled where the browser has no speech synthesis */ + .vcb { display: none; } + body.kiosk .vcb { display: block; right: calc(64px + var(--sr)); opacity: 1; color: #f0f6fc; border-color: #f0f6fc; transition: opacity .4s, color .2s, border-color .2s; } + body.kiosk.nav-idle .vcb:not(:focus-visible) { opacity: 0; } + body.light.kiosk .vcb { color: #1f2328; border-color: #1f2328; } + .vcb[aria-pressed="true"] { box-shadow: inset 0 -3px currentColor; } + body.kiosk .vcb:disabled { opacity: .35; cursor: not-allowed; } .cc { position: fixed; inset: 0; z-index: 4; pointer-events: none; overflow: hidden; display: none; } body.cc-on .cc { display: block; } .cc-f { position: absolute; left: 50%; top: 50%; width: ${W}px; height: ${H}px; transform-origin: 0 0; } @@ -820,6 +828,22 @@ }); ccb.innerHTML = ''; + // voice (V): text-to-speech of the caption lines in kiosk mode, only where the browser supports speech synthesis + /** @type {any} */ + const TTS = typeof window.speechSynthesis?.speak === "function" && typeof window.SpeechSynthesisUtterance === "function" ? window.speechSynthesis : null; + const vcb = h("button", { + class: "vcb", + type: "button", + "aria-pressed": "false", + "aria-keyshortcuts": "V", + onclick: e => { + e.stopPropagation(); + toggleVoice(); + }, + }); + vcb.disabled = !TTS; + vcb.innerHTML = + ''; // tour pill (top right, only during a tour): the tour title and position open the map; × shows every slide again const tourT = h("span", { class: "tourp-t" }), tourN = h("span", { class: "tourp-n" }); @@ -869,7 +893,10 @@ // kiosk mode starts captioned; turning CC off keeps it off for later kiosk runs until it is turned back on let capOn = false, capPref = true; - document.body.append(canvas, wash, gridc, stage, ccEl, progress, dots, arrows, vnb, ksb, ccb, ...(wzBtn ? [wzBtn] : []), notesBtn, smBtn, fzBtn, ...(config.sound ? [snd] : []), notes, tourP); + // voice is opt-in; once turned on it holds for later kiosk runs until it is turned off + let voiceOn = false, + voicePref = false; + document.body.append(canvas, wash, gridc, stage, ccEl, progress, dots, arrows, vnb, ksb, ccb, vcb, ...(wzBtn ? [wzBtn] : []), notesBtn, smBtn, fzBtn, ...(config.sound ? [snd] : []), notes, tourP); // the pressed state (sound on) and the struck-out icon (.off) always follow the sound service const paintSound = () => { snd.classList.toggle("off", !!sfx.muted); @@ -924,7 +951,7 @@ // still rotate in the window. Escape, K, the button or leaving fullscreen stop it; a manual move restarts the // countdown. One timer at a time, cleared on every re-arm and stop. const KIOSK_MS = Math.max(1000, Number(config.kioskInterval) || 15000); - /** @type {{ t: ReturnType | null, full: boolean, entered: boolean } | null} */ + /** @type {{ t: ReturnType | null, hold: number, full: boolean, entered: boolean } | null} */ let kiosk = null; /** @type {any} */ const doc = document; @@ -941,17 +968,25 @@ } return cur; }; - const kioskArm = () => { + /** @param {number} [ms] */ + const kioskArm = ms => { if (!kiosk) return; clearTimeout(kiosk.t); + // a fresh countdown (new slide, manual move, toggle) restarts the voice hold; only the 500 ms re-polls keep it + if (ms == null) kiosk.hold = 0; kiosk.t = setTimeout( () => { if (!kiosk) return; + // hold the slide while its voice is still speaking, for at most VOICE_HOLD_MS past the dwell (see "voice" below) + if (voiceBusy()) { + if (!kiosk.hold) kiosk.hold = performance.now(); + if (performance.now() - kiosk.hold < VOICE_HOLD_MS) return kioskArm(500); + } // hold the slide while any dialog (search, map, a deck's own modal) is open if (!document.querySelector("dialog[open], [aria-modal='true']")) go(kioskNext()); kioskArm(); }, - capOn ? Math.max(KIOSK_MS, capDwell(cur)) : KIOSK_MS + ms ?? (capOn ? Math.max(KIOSK_MS, capDwell(cur)) : KIOSK_MS) ); }; const paintKiosk = () => { @@ -970,7 +1005,7 @@ on = !!on; if (on === !!kiosk) return on; if (on) { - kiosk = { t: null, full: !!fsEl(), entered: false }; + kiosk = { t: null, hold: 0, full: !!fsEl(), entered: false }; const k = kiosk; if (config.sound && !sfx.muted) sfx.unlock?.(); const de = doc.documentElement, @@ -989,11 +1024,13 @@ } kioskArm(); if (capPref) setCap(true); + if (voicePref) setVoice(true); } else { const k = kiosk; clearTimeout(k.t); kiosk = null; if (capOn) setCap(false); + if (voiceOn) setVoice(false); // leave the fullscreen kiosk mode asked for, not one the presenter already had if (k.entered && fsEl()) exitFs(); } @@ -1136,6 +1173,7 @@ slides[n].enter?.(dir); chrome(n); if (capOn) capEnter(); + if (voiceOn) voiceEnter(); kioskArm(); } // progress, dots, dock buttons, notes and hash for slide n (also refreshed when a tour starts or ends) @@ -1306,6 +1344,7 @@ else if (e.key === "f" || e.key === "F") toggleFullscreen(); else if ((e.key === "k" || e.key === "K") && !e.repeat && !target.closest?.("input, textarea, select, [contenteditable]")) setKiosk(!kiosk); else if ((e.key === "c" || e.key === "C") && !e.repeat && !target.closest?.("input, textarea, select, [contenteditable]")) toggleCap(); + else if ((e.key === "v" || e.key === "V") && !e.repeat && !target.closest?.("input, textarea, select, [contenteditable]")) toggleVoice(); else if (e.key === "Escape" && kiosk && !e.defaultPrevented) { e.preventDefault(); setKiosk(false); @@ -1748,7 +1787,7 @@ ], [ "Show", - [[["N"], "Speaker notes"], [["F"], "Fullscreen"], [["K"], "Kiosk: auto-advance (Esc stops)"], [["C"], "Closed captioning (CC) in kiosk mode"], ...SOUND_KEYS, [["X"], "Leave the tour or view"], [["Esc"], "Close notes or dialogs"]], + [[["N"], "Speaker notes"], [["F"], "Fullscreen"], [["K"], "Kiosk: auto-advance (Esc stops)"], [["C"], "Closed captioning (CC) in kiosk mode"], [["V"], "Voice: read captions aloud in kiosk mode"], ...SOUND_KEYS, [["X"], "Leave the tour or view"], [["Esc"], "Close notes or dialogs"]], ], [ "Slide map", @@ -1833,6 +1872,7 @@ F: "full", K: "kiosk", C: "CC", + V: "voice", M: "sound", X: "leave", Esc: "close", @@ -2409,6 +2449,94 @@ const toggleCap = () => setCap((capPref = !capOn)); paintCap(); + // ---------- voice ---------- + // V (or the voice button in the kiosk dock) reads each slide's caption lines aloud with the browser's native + // speech synthesis (no network, no audio files: only voices with localService are used, never the unspecified + // browser default, so a browser with no local voice, or one still loading its list, stays silent), alternating two + // voices (or two pitches) for the two speakers. + // Without speechSynthesis the button stays disabled and V does nothing. Voice starts kiosk mode if needed, ends with + // it, and holds a kiosk slide until its last line is spoken: at most VOICE_HOLD_MS past the dwell, timed from the + // dwell's end and restarted with every new countdown, so a stalled engine never freezes the rotation. The first + // utterance is spoken inside the V or K gesture that turned it on. + const VOICE_HOLD_MS = 60000; + /** @type {{ done: boolean } | null} */ + let vc = null; + // Web Speech only tunes voice, rate, pitch and volume (no styles; browsers ignore SSML), so a relaxed sports-anchor + // read comes from ranking voices (natural/neural first, warm broadcast-style names next, novelty and robotic voices + // never), a touch lower pitch and an unhurried rate; each caption line is its own utterance, so lines get a beat. + const VOICE_RATE = 0.98, + VOICE_PITCH = 0.92; + const VOICE_NOVELTY = /\b(albert|bad news|bahh|bells|boing|bubbles|cellos|wobble|deranged|good news|hysterical|jester|junior|organ|princess|superstar|trinoids|whisper|zarvox)\b/i, + VOICE_ROBOTIC = /\b(eddy|flo|grandma|grandpa|reed|rocko|sandy|shelley|fred|ralph|kathy|espeak)\b/i, + VOICE_NATURAL = /natural|neural|premium|enhanced|studio/i, + VOICE_ANCHOR = /\b(andrew|guy|davis|brian|christopher|eric|roger|steffan|aria|jenny|ava|emma|michelle|evan|nathan|tom|alex|aaron|samantha|allison|zoe|daniel)\b/i; + const voiceScore = (/** @type {SpeechSynthesisVoice} */ v) => + (VOICE_NATURAL.test(v.name) ? 4 : 0) + (VOICE_ANCHOR.test(v.name) ? 2 : 0) + (VOICE_ROBOTIC.test(v.name) ? -3 : 0); + const voicePick = () => { + const all = (TTS.getVoices?.() || []).filter(v => v.localService && !VOICE_NOVELTY.test(v.name)), + lang = (document.documentElement.lang || navigator.language || "en").slice(0, 2).toLowerCase(), + mine = all.filter(v => String(v.lang || "").toLowerCase().startsWith(lang)), + pool = (mine.length ? mine : all).map((v, i) => ({ v, s: voiceScore(v) * 100 - i })).sort((a, b) => b.s - a.s).map(x => x.v), + first = pool[0] || null; + return [first, pool[1] || first]; + }; + let voiceWait = false; + function voiceEnter() { + if (!TTS) return; + TTS.cancel(); + const s = { done: false }; + vc = s; + const lines = capLines(cur).map(String).filter(Boolean), + voices = voicePick(); + if (!lines.length) return void (s.done = true); + if (!voices[0]) { + // no local voice: release the slide; voices load asynchronously, so speak this slide once they arrive + s.done = true; + if (!voiceWait && !(TTS.getVoices?.() || []).length && TTS.addEventListener) { + voiceWait = true; + TTS.addEventListener("voiceschanged", () => ((voiceWait = false), voiceOn && vc === s && voiceEnter()), { once: true }); + } + return; + } + lines.forEach((line, turn) => { + const u = new SpeechSynthesisUtterance(line); + const v = voices[turn % 2]; + u.voice = v; + u.lang = v.lang; + // one voice for both speakers: a lower and a higher pitch tell them apart + u.pitch = voices[0] === voices[1] && turn % 2 ? VOICE_PITCH + 0.2 : VOICE_PITCH; + u.rate = VOICE_RATE; + if (turn === lines.length - 1) u.onend = u.onerror = () => (s.done = true); + TTS.speak(u); + }); + } + const voiceBusy = () => !!(vc && !vc.done); + const paintVoice = () => { + const lbl = !TTS ? "Voice is not supported in this browser" : voiceOn ? "Turn off the voice" : "Turn on the voice: read captions aloud"; + vcb.setAttribute("aria-pressed", String(voiceOn)); + vcb.setAttribute("aria-label", TTS ? `${lbl} (V)` : lbl); + vcb.title = TTS ? `${lbl} (V)` : lbl; + }; + function setVoice(on) { + on = !!on && !!TTS; + if (on === voiceOn) return on; + voiceOn = on; + if (on) { + if (!kiosk) setKiosk(true); + voiceEnter(); + } else { + vc = null; + TTS?.cancel(); + } + paintVoice(); + kioskArm(); + return on; + } + const toggleVoice = () => { + if (TTS) setVoice((voicePref = !voiceOn)); + }; + paintVoice(); + // ---------- animated background ---------- const ctx = canvas.getContext("2d"); const hex = c => [1, 3, 5].map(i => parseInt(c.slice(i, i + 2), 16)); @@ -2517,7 +2645,7 @@ setView(v); if (v) go(firstVis()); }; - return { slides, rows, go, next, prev, band, current: () => cur, tour, tours: () => Object.keys(TOURS), kiosk: on => setKiosk(on ?? !kiosk), captions: on => setCap((capPref = on ?? !capOn)) }; + return { slides, rows, go, next, prev, band, current: () => cur, tour, tours: () => Object.keys(TOURS), kiosk: on => setKiosk(on ?? !kiosk), captions: on => setCap((capPref = on ?? !capOn)), voice: on => setVoice((voicePref = (on ?? !voiceOn) && !!TTS)) }; } window.CracktroDeck = { h, letters, resetIndex, create }; diff --git a/docs/tests/talk.spec.ts b/docs/tests/talk.spec.ts index fa30961b486..dcc47145225 100644 --- a/docs/tests/talk.spec.ts +++ b/docs/tests/talk.spec.ts @@ -1826,6 +1826,144 @@ test.describe("reusable runtime", () => { expect(errors).toEqual([]); }); + test("reads the caption lines aloud with browser speech synthesis and holds the kiosk slide until they end", async ({ page }) => { + await page.clock.install(); + await fakeFullscreen(page); + // a fake engine: speaks one utterance at a time for 15 s each, so two lines outlast the 15 s kiosk dwell + await page.addInitScript(() => { + const w = window as unknown as { spoken: string[]; voices: string[]; speechSynthesis: unknown; SpeechSynthesisUtterance: unknown }; + w.spoken = []; + w.voices = []; + // fake voices are plain objects, which the native voice setter rejects, so the utterance keeps its own + class Utterance extends SpeechSynthesisUtterance {} + const picked = new WeakMap(); + Object.defineProperty(Utterance.prototype, "voice", { + get() { + return picked.get(this) ?? null; + }, + set(v) { + picked.set(this, v); + }, + }); + w.SpeechSynthesisUtterance = Utterance; + let queue: SpeechSynthesisUtterance[] = []; + let timer: ReturnType | undefined; + const run = () => { + const u = queue[0]; + if (!u) return; + w.spoken.push(u.text); + w.voices.push((u.voice as { name: string } | null)?.name ?? ""); + timer = setTimeout(() => { + queue.shift(); + u.dispatchEvent(new Event("end")); + run(); + }, 15000); + }; + Object.defineProperty(window, "speechSynthesis", { + configurable: true, + value: { + // only local voices are used: the remote voice ranks higher but would need the network + getVoices: () => [ + { name: "Remote Natural Online", lang: "en-US", localService: false }, + { name: "Local Alex", lang: "en-US", localService: true }, + ], + speak: (u: SpeechSynthesisUtterance) => queue.push(u) === 1 && run(), + cancel: () => { + clearTimeout(timer); + queue = []; + }, + }, + }); + }); + const { errors } = await open(page, "/gh-aw/cracktro/tiny.html?cc&fs=none#hello"); + const voice = page.locator(".vcb"); + const spoken = () => page.evaluate(() => (window as unknown as { spoken: string[] }).spoken); + await expect(voice).toBeHidden(); + // voice is off by default: kiosk mode alone starts silent + await page.keyboard.press("k"); + await expect(page.locator("body")).toHaveClass(/\bkiosk\b/); + await expect(voice).toHaveAttribute("aria-pressed", "false"); + expect(await spoken()).toEqual([]); + await page.keyboard.press("Escape"); + await expect(page.locator("body")).not.toHaveClass(/\bkiosk\b/); + // V starts kiosk mode with the voice on and speaks the slide's first line from that gesture + await page.keyboard.press("v"); + await expect(page.locator("body")).toHaveClass(/\bkiosk\b/); + await expect(voice).toBeVisible(); + await expect(voice).toBeEnabled(); + await expect(voice).toHaveAttribute("aria-pressed", "true"); + await expect(voice).toHaveAttribute("title", "Turn off the voice (V)"); + expect(await spoken()).toEqual(["Good evening, the top story."]); + // the slide waits past its dwell until the second line ends (30 s) + await page.clock.runFor(20000); + await expect(heading(page)).toHaveText("Hello"); + expect(await spoken()).toEqual(["Good evening, the top story.", "Thanks, glad to be here."]); + expect(await page.evaluate(() => (window as unknown as { voices: string[] }).voices)).toEqual(["Local Alex", "Local Alex"]); + await page.clock.runFor(11000); + await expect(heading(page)).not.toHaveText("Hello"); + // the button turns it off without leaving kiosk mode; Escape ends kiosk mode, and the choice holds for the next run + await voice.click(); + await expect(voice).toHaveAttribute("aria-pressed", "false"); + await expect(page.locator("body")).toHaveClass(/\bkiosk\b/); + await page.keyboard.press("v"); + await expect(voice).toHaveAttribute("aria-pressed", "true"); + await page.keyboard.press("Escape"); + await expect(page.locator("body")).not.toHaveClass(/\bkiosk\b/); + await expect(voice).toHaveAttribute("aria-pressed", "false"); + await page.keyboard.press("k"); + await expect(voice).toHaveAttribute("aria-pressed", "true"); + expect(errors).toEqual([]); + }); + + test("releases a kiosk slide whose voice never ends 60 s after its dwell, not after its entry", async ({ page }) => { + await page.clock.install(); + await fakeFullscreen(page); + // a stalled engine: accepts utterances but never fires end or error + await page.addInitScript(() => { + // fake voices are plain objects, which the native voice setter rejects, so the utterance keeps its own + class Utterance extends SpeechSynthesisUtterance {} + const picked = new WeakMap(); + Object.defineProperty(Utterance.prototype, "voice", { + get() { + return picked.get(this) ?? null; + }, + set(v) { + picked.set(this, v); + }, + }); + (window as unknown as { SpeechSynthesisUtterance: unknown }).SpeechSynthesisUtterance = Utterance; + Object.defineProperty(window, "speechSynthesis", { + configurable: true, + value: { getVoices: () => [{ name: "Local Alex", lang: "en-US", localService: true }], speak: () => {}, cancel: () => {} }, + }); + }); + const { errors } = await open(page, "/gh-aw/cracktro/tiny.html?cc&fs=none#hello"); + await page.keyboard.press("v"); + await expect(page.locator("body")).toHaveClass(/\bkiosk\b/); + // dwell (15 s) plus most of the hold: still on the slide well past 60 s from entry + await page.clock.runFor(15000 + 59000); + await expect(heading(page)).toHaveText("Hello"); + await page.clock.runFor(2000); + await expect(heading(page)).not.toHaveText("Hello"); + expect(errors).toEqual([]); + }); + + test("disables the voice button where the browser has no speech synthesis", async ({ page }) => { + await page.clock.install(); + await fakeFullscreen(page); + await page.addInitScript(() => Object.defineProperty(window, "speechSynthesis", { configurable: true, value: undefined })); + const { errors } = await open(page, "/gh-aw/cracktro/tiny.html?cc&fs=none#hello"); + const voice = page.locator(".vcb"); + await page.keyboard.press("v"); + await expect(page.locator("body")).not.toHaveClass(/\bkiosk\b/); + await page.keyboard.press("k"); + await expect(voice).toBeVisible(); + await expect(voice).toBeDisabled(); + await expect(voice).toHaveAttribute("aria-pressed", "false"); + await expect(voice).toHaveAttribute("title", "Voice is not supported in this browser"); + expect(errors).toEqual([]); + }); + test("rolls a long caption turn up a row at a time under reduced motion, showing its opening before it scrolls off", async ({ page }) => { await page.emulateMedia({ reducedMotion: "reduce" }); await page.clock.install();