He said ${F} and then ${spaced(F)} again.`;
const toks = scriptTokens(script);
assert.deepEqual(toks.map((t) => t.w), scriptWordsOf(script), "the take's words are one per these");
const words = toks.map((t, i) => ({ w: t.w, start: i, end: i + 0.5 }));
const take = { file: "narration/posts/1/take-1.orpheus-zac.wav", script, words, seconds: 20 };
const s = resolveSlurs({ voice: "beep" }, LIST);
const b = takeBleeps(take, s);
// "He"(0) "said"(1) F(2) "and"(3) "then"(4) f,a,g,g,o,t (5..10) "again."(11)
assert.deepEqual(b, { mode: "beep", spans: [[1.96, 2.56], [4.96, 10.56]] });
assert.equal(takeBleeps(take, resolveSlurs({ voice: "skip" }, LIST)).mode, "mute");
assert.equal(takeBleeps(take, resolveSlurs({}, LIST)).mode, "beep", "the default");
assert.equal(takeBleeps(take, resolveSlurs({ on: false }, LIST)), null);
assert.equal(takeBleeps({ ...take, slurs: "skip" }, s), null, "its audio left them out");
assert.match(takeBleeps({ ...take, words: undefined }, s).error, /no word timings/);
assert.match(takeBleeps({ ...take, words: words.slice(1) }, s).error, /not of its script/);
const f = bleepFilters("v", "vb", b, { seconds: 20 }).join(";");
assert.match(f, /volume=0:enable='between\(t,1\.96,2\.56\)\+between\(t,4\.96,10\.56\)'/);
assert.match(f, /aevalsrc=exprs='0\.18\*sin\(2\*PI\*1000\*t\)/);
assert.doesNotMatch(bleepFilters("v", "vb", { mode: "mute", spans: [[1, 2]] }).join(";"), /aevalsrc/);
});
test("slurReport counts what the cut would mask, per slur and per post; cutSlurState says which a take is", () => {
const tl = [post(`${F} ${F}`, { id: "a" }), post("clean", { id: "b", narration: { script: `${N}` } }), { id: "c", type: "clip" }];
const r = slurReport(tl, resolveSlurs({ on: false }, LIST));
assert.equal(r.total, 3);
assert.deepEqual(r.bySlur["f-slur"], { mask: `${F[0]}*****`, n: 2, posts: ["a"] });
assert.deepEqual(r.posts.map((p) => p.id), ["a", "b"]);
assert.deepEqual(r.posts[1].where, ["script"]);
assert.equal(cutSlurState({ timeline: tl }), "censored");
assert.equal(cutSlurState({ timeline: tl, render: { posts: { slurs: { on: false } } } }), "uncensored");
assert.equal(cutSlurState({ timeline: [{ type: "clip" }] }), null);
assert.equal(cutSlurs({ render: { posts: { slurs: { level: "strong" } } } }).level, "strong");
});
// EDGE MASKS (render.posts.slurs.edges; operator, 5 Nov): the n-word's "-a" form and the f-slur told apart by
// their last letter. The forms are taken from the list by shape, never spelt here.
const NA = byId("n-word").forms.find((f) => f.length === 5 && f.endsWith("a"));
const NAS = byId("n-word").forms.find((f) => f.length === 6 && f.endsWith("s") && f.startsWith(NA.slice(0, 4)));
const NER = byId("n-word").forms.find((f) => f.endsWith("r") && f.length === 6);
const star = (w) => `${w[0]}${"*".repeat(w.length - 2)}${w.at(-1)}`;
test("edge masks: every form of an edged slur its first letter, stars, its last letter, in the case written", () => {
const E = resolveSlurs({ edges: [NA, F] }, LIST);
const shown = (t, s = E) => decodePlaceholder(maskSlurs(t, s).text);
// The operator's examples, by shape: n***a, n****s, f****t, f*****s, N***A.
assert.equal(star(NA), "n***a");
assert.equal(shown(NA), "n***a");
assert.equal(shown(NAS), "n****s");
assert.equal(shown(F), "f****t");
assert.equal(shown(FS), "f*****s");
assert.equal(shown(NA.toUpperCase()), "N***A");
assert.equal(shown(`${NA[0].toUpperCase()}${NA.slice(1)}`), "N***a", "each end in its own case");
// A form names the WHOLE slur: its other forms are edge-masked too (the "-er" one is told apart as well).
assert.equal(shown(NER), "n****r");
// By its id, or its word, the same.
assert.equal(shown(F, resolveSlurs({ edges: ["f-slur"] }, LIST)), "f****t");
assert.equal(shown(NA, resolveSlurs({ edges: [byId("n-word").word] }, LIST)), "n***a");
// A look-alike at an end is read back as its letter; spelt apart, one pill, the rest gaps (the indices hold).
assert.equal(shown(leet(F)), "f****t");
assert.equal(shown(`${NA.slice(0, 4)}@`), "n***a");
assert.equal(shown(`${NA.slice(0, 4)}@`.toUpperCase()), "N***A", "a look-alike end follows an all-caps word");
const sp = maskSlurs(`a ${spaced(F)} b`, E).text;
assert.equal(sp.split(/\s+/).length, `a ${spaced(F)} b`.split(/\s+/).length);
assert.equal(placeholdersHtml(sp), `a f****t${" ".repeat(F.length - 1)} b`);
// Only the slurs named: another keeps its first-letter mask.
assert.equal(shown(R), `${R[0]}${"*".repeat(R.length - 1)}`);
// The card's pill, a caption, the chapter line: all through the one mask.
const html = postCardHtml(post(`you ${F}, ${NA.toUpperCase()}`), { width: 1280, height: 720, redaction: { terms: [], slurs: E } });
assert.ok(html.includes('data-post-slur="">f****t') && html.includes('data-post-slur="">N***A'));
for (const w of [F, NA]) assert.ok(!html.toLowerCase().includes(w));
assert.equal(shownLine(`you ${F}`, post("x"), { terms: [], slurs: E }), "you f****t");
// ls / slurReport: each form's mask the cut draws, "/" between.
const r = slurReport([post(`${F} ${FS} ${F.toUpperCase()}`, { id: "a" })], E);
assert.deepEqual(r.bySlur["f-slur"], { mask: "f****t/f*****s", n: 3, posts: ["a"], edge: true });
// A take's refusal names the edge mask too.
assert.match(takeBleeps({ file: "t.wav", script: `said ${NA}` }, E).error, /\(n\*\*\*a\)/);
// The read is not a mask: the stand-in is said as before.
assert.deepEqual(spokenRead(`a ${NA}`, post("x"), { terms: [], slurs: resolveSlurs({ edges: [NA], voice: "placeholder" }, LIST) }), { text: "a n-word", slurs: "placeholder" });
});
test("edge masks: refused when not words; a cut without edges is unchanged (no key on an entry, the same masks)", () => {
assert.deepEqual(validateSlursRender({ edges: [NA, "f-slur"] }), []);
const errs = validateSlursRender({ edges: "x" }).concat(validateSlursRender({ edges: [3, ""] })).join(" | ");
assert.match(errs, /edges must be a list/);
assert.match(errs, /edges\[0\]/);
assert.match(errs, /edges\[1\]/);
// Without edges: no entry carries `edge`, so the render key and every mask are as before.
assert.ok(ON.entries.every((e) => !("edge" in e)));
assert.deepEqual(resolveSlurs({ edges: [] }, LIST), ON);
assert.equal(decodePlaceholder(maskSlurs(`${NA} ${F.toUpperCase()}`, ON).text), `n***** F*****`);
assert.equal(slurReport([post(`${F} ${FS}`, { id: "a" })], ON).bySlur["f-slur"].mask, `${F[0]}*****`);
});
test("barsHtml draws placeholders and gaps with the redaction's bars", () => {
const html = barsHtml(`${REDACT_MARK.repeat(3)} ${encodePlaceholder("k***")}${SLUR_GAP}`);
assert.equal(html, ` k***`);
});
test("takeSlurBleeps (post-render.mjs): a take's state is its own or its source's; no script of its own reads the post's; refused in the build's words", async () => {
const { takeSlurBleeps } = await import("./post-render.mjs");
const script = `you ${F} there`;
const words = scriptTokens(script).map((t, i) => ({ w: t.w, start: i, end: i + 0.5 }));
const red = { terms: [], slurs: resolveSlurs({ voice: "beep" }, LIST) };
const entry = (takes) => ({ id: "p1", type: "post", narration: { script, takes } });
const tts = { file: "narration/posts/1/take-1.orpheus-zac.wav", seconds: 3, words };
assert.deepEqual(takeSlurBleeps(entry([tts]), tts, red), { mode: "beep", spans: [[0.96, 1.56]], seconds: 3 });
// Skipped at synthesis: nothing to cover -- and a take derived from it reads the same.
const skipped = { ...tts, slurs: "skip", words: undefined };
const derived = { file: "narration/posts/1/take-2.enhance-x.wav", seconds: 3, source: { kind: "take", from: "take-1.orpheus-zac" } };
assert.equal(takeSlurBleeps(entry([skipped, derived]), derived, red), null);
assert.throws(() => takeSlurBleeps(entry([{ ...tts, words: undefined }]), { ...tts, words: undefined }, red), /p1: .*no word timings to beep.*posts narrate p1 --words.*--uncensored/);
assert.equal(takeSlurBleeps(entry([tts]), tts, { terms: [], slurs: resolveSlurs({}, LIST, { uncensored: true }) }), null);
assert.equal(takeSlurBleeps(entry([tts]), tts, null), null);
});
test("with read-follow: the pill sits in its word's slot inside the read's block, as a redaction bar does", () => {
const e = post(`First para here.\n\nThen you ${F} and more words follow here.`);
const html = postCardHtml(e, { width: 1280, height: 720, follow: true, redaction: { terms: [{ term: "more" }], slurs: ON } });
assert.match(html, /data-post-follow=/);
assert.ok(!html.toLowerCase().includes(F));
assert.match(html, /Then<\/span> you<\/span> f\*{5}<\/span><\/span> and<\/span> {
const { postSegmentArgs } = await import("./post-render.mjs");
const { postItemPlan, postLayout } = await import("./post-item.mjs");
const e = post(`you ${F} there`, { narration: { script: `you ${F} there`, takes: [{ file: "narration/posts/1/take-1.orpheus-zac.wav", seconds: 3, script: `you ${F} there` }] } });
const plan = postItemPlan(e, {});
const box = { width: 1440, height: 810 };
const args = (bleeps) => {
const argv = postSegmentArgs({
entry: e, box, plan, layout: postLayout(e, box), cards: { read: "/c/read.png" }, files: [], render: { fps: 30, audioRate: 48000 }, outPath: "/o/p1.mp4",
narration: { file: "/t/take.wav", gainDb: 0, ...(bleeps ? { bleeps } : {}) },
});
return argv[argv.indexOf("-filter_complex") + 1];
};
const plain = args(null);
const beeped = args({ mode: "beep", spans: [[0.96, 1.56]], seconds: 3 });
assert.doesNotMatch(plain, /pnbl/);
assert.match(beeped, /\[\d+:a\]aresample=48000,aformat=sample_fmts=fltp:channel_layouts=stereo,volume=0:enable='between\(t,0\.96,1\.56\)'\[pnbl_m\]/);
assert.match(beeped, /\[pnbl_m\]\[pnbl_t\]amix=inputs=2:normalize=0:duration=first\[pnbl\];\[pnbl\]aresample=48000/);
// Everything after the voice's input is the same mix.
assert.equal(beeped.slice(beeped.indexOf("[pnbl]aresample")).replace("[pnbl]", ""), plain.slice(plain.search(/\[\d+:a\]aresample/)).replace(/^\[\d+:a\]/, ""));
});