// A synthetic reaction stream for the clip finder's tests (release 35 C1): // a host reacting to a narrated video, as the inputs the analysis reads — // speaker turns (diarization.json), words, cues, per-window laugh scores — // and, for the scan tests, its sound. Nothing in it is a recording, a person // or a transcript: the "narration" is numbered filler words, the host says // the same few words, and the laughs are placed by hand. // // speaker 1 (the SUBJECT, the narrated video) talks in long runs; // speaker 0 (the HOST) interjects in the gaps, all the way through; // the host laughs at LAUGHS (strong ones in the gaps, one weak one). // // reactionStream() the inputs, as plain data // writeReactionCorpus(dir, o) a channel on disk: diarization.json, // transcript.cues.json, metadata.info.json, // and (o.audio) the sound as audio.wav // reactionAudio(o) the sound: VOICE_B narrates, VOICE_A interjects, // a laugh is LAUGH_TONE_HZ bursts — what the fake // tagger (fakeAudioTag.mjs) hears as laughter import { mkdirSync, writeFileSync } from "node:fs"; import path from "node:path"; import { VOICE_A, VOICE_B, syntheticVoice } from "../audio/syntheticVoice.mjs"; export const STREAM_SECONDS = 600; export const SUBJECT = 1; export const HOST = 0; /** The subject's runs; the host talks in the gaps between them. */ export const SUBJECT_RUNS = Object.freeze([ [0, 40], [44, 95], [100, 170], [176, 260], [266, 340], [345, 430], [436, 520], [526, 600], ]); /** The host's laughs: [start, end, strength]. 520 is a weak one. */ export const LAUGHS = Object.freeze([ [95, 97.5, 0.8], [340, 342, 0.7], [520, 521, 0.3], ]); /** The tone the synthetic laugh is made of, and the fake tagger listens for. */ export const LAUGH_TONE_HZ = 1500; const HOST_WORDS = ["wow", "that's", "crazy.", "no", "way.", "look", "at", "this."]; /** * @param {{ hop?: number, window?: number, laughWords?: boolean }} [o] * `laughWords`: the host's laughs are also in the words ("haha"), for the * no-model fallback. */ export function reactionStream({ hop = 0.5, window = 1, laughWords = true } = {}) { const turns = []; const gaps = []; SUBJECT_RUNS.forEach(([a, b], i) => { turns.push({ start: a, end: b, speaker: SUBJECT }); const next = SUBJECT_RUNS[i + 1]; if (next) gaps.push([b, next[0]]); }); for (const [a, b] of gaps) turns.push({ start: a, end: b, speaker: HOST }); turns.sort((x, y) => x.start - y.start); const words = []; let k = 0; for (const [a, b] of SUBJECT_RUNS) { // A word every 0.5 s, 0.4 s long; a sentence every 7 words. for (let t = a + 0.2; t + 0.4 <= b - 0.2; t += 0.5) { k += 1; words.push({ w: k % 7 === 0 ? `n${k}.` : `n${k}`, start: round3(t), end: round3(t + 0.4) }); } } for (const [a, b] of gaps) { const laugh = LAUGHS.find(([s]) => s >= a - 0.01 && s < b); let t = a + 0.1; if (laugh && laughWords) { words.push({ w: "haha", start: round3(laugh[0] + 0.2), end: round3(laugh[1] - 0.2) }); t = laugh[1] + 0.1; } let j = 0; for (; t + 0.35 <= b - 0.1; t += 0.45) { words.push({ w: HOST_WORDS[j % HOST_WORDS.length], start: round3(t), end: round3(t + 0.35) }); j += 1; } } words.sort((x, y) => x.start - y.start); // Cues: the words in runs of up to 8, as captions would carry them. const cues = []; for (let i = 0; i < words.length; i += 8) { const run = words.slice(i, i + 8); cues.push({ start: run[0].start, end: run[run.length - 1].end, text: run.map((w) => w.w).join(" ") }); } const n = Math.floor((STREAM_SECONDS - window) / hop) + 1; const scores = Array.from({ length: n }, (_, i) => { const a = i * hop; const b = a + window; const l = LAUGHS.find(([s, e]) => Math.min(b, e) - Math.max(a, s) >= window / 2); return l ? l[2] : 0.02; }); return { duration: STREAM_SECONDS, turns, words, cues, laughScan: { t0: 0, hop, window, scores } }; } const round3 = (x) => Math.round(x * 1000) / 1000; /** * The stream's sound at 16 kHz: VOICE_B over the subject's runs, VOICE_A over * the host's turns, LAUGH_TONE_HZ bursts (5 per second) over each laugh. * @param {{ seconds?: number, rate?: number }} [o] `seconds` cuts it short (a quick test) */ export function reactionAudio({ seconds = STREAM_SECONDS, rate = 16000 } = {}) { const out = new Float32Array(Math.round(seconds * rate)); const { turns } = reactionStream(); for (const t of turns) { if (t.start >= seconds) continue; const end = Math.min(t.end, seconds); const voice = syntheticVoice({ ...(t.speaker === HOST ? VOICE_A : VOICE_B), seconds: end - t.start, rate, phase: t.start, level: 0.25 }); out.set(voice.subarray(0, Math.max(0, out.length - Math.round(t.start * rate))), Math.round(t.start * rate)); } for (const [a, b] of LAUGHS) { if (a >= seconds) continue; for (let i = Math.round(a * rate); i < Math.min(out.length, Math.round(b * rate)); i += 1) { const t = i / rate; const burst = 0.5 - 0.5 * Math.cos(2 * Math.PI * 5 * t); out[i] = 0.5 * burst * Math.sin(2 * Math.PI * LAUGH_TONE_HZ * t); } } return out; } /** * The stream as a channel on disk. Returns the video dir. * @param {string} channelsDir * @param {{ channel?: string, video?: string, diarization?: boolean, audio?: Buffer | null, two?: boolean, chat?: boolean | Record | null, meta?: Record | null }} [o] * `audio`: WAV bytes to write as audio.wav (encodeWav16(reactionAudio())); * `diarization` false leaves diarization.json out; `two`: the two-video * stream (twoVideoStream) instead; `chat`: live_chat.cues.json beside it * (reactionChat's options, `true` for its defaults); `meta`: keys merged * into metadata.info.json (`webpage_url`, `channel`…). */ export function writeReactionCorpus(channelsDir, { channel = "synth-reacts", video = "react001", diarization = true, audio = null, two = false, chat = null, meta = null } = {}) { const s = two ? twoVideoStream() : reactionStream(); const dir = path.join(channelsDir, channel, "data", video); mkdirSync(dir, { recursive: true }); writeFileSync(path.join(channelsDir, channel, "config.json"), JSON.stringify({ name: "Synth Reacts" })); writeFileSync( path.join(dir, "transcript.cues.json"), JSON.stringify({ id: video, title: "Synthetic reaction stream", source: "whisper", duration: s.duration, uploadDate: "20240102", cues: s.cues }), ); writeFileSync(path.join(dir, "metadata.info.json"), JSON.stringify({ id: video, title: "Synthetic reaction stream", duration: s.duration, ...(meta ?? {}) })); if (chat) { const cues = reactionChat({ laughs: two ? TWO_LAUGHS : LAUGHS, duration: s.duration, ...(chat === true ? {} : chat) }); writeFileSync( path.join(dir, "live_chat.cues.json"), JSON.stringify({ version: 1, source: "live_chat", id: video, title: "Synthetic reaction stream", duration: s.duration, cues }), ); } if (diarization) { const speakers = new Set(s.turns.map((t) => t.speaker)).size; writeFileSync( path.join(dir, "diarization.json"), JSON.stringify({ videoId: video, generatedAt: "2026-10-18T00:00:00.000Z", audioSeconds: s.duration, speakers, turns: s.turns, engine: { engine: "sherpa-onnx", threshold: 0.9 } }), ); } if (audio) writeFileSync(path.join(dir, "audio.wav"), audio); return dir; } // ---- release 36: two narrated videos in one stream, and its chat ---------------- // // twoVideoStream() a host (0) introduces, reacts to video A (narrated by 1), // talks a while, reacts to video B (narrated by 2, with a // stray cluster 3 and a pause where the host talks over a // stopped video), then signs off — what auto-scope reads // reactionChat(o) a synthetic chat replay (live_chat.cues.json's cues): // a steady trickle of messages, and a burst of laugh // tokens `lag` seconds after each laugh (chat watches the // stream late), plus `chatOnly` bursts at times with no // laugh at all export const TWO_SECONDS = 2400; export const TWO_HOST = 0; export const TWO_SUBJECT_A = 1; export const TWO_SUBJECT_B = 2; /** Where each video's narration runs (its first line to its last). */ export const TWO_VIDEOS = Object.freeze([ [120, 1100], [1500, 2290], ]); /** The host's laughs in the two-video stream: [start, end, strength], each in a gap of the narration. */ export const TWO_LAUGHS = Object.freeze([ [355, 357.5, 0.8], [775, 777, 0.7], [1615, 1617.5, 0.8], [2135, 2137, 0.7], ]); /** Runs of `run` seconds with `gap` between them over [a, b]. */ function runsOver(a, b, run, gap) { const out = []; for (let t = a; t < b; t += run + gap) out.push([t, Math.min(b, t + run)]); return out; } export function twoVideoStream() { const turns = []; const subjectRuns = []; const hostTurns = []; // The intro: the host alone, in long turns too (he is not a video). hostTurns.push([2, 30], [31, 62], [64, 118]); // Video A: narration in 55 s runs, the host in the 5 s gaps. for (const r of runsOver(120, 1100, 55, 5)) subjectRuns.push([...r, TWO_SUBJECT_A]); // Between the videos: the host talks for 400 s (some long turns). hostTurns.push([1103, 1130], [1132, 1135], [1137, 1180], [1182, 1186], [1190, 1260], [1262, 1266], [1270, 1340], [1342, 1347], [1350, 1420], [1425, 1497]); // Video B: narration in 50 s runs; a stray cluster; the host pauses it at 1800 for 100 s. for (const r of runsOver(1500, 1800, 50, 5)) subjectRuns.push([...r, TWO_SUBJECT_B]); hostTurns.push([1801, 1830], [1832, 1836], [1838, 1870], [1872, 1898]); for (const r of runsOver(1900, 2290, 50, 5)) subjectRuns.push([...r, TWO_SUBJECT_B]); turns.push({ start: 1960.5, end: 1962, speaker: 3 }); // The outro. hostTurns.push([2292, 2330], [2333, 2337], [2340, 2390]); for (const [a, b, s] of subjectRuns) turns.push({ start: a, end: b, speaker: s }); // The host's interjections in the narration's gaps. const gaps = []; for (let i = 0; i + 1 < subjectRuns.length; i += 1) { const [, b] = subjectRuns[i]; const [a2] = subjectRuns[i + 1]; if (a2 - b > 0.5 && a2 - b < 10) gaps.push([b, a2]); } for (const [a, b] of gaps) hostTurns.push([a, b]); for (const [a, b] of hostTurns) turns.push({ start: a, end: b, speaker: TWO_HOST }); turns.sort((x, y) => x.start - y.start || x.speaker - y.speaker); const words = []; let k = 0; for (const [a, b] of subjectRuns) { for (let t = a + 0.2; t + 0.4 <= b - 0.2; t += 0.5) { k += 1; words.push({ w: k % 7 === 0 ? `n${k}.` : `n${k}`, start: round3(t), end: round3(t + 0.4) }); } } for (const [a, b] of hostTurns) { const laugh = TWO_LAUGHS.find(([s]) => s >= a - 0.01 && s < b); let t = a + 0.1; if (laugh) { words.push({ w: "haha", start: round3(laugh[0] + 0.2), end: round3(laugh[1] - 0.2) }); t = laugh[1] + 0.1; } let j = 0; for (; t + 0.35 <= b - 0.1; t += 0.45) { words.push({ w: HOST_WORDS[j % HOST_WORDS.length], start: round3(t), end: round3(t + 0.35) }); j += 1; } } words.sort((x, y) => x.start - y.start); const cues = []; for (let i = 0; i < words.length; i += 8) { const run = words.slice(i, i + 8); cues.push({ start: run[0].start, end: run[run.length - 1].end, text: run.map((w) => w.w).join(" ") }); } const hop = 0.5; const window = 1; const n = Math.floor((TWO_SECONDS - window) / hop) + 1; const scores = Array.from({ length: n }, (_, i) => { const a = i * hop; const b = a + window; const l = TWO_LAUGHS.find(([s, e]) => Math.min(b, e) - Math.max(a, s) >= window / 2); return l ? l[2] : 0.02; }); return { duration: TWO_SECONDS, turns, words, cues, laughScan: { t0: 0, hop, window, scores } }; } const CHAT_LAUGHS = ["LUL", "lmao", "😂", "hahaha", "KEKW", "W", "lol", "🤣", "LMFAO", "OMEGALUL"]; const CHAT_FILLER = ["hello", "what is this", "first time here", "nice", "true", "ok", "is this live", "chat is slow"]; /** * A synthetic chat replay: cues `{start, end, text: ": "}`, * as live_chat.cues.json carries them (normalizeLiveChat: end = start + 5). * @param {{ laughs?: readonly (readonly number[])[], duration?: number, lag?: number, every?: number, burstPerS?: number, burstS?: number, chatOnly?: readonly number[] }} [o] */ export function reactionChat({ laughs = LAUGHS, duration = STREAM_SECONDS, lag = 6, every = 2, burstPerS = 5, burstS = 4, chatOnly = [] } = {}) { const cues = []; let n = 0; for (let t = 0.7; t < duration; t += every) { n += 1; cues.push({ start: round3(t), end: round3(t + 5), text: `viewer${n % 37}: ${CHAT_FILLER[n % CHAT_FILLER.length]}` }); } const bursts = [...laughs.map((l) => l[0] + lag), ...chatOnly]; for (const at of bursts) { for (let i = 0; i < burstPerS * burstS; i += 1) { const t = at + i / burstPerS; if (t >= duration) break; n += 1; cues.push({ start: round3(t), end: round3(t + 5), text: `viewer${n % 37}: ${CHAT_LAUGHS[n % CHAT_LAUGHS.length]}` }); } } return cues.sort((a, b) => a.start - b.start); }