Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: send audio clips, stems and transcripts to other Audio pages (#12811)
Etherlfed78103abef
diff --git a/studio/frontend/src/features/audio/audio-page.tsx b/studio/frontend/src/features/audio/audio-page.tsxindex 07da40a5f37..ad217a64e73 100644--- a/studio/frontend/src/features/audio/audio-page.tsx+++ b/studio/frontend/src/features/audio/audio-page.tsx@@ -55,13 +55,15 @@ import {isMusicGenerationModel,} from "./catalog";import type { ClipSendHandlers } from "./components/clip-card";+import { sendClipToMusic } from "./components/music-send-to";+import { SaveVoiceDialog } from "./components/save-voice-dialog";import { WorkflowTitleMenu } from "./components/workflow-title-menu";import { galleryCache, useAudioGallery, useWorkflowHistory } from "./hooks/use-audio-gallery";import { useAudioHandoff } from "./hooks/use-audio-handoff";import { useAudioModelSlot } from "./hooks/use-audio-model-slot";import { useCloneGeneration } from "./hooks/use-clone-generation";import { useConvertGeneration } from "./hooks/use-convert-generation";-import { useEditGeneration } from "./hooks/use-edit-generation";+import { adoptEditSource, useEditGeneration } from "./hooks/use-edit-generation";import { useSeparateGeneration } from "./hooks/use-separate-generation";import { useSpeechGeneration } from "./hooks/use-speech-generation";import { useSttSidecar } from "./hooks/use-stt-sidecar";@@ -109,11 +111,18 @@ import {transcribeLanguagesFor,} from "./transcribe-languages";import { type AudioPickerRow, audioRowMatchesWorkflow } from "./picker-filter";-import { useAudioCloneStore } from "./stores/audio-clone-store";+import {+ referenceTranscript,+ useAudioCloneStore,+} from "./stores/audio-clone-store";import { useAudioConvertStore } from "./stores/audio-convert-store";import { useAudioEditStore } from "./stores/audio-edit-store";+import { useAudioSeparateStore } from "./stores/audio-separate-store";+import { useAudioVoicesStore } from "./stores/audio-voices-store";import { useAudioWorkspaceStore } from "./stores/audio-workspace-store";+import { clipSendTargets, transcriptSendTargets } from "./send-targets";import { AudioToolPanels } from "./tools/tool-panel-host";+import type { TranscriptSource } from "./transcript-model";import {type AudioWorkflowId,audioWorkflowTab,@@ -751,46 +760,112 @@ export function AudioPage({() => handleClearGallery(ttsWorkflow),[handleClearGallery, ttsWorkflow],);+ // Switching pages mid-run would stop the run in progress; wait for it instead.+ const runBusy = useCallback(() => {+ if (busyRef.current === null) return false;+ toast.info("Wait for the current audio task to finish, then send it.");+ return true;+ }, [busyRef]);const handleSendToConvert = useCallback(- (clip: AudioGalleryClip) => {+ (clip: AudioGalleryClip, name = clip.prompt) => {if (!transitionWorkflow("convert")) return;useAudioConvertStore.getState().setSource({kind: "clip",id: clip.id,- name: clip.prompt,+ name,durationS: clip.duration_s ?? null,});},[transitionWorkflow],);const sendHandlersFor = useCallback(- (clip: AudioGalleryClip): ClipSendHandlers => ({- clone: () => {- if (transitionWorkflow("clone"))- adoptReference(clipReference({ ...clip, workflow: clipWorkflow(clip) }));- },- convert: () => handleSendToConvert(clip),- transcribe: () => {- // Switching mid-run would stop the run in progress; wait for it instead.- if (busyRef.current !== null) {- toast.info("Wait for the current audio task to finish, then send the clip.");- return;- }- if (!transitionWorkflow("transcribe")) return;- // The clip goes in by id, as "From history" does; the run keeps the page's own settings.- useAudioTranscribeStore.setState({- source: {+ (clip: AudioGalleryClip): ClipSendHandlers => {+ const reference = () =>+ clipReference({ ...clip, workflow: clipWorkflow(clip) });+ const handlers: ClipSendHandlers = {+ clone: () => {+ if (transitionWorkflow("clone")) adoptReference(reference());+ },+ edit: () => {+ if (transitionWorkflow("edit")) adoptEditSource(reference());+ },+ convert: () => handleSendToConvert(clip),+ separate: () => {+ if (!transitionWorkflow("separate")) return;+ useAudioSeparateStore.getState().setSource({kind: "clip",id: clip.id,name: clip.prompt || "Generated clip",durationS: clip.duration_s,- transcript: clip.prompt || null,- language: null,+ });+ },+ transcribe: () => {+ if (!transitionWorkflow("transcribe")) return;+ // The clip goes in by id, as "From history" does; the run keeps the page's own settings.+ useAudioTranscribeStore.setState({+ source: {+ kind: "clip",+ id: clip.id,+ name: clip.prompt || "Generated clip",+ durationS: clip.duration_s,+ transcript: clip.prompt || null,+ language: null,+ },+ });+ },+ };+ return Object.fromEntries(+ clipSendTargets(clip, ttsWorkflow).map((id) => [+ id,+ () => {+ if (!runBusy()) handlers[id]?.();},- });- },- }),- [transitionWorkflow, busyRef, handleSendToConvert],+ ]),+ );+ },+ [transitionWorkflow, runBusy, handleSendToConvert, ttsWorkflow],+ );+ const sendTranscriptHandlersFor = useCallback(+ (transcript: {+ text: string;+ source?: TranscriptSource | null;+ duration: number | null;+ }): ClipSendHandlers => {+ const { text, source, duration } = transcript;+ // Its transcript comes along, so Edit and Clone skip transcribing it again.+ const selection = source+ ? { ...source, durationS: duration, transcript: text, language: null }+ : null;+ const handlers: ClipSendHandlers = {+ speak: () => {+ if (transitionWorkflow("speak")) setPrompt(text);+ },+ edit: () => {+ if (!(selection && transitionWorkflow("edit"))) return;+ adoptEditSource(selection);+ useAudioEditStore+ .getState()+ .setTranscript(text.trim(), selection.id);+ },+ clone: () => {+ if (!(selection && transitionWorkflow("clone"))) return;+ adoptReference(selection);+ // Replaces typed text for an earlier reference; blank past 30 s (Clone sends only the start).+ useAudioCloneStore+ .getState()+ .applyTranscript(selection, referenceTranscript(selection).trim());+ },+ };+ return Object.fromEntries(+ transcriptSendTargets({ text, source, duration }).map((id) => [+ id,+ () => {+ if (!runBusy()) handlers[id]?.();+ },+ ]),+ );+ },+ [transitionWorkflow, runBusy, setPrompt],);const handleUseTextAgain = useCallback((clip: AudioGalleryClip) => {@@ -803,8 +878,35 @@ export function AudioPage({},[transitionWorkflow, setPrompt],);+ const [voiceClip, setVoiceClip] = useState<{+ id: string;+ name: string;+ transcript: string;+ } | null>(null);+ const [savingVoice, setSavingVoice] = useState(false);+ useEffect(() => {+ if (!active) return;+ return () => setSavingVoice(false);+ }, [active]);+ const handleSaveVoice = useCallback((clip: AudioGalleryClip) => {+ setVoiceClip({+ id: clip.id,+ // A clip's text is no name; the voice it was made from is, when it has one.+ name: (clip.reference_name ?? "").replace(/\.[a-z0-9]{2,4}$/i, ""),+ transcript: referenceTranscript(+ clipReference({ ...clip, workflow: clipWorkflow(clip) }),+ ),+ });+ setSavingVoice(true);+ }, []);const handleSendStem = useCallback(async (target: SendTarget, clip: AudioGalleryClip, name: string) => {+ if (target.workflow === "voice") {+ setVoiceClip({ id: clip.id, name, transcript: "" });+ setSavingVoice(true);+ return;+ }+ if (runBusy()) return;if (target.workflow === "clone") {if (!transitionWorkflow("clone")) return;// Adopted like any other clip, so the old reference's transcript does not stay attached.@@ -816,12 +918,15 @@ export function AudioPage({});return;}+ if (target.workflow === "convert") {+ handleSendToConvert(clip, name);+ return;+ }+ if (target.workflow === "music") {+ sendClipToMusic(clip, "edit", name);+ return;+ }if (target.workflow === "transcribe") {- // As in sendHandlersFor: switching mid-run would stop the run in progress.- if (busyRef.current !== null) {- toast.info("Wait for the current audio task to finish, then send the stem.");- return;- }if (!transitionWorkflow("transcribe")) return;// A stem is a history clip, so it goes in by id like any other.useAudioTranscribeStore.setState({@@ -836,7 +941,7 @@ export function AudioPage({});}},- [transitionWorkflow, busyRef],+ [transitionWorkflow, runBusy, handleSendToConvert],);const pageModelLoaded =@@ -1429,6 +1534,26 @@ export function AudioPage({<MediaRailResizeHandle kind="audio" placement="page" className="hidden @[50rem]:block" />{/* Portals to body, and this page stays mounted off-route, so gate it like the composer. */}{active && <GuidedTour {...tour.tourProps} />}+ <SaveVoiceDialog+ open={active && savingVoice}+ onOpenChange={setSavingVoice}+ mode="create"+ initial={{+ name: voiceClip?.name ?? "",+ transcript: voiceClip?.transcript ?? "",+ language: "",+ }}+ onSubmit={async (details) => {+ if (!voiceClip) return;+ const voice = await useAudioVoicesStore.getState().save({+ source: { clip_id: voiceClip.id },+ name: details.name,+ transcript: details.transcript || null,+ language: details.language || null,+ });+ toast.success(`Saved ${voice.name}. Pick it under Saved voice next time.`);+ }}+ />{/* Keep the tabs centered over the preview at every width. The model rail holds at its(draggable) width when space permits and shrinks only to preserve the controls. */}<div className="pointer-events-none relative z-40 grid h-[calc(48px*var(--ui-space-scale,1))] shrink-0 grid-cols-[minmax(0,var(--media-rail-width,calc(408px*var(--ui-space-scale,1))))_minmax(13rem,1fr)] @max-[30rem]:grid-cols-[minmax(0,1fr)_auto]">@@ -1817,6 +1942,7 @@ export function AudioPage({speakerNames={speakerNames}renameSpeaker={renameSpeaker}selectRecord={selectRecord}+ sendHandlersFor={sendTranscriptHandlersFor}/><output aria-live="polite" aria-atomic="true" className="sr-only">{transcribeAnnouncement}@@ -1829,6 +1955,7 @@ export function AudioPage({workflow: ttsWorkflow,peaksById,sendHandlersFor,+ onSaveVoice: handleSaveVoice,pending:busy === "generating" && generationPresentation? {diff --git a/studio/frontend/src/features/audio/components/clip-card.tsx b/studio/frontend/src/features/audio/components/clip-card.tsxindex c8597c27643..88a119d06dd 100644--- a/studio/frontend/src/features/audio/components/clip-card.tsx+++ b/studio/frontend/src/features/audio/components/clip-card.tsx@@ -19,17 +19,17 @@ import { Waveform } from "./waveform";export type ClipSendHandlers = Partial<Record<AudioWorkflowId, () => void>>;-export function ClipSendToMenu({- current,- handlers,-}: {- current: AudioWorkflowId;- handlers: ClipSendHandlers;-}) {- const targets = AUDIO_WORKFLOWS.filter(- (tab) => tab.id !== current && handlers[tab.id],- );- if (targets.length === 0) return null;+export function SendToItems({ handlers }: { handlers: ClipSendHandlers }) {+ return AUDIO_WORKFLOWS.filter((tab) => handlers[tab.id]).map((tab) => (+ <DropdownMenuItem key={tab.id} onClick={handlers[tab.id]}>+ <HugeiconsIcon icon={tab.icon} strokeWidth={1.75} className="size-icon" />+ {tab.label}+ </DropdownMenuItem>+ ));+}++export function ClipSendToMenu({ handlers }: { handlers: ClipSendHandlers }) {+ if (!Object.values(handlers).some(Boolean)) return null;return (<DropdownMenuSub><DropdownMenuSubTrigger>@@ -41,16 +41,7 @@ export function ClipSendToMenu({Send to</DropdownMenuSubTrigger><DropdownMenuSubContent>- {targets.map((tab) => (- <DropdownMenuItem key={tab.id} onClick={handlers[tab.id]}>- <HugeiconsIcon- icon={tab.icon}- strokeWidth={1.75}- className="size-icon"- />- {tab.label}- </DropdownMenuItem>- ))}+ <SendToItems handlers={handlers} /></DropdownMenuSubContent></DropdownMenuSub>);@@ -58,7 +49,7 @@ export function ClipSendToMenu({const CARD_CLASS = "w-full max-w-xl gap-3 px-5 py-4";-/** Never autoplays; a clip a run just made takes focus on its play button once. */+/** never autoplays; a new clip focuses its play button once. */export function ClipCard({title,model,diff --git a/studio/frontend/src/features/audio/components/music-send-to.tsx b/studio/frontend/src/features/audio/components/music-send-to.tsxindex 4066d5045d0..9e9d0329a75 100644--- a/studio/frontend/src/features/audio/components/music-send-to.tsx+++ b/studio/frontend/src/features/audio/components/music-send-to.tsx@@ -13,7 +13,7 @@ import { useAudioMusicStore } from "../stores/audio-music-store";import { useAudioWorkspaceStore } from "../stores/audio-workspace-store";import { clipWorkflow } from "../workflows";-// History is per page, so these only ever show on Music itself.+// history is scoped per page, so these actions appear only on Music.const SEND_LABEL: Record<SendAction, string> = {edit: "Edit",extend: "Extend",@@ -27,12 +27,13 @@ const SEND_ICON = {export function sendClipToMusic(clip: AudioGalleryClip,action: SendAction,+ name = clip.prompt || "Generated clip",): void {useAudioMusicStore.getState().pushClipToEdit({kind: "clip",id: clip.id,- name: clip.prompt || "Generated clip",+ name,durationS: clip.duration_s,transcript: null,language: null,diff --git a/studio/frontend/src/features/audio/hooks/use-music-generation.ts b/studio/frontend/src/features/audio/hooks/use-music-generation.tsindex 3d08860c553..a66db0b48bc 100644--- a/studio/frontend/src/features/audio/hooks/use-music-generation.ts+++ b/studio/frontend/src/features/audio/hooks/use-music-generation.ts@@ -20,6 +20,7 @@ import {musicBlocker,reloadNotice,variationsFor,+ withWaitingEdit,} from "../music/music-policy";import { parseMusicCapabilities } from "../music/music-types";import type {@@ -112,16 +113,17 @@ export function useMusicGeneration({modelName: string | null;musicLoaded: boolean;}) {- const capabilities = useMemo(- () =>- parseMusicCapabilities(status?.audio_music) ??- (musicLoaded ? null : MUSIC_PREVIEW_CAPABILITIES),- [status?.audio_music, musicLoaded],- );const pickedMode = useAudioMusicStore((state) => state.mode);const song = useAudioMusicStore((state) => state.song);const sfx = useAudioMusicStore((state) => state.sfx);const edit = useAudioMusicStore((state) => state.edit);+ const editWaiting = edit.source !== null;+ const capabilities = useMemo(() => {+ const loaded =+ parseMusicCapabilities(status?.audio_music) ??+ (musicLoaded ? null : MUSIC_PREVIEW_CAPABILITIES);+ return loaded && withWaitingEdit(loaded, editWaiting);+ }, [status?.audio_music, musicLoaded, editWaiting]);const rule = capabilities? effectiveMusicMode(capabilities, pickedMode): null;diff --git a/studio/frontend/src/features/audio/music/music-policy.ts b/studio/frontend/src/features/audio/music/music-policy.tsindex eec8dd68611..1e4e25a94a9 100644--- a/studio/frontend/src/features/audio/music/music-policy.ts+++ b/studio/frontend/src/features/audio/music/music-policy.ts@@ -55,6 +55,17 @@ export function effectiveMusicMode();}+/** A clip sent to edit stays in view even when the model cannot edit; Edit then says to load one that can. */+export function withWaitingEdit(+ capabilities: MusicCapabilities,+ editWaiting: boolean,+): MusicCapabilities {+ if (!editWaiting || capabilities.modes.some((rule) => rule.id === "edit")) {+ return capabilities;+ }+ return { modes: [...capabilities.modes, { id: "edit" }] };+}+const SECTION_NAMES = ["Intro","Verse",diff --git a/studio/frontend/src/features/audio/pages/separate-page.tsx b/studio/frontend/src/features/audio/pages/separate-page.tsxindex bbd138873ff..5f9a3458796 100644--- a/studio/frontend/src/features/audio/pages/separate-page.tsx+++ b/studio/frontend/src/features/audio/pages/separate-page.tsx@@ -35,6 +35,7 @@ import {type SeparateGeneration,} from "../hooks/use-separate-generation";import { useStemSources } from "../hooks/use-stem-sources";+import { STEM_SEND_TARGETS } from "../send-targets";import { saveAudio } from "../save-audio";import {SEPARATE_MAX_SECONDS,@@ -281,12 +282,7 @@ function downloadGroup(group: SeparationGroup) {return saveAudio(stemZipName(group.title), null, () => zipStems(files));}-const SEND_TARGETS: readonly SendTarget[] = [- { id: "transcribe", workflow: "transcribe", label: "Transcribe" },- { id: "clone", workflow: "clone", label: "Clone (as reference)" },-];--/** Keyed by group so each one starts from its own clock. */+/** keyed by group so each mixer starts from its own clock. */function SelectedSeparation({group,autoFocus,@@ -331,7 +327,7 @@ function SelectedSeparation({stems={stems}autoFocus={autoFocus}active={active}- sendTargets={SEND_TARGETS}+ sendTargets={STEM_SEND_TARGETS}onDownloadStem={(clipId) => {const clip = group.stems.find((item) => item.id === clipId);const src = sources.srcById[clipId];diff --git a/studio/frontend/src/features/audio/pages/transcribe-page.tsx b/studio/frontend/src/features/audio/pages/transcribe-page.tsxindex ef826a71b8e..a86b7341266 100644--- a/studio/frontend/src/features/audio/pages/transcribe-page.tsx+++ b/studio/frontend/src/features/audio/pages/transcribe-page.tsx@@ -20,6 +20,7 @@ import { cn } from "@/lib/utils";import {Copy01Icon,Download01Icon,+ SentIcon,StopIcon,} from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";@@ -32,9 +33,14 @@ import {AudioSourceInput,type AudioSourceInputHandle,} from "../components/audio-source-input";+import { SendToItems } from "../components/clip-card";import { Field } from "../components/field";import { TranscriptView } from "../components/transcript-view";-import { TranscriptExportItems, TranscriptGallery } from "../transcript-gallery";+import {+ TranscriptExportItems,+ TranscriptGallery,+ type TranscriptSendHandlers,+} from "../transcript-gallery";import { TranscriptionProgress } from "../transcription-progress";import type { AudioHostState } from "../hooks/audio-host-state";import type { AudioSourceStatus } from "../hooks/audio-source-state";@@ -237,6 +243,7 @@ export function TranscribeOutput({speakerNames,renameSpeaker,selectRecord,+ sendHandlersFor,}: Pick<Transcription,| "transcriptionStartedAt"@@ -260,9 +267,16 @@ export function TranscribeOutput({| "renameSpeaker"| "selectRecord"> &- Pick<AudioHostState, "busy" | "active" | "mode">) {+ Pick<AudioHostState, "busy" | "active" | "mode"> & {+ sendHandlersFor: TranscriptSendHandlers;+ }) {const language = transcriptDetails.language ?? transcriptRecord?.language;const duration = transcriptDetails.duration ?? transcriptRecord?.duration;+ const sendHandlers = sendHandlersFor({+ text: transcript,+ source: transcriptDetails.source ?? transcriptRecord?.source,+ duration: duration ?? null,+ });return (<><div className="hover-scrollbar flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto">@@ -326,6 +340,19 @@ export function TranscribeOutput({/></DropdownMenuContent></DropdownMenu>+ {Object.keys(sendHandlers).length > 0 ? (+ <DropdownMenu>+ <DropdownMenuTrigger asChild={true}>+ <Button variant="secondary" size="sm">+ <HugeiconsIcon icon={SentIcon} className="mr-2 size-3.5" />+ Send to+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="start">+ <SendToItems handlers={sendHandlers} />+ </DropdownMenuContent>+ </DropdownMenu>+ ) : null}</div><div className="flex min-w-0 flex-wrap items-center gap-x-2 text-ui-11p5 text-muted-foreground"><span className="min-w-0 truncate">{transcribedName}</span>@@ -370,6 +397,7 @@ export function TranscribeOutput({latest={transcriptRecord}canSelect={confirmTranscriptReplacement}onSelect={selectRecord}+ sendHandlersFor={sendHandlersFor}onDelete={(ids) => {if (transcriptRecord &&diff --git a/studio/frontend/src/features/audio/pages/tts-workspace.tsx b/studio/frontend/src/features/audio/pages/tts-workspace.tsxindex 3cc240bdbbf..e322ee2348c 100644--- a/studio/frontend/src/features/audio/pages/tts-workspace.tsx+++ b/studio/frontend/src/features/audio/pages/tts-workspace.tsx@@ -21,6 +21,7 @@ import { cn } from "@/lib/utils";import {AudioWave01Icon,Copy01Icon,+ FloppyDiskIcon,SparklesIcon,StopIcon,} from "@hugeicons/core-free-icons";@@ -445,7 +446,6 @@ function ClipBadge({ text }: { text: string | null | undefined }) {}export function TtsOutput({- workflow,clips,selectedClip,selectedClipSrc,@@ -470,6 +470,7 @@ export function TtsOutput({onUseTextAgain,handleCopyPrompt,sendHandlersFor,+ onSaveVoice,pending,freshClipId,onFreshClipFocused,@@ -505,6 +506,7 @@ export function TtsOutput({handleClearGallery: () => Promise<void>;onUseTextAgain: (clip: AudioGalleryClip) => void;sendHandlersFor: (clip: AudioGalleryClip) => ClipSendHandlers;+ onSaveVoice: (clip: AudioGalleryClip) => void;pending: {title: string;status: string;@@ -517,7 +519,7 @@ export function TtsOutput({freshClipId: string | null;onFreshClipFocused: () => void;announcement: string;- /** A short tag after a clip's text, such as the voice a clone used. */+ /** short tag after a clip's text, such as the voice a clone used. */clipBadge?: (clip: AudioGalleryClip,place: "selected" | "history",@@ -574,7 +576,15 @@ export function TtsOutput({onAddToProject={(projectId) => addAudioClipToProject(clip.id, projectId)}leadingItems={<>- <ClipSendToMenu current={workflow} handlers={sendHandlersFor(clip)} />+ <ClipSendToMenu handlers={sendHandlersFor(clip)} />+ <DropdownMenuItem onClick={() => onSaveVoice(clip)}>+ <HugeiconsIcon+ icon={FloppyDiskIcon}+ strokeWidth={1.75}+ className="size-icon"+ />+ Save as voice…+ </DropdownMenuItem><DropdownMenuItem onClick={() => onUseTextAgain(clip)}><HugeiconsIconicon={SparklesIcon}diff --git a/studio/frontend/src/features/audio/send-targets.ts b/studio/frontend/src/features/audio/send-targets.tsnew file mode 100644index 00000000000..d6efced4cbe--- /dev/null+++ b/studio/frontend/src/features/audio/send-targets.ts@@ -0,0 +1,75 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// free of app imports so the node test runner can load it directly.++import {+ EDIT_SOURCE_MAX_SECONDS,+ EDIT_SOURCE_SLACK_SECONDS,+} from "./audio-run-request";+import type { SendTarget } from "./components/stem-mixer-types";+import type { TranscriptSource } from "./transcript-model";+import { type AudioWorkflowId, clipWorkflow } from "./workflows";++const SPEECH_WORKFLOWS: ReadonlySet<string> = new Set([+ "speak",+ "clone",+ "edit",+ "convert",+]);++// edit refuses a longer recording rather than cutting it.+function fitsEdit(durationS: number | null | undefined): boolean {+ return (+ durationS == null ||+ durationS <= EDIT_SOURCE_MAX_SECONDS + EDIT_SOURCE_SLACK_SECONDS+ );+}++/** edit accepts only speech, including its own results; other pages accept any clip. */+export function clipSendTargets(+ clip: {+ workflow?: string | null;+ audio_type?: string | null;+ duration_s: number | null;+ },+ current: AudioWorkflowId,+): AudioWorkflowId[] {+ const targets: AudioWorkflowId[] = [+ "clone",+ "convert",+ "separate",+ "transcribe",+ ];+ if (SPEECH_WORKFLOWS.has(clipWorkflow(clip)) && fitsEdit(clip.duration_s)) {+ targets.push("edit");+ }+ return targets.filter((id) => id !== current || id === "edit");+}++export const STEM_SEND_TARGETS: readonly SendTarget[] = [+ { id: "clone", workflow: "clone", label: "Clone (as reference)" },+ { id: "convert", workflow: "convert", label: "Convert" },+ { id: "music", workflow: "music", label: "Music edit" },+ { id: "transcribe", workflow: "transcribe", label: "Transcribe" },+ { id: "voice", workflow: "voice", label: "Save as voice…" },+];++/** text goes to speak; edit and clone also require its source audio. */+export function transcriptSendTargets({+ text,+ source,+ duration,+}: {+ text: string;+ source: TranscriptSource | null | undefined;+ duration: number | null | undefined;+}): AudioWorkflowId[] {+ if (!text.trim()) return [];+ const targets: AudioWorkflowId[] = ["speak"];+ if (!source) return targets;+ // edit cannot take a saved voice as its recording.+ if (source.kind !== "voice" && fitsEdit(duration)) targets.push("edit");+ targets.push("clone");+ return targets;+}diff --git a/studio/frontend/src/features/audio/stores/audio-clone-store.ts b/studio/frontend/src/features/audio/stores/audio-clone-store.tsindex e2ccdf988bc..ee64c9d08b8 100644--- a/studio/frontend/src/features/audio/stores/audio-clone-store.ts+++ b/studio/frontend/src/features/audio/stores/audio-clone-store.ts@@ -10,13 +10,13 @@ import {const AUDIO_CLONE_STORAGE_KEY = "unsloth_audio_clone_v1";-// Clone sends the reference's first 30 s, so a longer clip's full text would not match it.-function referenceTranscript(next: AudioSourceSelection | null): string {+// clone sends the reference's first 30 s, so a longer clip's full text would not match it.+export function referenceTranscript(next: AudioSourceSelection | null): string {if (!next || (next.durationS ?? 0) > REFERENCE_MAX_SECONDS) return "";return next.transcript || "";}-/** Also holds every page's tool values, not just Clone's. */+/** also holds every page's tool values, not just clone's. */interface AudioCloneState {reference: AudioSourceSelection | null;referenceText: string;diff --git a/studio/frontend/src/features/audio/transcript-gallery.tsx b/studio/frontend/src/features/audio/transcript-gallery.tsxindex c69c5e30fcf..89e4497c528 100644--- a/studio/frontend/src/features/audio/transcript-gallery.tsx+++ b/studio/frontend/src/features/audio/transcript-gallery.tsx@@ -30,12 +30,20 @@ import { copyToClipboard } from "@/lib/copy-to-clipboard";import { toast } from "@/lib/toast";import { cn } from "@/lib/utils";import { archiveTranscript, deleteTranscript, listTranscripts } from "./api";+import {+ type ClipSendHandlers,+ ClipSendToMenu,+} from "./components/clip-card";import { getTranscript } from "./transcribe-api";import {TRANSCRIPT_EXPORT_FORMATS,type TranscriptExportFormat,} from "./transcript-export";-import { detailsFrom, formatTimestamp } from "./transcript-model";+import {+ type TranscriptSource,+ detailsFrom,+ formatTimestamp,+} from "./transcript-model";import type { TranscriptRecord } from "./transcript-stream";export function TranscriptExportItems({@@ -98,6 +106,12 @@ function recordBadge(record: TranscriptRecord): string | null {return (record.segment_count ?? 0) > 0 ? "Timestamps" : null;}+export type TranscriptSendHandlers = (transcript: {+ text: string;+ source?: TranscriptSource | null;+ duration: number | null;+}) => ClipSendHandlers;+export function TranscriptGallery({active,currentId,@@ -106,6 +120,7 @@ export function TranscriptGallery({onDelete,canSelect,autoSelect,+ sendHandlersFor,}: {active: boolean;autoSelect: boolean;@@ -114,6 +129,7 @@ export function TranscriptGallery({onSelect: (record: TranscriptRecord) => void;onDelete: (ids: string[] | null) => void;canSelect: () => boolean;+ sendHandlersFor: TranscriptSendHandlers;}) {const [records, setRecords] = useState<TranscriptRecord[]>([]);const [archived, setArchived] = useState(false);@@ -306,6 +322,7 @@ export function TranscriptGallery({</Button></DropdownMenuTrigger><DropdownMenuContent align="end">+ <ClipSendToMenu handlers={sendHandlersFor(record)} /><TranscriptExportItemstimed={(record.segment_count ?? 0) > 0}label={(format) => (diff --git a/studio/frontend/tests/audio-clone-store.test.ts b/studio/frontend/tests/audio-clone-store.test.tsindex 5a4e1f00e2a..c3e0549c65b 100644--- a/studio/frontend/tests/audio-clone-store.test.ts+++ b/studio/frontend/tests/audio-clone-store.test.ts@@ -228,3 +228,37 @@ test("a reference longer than the 30 s cut brings no transcript, since only 30 s});assert.equal(store().referenceText, "Hi.");});++test("a transcript sent with its recording replaces words typed for another", () => {+ const store = () => useAudioCloneStore.getState();+ const sent = {+ kind: "clip" as const,+ id: "sent1",+ name: "take.wav",+ durationS: 3,+ transcript: "the sent words",+ };+ store().setReferenceText("typed for the old clip");+ store().adoptReference(sent);+ assert.equal(store().referenceText, "typed for the old clip");+ store().applyTranscript(sent, "the sent words");+ assert.equal(store().referenceText, "the sent words");+});++test("a sent transcript of a recording over 30 s leaves Clone's text blank", async () => {+ const { referenceTranscript } = await import(+ "../src/features/audio/stores/audio-clone-store.ts"+ );+ const store = () => useAudioCloneStore.getState();+ const long = {+ kind: "clip" as const,+ id: "long1",+ name: "talk.wav",+ durationS: 45,+ transcript: "forty five seconds of words",+ };+ store().setReferenceText("typed for the old clip");+ store().adoptReference(long);+ store().applyTranscript(long, referenceTranscript(long));+ assert.equal(store().referenceText, "");+});diff --git a/studio/frontend/tests/audio-convert-policy.test.ts b/studio/frontend/tests/audio-convert-policy.test.tsindex 6cd016ef022..74f0e139a81 100644--- a/studio/frontend/tests/audio-convert-policy.test.ts+++ b/studio/frontend/tests/audio-convert-policy.test.ts@@ -372,7 +372,7 @@ test("Use again re-uploads a conversion's kept source instead of its expiring upconst SEND_TO_HAS_CONVERT = /convert: \(\) => handleSendToConvert\(clip\),/;const SEND_TO_CLONE_KEEPS_LABELS_OUT =- /adoptReference\(clipReference\(\{ \.\.\.clip, workflow: clipWorkflow\(clip\) \}\)\)/;+ /const reference = \(\) =>\s*clipReference\(\{ \.\.\.clip, workflow: clipWorkflow\(clip\) \}\);\s*const handlers: ClipSendHandlers = \{\s*clone: \(\) => \{\s*if \(transitionWorkflow\("clone"\)\) adoptReference\(reference\(\)\);/;const WORKSPACE_FOCUSES_A_FRESH_CUSTOM_PLAYER =/renderPlayer\(\s*selectedClip,\s*selectedClipSrc,\s*selectedClip\.id === freshClipId \? focusFreshClip : undefined,?\s*\)/;diff --git a/studio/frontend/tests/audio-edit-store.test.ts b/studio/frontend/tests/audio-edit-store.test.tsindex c9868524f80..6d564d9ac85 100644--- a/studio/frontend/tests/audio-edit-store.test.ts+++ b/studio/frontend/tests/audio-edit-store.test.ts@@ -54,6 +54,11 @@ test("② follows ① until the user types in it, and Reset puts it back", () =>state().setEdited("It was a rainy day.");state().setTranscript("It was a fine day!");assert.deepEqual(draft(), ["It was a rainy day.", "in2"]);+ state().setTranscript("A newer saved transcript.", "in2");+ assert.deepEqual(+ [state().transcript, ...draft()],+ ["A newer saved transcript.", "It was a rainy day.", "in2"],+ );state().setDelivery({ pitchSteps: 4 });assert.deepEqual(state().delivery, { speed: 1.5, pitchSteps: 4 });const { state: saved, version } = JSON.parse(store.get(KEY) ?? "{}");diff --git a/studio/frontend/tests/audio-music-policy.test.ts b/studio/frontend/tests/audio-music-policy.test.tsindex 9c9b6fd568b..a8bdbd3ea59 100644--- a/studio/frontend/tests/audio-music-policy.test.ts+++ b/studio/frontend/tests/audio-music-policy.test.ts@@ -15,6 +15,7 @@ const {buildMusicRunRequest,durationLabel,effectiveMusicMode,+ withWaitingEdit,musicModeHint,musicModeLabel,insertSectionTag,@@ -405,3 +406,23 @@ test("instrumental-only models say so in the mode label and length wording", ()"Length (seconds, approximate)",);});++test("a clip waiting in Edit keeps the Edit tab, even on a model that cannot edit", () => {+ const songOnly = { modes: [{ id: "song" as const }] };+ const waiting = withWaitingEdit(songOnly, true);+ assert.deepEqual(+ waiting.modes.map((rule) => rule.id),+ ["song", "edit"],+ );+ // The added mode has no actions, so the page says the model cannot edit and Generate stays blocked.+ assert.equal(effectiveMusicMode(waiting, "edit").actions, undefined);+ assert.equal(effectiveMusicMode(songOnly, "edit").id, "song");+ assert.equal(withWaitingEdit(songOnly, false), songOnly);+ const editing = {+ modes: [+ { id: "song" as const },+ { id: "edit" as const, actions: ["repaint" as const] },+ ],+ };+ assert.equal(withWaitingEdit(editing, true), editing);+});diff --git a/studio/frontend/tests/audio-send-targets.test.ts b/studio/frontend/tests/audio-send-targets.test.tsnew file mode 100644index 00000000000..1bf972fe396--- /dev/null+++ b/studio/frontend/tests/audio-send-targets.test.ts@@ -0,0 +1,148 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import assert from "node:assert/strict";+import test from "node:test";++import { readSrc, registerBundlerResolver } from "./helpers/kit.ts";++registerBundlerResolver();+const { STEM_SEND_TARGETS, clipSendTargets, transcriptSendTargets } =+ await import("../src/features/audio/send-targets.ts");++const clip = (workflow: string, duration_s: number | null = 4) => ({+ workflow,+ duration_s,+});++test("speech clips can be edited, and Edit takes its own results again", () => {+ assert.deepEqual(clipSendTargets(clip("speak"), "speak"), [+ "clone",+ "convert",+ "separate",+ "transcribe",+ "edit",+ ]);+ assert.ok(clipSendTargets(clip("clone"), "clone").includes("edit"));+ assert.ok(clipSendTargets(clip("convert"), "convert").includes("edit"));+ assert.deepEqual(clipSendTargets(clip("edit"), "edit"), [+ "clone",+ "convert",+ "separate",+ "transcribe",+ "edit",+ ]);+ assert.ok(!clipSendTargets(clip("clone"), "clone").includes("clone"));+ assert.ok(!clipSendTargets(clip("convert"), "convert").includes("convert"));+});++test("music is split into stems but not sent to speech Edit", () => {+ assert.deepEqual(clipSendTargets(clip("music", 30), "music"), [+ "clone",+ "convert",+ "separate",+ "transcribe",+ ]);+ // older clips carry only an audio type+ assert.ok(+ !clipSendTargets(+ { audio_type: "minimax_music3", duration_s: 10 },+ "music",+ ).includes("edit"),+ );+});++test("a clip longer than Edit takes is not offered to Edit", () => {+ assert.ok(clipSendTargets(clip("speak", 30.05), "speak").includes("edit"));+ assert.ok(!clipSendTargets(clip("speak", 31), "speak").includes("edit"));+ // an unknown length is left to Edit's own check+ assert.ok(clipSendTargets(clip("speak", null), "speak").includes("edit"));+});++test("stems go to Clone, Convert, Music edit and Transcribe, or become a voice", () => {+ assert.deepEqual(+ STEM_SEND_TARGETS.map((target) => target.workflow),+ ["clone", "convert", "music", "transcribe", "voice"],+ );+ assert.equal(+ STEM_SEND_TARGETS.find((target) => target.workflow === "music")?.label,+ "Music edit",+ );+});++test("a transcript's text goes to Speak; Edit and Clone also need its audio", () => {+ const input = { kind: "input" as const, id: "a1", name: "take.wav" };+ assert.deepEqual(+ transcriptSendTargets({ text: "hello", source: input, duration: 12 }),+ ["speak", "edit", "clone"],+ );+ assert.deepEqual(+ transcriptSendTargets({ text: "hello", source: null, duration: 12 }),+ ["speak"],+ );+ assert.deepEqual(+ transcriptSendTargets({+ text: "hello",+ source: { kind: "voice", id: "v1", name: "Narrator" },+ duration: 8,+ }),+ ["speak", "clone"],+ );+ assert.deepEqual(+ transcriptSendTargets({ text: "hello", source: input, duration: 95 }),+ ["speak", "clone"],+ );+ assert.deepEqual(+ transcriptSendTargets({ text: " ", source: input, duration: 3 }),+ [],+ );+});++test("the Audio page wires every send, and waits out a running task first", () => {+ const host = readSrc("features/audio/audio-page.tsx");+ assert.match(host, /clipSendTargets\(clip, ttsWorkflow\)/);+ assert.match(host, /transcriptSendTargets\(\{ text, source, duration \}\)/);+ assert.match(host, /if \(!runBusy\(\)\) handlers\[id\]\?\.\(\)/);+ assert.match(+ host,+ /if \(transitionWorkflow\("edit"\)\) adoptEditSource\(reference\(\)\)/,+ );+ assert.match(host, /useAudioSeparateStore\.getState\(\)\.setSource\(\{/);+ assert.match(host, /sendClipToMusic\(clip, "edit", name\)/);+ const music = readSrc("features/audio/hooks/use-music-generation.ts");+ assert.match(+ music,+ /return loaded && withWaitingEdit\(loaded, editWaiting\);/,+ );+ assert.match(host, /source: \{ clip_id: voiceClip\.id \}/);+ assert.match(host, /<SaveVoiceDialog\s+open=\{active && savingVoice\}/);+ assert.match(+ host,+ /useEffect\(\(\) => \{\s*if \(!active\) return;\s*return \(\) => setSavingVoice\(false\);\s*\}, \[active\]\);/,+ );+ const transcriptSend = host.slice(+ host.indexOf("const sendTranscriptHandlersFor"),+ host.indexOf("const handleUseTextAgain"),+ );+ assert.doesNotMatch(transcriptSend, /runTranscription|handleTranscribe/);+ assert.match(+ transcriptSend,+ /adoptEditSource\(selection\);\s*useAudioEditStore\s*\.getState\(\)\s*\.setTranscript\(text\.trim\(\), selection\.id\);/,+ );+ assert.match(+ transcriptSend,+ /adoptReference\(selection\);[^]*?useAudioCloneStore\s*\.getState\(\)\s*\.applyTranscript\(selection, referenceTranscript\(selection\)\.trim\(\)\);/,+ );++ const menu = readSrc("features/audio/pages/tts-workspace.tsx");+ assert.match(menu, /onClick=\{\(\) => onSaveVoice\(clip\)\}/);+ const transcribe = readSrc("features/audio/pages/transcribe-page.tsx");+ assert.match(transcribe, /<SendToItems handlers=\{sendHandlers\} \/>/);+ const gallery = readSrc("features/audio/transcript-gallery.tsx");+ assert.match(+ gallery,+ /<ClipSendToMenu handlers=\{sendHandlersFor\(record\)\} \/>/,+ );+ const separate = readSrc("features/audio/pages/separate-page.tsx");+ assert.match(separate, /sendTargets=\{STEM_SEND_TARGETS\}/);+});diff --git a/studio/frontend/tests/audio-separate.test.ts b/studio/frontend/tests/audio-separate.test.tsindex 4f735a20b34..285036a23d0 100644--- a/studio/frontend/tests/audio-separate.test.ts+++ b/studio/frontend/tests/audio-separate.test.ts@@ -281,32 +281,28 @@ test("a loaded separation model is a main-slot audio model", () => {test("host and page wiring for Separate", () => {const host = readSrc("features/audio/audio-page.tsx");- // Leaving Audio stops a Separate recording and releases the mic, as on Clone.assert.match(host,/ttsWorkflow === "separate" \? \(\s*<AudioActiveProvider value=\{active\}>\s*<SeparateRail/,);assert.match(host, /ttsWorkflow === "separate"\s*\? separate\.blocker/);assert.match(host, /reason: "The loaded model separates audio\."/);- // Trained speech checkpoints are not separation models: only Speak and Music offer them.assert.match(host,/ttsWorkflow !== "speak" && ttsWorkflow !== "music"\s*\? \[\]/,);- // A stem sent to Transcribe mid-run would be dropped when the run stops.+ // switching to Transcribe mid-run would stop the run and drop the stemassert.match(host,- /target\.workflow === "transcribe"\) \{[\s\S]*?busyRef\.current !== null[\s\S]*?return;[\s\S]*?if \(!transitionWorkflow\("transcribe"\)\) return;[\s\S]*?useAudioTranscribeStore\.setState\(\{\s*source: \{\s*kind: "clip",\s*id: clip\.id/,+ /const handleSendStem = useCallback\([\s\S]*?if \(runBusy\(\)\) return;[\s\S]*?target\.workflow === "transcribe"\) \{\s*if \(!transitionWorkflow\("transcribe"\)\) return;[\s\S]*?useAudioTranscribeStore\.setState\(\{\s*source: \{\s*kind: "clip",\s*id: clip\.id/,);- // A separation that a refresh missed falls back on the Separate page.const generation = readSrc("features/audio/hooks/use-separate-generation.ts");assert.match(generation, /showRunResult\(\{[^}]*workflow: "separate"/);const page = readSrc("features/audio/pages/separate-page.tsx");assert.match(page, /allowSavedVoice=\{false\}/);assert.match(page, /expiredMessage=\{SEPARATE_TRACK_EXPIRED_MESSAGE\}/);assert.match(page, /maxRecordSeconds=\{SEPARATE_MAX_SECONDS - 1\}/);- // The mixer's own sources pin the group; a failed fetch retries instead of loading forever,- // and a stem that cannot load is marked so the mixer plays the others.+ // mixer sources pin the group; failed fetches retry, while unavailable stems are skippedassert.match(page, /useStemSources\(inputs, attempt\)/);assert.match(page, /sources\.failedIds\.length > 0/);assert.match(page, /setAttempt\(\(n\) => n \+ 1\)/);diff --git a/studio/frontend/tests/audio-workspace-split.test.ts b/studio/frontend/tests/audio-workspace-split.test.tsindex d056f4fbd68..2f3b03dcc59 100644--- a/studio/frontend/tests/audio-workspace-split.test.ts+++ b/studio/frontend/tests/audio-workspace-split.test.ts@@ -133,7 +133,6 @@ test("results show as a clip card with a waveform, never autoplaying", () => {assert.doesNotMatch(output + card, /autoPlay/);assert.match(output, /<ClipCard\s+\/\/[^\n]*\n\s*key=\{selectedClip\.id\}/);assert.match(card, /<Waveform\s+peaks=\{peaks\}/);- // A run in progress stands where its clip will appear, with Stop, and no second live region.assert.match(output,/\{pending \? \(\s*<PendingClipCard \{\.\.\.pending\} \/>/,@@ -146,12 +145,10 @@ test("results show as a clip card with a waveform, never autoplaying", () => {assert.doesNotMatch(card, /aria-live/);});-test("Send to lists the other Audio pages from the shared workflow list", () => {+test("Send to lists Audio pages from the shared workflow list", () => {const card = readSrc("features/audio/components/clip-card.tsx");- assert.match(- card,- /AUDIO_WORKFLOWS\.filter\(\s*\(tab\) => tab\.id !== current && handlers\[tab\.id\],?\s*\)/,- );+ // send-targets decides eligibility while the menu preserves page order+ assert.match(card, /AUDIO_WORKFLOWS\.filter\(\(tab\) => handlers\[tab\.id\]\)/);assert.match(host,/if \(!transitionWorkflow\("transcribe"\)\) return;[\s\S]{0,200}?useAudioTranscribeStore\.setState\(\{\s*source: \{\s*kind: "clip",\s*id: clip\.id,/,@@ -185,11 +182,15 @@ test("auto-selecting a page's history keeps another page's unsaved clip", () =>});test("Send to waits for a running task instead of stopping it and dropping the clip", () => {- // A switch mid-run stops the run, but the page stays busy until the stopped run settles, so the- // transcription was refused and the clip silently dropped.+ // switching mid-run can reject transcription and drop the clip before the stopped run settles+ assert.match(+ host,+ /const runBusy = useCallback\(\(\) => \{\s*if \(busyRef\.current === null\) return false;\s*toast\.info\([^)]*\);\s*return true;/,+ );+ // Transcribe must use the same busy guard as every other targetassert.match(host,- /transcribe: \(\) => \{[\s\S]*?if \(busyRef\.current !== null\) \{\s*toast\.info\([^)]*\);\s*return;\s*\}\s*if \(!transitionWorkflow\("transcribe"\)\) return;/,+ /clipSendTargets\(clip, ttsWorkflow\)\.map\(\(id\) => \[\s*id,\s*\(\) => \{\s*if \(!runBusy\(\)\) handlers\[id\]\?\.\(\);/,);});