Repository navigation
[Feature] Unsloth Studio / Desktop: let the mic send audio straight to any audio-input model - #16976
Conversation
Adds a Mic button setting in Voice: Transcribe with ASR (default, unchanged) or Send audio to the model. In model mode, while the loaded chat model has audio input, the composer mic records a WAV clip and attaches it through the same audio attachment adapter as an uploaded file. Any other model, Compare, or the default setting keeps dictation as it is. Refs unslothai#16056
…limit The attachment adapter refuses a clip over 25 MB, so a long recording was buffered without bound and then dropped at Stop. Auto-stop just under the limit and keep the clip.
The GGUF row left has_audio_input out, so it read False, and the chat store replaces its rows from this list. A loaded Gemma 4 E2B GGUF with an audio mmproj reported has_audio_input true in status but false in the list, which switched off audio attachments and the mic's model mode on any list refresh. Also pins the frontend gate to the generic flag and to each route that sets it.
PcmRecorder.stop() always joins the buffers and encodes a WAV before it emits, so cancelling a long recording did that work just to drop it. Add PcmRecorder.discard() and use it from the clip session's cancel.
The clip session capped a recording at the full 25MB, so with audio already attached, or an MLX model that takes one file, the attachment adapter refused the clip only after it was recorded. Size the auto-stop to what is left and refuse before opening the mic when nothing is.
The auto-stop leaves a second of slack and never goes under one second, so a small room could still overflow, and audio dropped on the composer mid-recording could take the room the clip was sized for. Trim the WAV to the room at stop, refuse rooms under a second at 16 kHz, and have the audio attachment adapter refuse other audio while a clip records.
The clip records with PcmRecorder (Web Audio) but was gated on the MediaRecorder check, so a browser without MediaRecorder was refused a path it supports.
A session cancelled while getUserMedia was pending released the shared hold when the request resolved, even if a newer recording had started, so audio could be attached during that recording again.
When the saved mic was missing, the clip session asked for the default mic even if the user had cancelled while the first request was pending, so the mic came on after the cancel.
The clip is gated and sized for the model it started on, but the attachment adapter checks the model active at Stop, so switching to a text-only model lost the recording only after it was made. Cancel it with a toast as soon as the checkpoint changes.
A local load publishes its target in loadingModelPick and moves the checkpoint only once it succeeds, so a Stop during the load attached the clip for a model that may not take audio.
The pre-check assumes 16 kHz. When the context falls back to device rate, a room that holds one second at 16 kHz holds a third of one, so the trimmed clip cut the utterance short. Refuse it once the rate is known.
The device-rate refusal discards the recorder before start(), and discard() returned early on an inactive recorder, leaving its AudioContext and nodes open. Tear down any recorder not yet torn down, once.
|
Codex review on the fork mirror (LeoBorcherding#754) found no major issues at |
…o voice mode any-audio Takes unslothai#16976's current mic clip code (attachment room, model-change discard, PCM support gate, cancel without encode) over the earlier cherry-picks. Voice mode's pieces are kept: the composer's voice wrapper in thread.tsx, the voice-mode wording of the mic setting, and the overlay-prefs stub in mic-target.test.ts.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…gs store (#17293) ## Summary `main` is red in the frontend unit tests (`Frontend build + bundle sanity` and `Frontend unit tests (Windows)`) since #16976 merged: ``` # Error: no stub for import "./stt-context" in .../features/settings/stores/voice-settings-store.ts not ok 888 - tests/mic-target.test.ts ``` #15810 (merged at 15:43 UTC) moved the voice context settings into `stores/stt-context.ts` and made `voice-settings-store.ts` import it. #16976 (merged about an hour later) added `tests/mic-target.test.ts`, which loads that store through `loadWithStubs` with a stub list written before that import existed. `loadWithStubs` throws on any unstubbed import, so the whole file fails at load, and every PR based on current `main` inherits the red. #16976's own code is fine; only its test's stub list is out of date. The fix passes the real `stt-context` module, the same way `voice-settings-storage-sync.test.ts` already does after #15810. ## Changes - `studio/frontend/tests/mic-target.test.ts`: add `"./stt-context": sttContext` to the store's stubs. ## Testing - `node --test tests/mic-target.test.ts`: 20 passed. On `main` the same file fails to load (0 passed, 1 failed). - `npm test` (whole frontend unit suite): 15450 tests, 0 failed.
Resolves the unslothai#16976 squash (main's mic clip files win) and part C's overlap with main: composer pieces keep main's memoized elements behind showDictationUi, gpu_arbiter keeps both the restyle release and the beside check.
Closes #16056.
What it does
A new Mic button setting in Settings → Voice → Dictation:
recording-<time>.wavhas_audio_inputcapability (the same flag behind the "Audio Input" badge) and names no model family.AudioAttachmentAdapter, the same path as uploading a wav/mp3, so the backend sees nothing new. It is recorded as WAV with the existingPcmRecorder(Web Audio, noMediaRecorderneeded), because MediaRecorder's webm would be routed as video.Staying inside the attachment limits. A recording is sized to the audio room left in the composer (25 MB per message, minus clips already attached; MLX models take one audio file) and stops itself just under it. With no room left, it says why and never opens the mic. While a clip records, other audio can't be attached, and switching or loading a chat model discards the recording with a toast, since the clip was sized for the model it started on. Cancel drops the buffers without encoding them.
Backend fix included.
/api/models/listbuilt a loaded GGUF's row withouthas_audio_input, so it read False even when status said True. The chat store replaces its rows from that list, so a list refresh turned off audio attachments (and this mic mode) for GGUFs with an audio mmproj. The row now carries the backend's value.Models covered
Every one of these reaches the gate through
has_audio_input:clip.has_audio_encoderunsloth/gemma-4-E2B-it-GGUFQ4_K_M +mmproj-F16<|audio|>tokenLiquidAI/LFM3-Omni-2B-GGUFQ8_0clip.has_audio_encoder<audio_soft_token>intokenizer_config.jsonaudio_tokenplus top-levelaudio_configprocessor_config.jsonaudio_token_classify_mlx_audio_type)Verified end to end
MacBook Pro M5, macOS 26, Unsloth Studio from this branch at
f60f99472d(isolated install), Chromium. The mic was scripted:getUserMediawas fed a macOSsayWAV, so the clip is real speech and the actual mic button, recording bar and send path all ran.unsloth/gemma-4-E2B-it-GGUFQ4_K_MLiquidAI/LFM3-Omni-2B-GGUFQ8_0The stored Gemma 4 user message has no text and one
audiopart (wav, about 180 KB), so the reply came from the audio. Before the backend fix, the Gemma 4 list row readhas_audio_input: falsewhile status readtrue; after it, both readtrue, and the same holds for the LFM3-Omni GGUF.The commits after
f60f99472donly add guards on edge cases (cancel, attachment room, a model switch mid-recording, a browser withoutMediaRecorder, a device-rate audio context). They are covered by the unit tests below and were not re-run in the browser.LFM3-Omni GGUF via stop-and-send:
Not run: the safetensors paths (Gemma 3n, Gemma 4, LFM3-Omni on transformers) and Qwen3-Omni on MLX. They use the same frontend path, and their detection is covered by existing backend tests.
Tests
tests/mic-target.test.ts(18): default is ASR, older saved settings stay ASR, a savedmodelpick survives a reload; the gate needs both the setting and audio input; the option is disabled without it; Compare never routes; no model family is named; each route into the store mapshas_audio_input; stop-and-send submits a clip; the audio room (images ignored, extension-only m4a counted, file count, size, staged clip, minimum room); the attachment adapter refuses audio while a clip records; the clip path gates on PCM support.tests/mic-clip-recording.test.ts(14): auto-stop at the room keeps the clip; an early Stop clears it; cancel discards without encoding; no room never opens the mic; the audio hold is released on stop, cancel and refusal, and only by its own session; cancel during a missing-device request skips the default-mic fallback; a model switch or load mid-recording discards the clip; a room too small at device rate is refused.tests/pcm-recorder.test.ts(5 new):discard()encodes nothing, fires no events and closes even an unstarted recorder once;stop()trims tomaxBytes;bytesForuses the actual rate; support withoutMediaRecorder.studio/backend/tests/test_models_list_gguf_audio_input.py(3): the GGUF list row carrieshas_audio_input. Fails on main.tests/chat-audio-upload.test.ts: the "one Dictate entry" check counts the mic's label, which still reads "Dictate" outside model mode.9ae4449120:npm run typecheckclean,npm test14,964 pass / 0 fail.UI before / after
Settings > Voice > Dictation, merge base
781b72f0evs head9e6a976f1, no model loaded. The new Mic button row defaults to Transcribe with ASR, and "Send audio to the model" stays disabled until an audio-input model is loaded.