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: let read aloud go past 2048 tokens and warn when cut short (#13648)

Nilayb44035a64a2f
diff --git a/studio/frontend/scripts/check-bundle-budget.ts b/studio/frontend/scripts/check-bundle-budget.ts
index 658c15a1621..ad1e03acac6 100644
--- a/studio/frontend/scripts/check-bundle-budget.ts
+++ b/studio/frontend/scripts/check-bundle-budget.ts
@@ -83,8 +83,11 @@ export const BUDGET = {
// The KV cache, GPU memory limit and seed engine options (#13596) add 5.7 KB raw / 1.4 KB transfer
// (6,573.5 -> 6,579.2 KB raw, 1,976.9 -> 1,978.3 KB transfer against abfe3142c, one machine and
// build), inline in the eager chat and settings chunks like the other engine options; raised by that.
- transferBytes: 2_026_500,
- rawBytes: 6_743_000,
+ // Read aloud's token cap and length warning add 0.2 KB raw / 0.1 KB transfer to the eager chat chunk
+ // (6,739,816 -> 6,740,052 B raw, 2,021,725 -> 2,021,835 B transfer against af9d97837e, one machine
+ // and build), which took main over; raised by that.
+ transferBytes: 2_026_610,
+ rawBytes: 6_743_236,
};
// The chunk count is reported but not budgeted. Splitting a page out of the entry raises it while lowering the
diff --git a/studio/frontend/src/features/chat/adapters/studio-speech-synthesis-adapter.ts b/studio/frontend/src/features/chat/adapters/studio-speech-synthesis-adapter.ts
index 472a09dba75..9b81891aaff 100644
--- a/studio/frontend/src/features/chat/adapters/studio-speech-synthesis-adapter.ts
+++ b/studio/frontend/src/features/chat/adapters/studio-speech-synthesis-adapter.ts
@@ -1,6 +1,7 @@
// 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 { TTS_MAX_TOKENS } from "@/features/audio/audio-workspace-constants";
import { authFetch } from "@/features/auth";
import { useVoiceSettingsStore } from "@/features/settings/stores/voice-settings-store";
import { toast } from "@/lib/toast";
@@ -232,6 +233,7 @@ export async function generateStudioTtsAudio(
stream: false,
// Read aloud is not a Speak run, so it stays out of Speak's history.
persist: false,
+ max_tokens: TTS_MAX_TOKENS,
...(ttsStudioVoiceId ? { voice_id: ttsStudioVoiceId } : {}),
}),
signal,
@@ -261,10 +263,18 @@ export async function generateStudioTtsAudio(
}
throw new Error(detail);
}
- const data = (await response.json()) as { audio?: { data?: string } };
+ const data = (await response.json()) as {
+ audio?: { data?: string };
+ choices?: { finish_reason?: string }[];
+ };
if (!data.audio?.data) {
throw new Error("The TTS model returned no audio.");
}
+ if (data.choices?.[0]?.finish_reason === "length") {
+ toast.warning(
+ "Read aloud stopped at the speech model's length limit before the end of the reply.",
+ );
+ }
return `data:audio/wav;base64,${data.audio.data}`;
}
diff --git a/studio/frontend/tests/read-aloud-studio-voice.test.ts b/studio/frontend/tests/read-aloud-studio-voice.test.ts
index d95315ad043..1b71ad8b427 100644
--- a/studio/frontend/tests/read-aloud-studio-voice.test.ts
+++ b/studio/frontend/tests/read-aloud-studio-voice.test.ts
@@ -21,6 +21,9 @@ type Adapter = {
type Reply = { status: number; body: unknown };
+// Not the real ceiling, so a copy of the number in the adapter fails the body check.
+const MAX_TOKENS = 1234;
+
/** The adapter with the voice setting faked and a fetch that logs each body. */
function load(
voiceId: string,
@@ -28,6 +31,7 @@ function load(
) {
const posted: Record<string, unknown>[] = [];
const setVoiceIds: string[] = [];
+ const warnings: string[] = [];
const adapter = loadWithStubs<Adapter>(
new URL(
"../src/features/chat/adapters/studio-speech-synthesis-adapter.ts",
@@ -63,10 +67,18 @@ function load(
}),
},
},
- "@/lib/toast": { toast: { error: () => {} } },
+ "@/lib/toast": {
+ toast: {
+ error: () => {},
+ warning: (message: string) => warnings.push(message),
+ },
+ },
+ "@/features/audio/audio-workspace-constants": {
+ TTS_MAX_TOKENS: MAX_TOKENS,
+ },
},
);
- return { adapter, posted, setVoiceIds };
+ return { adapter, posted, setVoiceIds, warnings };
}
test("read aloud keeps its clip out of history and speaks in the model's voice by default", async () => {
@@ -80,10 +92,32 @@ test("read aloud keeps its clip out of history and speaks in the model's voice b
messages: [{ role: "user", content: "hello" }],
stream: false,
persist: false,
+ max_tokens: MAX_TOKENS,
},
]);
});
+test("read aloud warns only when the speech stops before the end of the reply", async () => {
+ const spoken = async (finishReason: string) => {
+ const { adapter, warnings } = load("", {
+ status: 200,
+ body: {
+ audio: { data: "UklGRg==" },
+ choices: [{ finish_reason: finishReason }],
+ },
+ });
+ assert.equal(
+ await adapter.generateStudioTtsAudio("a reply"),
+ "data:audio/wav;base64,UklGRg==",
+ );
+ return warnings;
+ };
+ const cut = await spoken("length");
+ assert.equal(cut.length, 1);
+ assert.match(cut[0], /before the end of the reply/);
+ assert.deepEqual(await spoken("stop"), []);
+});
+
test("read aloud sends the saved voice chosen in Settings", async () => {
const { adapter, posted } = load("8f2c");
await adapter.generateStudioTtsAudio("hello");
diff --git a/studio/frontend/tests/tts-custom-connections-disabled.test.ts b/studio/frontend/tests/tts-custom-connections-disabled.test.ts
index 2ffb9b693c4..61a57567797 100644
--- a/studio/frontend/tests/tts-custom-connections-disabled.test.ts
+++ b/studio/frontend/tests/tts-custom-connections-disabled.test.ts
@@ -120,6 +120,7 @@ function load(
},
},
"@/lib/toast": { toast: { error: () => {} } },
+ "@/features/audio/audio-workspace-constants": { TTS_MAX_TOKENS: 8192 },
},
);
return {