"use client"; import { Options } from "@/components/ui/disclosure"; import Link from "next/link"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import Waveform from "@/components/Waveform"; import { buttonVariants } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { postBenchHref, readsHref } from "@/lib/hrefs"; import { CAST_CONVERT_ENGINES, CAST_CONVERT_PITCH, CAST_PITCH_ENGINES, CAST_SEMITONES_MAX, convertPitchLabel } from "umtool-report-to-video/cast"; import { POST_DERIVE_OPS, POST_NARRATION_DEFAULTS, mixPhaseAt, pickedTake, postNarrationKnobs, scriptParts, takeIdOf, takeSourceOf } from "umtool-report-to-video/post-narration"; import { projectFileMedia } from "./bench/benchMedia"; import { usePeaks } from "./bench/usePeaks"; import { useNotes } from "@/lib/annotations/useNotes"; import { MIC_KEY, ls, useMic } from "./useMic"; import type { PostPlan } from "./review/PostItemPlayer"; import { wordZoomTimes, zoomSpan } from "umtool-report-to-video/word-zoom"; import PostAttachmentLane from "./PostAttachmentLane"; import ReadAgain, { madeWithText, playNow, useAutoPlay, type KeepForCharacter, type Tuning } from "./read/ReadAgain"; import { lineOwnOf } from "@/lib/report/tuneAsk.mjs"; import { useKeepForCharacter } from "./read/keepForCharacter"; import { LEGACY_EDIT_TEXT, legacyReadOf } from "umtool-report-to-video/post-item"; // --------------------------------------------------------------------------- // A POST's NARRATION ON THE BENCH (report-to-video/post-narration.mjs; // knobs.md, "A narrated post item"), beside the post bench's player: // // the lanes each video's or GIF's whole waveform with its window (the in/out // handles, PostAttachmentLane: the bench's draft, as its number // fields; Re-pick best: posts fit's scan), and the read on the // item's clock -- the take's waveform from its lead (drag it), // the muffle under it, the ramp back to clean // record THE RECORDING SESSION (operator, 2 Nov: "I think I'll record my // voice"): the mic, a level meter, a 3-2-1 count-in, the script as // a teleprompter PART BY PART (Record / Stop / Redo part / Next // part), play back, Keep -- saved as a recorded take and picked // takes each take (play it, its parts, Pick, its note), Approve, the // script, Re-take with direction (the EDITOR's tts op, a job) // the mix wet, lead, tail, ramp, linger, rate, short, attach, clip, duck // // Every change is one write (POST /api/report/post-narration), the writer // `umtool posts narrate` runs; the bench takes the entry it returns. // --------------------------------------------------------------------------- // A derived take's step. A convert's `pitch` / `semitones`: the pitch the converted read lands on (knobs.md, "The // pitch a converted read lands on") -- absent for the stock voice's own. type Step = { op: string; engine?: string; voice?: string; pitch?: string; semitones?: number }; // The engines whose convert can FOLLOW the read's pitch (cast.mjs CAST_PITCH_ENGINES), and the modes in plain words. const PITCH_WORDS: Record = { target: "the stock voice's own pitch", source: "follow my pitch", contour: "my intonation, at the voice's register", }; type Take = { file: string; engine?: string; voice?: string; seconds: number; note?: string; script?: string; label?: string; tuning?: Tuning; reading?: number; read?: { kind?: string }; source?: { kind: string; from?: string; voice?: string; engine?: string }; steps?: Step[]; parts?: Array<{ n: number; para?: number; text?: string; start: number; seconds: number; file?: string }>; words?: Array<{ w: string; start: number; end: number }> }; type Narration = { script?: string; takes?: Take[]; pick?: number; approved?: boolean; off?: boolean; window?: { media: number; start: number; end: number; score?: number; reason?: string } } & Record; type Entry = Record & { id: string; narration?: Narration; media?: Array & { src: string; kind: string; seconds?: number; start?: number; end?: number }> }; type Progress = { items: Array<{ id: string; n: number; plays: string; approved: boolean }>; counts: { posts: number; recorded: number; synthesized: number; none: number; approved: number } }; const fileUrl = (project: string, rel: string) => `/api/report/file?project=${encodeURIComponent(project)}&path=${encodeURIComponent(rel)}`; const LABEL_KEY = "umtool.post-narration.label"; export default function PostNarrationPanel({ project, entry, token, plan, render, onEntry, onTrim, s, setS, setPlaying, prev, next, fromPlay, keepForCharacter, }: { project: string; entry: Entry; token: string | null; plan: PostPlan; render: Record; /** The writer's answer: the entry as it is now, and the manifest's token. */ onEntry: (e: Entry, token: string | null) => void; /** An attachment lane's handle moved: its start / end in the bench's draft (undefined: the file's own). */ onTrim: (i: number, patch: { start?: number; end?: number }) => void; s: number; setS: (s: number) => void; setPlaying: (p: boolean) => void; prev: string | null; next: string | null; fromPlay: boolean; /** S2's seam (lane character-tuning): keep a Tune's numbers for the item's character. Absent: no button. */ keepForCharacter?: KeepForCharacter; }) { const n = entry.narration ?? {}; const takes = n.takes ?? []; const picked = pickedTake(entry) as (Take & { index: number }) | null; const k = postNarrationKnobs(entry, render) as typeof POST_NARRATION_DEFAULTS & Record; const [error, setError] = useState(null); const [status, setStatus] = useState(null); const [rereadTempo, setRereadTempo] = useState(""); const [rereadDrop, setRereadDrop] = useState(""); const [rereadUrls, setRereadUrls] = useState(false); const btn = cn(buttonVariants({ variant: "outline", size: "sm" })); const post = useCallback( async (body: Record) => { setError(null); const res = await fetch("/api/report/post-narration", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, id: entry.id, token, ...body }) }); const j = (await res.json().catch(() => ({}))) as { entry?: Entry; token?: string; error?: string; errors?: string[]; jobId?: string; file?: string; untouched?: boolean; why?: string; window?: Narration["window"]; busy?: boolean }; if (!res.ok) { setError(j.errors?.join("; ") ?? j.error ?? `HTTP ${res.status}`); return null; } if (j.entry) onEntry(j.entry, j.token ?? null); return j; }, [project, entry.id, token, onEntry], ); const set = (patch: Record) => post({ op: "set", patch }).then((j) => j && setStatus("saved")); // ---- the cut's reading progress ------------------------------------------- const [progress, setProgress] = useState(null); useEffect(() => { let live = true; fetch(`/api/report/post-narration?project=${encodeURIComponent(project)}`, { cache: "no-store" }) .then((r) => (r.ok ? r.json() : null)) .then((j) => live && j && setProgress(j as Progress)) .catch(() => {}); return () => { live = false; }; }, [project, entry]); const nextToRecord = progress?.items.find((x) => x.plays !== "recorded" && x.id !== entry.id) ?? null; // ---- the operator's notes on the cut's posts (the notes system: an entry's, a moment's in it) ---- const notesApi = useNotes({ project }); const noteEntry = (a: { kind: string; entry?: string }) => (a.kind === "entry" || a.kind === "cut" || a.kind === "moment" || a.kind === "edit" ? a.entry ?? null : null); const openNotes = notesApi.notes.filter((x) => x.status === "open"); const mine = openNotes.filter((x) => noteEntry(x.anchor as { kind: string; entry?: string }) === entry.id); const withNotes = progress ? progress.items.filter((x) => openNotes.some((nn) => noteEntry(nn.anchor as { kind: string; entry?: string }) === x.id)) : []; const nextWithNote = withNotes.find((x) => x.n > (progress?.items.find((y) => y.id === entry.id)?.n ?? 0)) ?? withNotes[0] ?? null; const [noteText, setNoteText] = useState(""); // ---- the recording session -------------------------------------------------- const mic = useMic(); const [label, setLabel] = useState("operator"); useEffect(() => setLabel(ls.get(LABEL_KEY) ?? "operator"), []); const [script, setScript] = useState(n.script ?? ""); useEffect(() => setScript(entry.narration?.script ?? ""), [entry.id, entry.narration?.script]); const parts = useMemo(() => scriptParts(script), [script]); const [part, setPart] = useState(0); const [blobs, setBlobs] = useState>([]); const [phase, setPhase] = useState<"idle" | "count" | "recording" | "saving">("idle"); const [count, setCount] = useState(0); useEffect(() => { setPart(0); setBlobs([]); setPhase("idle"); }, [entry.id]); const record = async () => { if (phase !== "idle" || !parts.length) return; setPhase("count"); for (const c of [3, 2, 1]) { setCount(c); await new Promise((r) => setTimeout(r, 700)); } setCount(0); if (!(await mic.start())) { setPhase("idle"); return; } setPhase("recording"); }; const stop = async () => { if (phase !== "recording") return; const blob = await mic.stop(); setPhase("idle"); if (!blob) return; setBlobs((b) => { const out = [...b]; if (out[part]) URL.revokeObjectURL(out[part]!.url); out[part] = { blob, url: URL.createObjectURL(blob) }; return out; }); // Auto-advance to the next part not yet recorded. setPart((p) => (p < parts.length - 1 ? p + 1 : p)); }; const allIn = parts.length > 0 && parts.every((_, i) => !!blobs[i]); const keep = async () => { if (!allIn) return; setPhase("saving"); setError(null); const fd = new FormData(); fd.set("project", project); fd.set("id", entry.id); fd.set("label", label); if (script !== (n.script ?? "")) fd.set("script", script); parts.forEach((p, i) => { fd.append("part", blobs[i]!.blob, `p${i + 1}.webm`); fd.append("text", p.text); fd.append("para", String(p.para)); }); const res = await fetch("/api/report/post-narration", { method: "POST", body: fd }); const j = (await res.json().catch(() => ({}))) as { entry?: Entry; token?: string; error?: string; take?: Take }; setPhase("idle"); if (!res.ok || !j.entry) { setError(j.error ?? `HTTP ${res.status}`); return; } onEntry(j.entry, j.token ?? null); setBlobs([]); setPart(0); setStatus(`kept ${j.take?.file ?? "the recording"} (picked)`); // Re-record, then re-run the chain: the steps the last recording's derived takes applied, on the new one. if (rerunChain) { const newIndex = (j.entry.narration?.takes ?? []).length - 1; const lastRecorded = [...takes.keys()].reverse().find((i) => takeSourceOf(takes[i]).kind === "recorded"); const steps = lastRecorded === undefined ? [] : (tree.kids.get(lastRecorded) ?? []).flatMap((k) => takes[k].steps ?? []); if (steps.length) setChain(steps.map((step) => ({ from: newIndex, step }))); } }; // R records, S stops (Space is the bench's play). useEffect(() => { const onKey = (ev: KeyboardEvent) => { const tgt = ev.target as HTMLElement | null; if (tgt?.closest("input, textarea, select")) return; if (ev.key === "r" && !ev.metaKey && !ev.ctrlKey) { ev.preventDefault(); void record(); } else if (ev.key === "s" && !ev.metaKey && !ev.ctrlKey) { ev.preventDefault(); void stop(); } }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }); // ---- a re-take with direction (the editor's tts op) -------------------------- const [dir, setDir] = useState({ note: "", voice: "", speed: "" }); const [job, setJob] = useState<{ id: string; file: string; note: string; script: string; state: string; error?: string; polls?: number; again?: boolean; waiting?: string | null; derive?: { from: number; op: string; engine?: string | null; voice?: string | null; pitch?: string | null; semitones?: number | null } } | null>(null); // Derived takes still to make after a re-record ("re-run the chain"), from the new take. const [chain, setChain] = useState>([]); const [rerunChain, setRerunChain] = useState(true); const [notInstalled, setNotInstalled] = useState(null); const derive = async (from: number, step: Step) => { setNotInstalled(null); const j = (await post({ op: "derive", from, op2: step.op, engine: step.engine || undefined, voice: step.voice || undefined, ...(step.op === "convert" && step.pitch ? { pitch: step.pitch, ...(typeof step.semitones === "number" ? { semitones: step.semitones } : {}) } : {}) })) as ({ jobId?: string; file?: string; installed?: boolean; error?: string } & Record) | null; if (j && j.installed === false) { setNotInstalled(j.error ?? `the editor has no ${step.op} engine yet`); setChain([]); return; } // What the server asked the editor with (a convert's defaults are its character's): the keeper records those. const asked = (k: string) => (typeof j?.[k] === "string" && j[k] ? (j[k] as string) : null); if (j?.jobId && j.file) setJob({ id: j.jobId, file: j.file, note: "", script, state: "running", derive: { from, op: step.op, engine: asked("engine") ?? step.engine ?? null, voice: asked("voice") ?? step.voice ?? null, pitch: asked("pitch") ?? step.pitch ?? null, semitones: typeof j.semitones === "number" ? j.semitones : step.semitones ?? null } }); }; const retake = async () => { const j = await post({ op: "take", note: dir.note || undefined, voice: dir.voice || undefined, speed: dir.speed ? Number(dir.speed) : undefined, script }); if (j?.jobId && j.file) setJob({ id: j.jobId, file: j.file, note: dir.note, script, state: "running" }); }; // A READ OF THIS POST MADE BUT NOT KEPT (a bench that lost it, review 2 finding 2): followed again on load, the same // `?job` GET landing its take. useEffect(() => { let live = true; fetch(`/api/report/post-narration?project=${encodeURIComponent(project)}&id=${encodeURIComponent(entry.id)}&pending=1`, { cache: "no-store" }) .then((r) => (r.ok ? r.json() : null)) .then((j: { pending?: { jobId: string; file: string; script: string | null; note: string | null } | null } | null) => { const p = j?.pending; if (live && p) setJob((cur) => (cur?.state === "running" ? cur : { id: p.jobId, file: p.file, note: p.note ?? "", script: p.script ?? n.script ?? "", state: "running", again: true })); }) .catch(() => {}); return () => { live = false; }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [project, entry.id]); // ---- READ AGAIN (lane line-rerun): the next reading, unpicked, played as it lands ------------------------------ const [autoplay, setAutoplay] = useAutoPlay(); const [landed, setLanded] = useState(null); // One press at a time, synchronously (review 1, finding 4): a second press before the first's answer is ignored. const pressing = useRef(false); const readAgain = async (words: string, tuning: Tuning | null) => { const j = await post({ op: "take", script: words, reading: "next", keepPick: true, ...(tuning ? { tuning } : {}), voice: dir.voice || undefined }); if (!j) return; if (j.jobId && j.file) setJob({ id: j.jobId, file: j.file, note: "", script: words, state: "running", again: true }); }; const press = async (fn: () => Promise) => { if (pressing.current || job?.state === "running") return; pressing.current = true; try { await fn(); } finally { pressing.current = false; } }; const readEdited = async (tuning: Tuning | null) => { const saved = await post({ op: "set", patch: { script } }); if (saved) await readAgain(script, tuning); }; // How this text was last made (its last synthesized take's tuning, else the playing take's): Tune starts there. const madeTake = useMemo(() => { const synth = takes.filter((t) => takeSourceOf(t).kind === "tts" && t.read?.kind !== "thread" && t.tuning); const same = synth.filter((t) => (t.script ?? "").replace(/\s+/g, " ").trim() === (n.script ?? "").replace(/\s+/g, " ").trim()); return (same.at(-1) ?? (picked?.tuning ? picked : null) ?? synth.at(-1)) ?? null; }, [takes, n.script, picked]); const madeWith = madeTake?.tuning ?? null; const legacy = legacyReadOf(entry); useEffect(() => { if (!job || job.state !== "running") return; const t = setTimeout(async () => { const q = new URLSearchParams({ project, id: entry.id, job: job.id, file: job.file, script: job.script, ...(job.note ? { note: job.note } : {}), ...(job.derive ? { derive: String(job.derive.from), op: job.derive.op, ...(job.derive.engine ? { engine: job.derive.engine } : {}), ...(job.derive.voice ? { voice: job.derive.voice } : {}), ...(job.derive.pitch ? { pitch: job.derive.pitch } : {}), ...(typeof job.derive.semitones === "number" ? { semitones: String(job.derive.semitones) } : {}) } : {}), }); // The bench out of reach: asked again, up to five times running; then failed (review 1, finding 5). const r = await fetch(`/api/report/post-narration?${q}`, { cache: "no-store" }).catch(() => null); if (!r) { const misses = (job.polls ?? 0) + 1; // Lost, not failed (review 2, finding 2): the job and its file are kept -- Check again lands the take the same way. setJob(misses >= 5 ? { ...job, state: "lost", error: "the bench did not answer" } : { ...job, polls: misses }); return; } const j = (await r.json().catch(() => ({}))) as { state?: string; error?: string; entry?: Entry; token?: string; waiting?: string }; if (j.state === "done") { setJob({ ...job, state: "done", waiting: null }); setStatus(job.again ? `new reading ${job.file} -- Pick makes it the one` : `new take ${job.file} (picked)`); if (job.again) { setLanded(job.file); if (autoplay) playNow(fileUrl(project, job.file)); } if (j.entry) onEntry(j.entry, j.token ?? null); else window.location.reload(); } else if (j.state === "failed" || !r.ok) setJob({ ...job, state: "failed", error: j.error ?? `HTTP ${r.status}` }); // Still queued or running on the editor (waiting for a render, it says so): ask again. No state: failed. else if (j.state !== "running") setJob({ ...job, state: "failed", error: j.error ?? "the job is gone" }); else setJob({ ...job, polls: 0, waiting: j.waiting ?? null }); }, 1500); return () => clearTimeout(t); // eslint-disable-next-line react-hooks/exhaustive-deps }, [job, project, entry.id]); useEffect(() => { if (!chain.length || job?.state === "running") return; const [first, ...rest] = chain; setChain(rest); void derive(first.from, first.step); // eslint-disable-next-line react-hooks/exhaustive-deps }, [chain, job?.state]); // The takes as a small tree: each source take (synthesized, recorded) with the takes derived from it under it. const tree = useMemo(() => { const byId = new Map(takes.map((t, i) => [takeIdOf(t), i])); const kids = new Map(); const roots: number[] = []; takes.forEach((t, i) => { const src = takeSourceOf(t) as { kind: string; from?: string }; const up = src.kind === "take" && src.from ? byId.get(src.from) : undefined; if (up === undefined) roots.push(i); else kids.set(up, [...(kids.get(up) ?? []), i]); }); const out: Array<{ i: number; depth: number }> = []; const walk = (i: number, depth: number) => { out.push({ i, depth }); for (const k of kids.get(i) ?? []) walk(k, depth + 1); }; roots.forEach((i) => walk(i, 0)); return { rows: out, kids }; }, [takes]); const [deriveDraft, setDeriveDraft] = useState<{ op: string; engine: string; voice: string; pitch: string; semitones: string }>({ op: "enhance", engine: "", voice: "", pitch: "target", semitones: "" }); // What a convert of THIS post defaults to: its author's character in the cast (else the narrator) -- the engine, the // stock voice and the pitch every recording made that character's lands on (`umtool cast set --convert-pitch …`). const [castConvert, setCastConvert] = useState<{ name: string; engine?: string | null; voice?: string | null; pitch?: string; semitones?: number } | null>(null); // The character whose SYNTHETIC preset reads his words now (lane character-tuning): a Tune is kept for it, and its // tuning is where the Tune starts -- unless his last read was his own. const readsAs = useKeepForCharacter(project, entry.id, "post", madeTake ? { tuning: madeTake.tuning ?? null, tuningAsked: (madeTake as { tuningAsked?: unknown }).tuningAsked } : null); useEffect(() => { let live = true; setCastConvert(null); fetch(`/api/report/post-narration?project=${encodeURIComponent(project)}&id=${encodeURIComponent(entry.id)}&convert=1`, { cache: "no-store" }) .then((r) => (r.ok ? r.json() : null)) .then((j: { character?: { id?: string; name: string; layer?: string } | null; convert?: { engine?: string | null; voice?: string | null; pitch?: string; semitones?: number } | null } | null) => { if (live && j?.character && j.convert) setCastConvert({ name: j.character.name, ...j.convert }); }) .catch(() => {}); return () => { live = false; }; }, [project, entry.id]); // Choosing the op: a convert starts from the character's entry (its engine and voice only where the field is // empty); an enhance drops a convert engine left in the field. const chooseDeriveOp = (op: string) => setDeriveDraft((d) => op !== "convert" ? { ...d, op, engine: (CAST_CONVERT_ENGINES as readonly string[]).includes(d.engine.trim()) ? "" : d.engine } : { op, engine: d.engine || castConvert?.engine || "", voice: d.voice || castConvert?.voice || "", pitch: castConvert?.pitch ?? "target", semitones: castConvert?.semitones ? String(castConvert.semitones) : "", }, ); // The pitch controls are an engine's that can follow one; without it the convert lands on the stock voice's own. const derivePitched = deriveDraft.op === "convert" && (CAST_PITCH_ENGINES as readonly string[]).includes(deriveDraft.engine.trim()); const deriveSemitones = Number(deriveDraft.semitones || 0); const deriveSemitonesBad = derivePitched && deriveDraft.pitch !== "target" && !(Number.isFinite(deriveSemitones) && Math.abs(deriveSemitones) <= CAST_SEMITONES_MAX); const deriveStep = (): Step => ({ op: deriveDraft.op, ...(deriveDraft.engine.trim() ? { engine: deriveDraft.engine.trim() } : {}), ...(deriveDraft.op === "convert" && deriveDraft.voice.trim() ? { voice: deriveDraft.voice.trim() } : {}), ...(derivePitched ? { pitch: deriveDraft.pitch, ...(deriveDraft.pitch !== "target" ? { semitones: deriveSemitones } : {}) } : {}), }); // ---- the lanes ------------------------------------------------------------------ // One lane per timed attachment (a video, a GIF), its in and out the bench's draft (onTrim). const timed = (entry.media ?? []).map((m, i) => ({ m, i })).filter(({ m }) => m.kind === "video" || m.kind === "gif"); const vi = (entry.media ?? []).findIndex((m) => m.kind === "video"); const stepOf = (i: number) => plan.steps.find((st) => st.items.some((m) => m.i === i)) ?? null; const tMedia = useMemo(() => projectFileMedia({ project, path: picked?.file ?? "", seconds: picked?.seconds || 1 }), [project, picked?.file, picked?.seconds]); const tPeaks = usePeaks(picked ? tMedia : { ...tMedia, peaksUrl: null }); // The word zooms on the read (word-zoom.mjs): worked out once per change, not per frame. const zoomSpans = useMemo( () => wordZoomTimes(entry, render) .filter((z) => typeof z.t === "number") .map((z) => ({ i: z.i, ...zoomSpan((entry.fx as Array>)[z.i], z.t as number) })), [entry, render], ); const sch = plan.narration ?? null; const total = plan.total; const pct = (v: number) => `${(v / Math.max(0.1, total)) * 100}%`; const drag = useRef<{ x: number; lead: number; w: number } | null>(null); const [leadDraft, setLeadDraft] = useState(null); const lead = leadDraft ?? Number(k.lead); const mixKnob = (key: string, labelText: string, o: { step?: number; min?: number; max?: number; options?: string[] }) => ( ); // THE LANES: each attachment's window, the read on the item's clock (every write the draft's). const lanes = timed.length || (sch && picked) ? (
{timed.map(({ m, i }) => ( {i === vi && ( )} {i === vi && n.window?.reason && ( chosen: {n.window.reason} )} ))} {sch && picked && (
the read · {picked.file.split("/").pop()} · {picked.seconds.toFixed(1)} s{(sch.rate ?? 1) !== 1 ? ` read in ${sch.seconds.toFixed(1)} s at ${sch.rate}×` : ""} from {lead.toFixed(2)} s · muffled to {sch.voiceEnd.toFixed(1)} s, clean from {sch.rampEnd.toFixed(1)} s · {mixPhaseAt(sch, s)}
{ if (!drag.current) return; const dt = ((e.clientX - drag.current.x) / drag.current.w) * total; setLeadDraft(Math.max(0, Math.min(5, Math.round((drag.current.lead + dt) * 20) / 20))); }} onPointerUp={() => { if (!drag.current) return; drag.current = null; if (leadDraft !== null && leadDraft !== Number(k.lead)) void set({ lead: leadDraft }).then(() => setLeadDraft(null)); else setLeadDraft(null); }} onClick={(e) => { const r = e.currentTarget.getBoundingClientRect(); setS(((e.clientX - r.left) / r.width) * total); }} > {/* The muffle under the read, the ramp back to clean. */} {sch.duck &&
} {sch.duck &&
} {plan.steps.map((st, j) => (
))}
{ e.stopPropagation(); (e.currentTarget.parentElement as HTMLElement).setPointerCapture(e.pointerId); drag.current = { x: e.clientX, lead, w: (e.currentTarget.parentElement as HTMLElement).getBoundingClientRect().width }; }} data-post-lane-voice="" > {tPeaks && ( {}} onReachEdge={() => {}} height={52} /> )} {(picked.parts ?? []).map((p) => ( ))}
{/* The word zooms on the read: from the lead-in to back out (word-zoom.mjs). */} {zoomSpans.map((sp) => (
))}
)}
) : null; return (
{/* The cut's reading: how far along, and where next. */}
{progress ? ( recorded {progress.counts.recorded} of {progress.counts.posts} · placeholder (synthesized) {progress.counts.synthesized} · none {progress.counts.none} · approved {progress.counts.approved} ) : ( reading the cut… )} {nextToRecord && ( next to record: #{nextToRecord.n} › )} {withNotes.length > 0 && ( {withNotes.length} with notes{nextWithNote && nextWithNote.id !== entry.id && ( <> {" · "} next with a note: #{nextWithNote.n} › )} )} N / P: next / previous post · R record · S stop · Space play {prev && } {next && }
{/* The operator's notes on this post (the notes system), and one more. */}
{mine.map((x) => (

note {x.text} {x.replies.length ? ({x.replies.length} repl{x.replies.length === 1 ? "y" : "ies"}) : null}

))}
setNoteText(e.target.value)} placeholder="a note on this post (direction for a re-take, a fix)" className="min-w-0 flex-1 rounded border border-seam bg-ground px-1.5 py-0.5" data-post-note-text="" />
{lanes} {/* THE RECORDING SESSION. */}

record your read

0.85 ? "bg-red-500" : "bg-emerald-500")} style={{ width: `${mic.level * 100}%` }} />
{mic.error && {mic.error}}
{/* The teleprompter: every part, the one being read large. */}
    {parts.map((p, i) => (
  1. phase === "idle" && setPart(i)} data-post-part={p.n} data-post-part-current={i === part ? "1" : undefined} data-post-part-recorded={blobs[i] ? "1" : undefined} > {parts.length > 1 && {p.n}.} {p.text}
  2. ))} {!parts.length &&
  3. no script yet — write it under “script” below
  4. }
{phase === "count" && ( {count} )} {parts.length > 1 && ( )} {blobs[part] && ( // eslint-disable-next-line jsx-a11y/media-has-caption
{/* TAKES, THE SCRIPT, A RE-TAKE WITH DIRECTION. */}

takes

    {tree.rows.map(({ i, depth }) => { const t = takes[i]; const src = takeSourceOf(t) as { kind: string; voice?: string; engine?: string }; const step = (t.steps ?? [])[0]; return (
  • {depth ? "└ " : ""}#{i + 1} {src.kind === "recorded" ? `recorded · ${src.voice ?? t.voice ?? "?"}` : src.kind === "take" ? `${step?.op ?? "derived"}${step?.engine ? ` · ${step.engine}` : ""}${step?.voice ? ` → ${step.voice}` : ""}${convertPitchLabel(step) ? ` · pitch: ${convertPitchLabel(step)}` : ""}` : `${t.engine ?? "?"} · ${t.voice ?? "?"}`} {Number(t.seconds).toFixed(1)} s {madeWithText(t) && {madeWithText(t)}} {(t as { tuningOwn?: Tuning }).tuningOwn && line's own: {Object.entries((t as { tuningOwn?: Tuning }).tuningOwn ?? {}).map(([k, v]) => `${k.replace("_", " ")} ${v}`).join(", ")}} {landed === t.file && new} {/* eslint-disable-next-line jsx-a11y/media-has-caption */}
    {t.script && src.kind === "tts" && t.read?.kind !== "thread" &&
    {t.script}
    } {(t.parts?.length ?? 0) > 1 && (
      {t.parts!.map((p) => (
    1. {p.n}. {p.text ?? ""} {p.start.toFixed(1)}+{p.seconds.toFixed(1)} s {p.file && ( // eslint-disable-next-line jsx-a11y/media-has-caption
    2. ))}
    )}
  • ); })} {!takes.length &&
  • no take yet: record one above, or ask the editor for a placeholder below
  • }
{picked && (
run AI on take #{picked.index + 1} setDeriveDraft({ ...deriveDraft, engine: e.target.value })} placeholder="engine" className="w-24 rounded border border-seam bg-ground px-1 py-0.5" data-post-derive-engine="" /> {deriveDraft.op === "convert" && ( setDeriveDraft({ ...deriveDraft, voice: e.target.value })} placeholder="stock voice" className="w-24 rounded border border-seam bg-ground px-1 py-0.5" data-post-derive-voice="" /> )} {derivePitched && ( )} {derivePitched && deriveDraft.pitch !== "target" && ( )} {deriveDraft.op === "convert" && castConvert && ( {castConvert.name}'s in the cast: {[castConvert.engine, castConvert.voice, convertPitchLabel(castConvert) ? `pitch ${convertPitchLabel(castConvert)}` : null].filter(Boolean).join(" · ")} )} {notInstalled && ( {notInstalled} )}
)}