Skip to content

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.

Studio: fix audio mic choice, reload page, tour copy and palette search (#12813)

Etherldd04695e21b4
diff --git a/studio/frontend/src/components/command-palette.tsx b/studio/frontend/src/components/command-palette.tsx
index 22c304cc8db..710f4609901 100644
--- a/studio/frontend/src/components/command-palette.tsx
+++ b/studio/frontend/src/components/command-palette.tsx
@@ -130,6 +130,7 @@ const WORKSPACES: {
id: "switchToAudio",
icon: AudioWave01Icon,
labelKey: "shell.navigation.audio",
+ aliases: ["speech", "tts", "voice", "music", "transcribe"],
},
{
id: "switchToExport",
diff --git a/studio/frontend/src/features/audio/audio-cpp-catalog.ts b/studio/frontend/src/features/audio/audio-cpp-catalog.ts
index 536e4ae161c..3d8c77a8b28 100644
--- a/studio/frontend/src/features/audio/audio-cpp-catalog.ts
+++ b/studio/frontend/src/features/audio/audio-cpp-catalog.ts
@@ -253,10 +253,6 @@ export function audioCppModelSpeaks(id: string | null | undefined): boolean {
return !model || audioCppWorkflowsFor(model).includes("speak");
}
-export function audioCppModelsForTask(task: AudioCppTask): AudioCppModel[] {
- return AUDIO_CPP_MODELS.filter((model) => model.task === task);
-}
-
/** Music length the backend clamps to, whatever max_tokens asks for. */
export const AUDIO_CPP_MUSIC_MIN_SECONDS = 5;
export const AUDIO_CPP_MUSIC_MAX_SECONDS = 240;
diff --git a/studio/frontend/src/features/audio/audio-page-policy.ts b/studio/frontend/src/features/audio/audio-page-policy.ts
index 126b845b6e2..5991e416a26 100644
--- a/studio/frontend/src/features/audio/audio-page-policy.ts
+++ b/studio/frontend/src/features/audio/audio-page-policy.ts
@@ -163,8 +163,6 @@ const NATIVE_TTS_AUDIO_TYPES = new Set([
export const MOSS_TTS_FRAMES_PER_SECOND = 12.5;
export const MOSS_TTS_DEFAULT_SECONDS = 15;
export const MOSS_TTS_MAX_FRAMES = 32768;
-export const MOSS_TTS_MAX_SECONDS =
- MOSS_TTS_MAX_FRAMES / MOSS_TTS_FRAMES_PER_SECOND;
export const MINIMAX_MUSIC_FRAMES_PER_SECOND = 25;
export const MINIMAX_MUSIC_DEFAULT_SECONDS = 30;
export const MINIMAX_MUSIC_MAX_FRAMES = 9000;
@@ -653,27 +651,3 @@ export function reconcileSttSelection({
}
return preservePending ? selectedRepo : null;
}
-
-/**
- * The line said above Generate when the run will load or switch the model first, so the wait is
- * expected: "Loads Kokoro for Speak, about 5 s". Null when nothing will load.
- */
-export function modelLoadNote({
- model,
- page,
- seconds,
-}: {
- model: string | null;
- page: string;
- seconds?: number | null;
-}): string | null {
- if (!model) return null;
- const about =
- seconds !== null &&
- seconds !== undefined &&
- Number.isFinite(seconds) &&
- seconds > 0
- ? `, about ${Math.max(1, Math.round(seconds))} s`
- : "";
- return `Loads ${model} for ${page}${about}`;
-}
diff --git a/studio/frontend/src/features/audio/audio-page.tsx b/studio/frontend/src/features/audio/audio-page.tsx
index ffb7cc7b8c4..07da40a5f37 100644
--- a/studio/frontend/src/features/audio/audio-page.tsx
+++ b/studio/frontend/src/features/audio/audio-page.tsx
@@ -120,6 +120,7 @@ import {
clipWorkflow,
loadedModelRunsWorkflow,
slotForWorkflow,
+ workflowForLoadedModel,
} from "./workflows";
const SPEAKERS_MODEL_REPO = `${AUDIO_CPP_REPO}/MOSS-Transcribe-Diarize-GGUF`;
@@ -715,8 +716,16 @@ export function AudioPage({
useEffect(() => {
if (adoptedLoadedModel.current || status === null) return;
adoptedLoadedModel.current = true;
- if (modeRef.current === "speak" && ttsLoaded && musicGeneration) {
- useAudioWorkspaceStore.getState().adoptWorkflow("music");
+ // A reload opens the loaded model's page (HTDemucs opens Separate); a link or tab pick still wins.
+ if (modeRef.current === "speak" && ttsLoaded) {
+ const workspace = useAudioWorkspaceStore.getState();
+ workspace.adoptWorkflow(
+ workflowForLoadedModel({
+ current: workspace.workflow,
+ audioWorkflows: status.audio_workflows,
+ music: musicGeneration,
+ }),
+ );
}
}, [status, ttsLoaded, musicGeneration]);
diff --git a/studio/frontend/src/features/audio/components/audio-source-input.tsx b/studio/frontend/src/features/audio/components/audio-source-input.tsx
index b5335a7049b..34ddf92ee21 100644
--- a/studio/frontend/src/features/audio/components/audio-source-input.tsx
+++ b/studio/frontend/src/features/audio/components/audio-source-input.tsx
@@ -347,7 +347,7 @@ export function AudioSourceInput({
fileRef.current?.click();
}}
>
- Try another file
+ {tab === "record" ? "Upload a file" : "Try another file"}
</Button>
<Button
type="button"
diff --git a/studio/frontend/src/features/audio/hooks/audio-source-state.ts b/studio/frontend/src/features/audio/hooks/audio-source-state.ts
index a852c6d4fbf..26c13fc0092 100644
--- a/studio/frontend/src/features/audio/hooks/audio-source-state.ts
+++ b/studio/frontend/src/features/audio/hooks/audio-source-state.ts
@@ -166,3 +166,33 @@ export function audioFileProblem(file: {
}
return null;
}
+
+/** The Settings → Voice microphone, like dictation; "default" leaves the choice to the browser. */
+export function micAudioConstraints(
+ deviceId: string | null | undefined,
+): MediaTrackConstraints {
+ const base = { echoCancellation: true, noiseSuppression: true };
+ return deviceId && deviceId !== "default"
+ ? { ...base, deviceId: { exact: deviceId } }
+ : base;
+}
+
+export function micErrorMessage(error: unknown, desktop: boolean): string {
+ const name =
+ error && typeof error === "object" && "name" in error
+ ? (error as { name?: unknown }).name
+ : undefined;
+ if (name === "NotAllowedError" || name === "SecurityError") {
+ // The desktop WebView has no site-permission UI, so Settings is the only way back.
+ return desktop
+ ? "Microphone access is blocked. Open Settings > Voice and click Allow microphone, or upload a file instead."
+ : "Microphone access is blocked. Allow it for this page, or upload a file instead.";
+ }
+ if (name === "NotFoundError" || name === "OverconstrainedError") {
+ return "No microphone was found. Connect one, or upload a file instead.";
+ }
+ if (name === "NotReadableError" || name === "AbortError") {
+ return "The microphone is in use or unavailable. Try again, or upload a file instead.";
+ }
+ return "Could not use the microphone. Allow access, or upload a file instead.";
+}
diff --git a/studio/frontend/src/features/audio/hooks/use-audio-handoff.ts b/studio/frontend/src/features/audio/hooks/use-audio-handoff.ts
index 9fd2ad5aec0..b72bcf829c2 100644
--- a/studio/frontend/src/features/audio/hooks/use-audio-handoff.ts
+++ b/studio/frontend/src/features/audio/hooks/use-audio-handoff.ts
@@ -156,5 +156,3 @@ export function useAudioHandoff({
navigateSelf,
};
}
-
-export type AudioHandoff = ReturnType<typeof useAudioHandoff>;
diff --git a/studio/frontend/src/features/audio/hooks/use-audio-source.ts b/studio/frontend/src/features/audio/hooks/use-audio-source.ts
index 894f56a910c..eb81d5f1787 100644
--- a/studio/frontend/src/features/audio/hooks/use-audio-source.ts
+++ b/studio/frontend/src/features/audio/hooks/use-audio-source.ts
@@ -5,6 +5,9 @@ import {
type SegmentRecorder,
createAudioRecorder,
} from "@/features/chat/adapters/pcm-recorder";
+import { isMissingDeviceError } from "@/features/chat/adapters/studio-web-speech-dictation-adapter";
+import { useVoiceSettingsStore } from "@/features/settings/stores/voice-settings-store";
+import { isTauri } from "@/lib/api-base";
import { useCallback, useEffect, useReducer, useRef, useState } from "react";
import { AudioApiError, fetchAudioBlob, uploadAudioInput } from "../api";
import {
@@ -17,6 +20,8 @@ import {
INITIAL_AUDIO_SOURCE_STATE,
audioFileProblem,
audioSourceReducer,
+ micAudioConstraints,
+ micErrorMessage,
} from "./audio-source-state";
// A reference only needs seconds; a long take is still usable, the server keeps the first 30 s.
@@ -53,6 +58,20 @@ function errorText(error: unknown, fallback: string): string {
return error instanceof Error && error.message ? error.message : fallback;
}
+async function openMicrophone(deviceId: string): Promise<MediaStream> {
+ try {
+ return await navigator.mediaDevices.getUserMedia({
+ audio: micAudioConstraints(deviceId),
+ });
+ } catch (error) {
+ // Saved mic may be unplugged; fall back to the default, as dictation does.
+ if (deviceId === "default" || !isMissingDeviceError(error)) throw error;
+ return navigator.mediaDevices.getUserMedia({
+ audio: micAudioConstraints(null),
+ });
+ }
+}
+
export function recordingSupported(): boolean {
return (
typeof navigator !== "undefined" &&
@@ -242,17 +261,13 @@ export function useAudioSource({
const ticket = ++acquisition.current;
let stream: MediaStream;
try {
- stream = await navigator.mediaDevices.getUserMedia({
- audio: { echoCancellation: true, noiseSuppression: true },
- });
- } catch {
+ stream = await openMicrophone(
+ useVoiceSettingsStore.getState().micDeviceId,
+ );
+ } catch (error) {
acquiring.current = false;
if (ticket !== acquisition.current) return;
- dispatch({
- type: "fail",
- message:
- "Could not use the microphone. Allow access, or upload a file instead.",
- });
+ dispatch({ type: "fail", message: micErrorMessage(error, isTauri) });
return;
}
acquiring.current = false;
diff --git a/studio/frontend/src/features/audio/tour/steps.tsx b/studio/frontend/src/features/audio/tour/steps.tsx
index 5d3a1152424..2b838b8bb78 100644
--- a/studio/frontend/src/features/audio/tour/steps.tsx
+++ b/studio/frontend/src/features/audio/tour/steps.tsx
@@ -20,17 +20,15 @@ const modeStep: TourStep = {
),
};
+const MAIN_SLOT = "Loading one replaces the model in the main slot.";
+
const MODEL_STEP_BODY: Record<AudioWorkflowId, string> = {
- speak:
- "Text-to-speech models, including voices you fine-tuned under On Device.",
- clone:
- "Models that can speak in the voice of a short recording you give them.",
- edit: "Models that can change words in a recording and keep the voice.",
- convert:
- "Voice conversion models. Loading one replaces the model in the main slot.",
- music: "Music models. Loading one replaces the model in the main slot.",
- separate:
- "Source separation models. Loading one replaces the model in the main slot.",
+ speak: `Text-to-speech models, including voices you fine-tuned under On Device. ${MAIN_SLOT}`,
+ clone: `Models that can speak in the voice of a short recording you give them. ${MAIN_SLOT}`,
+ edit: `Models that can change words in a recording and keep the voice. ${MAIN_SLOT}`,
+ convert: `Voice conversion models. ${MAIN_SLOT}`,
+ music: `Music models. ${MAIN_SLOT}`,
+ separate: `Source separation models. ${MAIN_SLOT}`,
transcribe:
"Speech recognition models. They run beside your chat model, not in its place.",
};
@@ -51,7 +49,7 @@ const outputStep: TourStep = {
body: (
<>
Clips play here and stay in the history list beside them, ready to
- download. Transcripts appear here too, but are not kept after you leave.
+ download. Transcripts appear here too and keep their own history.
</>
),
};
diff --git a/studio/frontend/tests/audio-page-policy.test.ts b/studio/frontend/tests/audio-page-policy.test.ts
index 63a29082bd1..4b196a414bf 100644
--- a/studio/frontend/tests/audio-page-policy.test.ts
+++ b/studio/frontend/tests/audio-page-policy.test.ts
@@ -19,7 +19,6 @@ import {
macTtsPickAction,
mergeGalleryPage,
minimaxMusicFramesForSeconds,
- modelLoadNote,
nativeAudioInstructionsKind,
persistedClipForGeneration,
reconcileSttSelection,
@@ -833,16 +832,6 @@ test("history scrolling loads until the page gains a row, not one gallery page",
);
});
-test("a run that loads a model first says so before it starts", () => {
- assert.equal(
- modelLoadNote({ model: "Kokoro", page: "Speak", seconds: 4.6 }),
- "Loads Kokoro for Speak, about 5 s",
- );
- assert.equal(modelLoadNote({ model: "Kokoro", page: "Speak" }), "Loads Kokoro for Speak");
- assert.equal(modelLoadNote({ model: "Kokoro", page: "Speak", seconds: 0.2 }), "Loads Kokoro for Speak, about 1 s");
- assert.equal(modelLoadNote({ model: null, page: "Speak", seconds: 5 }), null);
-});
-
test("paging for a visible row skips hidden edit originals, like the list does", () => {
const gallery = readSrc("features/audio/hooks/use-audio-gallery.tsx");
assert.match(
diff --git a/studio/frontend/tests/audio-source-input.test.ts b/studio/frontend/tests/audio-source-input.test.ts
index d7debec3252..d48c33d0433 100644
--- a/studio/frontend/tests/audio-source-input.test.ts
+++ b/studio/frontend/tests/audio-source-input.test.ts
@@ -11,6 +11,8 @@ const {
audioFileProblem,
audioSourceReducer,
INITIAL_AUDIO_SOURCE_STATE,
+ micAudioConstraints,
+ micErrorMessage,
REFERENCE_EXPIRED_MESSAGE,
} = await import("../src/features/audio/hooks/audio-source-state.ts");
const { AUDIO_INPUT_MAX_BYTES, selectionExpired } = await import(
@@ -260,6 +262,44 @@ test("a superseded microphone request releases its stream", () => {
);
});
+test("recording uses the Settings → Voice microphone and falls back when it is gone", () => {
+ assert.deepEqual(micAudioConstraints("default"), {
+ echoCancellation: true,
+ noiseSuppression: true,
+ });
+ assert.deepEqual(micAudioConstraints(null), micAudioConstraints("default"));
+ assert.deepEqual(micAudioConstraints("usb-mic"), {
+ echoCancellation: true,
+ noiseSuppression: true,
+ deviceId: { exact: "usb-mic" },
+ });
+ assert.match(
+ hook,
+ /stream = await openMicrophone\(\s*useVoiceSettingsStore\.getState\(\)\.micDeviceId,\s*\);/,
+ );
+ assert.match(
+ hook,
+ /if \(deviceId === "default" \|\| !isMissingDeviceError\(error\)\) throw error;\s*return navigator\.mediaDevices\.getUserMedia\(\{\s*audio: micAudioConstraints\(null\),/,
+ );
+ assert.match(hook, /message: micErrorMessage\(error, isTauri\)/);
+ // A failed recording never picked a file, so its way out is uploading one.
+ assert.match(card, /\{tab === "record" \? "Upload a file" : "Try another file"\}/);
+});
+
+test("a blocked microphone and a missing one say different things", () => {
+ const named = (name: string) => Object.assign(new Error("x"), { name });
+ // Firefox and WebKit throw plain objects, so the name is what counts.
+ assert.match(micErrorMessage({ name: "NotAllowedError" }, false), /blocked\. Allow it for this page/);
+ assert.match(micErrorMessage(named("NotAllowedError"), true), /Open Settings > Voice and click Allow microphone/);
+ assert.match(micErrorMessage(named("NotFoundError"), false), /^No microphone was found\./);
+ assert.match(micErrorMessage({ name: "OverconstrainedError" }, true), /^No microphone was found\./);
+ assert.match(micErrorMessage(named("NotReadableError"), false), /in use or unavailable/);
+ assert.equal(
+ micErrorMessage(new Error("boom"), false),
+ "Could not use the microphone. Allow access, or upload a file instead.",
+ );
+});
+
test("the chooser accepts MP4 like the drop check does", () => {
const input = readSrc("features/audio/components/audio-source-input.tsx");
assert.match(input, /const AUDIO_EXTS = "[^"]*\bmp4\b/);
diff --git a/studio/frontend/tests/audio-workspace-split.test.ts b/studio/frontend/tests/audio-workspace-split.test.ts
index ff60b2e382b..d056f4fbd68 100644
--- a/studio/frontend/tests/audio-workspace-split.test.ts
+++ b/studio/frontend/tests/audio-workspace-split.test.ts
@@ -46,7 +46,11 @@ test("a loaded model opens the page that fits it", () => {
slot,
/const loadedWorkflow = workflowForLoadedModel\(\{\s*current: useAudioWorkspaceStore\.getState\(\)\.workflow,\s*audioWorkflows: res\.audio_workflows,\s*music: isMusicGenerationModel\(repoId, res\.audio_type\),\s*\}\);[\s\S]{0,200}?rememberModel\(loadedWorkflow, repoId\);\s*if \(modeRef\.current === "speak"\) workspace\.commitWorkflow\(loadedWorkflow\);/,
);
- assert.match(host, /adoptWorkflow\("music"\)/);
+ assert.match(
+ host,
+ /if \(modeRef\.current === "speak" && ttsLoaded\) \{\s*const workspace = useAudioWorkspaceStore\.getState\(\);\s*workspace\.adoptWorkflow\(\s*workflowForLoadedModel\(\{\s*current: workspace\.workflow,\s*audioWorkflows: status\.audio_workflows,\s*music: musicGeneration,/,
+ );
+ assert.doesNotMatch(host, /adoptWorkflow\("music"\)/);
});
test("?workflow= names the page ahead of ?task=, and both go through the workflow gate", () => {
diff --git a/studio/frontend/tests/command-palette-handoffs.test.ts b/studio/frontend/tests/command-palette-handoffs.test.ts
index 1aba98a5816..7ebb6c37283 100644
--- a/studio/frontend/tests/command-palette-handoffs.test.ts
+++ b/studio/frontend/tests/command-palette-handoffs.test.ts
@@ -18,6 +18,8 @@ const SEARCH_STORE_OPENER = /opener: HTMLElement \| null/;
const EXPLICIT_SEARCH_OPENER = /options\?\.opener !== undefined/;
const SEARCH_CLOSE_FOCUS = /onCloseAutoFocus=\{\(event\) => \{/;
const RESTORE_SEARCH_OPENER = /opener\.focus\(\{ preventScroll: true \}\)/;
+const AUDIO_ALIASES =
+ /labelKey: "shell\.navigation\.audio",\s*aliases: \["speech", "tts", "voice", "music", "transcribe"\],/;
const palette = await readFile(
new URL("../src/components/command-palette.tsx", import.meta.url),
@@ -71,3 +73,7 @@ test("a chord that navigates behind the palette closes it", () => {
/useEffect\(\(\) => \{\s*useCommandPaletteStore\.getState\(\)\.close\(\);\s*\}, \[href\]\);/,
);
});
+
+test("the Audio entry is found by what its pages do", () => {
+ assert.match(palette, AUDIO_ALIASES);
+});
diff --git a/studio/src-tauri/Info.plist b/studio/src-tauri/Info.plist
index 1d75e566280..b99af45063b 100644
--- a/studio/src-tauri/Info.plist
+++ b/studio/src-tauri/Info.plist
@@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>NSMicrophoneUsageDescription</key>
- <string>Unsloth uses the microphone you select for local voice dictation.</string>
+ <string>Unsloth uses the microphone you select for local voice dictation and audio recording.</string>
</dict>
</plist>