"use client"; import { useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { CharacterTuning, type StaleRead, type TuningFields } from "./CharacterTuning"; // --------------------------------------------------------------------------- // A CHARACTER IS A PRESET (components/projects/VoicesPanel.tsx; /api/report/voices; the CLI is `umtool cast set`, // `umtool cast project

add|set|rm|undo|pool|keep`, `umtool posts character`). Works with the operator alone: // every field is a form field, every write the CLI's own command -- nothing here needs an agent. // // PresetEditor one character's two presets: SYNTHETIC (the stock voice, its speed, its Orpheus tuning and a // line to try it on: CharacterTuning.tsx) and RECORDED (what a // recording of them is made into: the stock voice it is converted to, the engine, the pitch // and semitones, cleaned or not, its edges trimmed or not and the room kept, and a DIRECTION // -- one line for the person reading, never sent to a model) -- the cast's or this video's own // ProjectCharacters THIS VIDEO's OWN characters (narration/characters.json): people who must not enter the pool // (anonymous ones go by "Anon 1" … here, in recording notes and on the cut's cards), add one, remove one, undo, "Add to the // pool"; and the post items that name a character of their own // --------------------------------------------------------------------------- export type Convert = { engine?: string; voice?: string; pitch?: "target" | "source" | "contour"; semitones?: number }; export type Synthetic = { voice?: string; speed?: number; tuning?: TuningFields }; export type Recorded = { convert?: Convert; enhance?: boolean; trim?: { on?: boolean; padMs?: number }; direction?: string }; export type PresetCharacter = { id: string; name: string; handles?: string[]; voice?: string; convert?: Convert; synthetic?: Synthetic; recorded?: Recorded; speakers?: string[]; note?: string; narrator?: boolean; anonymous?: boolean; shown?: string; layer?: "cast" | "project"; }; export type Engine = { id: string; label: string; voices: string[]; defaultVoice: string; weight: string }; export type ItemCharacter = { id: string; handle: string | null; character: string; found: boolean; layer: "cast" | "project" | null; name?: string; voice: { spec: string; from: string; speed?: number } }; type Post = { id: string; handle: string; author: string; text: string }; type PostFn = (body: Record) => Promise | null>; 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 pretty = (spec: string) => spec.replace(":", " · "); /** A recorded preset in words: "a recording → kokoro · am_michael (seed-vc), pitch contour +2 st · not cleaned · …". */ export function recordedWords(c: PresetCharacter): string { const rec = c.recorded; if (!rec) return ""; const bits: string[] = []; const cv = rec.convert; if (cv) { const n = Number(cv.semitones) || 0; const pitch = cv.pitch && cv.pitch !== "target" ? `, pitch ${cv.pitch}${n ? ` ${n > 0 ? "+" : "−"}${Math.abs(n)} st` : ""}` : ""; bits.push(`a recording → ${pretty(cv.voice ?? c.voice ?? "?")}${cv.engine ? ` (${cv.engine})` : ""}${pitch}`); } if (rec.enhance === false) bits.push("not cleaned"); if (rec.trim?.on === false) bits.push("edges not trimmed"); else if (typeof rec.trim?.padMs === "number") bits.push(`trim pad ${rec.trim.padMs} ms`); if (rec.direction) bits.push(`direction: “${rec.direction}”`); return bits.join(" · "); } /** A stock voice picked as engine + voice; `none` (a label) offers "no voice of its own". */ export function VoicePick({ value, onChange, engines, none = null, name }: { value: string; onChange: (v: string) => void; engines: Engine[]; none?: string | null; name: string }) { const at = value.indexOf(":"); const eng = at > 0 ? value.slice(0, at) : ""; const voice = at > 0 ? value.slice(at + 1) : ""; const engine = engines.find((e) => e.id === eng) ?? null; // A voice the editor's list does not carry (an older cast entry) stays selectable as it is. const voices = engine ? (engine.voices.includes(voice) || !voice ? engine.voices : [voice, ...engine.voices]) : []; return ( {engine && ( )} ); } type Form = { name: string; shown: string; voice: string; speed: string; convertVoice: string; convertEngine: string; convertPitch: string; convertSemitones: string; enhance: boolean; trim: boolean; trimPad: string; direction: string; }; const formOf = (c: PresetCharacter): Form => ({ name: c.name ?? "", shown: c.shown ?? "", voice: c.synthetic?.voice ?? c.voice ?? "", speed: typeof c.synthetic?.speed === "number" ? String(c.synthetic.speed) : "", convertVoice: c.recorded?.convert?.voice ?? "", convertEngine: c.recorded?.convert?.engine ?? "", convertPitch: c.recorded?.convert?.pitch ?? "", convertSemitones: typeof c.recorded?.convert?.semitones === "number" ? String(c.recorded.convert.semitones) : "", enhance: c.recorded?.enhance !== false, trim: c.recorded?.trim?.on !== false, trimPad: typeof c.recorded?.trim?.padMs === "number" ? String(c.recorded.trim.padMs) : "", direction: c.recorded?.direction ?? "", }); /** * ONE CHARACTER's PRESETS, editable: Save is `umtool cast set …` (scope "cast": every project) or `umtool cast * project

set …` (scope "project": this video only). A field left empty is its default again. */ export function PresetEditor({ c, scope, engines, convertEngines, busy, post, onSaved, onClose, project = null, stale = [], }: { c: PresetCharacter; scope: "cast" | "project"; engines: Engine[]; convertEngines: string[]; busy: boolean; post: PostFn; onSaved: (what: string) => void; onClose: () => void; /** The project the page is of: its tuning tried on this project's lines (none: no tuning row). */ project?: string | null; /** The reads by this character made with other settings than its tuning now (cast.mjs tuningStale). */ stale?: StaleRead[]; }) { // (The panel keys this editor by the character as it is stored: another one opened, or this one saved, is a new form. // Its Orpheus tuning is left out of the key: Keep these settings must not throw away unsaved edits above it.) const [f, setF] = useState

(() => formOf(c)); const set = (k: K, v: Form[K]) => setF((x) => ({ ...x, [k]: v })); const follows = f.convertPitch === "source" || f.convertPitch === "contour"; const save = async () => { const j = await post({ op: "character-set", scope, id: c.id, ...(f.name.trim() && f.name.trim() !== c.name ? { name: f.name.trim() } : {}), ...(c.anonymous && f.shown.trim() && f.shown.trim() !== (c.shown ?? "") ? { shown: f.shown.trim() } : {}), voice: f.voice, speed: f.voice ? f.speed : "", convertVoice: f.convertVoice, convertEngine: f.convertEngine, convertPitch: f.convertPitch, convertSemitones: follows ? f.convertSemitones : "", // On is the default: said only when it is off, so a preset nobody touched stays as short as it was. enhance: f.enhance ? "" : "off", trim: f.trim ? (f.trimPad.trim() ? "on" : "") : "off", trimPad: f.trim ? f.trimPad.trim() : "", direction: f.direction.trim(), }); if (j) onSaved(`${c.name}: its presets saved ${scope === "cast" ? "in the cast (every project)" : "for this video only"}`); }; const row = "flex flex-wrap items-center gap-x-3 gap-y-1.5"; const lab = "inline-flex items-center gap-1.5"; return (

presets · {c.anonymous ? `${c.shown} (anonymous)` : c.name} {scope === "cast" ? "the cast: the same in every project" : "this video only"}

{c.anonymous && ( )}

synthetic · a read the editor synthesizes

voice set("voice", v)} engines={engines} none={scope === "project" ? "none of its own (the cast's, the narrator's…)" : null} />
{project && (c.synthetic?.voice ?? c.voice) && ( )}

recorded · a recording of them, made their read

converted to set("convertVoice", v)} engines={engines} none={f.voice ? `its own voice (${pretty(f.voice)})` : "its own voice"} />
); } /** THIS VIDEO's OWN characters, and the items that name a character of their own. */ export function ProjectCharacters({ own, cast, itemCharacters, posts, charactersError, busy, post, onChanged, onOpen, open, }: { own: PresetCharacter[]; cast: PresetCharacter[]; itemCharacters: ItemCharacter[]; posts: Post[]; charactersError?: string; busy: boolean; post: PostFn; onChanged: (what: string) => void; onOpen: (id: string) => void; open: string | null; }) { const [add, setAdd] = useState({ id: "", name: "", handles: "", anonymous: false, shown: "" }); const [item, setItem] = useState({ item: posts[0]?.id ?? "", character: "" }); const cell = "border-t border-seam px-2 py-1 align-top"; const idOk = /^[a-z0-9][a-z0-9_-]{0,47}$/.test(add.id); const send = async (body: Record, what: string) => { const j = await post(body); if (j) onChanged(what); return j; }; return (

this video's own characters · {own.length} people who stay out of the pool — an anonymous one goes by its shown name here, in recording notes and on the cut's cards

{charactersError &&

this video's characters are not read: {charactersError}

} {own.length > 0 && ( {own.map((c) => ( ))}
{c.anonymous ? c.shown : c.name} {c.anonymous && anonymous} {(c.handles ?? []).map((h) => `@${h}`).join(" ")} {c.voice ? pretty(c.voice) : no voice of its own} {typeof c.synthetic?.speed === "number" ? ` ×${c.synthetic.speed}` : ""} {recordedWords(c)} {" "} {!c.anonymous && ( )}{" "}
)}
setAdd({ ...add, id: e.target.value.toLowerCase() })} placeholder="id (anon-1)" className={cn(input, "w-28")} aria-label="the new character's id" /> setAdd({ ...add, name: e.target.value })} placeholder={add.anonymous ? "your label for them (optional)" : "name"} className={cn(input, "w-44")} aria-label="the new character's name" /> setAdd({ ...add, handles: e.target.value })} placeholder="handles: a,b" className={cn(input, "w-40")} aria-label="the handles it covers" /> {add.anonymous && setAdd({ ...add, shown: e.target.value })} placeholder="shown as (Anon 1, Anon 2 …)" className={cn(input, "w-44")} aria-label="the name it is shown under" />}

an item read as a character of its own · {itemCharacters.length} its presets answer for that item before its author's handle does

{itemCharacters.length > 0 && (
    {itemCharacters.map((it) => (
  • {it.id} {it.handle ? ` @${it.handle}` : ""} — read as {it.name ?? it.character} {it.found ? ( <> {" "} ({it.layer === "project" ? "this video's" : "the cast's"}): {pretty(it.voice.spec)} {typeof it.voice.speed === "number" ? ` ×${it.voice.speed}` : ""} ) : ( — no such character: it reads as its author does ({pretty(it.voice.spec)}) )}{" "}
  • ))}
)} {posts.length > 0 && (
)}
); }