commit f72ebd72f0fc80fa8571c64e226e4a9e52dba62d
parent 668d1419cbdde267580ef01881464d708b4d9dcc
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Thu, 5 Nov 2026 02:02:52 -0500
umtool: a cut of posts' Reads and voices on the Cut tab -- the pronunciation lexicon (posts say: add, remove, try it, the picked reads that still say an entry the old way) and the voice map (posts voices: set, remove, the cut's authors with the voice each gets) as two small tables; GET/POST /api/report/pronunciation runs the CLI's own sayCommand and voicesCommand with --json (the files' one writer each)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
3 files changed, 237 insertions(+), 0 deletions(-)
diff --git a/umtool/app/api/report/pronunciation/route.ts b/umtool/app/api/report/pronunciation/route.ts
@@ -0,0 +1,60 @@
+import { projectRef } from "@/lib/projects";
+import { refuseCaller } from "@/lib/report/caller";
+import { sayCommand, voicesCommand } from "@/lib/report/postSay.mjs";
+
+export const dynamic = "force-dynamic";
+
+// A POST PROJECT's PRONUNCIATION LEXICON and VOICE MAP in the app (lane/ui-simplify, 5 Nov; terminal-only
+// before: `umtool posts say` / `umtool posts voices`). The CLI's own commands (lib/report/postSay.mjs), run
+// here with --json -- the files' one writer each (narration/lexicon.json, narration/voices.json).
+//
+// GET ?project -> { lexicon: say ls, voices: voices ls, stale: say stale }
+// POST { project, op: "say-add", word, say, case?, item?, note? } posts say <p> add <word> "<say>" [--case] [--item] [--note]
+// { project, op: "say-remove", n } posts say <p> remove <n> (1-based, as ls lists it)
+// { project, op: "say-try", text, item? } posts say <p> try "<text>"
+// { project, op: "voices-set", handle, voice } posts voices <p> set <handle|*> <voice>
+// { project, op: "voices-remove", handle } posts voices <p> remove <handle|*>
+type Flags = Map<string, string | true>;
+
+async function run(fn: (out: (s: string) => void) => Promise<number>) {
+ const out: string[] = [];
+ try {
+ const exit = await fn((s) => out.push(s));
+ return { exit, json: JSON.parse(out.join("\n") || "null") as Record<string, unknown> | null };
+ } catch (e) {
+ return { exit: 1, json: null, error: e instanceof Error ? e.message : String(e) };
+ }
+}
+const say = (project: NonNullable<Awaited<ReturnType<typeof projectRef>>>, rest: string[], flags: Flags = new Map()) =>
+ run((out) => sayCommand(project, rest, { flags, str: (k: string) => String(flags.get(k) ?? ""), json: true, out }));
+const voices = (project: NonNullable<Awaited<ReturnType<typeof projectRef>>>, rest: string[]) => run((out) => voicesCommand(project, rest, { json: true, out }));
+
+export async function GET(request: Request) {
+ const project = await projectRef(new URL(request.url).searchParams.get("project") ?? "");
+ if (!project) return Response.json({ error: "no such project" }, { status: 404 });
+ const [lexicon, voiceMap, stale] = await Promise.all([say(project, ["ls"]), voices(project, ["ls"]), say(project, ["stale"])]);
+ return Response.json({ lexicon, voices: voiceMap, stale }, { headers: { "cache-control": "no-store" } });
+}
+
+export async function POST(request: Request) {
+ const refused = refuseCaller(request, "/api/report/pronunciation");
+ if (refused) return refused;
+ const b = (await request.json().catch(() => null)) as Record<string, unknown> | null;
+ if (!b) return Response.json({ error: "bad json" }, { status: 400 });
+ const project = await projectRef(String(b.project ?? ""));
+ if (!project) return Response.json({ error: "no such project" }, { status: 404 });
+ const s = (k: string) => (typeof b[k] === "string" ? (b[k] as string) : "");
+ const flags: Flags = new Map();
+ if (s("item")) flags.set("--item", s("item"));
+ let r;
+ if (b.op === "say-add") {
+ if (b.case === true) flags.set("--case", true);
+ if (s("note")) flags.set("--note", s("note"));
+ r = await say(project, ["add", s("word"), s("say")], flags);
+ } else if (b.op === "say-remove") r = await say(project, ["remove", String(Number(b.n))], flags);
+ else if (b.op === "say-try") r = await say(project, ["try", s("text")], flags);
+ else if (b.op === "voices-set") r = await voices(project, ["set", s("handle"), s("voice")]);
+ else if (b.op === "voices-remove") r = await voices(project, ["remove", s("handle")]);
+ else return Response.json({ error: "op must be say-add, say-remove, say-try, voices-set or voices-remove" }, { status: 400 });
+ return Response.json(r, { status: r.exit === 0 ? 200 : 400, headers: { "cache-control": "no-store" } });
+}
diff --git a/umtool/components/projects/PronunciationPanel.tsx b/umtool/components/projects/PronunciationPanel.tsx
@@ -0,0 +1,170 @@
+"use client";
+
+import { useCallback, useEffect, useState } from "react";
+import { buttonVariants } from "@/components/ui/button";
+import { cn } from "@/lib/utils";
+
+// ---------------------------------------------------------------------------
+// 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 };
+type View = {
+ lexicon: { json: { lexicon?: Lex[] } | null; error?: string };
+ voices: { json: { voices?: Record<string, string>; narrator?: string; engine?: string; authors?: Author[] } | null; error?: string };
+ stale: { json: { reads?: { id: string; take: string; entries: { word: string; say: string }[]; fix: string }[] } | null };
+};
+
+export default function PronunciationPanel({ project }: { project: string }) {
+ const [view, setView] = useState<View | null>(null);
+ const [error, setError] = useState<string | null>(null);
+ const [busy, setBusy] = useState(false);
+ const [word, setWord] = useState("");
+ const [sayAs, setSayAs] = useState("");
+ const [tryText, setTryText] = useState("");
+ const [tried, setTried] = useState<string | null>(null);
+ const [handle, setHandle] = useState("");
+ const [voice, setVoice] = 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<string, unknown>) => {
+ 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 (
+ <div className="grid basis-full grid-cols-1 gap-4 text-[12px] lg:grid-cols-2" data-pronunciation-panel="">
+ <section data-lexicon={lex.length}>
+ <h3 className="micro mb-1">Pronunciation · {lex.length}</h3>
+ <table className="w-full border-collapse">
+ <tbody>
+ {lex.map((x, i) => (
+ <tr key={`${x.word}:${x.item ?? ""}:${i}`} data-lexicon-row={x.word}>
+ <td className={cn(cell, "font-mono")}>{x.word}</td>
+ <td className={cell}>→ {x.say}</td>
+ <td className={cn(cell, "text-muted")}>
+ {x.case ? "with case " : ""}
+ {x.item ? `${x.item} only` : ""}
+ {x.note ? ` · ${x.note}` : ""}
+ </td>
+ <td className={cn(cell, "text-right")}>
+ <button type="button" data-lexicon-remove={i + 1} disabled={busy} onClick={() => void post({ op: "say-remove", n: i + 1 })} className={buttonVariants({ variant: "quiet", size: "sm" })} aria-label={`remove ${x.word}`}>
+ ✕
+ </button>
+ </td>
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ <div className="mt-1 flex flex-wrap items-center gap-1.5">
+ <input data-lexicon-word="" value={word} onChange={(e) => setWord(e.target.value)} placeholder="word or phrase (tbh)" className={cn(input, "w-36 font-mono")} />
+ <input data-lexicon-say="" value={sayAs} onChange={(e) => setSayAs(e.target.value)} placeholder="said as (T-B-H)" className={cn(input, "w-36")} />
+ <button
+ type="button"
+ data-lexicon-add=""
+ disabled={busy || !word.trim() || !sayAs.trim()}
+ onClick={() => void post({ op: "say-add", word, say: sayAs }).then((ok) => ok && (setWord(""), setSayAs("")))}
+ className={buttonVariants({ variant: "outline", size: "sm" })}
+ >
+ Add
+ </button>
+ </div>
+ <div className="mt-1.5 flex flex-wrap items-center gap-1.5">
+ <input data-lexicon-try="" value={tryText} onChange={(e) => setTryText(e.target.value)} placeholder="try it: text a voice would read" className={cn(input, "w-64")} />
+ <button type="button" data-lexicon-try-go="" disabled={busy || !tryText.trim()} onClick={() => void post({ op: "say-try", text: tryText }).then((j) => setTried(j?.json?.said ?? null))} className={buttonVariants({ variant: "quiet", size: "sm" })}>
+ Try it
+ </button>
+ {tried !== null && (
+ <span className="text-text-2" data-lexicon-tried="">
+ said: “{tried}”
+ </span>
+ )}
+ </div>
+ {stale.length > 0 && (
+ <div className="mt-1.5 text-[11.5px] text-doubt-text" data-lexicon-stale={stale.length}>
+ {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.
+ </div>
+ )}
+ </section>
+ <section data-voice-map={Object.keys(v?.voices ?? {}).length}>
+ <h3 className="micro mb-1">
+ Voices · the narrator {v?.engine ?? ""} {v?.narrator ?? ""}
+ </h3>
+ <table className="w-full border-collapse">
+ <tbody>
+ {Object.entries(v?.voices ?? {}).map(([h, voiceName]) => (
+ <tr key={h} data-voice-map-row={h}>
+ <td className={cn(cell, "font-mono")}>{h === "*" ? "* everyone else" : `@${h}`}</td>
+ <td className={cell}>{voiceName}</td>
+ <td className={cn(cell, "text-right")}>
+ <button type="button" data-voice-map-remove={h} disabled={busy} onClick={() => void post({ op: "voices-remove", handle: h })} className={buttonVariants({ variant: "quiet", size: "sm" })} aria-label={`remove ${h}`}>
+ ✕
+ </button>
+ </td>
+ </tr>
+ ))}
+ {(v?.authors ?? [])
+ .filter((a) => !a.mapped)
+ .slice(0, 8)
+ .map((a) => (
+ <tr key={a.handle} className="text-muted" data-voice-author={a.handle}>
+ <td className={cn(cell, "font-mono")}>@{a.handle}</td>
+ <td className={cell}>
+ {a.voice} (default) · {a.items} item{a.items === 1 ? "" : "s"}, {a.context} context
+ </td>
+ <td className={cn(cell, "text-right")}>
+ <button type="button" onClick={() => setHandle(a.handle)} className={buttonVariants({ variant: "quiet", size: "sm" })}>
+ set
+ </button>
+ </td>
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ <div className="mt-1 flex flex-wrap items-center gap-1.5">
+ <input data-voice-map-handle="" value={handle} onChange={(e) => setHandle(e.target.value)} placeholder="handle (or *)" className={cn(input, "w-36 font-mono")} />
+ <input data-voice-map-voice="" value={voice} onChange={(e) => setVoice(e.target.value)} placeholder="voice (tara)" className={cn(input, "w-28")} />
+ <button
+ type="button"
+ data-voice-map-set=""
+ disabled={busy || !handle.trim() || !voice.trim()}
+ onClick={() => void post({ op: "voices-set", handle, voice }).then((ok) => ok && (setHandle(""), setVoice("")))}
+ className={buttonVariants({ variant: "outline", size: "sm" })}
+ >
+ Set
+ </button>
+ </div>
+ </section>
+ {error && (
+ <p role="alert" className="m-0 text-reject-text lg:col-span-2" data-pronunciation-error="">
+ {error}
+ </p>
+ )}
+ </div>
+ );
+}
diff --git a/umtool/components/projects/report/CutTab.tsx b/umtool/components/projects/report/CutTab.tsx
@@ -15,6 +15,7 @@ import FetchUnfetchedButton from "../FetchUnfetchedButton";
import PlayLink from "../PlayLink";
import { AddClipToggle } from "../AddClip";
import { Advanced, Options } from "@/components/ui/disclosure";
+import PronunciationPanel from "../PronunciationPanel";
import TightWindowsPanel from "./TightWindowsPanel";
import { clipRecord, storedUrlOf } from "@/lib/clips/stored";
import { Fragment } from "react";
@@ -481,6 +482,12 @@ export default async function CutTab({ project, detail, search, tabHref }: Repor
)}
{fetchBody && <FetchWindowsPanel project={project.id} items={fetchBody.items} skipped={fetchBody.skipped} lastRun={fetchBody.lastRun} />}
</Options>
+ {/* A cut of posts: what the voices say (the lexicon) and who reads whom (the voice map). */}
+ {entries.some((x) => x.kind === "post") && (
+ <Options id="cut-reads" label="Reads and voices" hint="pronunciation · voice map · try it">
+ <PronunciationPanel project={project.id} />
+ </Options>
+ )}
<Advanced id="cut" hint="voices · tight windows · bench prep">
{clips.length > 0 && (
<VoiceMatchPanel