Files
raea/sdk/cloud/test/sound.ts
shaneandshinyobjectz 6af8bfa5bb Cut checks a box can fail on: raea sound check, text placement from the farm's scene read, and full render manifests (#267)
Shane on Dutch (11-29): words faded and cut in two, lines too quiet to hear, effects no one hears, and text laid
over the people and the dog the shot is about.

- raea sound check VIDEO (server/sound.ts): each voice clip's edit points against the take's words and its sound.
  A cut inside a word or on a word's sound is an error, and the message names the pause (or the boundary) to move
  it to. Lines more than 6 dB from the cut's median are an error, with the gainDb that evens them. An effect 10 dB
  or more under the voice is an error, since no one hears it. Buried or fighting music is a warning. offload.ts runs
  it after every render that has a manifest.
- The farm's POST /v1/scene (deploy/modal/farm_scene.py) reads a frame: people as a mask, faces, COCO's things,
  and words in the shot (four small OpenCV zoo models on the CPU, each pinned by its hash).
- server/place.ts turns a scene into costs. raea frames check now fails text over a face, a dog or a person when a
  clear place of its size exists, and names that place. raea frames place FILE lists the clear places in a take.
  Stacked lines move as one block, our own text isn't counted as the shot's words, and passers-by's small faces
  don't count.
- The farm wrote a split render's probe manifest (frame 0 only) as the render's. Each run now writes its own and
  the farm joins them, so the checks see every frame and every clip.

Tests: test/sound.ts (7), test/place.ts (4, on scene reads of three interview frames, boxes only),
test/farm_plan.py (the joined manifest).

Co-authored-by: shinyobjectz <[email protected]>
2026-11-29 09:20:52 -08:00

81 lines
4.7 KiB
TypeScript

// `raea sound check`'s measures (server/sound.ts), on made-up takes: node test/sound.ts
// 11-29 (Dutch): words cut in two at a clip's edge, a guest's line 15 dB under the host's, effects 18 dB under the voice
import assert from "node:assert/strict"
import { balance, busOf, editPoints, nearestGap, type Clip, type Heard, type Levels } from "../server/sound.ts"
const ok = (m: string) => console.log(`ok ${m}`)
// a take: words at 1.00-1.40, 1.50-1.90 ("very" "loud") and 2.40-2.80 ("next"); speech at -20 dB, the street at -50
const words = [
{ text: "very", start: 1.0, end: 1.4 },
{ text: "loud", start: 1.5, end: 1.9 },
{ text: "next", start: 2.4, end: 2.8 },
]
const db: number[] = []
for (let t = 0; t < 4; t += 0.01) db.push(words.some((w) => t >= w.start - 0.005 && t <= w.end + 0.005) ? -20 : -50)
const take: Levels = { start: 0, db }
const fps = 30
const clip = (at: number, dur: number, extra: Partial<Clip> = {}): Clip => ({ key: "n1", from: 30, to: 30 + Math.round(dur * fps), src: "/w/work/media/raw/take.mov", at, gainDb: 0, bus: "voice", ...extra })
// cut in the gaps: 0.90 to 2.10 (both edges in silence)
assert.deepEqual(editPoints(clip(0.9, 1.2), fps, words, take), [])
ok("a clip cut in the gaps around its words passes")
// out at 1.70: inside "loud"
const inWord = editPoints(clip(0.9, 0.8), fps, words, take)
assert.equal(inWord.length, 1)
assert.equal(inWord[0].kind, "edit-in-word")
assert.match(inWord[0].says, /“loud”/)
assert.match(inWord[0].says, /move it to 1\.4\d s/)
ok("an out point inside a word is an error, with the gap before it to move to")
// in at 1.01: a hair past the start of "very" (inside the 20 ms grace), so it's on sound, not inside the word
const onSound = editPoints(clip(1.01, 1.0), fps, words, take)
assert.equal(onSound[0]?.kind, "edit-on-sound", JSON.stringify(onSound))
assert.match(onSound[0].says, /first sound/)
ok("an in point on a word's first sound is an error")
// "loud" and "next" run together with no pause: a cut on their boundary is tight (a warning), not a cut word
const run = [{ text: "say", start: 1.0, end: 1.4 }, { text: "so", start: 1.42, end: 1.7 }, { text: "then", start: 1.72, end: 2.0 }]
const runDb: number[] = []
for (let t = 0; t < 4; t += 0.01) runDb.push(t >= 0.995 && t <= 2.005 ? -20 : -50)
const tight = editPoints(clip(0.9, 0.81), fps, run, { start: 0, db: runDb })
assert.deepEqual(tight.map((x) => [x.level, x.kind]), [["warn", "edit-on-sound"]], JSON.stringify(tight))
assert.match(tight[0].says, /between “so” and “then”/)
const cutSo = editPoints(clip(0.9, 0.65), fps, run, { start: 0, db: runDb })
assert.equal(cutSo[0]?.level, "error")
assert.match(cutSo[0].says, /no pause within 400 ms; the nearest boundary between words is 1\.71 s/)
ok("a cut on the boundary of words that run together is a warning; inside one, the nearest boundary is said")
assert.equal(nearestGap(take, 1.7, -20, words, -1, 1.0), 1.45)
assert.equal(nearestGap({ start: 0, db: db.map(() => -20) }, 1.7, -20, [], -1, 0), null)
ok("the nearest gap is found, and a take with none says so")
// levels: three lines at -14, one guest at -29 (15 dB under: Gigi's hook B); an effect at -32; music at -50
const line = (from: number, level: number, extra: Partial<Clip> = {}): Heard => ({ clip: { ...clip(1, 2), from, to: from + 60, ...extra }, kind: "voice", level })
const heard: Heard[] = [
line(0, -14),
line(60, -29, { src: "/w/work/media/raw/guest.mov" }),
line(120, -15),
line(180, -13),
{ clip: { ...clip(0, 1), from: 90, to: 120, src: "/w/work/media/elevenlabs/sfx_pop.mp3", bus: "sfx", gainDb: -14 }, kind: "sfx", level: -32 },
{ clip: { ...clip(0, 20), from: 0, to: 600, src: "/w/work/media/elevenlabs/music.mp3", bus: "music", gainDb: -20 }, kind: "music", level: -50 },
]
const b = balance(heard, fps)
const quiet = b.find((x) => x.kind === "level")
assert.equal(quiet?.level, "error")
assert.match(quiet!.says, /guest\.mov/)
assert.match(quiet!.says, /15 dB under/)
assert.match(quiet!.says, /gainDb to 15\.0/)
assert.equal(b.filter((x) => x.kind === "level").length, 1, "the lines within 4 dB of each other pass")
const sfx = b.find((x) => x.kind === "effect-unheard")
assert.equal(sfx?.level, "error")
assert.match(sfx!.says, /18 dB under the voice/)
assert.equal(b.find((x) => x.kind === "music")?.level, "warn")
ok("a line 15 dB under the others is an error with the gain that evens it; an effect 18 dB under is unheard; buried music is said")
assert.equal(busOf({ ...clip(0, 1), bus: undefined, src: "/x/media/elevenlabs/sfx_tap.mp3" }), "sfx")
assert.equal(busOf({ ...clip(0, 1), bus: undefined, src: "/x/media/raw/Interview1.MOV" }), "voice")
assert.equal(busOf({ ...clip(0, 1), bus: "music", src: "/x/a.mp3" }), "music")
ok("a clip's kind from its bus, or its file's name when it has none")