"use client"; import { useCallback, useEffect, useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { jobsHref, voicesHref } from "@/lib/hrefs"; // --------------------------------------------------------------------------- // READS AND VOICES for a cut of posts (lane/ui-simplify, 5 Nov): the // pronunciation lexicon (`umtool posts say`) and the voice map (`umtool posts // voices`) as two small tables, with "try it" -- what a voice would be asked to // say -- and the picked reads that still say an entry the old way. Every write // is POST /api/report/pronunciation, the CLI's own commands. // --------------------------------------------------------------------------- type Lex = { word: string; say: string; case?: boolean; item?: string; note?: string }; type Author = { handle: string; items: number; context: number; voice: string; mapped: boolean; from?: string; character?: string }; type View = { lexicon: { json: { lexicon?: Lex[] } | null; error?: string }; voices: { json: { voices?: Record; narrator?: string; engine?: string; authors?: Author[] } | null; error?: string }; stale: { json: { reads?: { id: string; take: string; entries: { word: string; say: string }[]; fix: string }[] } | null }; redact?: { json: { redact?: (string | { term: string; substring?: boolean; note?: string })[]; corpusTerms?: number; markedPosts?: number } | null; error?: string }; mix?: Record; slurs?: { json: { on?: boolean; level?: string; visual?: string; voice?: string; listed?: number; add?: number; except?: number; edges?: string[]; total?: number } | null; error?: string }; }; export default function PronunciationPanel({ project }: { project: string }) { const [view, setView] = useState(null); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const [word, setWord] = useState(""); const [sayAs, setSayAs] = useState(""); const [tryText, setTryText] = useState(""); const [tried, setTried] = useState(null); const [handle, setHandle] = useState(""); const [voice, setVoice] = useState(""); const [queued, setQueued] = useState(null); const [term, setTerm] = useState(""); const [slurWord, setSlurWord] = useState(""); const [mixKey, setMixKey] = useState("rate"); const [mixValue, setMixValue] = useState(""); const load = useCallback(async () => { const r = await fetch(`/api/report/pronunciation?project=${encodeURIComponent(project)}`, { cache: "no-store" }); const j = await r.json().catch(() => null); if (!r.ok || !j) setError(j?.error ?? `HTTP ${r.status}`); else setView(j as View); }, [project]); useEffect(() => { void load(); }, [load]); const post = async (body: Record) => { setBusy(true); setError(null); const r = await fetch("/api/report/pronunciation", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, ...body }) }); const j = (await r.json().catch(() => ({}))) as { error?: string; json?: { said?: string } | null }; setBusy(false); if (!r.ok) { setError(j.error ?? `HTTP ${r.status}`); return null; } if (body.op !== "say-try") await load(); return j; }; const lex = view?.lexicon.json?.lexicon ?? []; const v = view?.voices.json; const stale = view?.stale.json?.reads ?? []; const input = "rounded-[3px] border border-seam-2 bg-ground px-1.5 py-[3px] text-[11.5px] text-text outline-none focus:border-signal"; const cell = "border-t border-seam px-1.5 py-0.5 align-top"; return (

Pronunciation · {lex.length}

{lex.map((x, i) => ( ))}
{x.word} → {x.say} {x.case ? "with case " : ""} {x.item ? `${x.item} only` : ""} {x.note ? ` · ${x.note}` : ""}
setWord(e.target.value)} placeholder="word or phrase (tbh)" className={cn(input, "w-36 font-mono")} /> setSayAs(e.target.value)} placeholder="said as (T-B-H)" className={cn(input, "w-36")} />
setTryText(e.target.value)} placeholder="try it: text a voice would read" className={cn(input, "w-64")} /> {tried !== null && ( said: “{tried}” )}
{stale.length > 0 && (
{stale.length} picked read{stale.length === 1 ? "" : "s"} still say an entry the old way: {stale.map((s) => s.id).join(", ")} — re-read on each post's bench.
)}

Voices · the narrator {v?.engine ?? ""} {v?.narrator ?? ""} audition and compare voices · the cast →

{Object.entries(v?.voices ?? {}).map(([h, voiceName]) => ( ))} {(v?.authors ?? []) .filter((a) => !a.mapped) .slice(0, 8) .map((a) => ( ))}
{h === "*" ? "* everyone else" : `@${h}`} {voiceName}
@{a.handle} {a.voice} ({a.from === "cast" ? `cast: ${a.character ?? ""}` : "default"}) · {a.items} item{a.items === 1 ? "" : "s"}, {a.context} context
setHandle(e.target.value)} placeholder="handle (or *)" className={cn(input, "w-36 font-mono")} /> setVoice(e.target.value)} placeholder="voice (tara)" className={cn(input, "w-28")} />
{/* What the cut publishes blanked (posts redact) and the slur filter (posts slurs): their own commands. */}

Redacted words · {(view?.redact?.json?.redact ?? []).length}

{(view?.redact?.json?.redact ?? []).map((x, i) => { const t = typeof x === "string" ? { term: x } : x; return ( ); })}
{t.term} {t.substring ? "inside words too " : ""} {t.note ?? ""}
setTerm(e.target.value)} placeholder="a word or phrase to blank" className={cn(input, "w-48")} /> a bar on the card, out of the read and the captions

Slur filter · {view?.slurs?.json?.on ? "on" : "off"} · {view?.slurs?.json?.total ?? 0} masked

{( [ ["level", ["strong", "all"]], ["visual", ["blackout", "placeholder"]], ["voice", ["skip", "beep", "placeholder"]], ] as const ).map(([k, opts]) => ( ))}
setSlurWord(e.target.value)} placeholder="a word" className={cn(input, "w-32")} /> {(["add", "except", "remove"] as const).map((v) => ( ))} {/* An EDGE mask (posts slurs edges): that slur's every form first letter, stars, last letter ("n***a"). */} {([false, true] as const).map((off) => ( ))} {view?.slurs?.json?.add ?? 0} added · {view?.slurs?.json?.except ?? 0} excepted {view?.slurs?.json?.edges?.length ? · edges: {view.slurs.json.edges.join(", ")} : null}
{/* The cut's narration mix (posts narrate --cut): what every post reads with unless it says otherwise. */}

The cut's narration mix

{Object.keys(view?.mix ?? {}).length ? JSON.stringify(view?.mix) : "the defaults"}

setMixValue(e.target.value)} placeholder="value (or default)" className={cn(input, "w-36 font-mono")} />
{/* The whole cut's reads, long: steps of the queue (/jobs: their state, Retry, Cancel). */}
every post {queued && ( queued {queued} —{" "} its state on Jobs )}
{error && (

{error}

)}
); }