Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Spoken language: a language stored as a name shows and sends as the model's code

Claudec30677123309
diff --git a/src/components/canvas/nodes.tsx b/src/components/canvas/nodes.tsx
index c6d4ba43..f3e7db0b 100644
--- a/src/components/canvas/nodes.tsx
+++ b/src/components/canvas/nodes.tsx
@@ -91,7 +91,7 @@ import {
} from "@/lib/catalog/canvas";
import { OPERATION_LABELS, type Engine, type MediaKind, type ModelDef, type OutputFile } from "@/lib/catalog/types";
import { formatCost } from "@/lib/format";
-import { spokenLanguageName, spokenLanguageOptions } from "@/lib/speech-languages";
+import { matchSpokenLanguage, spokenLanguageName, spokenLanguageOptions } from "@/lib/speech-languages";
import { cn } from "@/lib/utils";
import { NodeIcon, PORT_COLOR, useEditorActions, useEditorGlobals, useEditorSelector, useNodeResults, useNodeView, type EditorSnapshot, type NodeResults } from "./canvas-context";
@@ -578,12 +578,15 @@ function ModelOptions({ id, model, data }: { id: string; model: ModelDef; data:
}
// Transcribers: the language of the speech, detected unless you pick one.
if (o.sourceLanguages?.length) {
- const codes = ["auto", ...spokenLanguageOptions(o.sourceLanguages).map((l) => l.code)];
+ const listed = spokenLanguageOptions(o.sourceLanguages).map((l) => l.code);
+ // A stored language the model doesn't list (or lists by another code) shows as what is sent.
+ const value = p.sourceLanguage ? (matchSpokenLanguage(p.sourceLanguage, listed) ?? p.sourceLanguage) : "auto";
+ const codes = ["auto", ...(listed.includes(value) || value === "auto" ? [] : [value]), ...listed];
items.push(
<OptionSelect
key="spoken"
label="Spoken language"
- value={p.sourceLanguage ?? "auto"}
+ value={value}
options={codes}
onChange={(v) => set({ sourceLanguage: v === "auto" ? undefined : v })}
format={(v) => (v === "auto" ? "Detect language" : spokenLanguageName(v))}
diff --git a/src/components/studio/settings-panel.tsx b/src/components/studio/settings-panel.tsx
index 85a72f2e..e09e6510 100644
--- a/src/components/studio/settings-panel.tsx
+++ b/src/components/studio/settings-panel.tsx
@@ -9,7 +9,7 @@ import { Switch } from "@/components/ui/switch";
import { OPERATION_LABELS, type GenParams, type ModelDef, type Operation } from "@/lib/catalog/types";
import { durationLabel, hiddenChanges, settingsSummary, type SettingsShape } from "@/lib/composer";
import { ratioValue } from "@/lib/format";
-import { spokenLanguageOptions } from "@/lib/speech-languages";
+import { matchSpokenLanguage, spokenLanguageName, spokenLanguageOptions } from "@/lib/speech-languages";
import { cn } from "@/lib/utils";
import { SliderControls } from "./audio-controls";
import { Chip } from "./chip";
@@ -88,16 +88,23 @@ function SeedInput({ value, onChange }: { value: number; onChange: (v: number) =
);
}
-/** The language of the speech a transcriber hears: detected unless you pick one (sent as params.sourceLanguage). */
+/**
+ * The language of the speech a transcriber hears: detected unless you pick one (sent as
+ * params.sourceLanguage). A stored value the model doesn't list stays on show as it is, so the
+ * picker says what the chip says and the request sends.
+ */
function SpokenLanguage({ codes, value, onChange }: { codes: string[]; value?: string; onChange: (v: string | undefined) => void }) {
const options = useMemo(() => spokenLanguageOptions(codes), [codes]);
+ const listed = value ? matchSpokenLanguage(value, options.map((l) => l.code)) : undefined;
+ const selected = !value ? "auto" : (listed ?? value);
return (
- <Select value={value && codes.includes(value) ? value : "auto"} onValueChange={(v) => onChange(v === "auto" ? undefined : v)}>
+ <Select value={selected} onValueChange={(v) => onChange(v === "auto" ? undefined : v)}>
<SelectTrigger className="w-full" aria-label="Spoken language">
<SelectValue />
</SelectTrigger>
<SelectContent className="max-h-72">
<SelectItem value="auto">Detect automatically</SelectItem>
+ {value && !listed && <SelectItem value={value}>{spokenLanguageName(value)}</SelectItem>}
{options.map((l) => (
<SelectItem key={l.code} value={l.code}>
{l.name}
diff --git a/src/components/studio/studio-page.tsx b/src/components/studio/studio-page.tsx
index 72c45052..a4d78273 100644
--- a/src/components/studio/studio-page.tsx
+++ b/src/components/studio/studio-page.tsx
@@ -11,6 +11,7 @@ import type { Generation, MediaKind, ModelDef, Preset } from "@/lib/catalog/type
import { useEngine, useGenerations } from "@/lib/api";
import { handoffKey, mergeHandoff, promptShown } from "@/lib/composer";
import { reuseSignature, withSignatureWords } from "@/lib/catalog/palettes";
+import { matchSpokenLanguage } from "@/lib/speech-languages";
import { SoulPresetCards } from "@/components/moodboards/soul-preset-cards";
import type { StudioCatalog } from "@/lib/studio-catalog";
import { cn } from "@/lib/utils";
@@ -71,7 +72,7 @@ function initialDraft(
}
/** Rebuild a composer draft from a past generation ("Reuse"). */
-function draftFromGeneration(g: Generation, config: StudioConfig): Partial<Draft> {
+function draftFromGeneration(g: Generation, config: StudioConfig, getModel: (id: string) => ModelDef | undefined): Partial<Draft> {
// A run styled by the Color signature / Moodboard chips comes back as it was before they routed it,
// with the picks on the chips (studios without the chips get the styled prompt instead).
const signed = config.signature ? reuseSignature(g.request) : null;
@@ -84,11 +85,15 @@ function draftFromGeneration(g: Generation, config: StudioConfig): Partial<Draft
if (r.inputs?.endImage) slots.endImage = slot(r.inputs.endImage);
if (r.inputs?.video) slots.video = slot(r.inputs.video);
if (r.inputs?.audio) slots.audio = slot(r.inputs.audio);
+ const params = { ...r.params };
+ // A spoken language stored as a name (Assist's "Spanish") or a locale comes back as the model's own code.
+ const languages = getModel(r.modelId)?.options.sourceLanguages;
+ if (languages?.length && params.sourceLanguage) params.sourceLanguage = matchSpokenLanguage(params.sourceLanguage, languages) ?? params.sourceLanguage;
return {
prompt: r.prompt ?? "",
negativePrompt: r.negativePrompt ?? "",
modelId: r.modelId,
- params: { ...r.params },
+ params,
slots,
refs,
presetId: r.presetId,
@@ -233,14 +238,15 @@ function StudioBody({ header, tabs }: { header?: React.ReactNode; tabs?: React.R
// While the feed loads (and in the prerendered shell) the page shows the hero and the composer, never a blank area.
const hasItems = items.length > 0;
const offscreen = useOffscreenResults(feed.data);
+ const catalog = useCatalog();
const reuse = useCallback(
(g: Generation) => {
- setDraft(draftFromGeneration(g, config));
+ setDraft(draftFromGeneration(g, config, catalog.getModel));
if (g.engine !== engine) setEngine(g.engine);
requestAnimationFrame(() => document.querySelector<HTMLTextAreaElement>("[data-composer] textarea")?.focus());
},
- [config, engine, setDraft, setEngine],
+ [catalog, config, engine, setDraft, setEngine],
);
return (
diff --git a/src/lib/speech-languages.ts b/src/lib/speech-languages.ts
index fc0bd6de..0f0def36 100644
--- a/src/lib/speech-languages.ts
+++ b/src/lib/speech-languages.ts
@@ -71,3 +71,21 @@ export function spokenLanguageOptions(codes: readonly string[]): { code: string;
}
return out.sort((a, b) => a.name.localeCompare(b.name, "en"));
}
+
+/**
+ * The code in a model's list that means `value`: the code itself (any case), its base language
+ * ("es-MX", "pt_BR", "German (de)"), or its English name ("Spanish", as Assist stores it), also when
+ * the list names that language by another code. Undefined when the model doesn't list it.
+ */
+export function matchSpokenLanguage(value: string, codes: readonly string[]): string | undefined {
+ const v = value.trim();
+ if (!v) return undefined;
+ const find = (code: string) => codes.find((c) => c.toLowerCase() === code.toLowerCase());
+ const exact = find(v);
+ if (exact) return exact;
+ const base = /\(([a-z]{2,3})\)\s*$/i.exec(v)?.[1] ?? /^([a-z]{2,3})(?:[-_][a-z0-9]+)+$/i.exec(v)?.[1];
+ const byBase = base && find(base);
+ if (byBase) return byBase;
+ const name = (base || /^[a-z]{2,3}$/i.test(v) ? spokenLanguageName((base ?? v).toLowerCase()) : v).toLowerCase();
+ return codes.find((c) => spokenLanguageName(c).toLowerCase() === name);
+}
diff --git a/tests/composer.test.ts b/tests/composer.test.ts
index d843c90a..86fbca56 100644
--- a/tests/composer.test.ts
+++ b/tests/composer.test.ts
@@ -25,7 +25,7 @@ import { appStudio, EDIT_STUDIO, IMAGE_STUDIO, JOIN_CLIPS_STUDIO, LIPSYNC_STUDIO
import { studioCatalog } from "@/lib/studio-catalog";
import { buildPayload } from "@/lib/catalog/payload";
import { asrLanguage, whisperLanguage } from "@/lib/comfy";
-import { spokenLanguageName, spokenLanguageOptions } from "@/lib/speech-languages";
+import { matchSpokenLanguage, spokenLanguageName, spokenLanguageOptions } from "@/lib/speech-languages";
const model = (id: string) => {
const m = getModel(id);
@@ -95,6 +95,22 @@ describe("settings summary", () => {
expect(spokenLanguageOptions(model("whisper").options.sourceLanguages!).length).toBeGreaterThan(90);
});
+ it("finds a model's code for a language stored as a name, a locale or an alias", () => {
+ const scribe = model("scribe-v2").options.sourceLanguages!;
+ // Assist stores the language as free text ("Spanish"): reused in Audio → Transcribe, the picker
+ // selects Spanish and the request sends the code, as the chip says.
+ expect(matchSpokenLanguage("Spanish", scribe)).toBe("es");
+ expect(matchSpokenLanguage("spanish", scribe)).toBe("es");
+ expect(matchSpokenLanguage("es", scribe)).toBe("es");
+ expect(matchSpokenLanguage("ES-mx", scribe)).toBe("es");
+ expect(matchSpokenLanguage("pt_BR", scribe)).toBe("pt");
+ expect(matchSpokenLanguage("German (de)", scribe)).toBe("de");
+ // The picker lists one code per name: another code for the same language finds it.
+ expect(matchSpokenLanguage("tl", ["en", "fil"])).toBe("fil");
+ expect(matchSpokenLanguage("Klingon", scribe)).toBeUndefined();
+ expect(matchSpokenLanguage(" ", scribe)).toBeUndefined();
+ });
+
it("counts the changes the chip doesn't spell out", () => {
const m = model("elevenlabs-v4");
const slider = m.options.sliders![0];