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: install the gstreamer recording plugins with the deb package (#12905)

Maheswar Kumar980c5ceeaa59
diff --git a/studio/frontend/src/features/chat/adapters/pcm-recorder.ts b/studio/frontend/src/features/chat/adapters/pcm-recorder.ts
index c78c73fa548..d805b7fe5ac 100644
--- a/studio/frontend/src/features/chat/adapters/pcm-recorder.ts
+++ b/studio/frontend/src/features/chat/adapters/pcm-recorder.ts
@@ -37,9 +37,9 @@ const OPUS_MIME_TYPES = ["audio/webm;codecs=opus", "audio/ogg;codecs=opus"];
// so the platform is what separates them from WebKitGTK.
const APPLE_WEBKIT = /iPad|iPhone|iPod|Macintosh|Mac OS X/;
-/** Whether this engine's MediaRecorder can be trusted to encode audio. Kept a capability test
- * rather than a Linux check so every engine that does work keeps recording as it does
- * today, and only the broken one takes the PCM path. */
+/** Whether this engine's MediaRecorder claims it can encode audio; `start()` may still refuse.
+ * Kept a capability test rather than a Linux check so every engine that does work keeps
+ * recording as it does today, and only the broken one takes the PCM path. */
export function mediaRecorderCanEncodeAudio(
isTypeSupported: (type: string) => boolean = (type) =>
typeof MediaRecorder !== "undefined" && MediaRecorder.isTypeSupported(type),
@@ -245,14 +245,80 @@ export class PcmRecorder implements SegmentRecorder {
}
}
+type RecorderListener = ((event: RecordedDataEvent) => void) &
+ ((event: Event) => void);
+
+let mediaRecorderRefusedStart = false;
+
+/** A MediaRecorder that becomes a PcmRecorder if `start()` is refused: WebKitGTK advertises Opus,
+ * then throws NotSupportedError without gst-plugins-bad's `uritranscodebin` (#11939). */
+class StartFallbackRecorder implements SegmentRecorder {
+ private recorder: SegmentRecorder;
+ private readonly stream: MediaStream;
+ private readonly listeners: [
+ "dataavailable" | "stop",
+ RecorderListener,
+ AddEventListenerOptions | undefined,
+ ][] = [];
+
+ constructor(stream: MediaStream, mimeType?: string) {
+ this.stream = stream;
+ this.recorder = new MediaRecorder(
+ stream,
+ mimeType ? { mimeType } : undefined,
+ );
+ }
+
+ get state(): RecordingState {
+ return this.recorder.state;
+ }
+
+ get mimeType(): string {
+ return this.recorder.mimeType;
+ }
+
+ addEventListener(
+ type: "dataavailable" | "stop",
+ listener: RecorderListener,
+ options?: AddEventListenerOptions,
+ ): void {
+ this.listeners.push([type, listener, options]);
+ this.recorder.addEventListener(type as "stop", listener, options);
+ }
+
+ start(timesliceMs?: number): void {
+ try {
+ this.recorder.start(timesliceMs);
+ } catch (error) {
+ // An ended stream is refused with the same error name and is not the engine's fault.
+ if (
+ (error as { name?: unknown } | null)?.name !== "NotSupportedError" ||
+ !this.stream.active
+ ) {
+ throw error;
+ }
+ mediaRecorderRefusedStart = true;
+ this.recorder = new PcmRecorder(this.stream);
+ for (const [type, listener, options] of this.listeners) {
+ this.recorder.addEventListener(type as "stop", listener, options);
+ }
+ this.recorder.start(timesliceMs);
+ }
+ }
+
+ stop(): void {
+ this.recorder.stop();
+ }
+}
+
/** A recorder for `stream`: MediaRecorder where it encodes, PCM where it does not. `mimeType`
* is the MediaRecorder preference and is unused on the PCM path, which always makes WAV. */
export function createAudioRecorder(
stream: MediaStream,
mimeType?: string,
): SegmentRecorder {
- if (!mediaRecorderCanEncodeAudio()) {
+ if (mediaRecorderRefusedStart || !mediaRecorderCanEncodeAudio()) {
return new PcmRecorder(stream);
}
- return new MediaRecorder(stream, mimeType ? { mimeType } : undefined);
+ return new StartFallbackRecorder(stream, mimeType);
}
diff --git a/studio/frontend/tests/pcm-recorder.test.ts b/studio/frontend/tests/pcm-recorder.test.ts
index 193ff10c971..aa98a2e1183 100644
--- a/studio/frontend/tests/pcm-recorder.test.ts
+++ b/studio/frontend/tests/pcm-recorder.test.ts
@@ -106,9 +106,12 @@ Object.assign(globalThis, {
window: { AudioContext: FakeAudioContext },
});
-const { PcmRecorder, encodeWav, mediaRecorderCanEncodeAudio } = await import(
- "../src/features/chat/adapters/pcm-recorder.ts"
-);
+const {
+ PcmRecorder,
+ createAudioRecorder,
+ encodeWav,
+ mediaRecorderCanEncodeAudio,
+} = await import("../src/features/chat/adapters/pcm-recorder.ts");
const newRecorder = () => {
FakeAudioContext.last = null;
@@ -348,6 +351,64 @@ test("secondsWithin keeps a WAV inside the upload cap", () => {
assert.ok(44 + seconds * 32_000 + inFlightBytes < cap);
});
+// --- MediaRecorder that advertises Opus but refuses to start (#11939) --------
+
+test("a MediaRecorder that refuses to start falls back to PCM", () => {
+ let startError = new Error("device lost");
+ let constructed = 0;
+ class RefusingMediaRecorder {
+ static isTypeSupported = (type: string) =>
+ type === "audio/webm;codecs=opus";
+ state = "inactive";
+ mimeType = "audio/webm;codecs=opus";
+ constructor() {
+ constructed += 1;
+ }
+ addEventListener(): void {}
+ start(): void {
+ throw startError;
+ }
+ stop(): void {}
+ }
+ Object.assign(globalThis, { MediaRecorder: RefusingMediaRecorder });
+ const stream = { active: true } as unknown as MediaStream;
+
+ // Anything but the engine's refusal is still the caller's error.
+ assert.throws(() => createAudioRecorder(stream).start(250), /device lost/);
+
+ startError = Object.assign(new Error("unsupported"), {
+ name: "NotSupportedError",
+ });
+ // So is the same error name for a stream whose tracks have ended.
+ const ended = { active: false } as unknown as MediaStream;
+ assert.throws(() => createAudioRecorder(ended).start(250), /unsupported/);
+ const recorder = createAudioRecorder(stream, "audio/webm;codecs=opus");
+ const events: string[] = [];
+ let recorded: { data: Blob } | null = null;
+ recorder.addEventListener("dataavailable", (event) => {
+ events.push("dataavailable");
+ recorded = event;
+ });
+ recorder.addEventListener("stop", () => events.push("stop"), { once: true });
+ recorder.start(250);
+ assert.equal(recorder.state, "recording");
+ assert.equal(recorder.mimeType, "audio/wav");
+ FakeAudioContext.last?.processor.emit(new Float32Array([1, -1]));
+ recorder.stop();
+ assert.deepEqual(events, ["dataavailable", "stop"]);
+ assert.equal((recorded as unknown as { data: Blob }).data.type, "audio/wav");
+ // The listener options survive the swap: a once listener does not fire again.
+ recorder.start();
+ recorder.stop();
+ assert.deepEqual(events, ["dataavailable", "stop", "dataavailable"]);
+
+ // Later segments skip the recorder that is known not to start.
+ assert.equal(constructed, 3);
+ assert.ok(createAudioRecorder(stream) instanceof PcmRecorder);
+ assert.equal(constructed, 3);
+ delete (globalThis as { MediaRecorder?: unknown }).MediaRecorder;
+});
+
// --- Neither call site may construct a MediaRecorder directly again ----------
test("the recording call sites go through createAudioRecorder", () => {
diff --git a/studio/src-tauri/tauri.conf.json b/studio/src-tauri/tauri.conf.json
index b9837c4a42c..ac91427ed37 100644
--- a/studio/src-tauri/tauri.conf.json
+++ b/studio/src-tauri/tauri.conf.json
@@ -90,6 +90,7 @@
}
},
"deb": {
+ "recommends": ["gstreamer1.0-plugins-bad"],
"desktopTemplate": "./linux/unsloth.desktop",
"files": {
"/usr/share/polkit-1/actions/ai.unsloth.studio.update.policy": "./linux/ai.unsloth.studio.update.policy"
diff --git a/tests/studio/test_tauri_branding_contract.py b/tests/studio/test_tauri_branding_contract.py
index 9506ca933d3..4caa0877e4b 100644
--- a/tests/studio/test_tauri_branding_contract.py
+++ b/tests/studio/test_tauri_branding_contract.py
@@ -68,6 +68,9 @@ def test_desktop_package_transitions_preserve_legacy_installs() -> None:
deb = config["bundle"]["linux"]["deb"]
for field in ("provides", "conflicts", "replaces"):
assert deb[field] == ["unsloth-studio-desktop"]
+ # Recommends, not Depends: Ubuntu ships it in universe, so a Depends blocks install where that is off.
+ assert deb["recommends"] == ["gstreamer1.0-plugins-bad"]
+ assert "depends" not in deb
installer = read(TAURI / "windows/installer.nsi")
assert '!define INSTALLIDENTITY "Unsloth Studio (Desktop)"' in installer