Skip to content

[Feature] Unsloth Studio / Desktop: let the mic send audio straight to any audio-input model - #16976

Merged
danielhanchen merged 20 commits into
unslothai:mainfrom
LeoBorcherding:feat/mic-to-model-audio
Nov 9, 2026
Merged

danielhanchen merged 20 commits into
unslothai:mainfrom
LeoBorcherding:feat/mic-to-model-audio

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #16056.

What it does

A new Mic button setting in Settings → Voice → Dictation:

option what the composer mic does
Transcribe with ASR (default) today's dictation, unchanged: browser, local STT (Qwen3-ASR and the rest) or a custom endpoint types into the box
Send audio to the model while the loaded chat model takes audio input, the mic records a clip and attaches it to the message as recording-<time>.wav
  • Opt-in. Nobody's mic changes unless they pick the second option, and saved settings without the field load as ASR.
  • The option is disabled until a model with audio input is loaded. With it picked and a text-only model loaded, the mic falls back to dictation, and the tooltip says which one you get ("Dictate" or "Record audio for the model").
  • Works for any audio-input chat model. The gate reads only the generic has_audio_input capability (the same flag behind the "Audio Input" badge) and names no model family.
  • The clip goes through the existing AudioAttachmentAdapter, the same path as uploading a wav/mp3, so the backend sees nothing new. It is recorded as WAV with the existing PcmRecorder (Web Audio, no MediaRecorder needed), because MediaRecorder's webm would be routed as video.
  • The recording UI is the dictation bar as it is: level meter, Stop, Escape to discard. Stop-and-send submits the clip with no transcript needed.
  • Single chat only. Compare keeps dictating into both panes, since the two models may differ.

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/list built a loaded GGUF's row without has_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:

model how audio input is detected run end to end?
Gemma 4 E2B/E4B/12B (GGUF + audio mmproj) mmproj clip.has_audio_encoder yes: unsloth/gemma-4-E2B-it-GGUF Q4_K_M + mmproj-F16
LFM3-Omni-2B (GGUF, and the Omni GGUFs built on it) mmproj audio encoder or the <|audio|> token yes: LiquidAI/LFM3-Omni-2B-GGUF Q8_0
any other GGUF whose mmproj has an audio encoder mmproj clip.has_audio_encoder same path as above
Gemma 3n (safetensors) <audio_soft_token> in tokenizer_config.json no, detection tests only
Gemma 4 E2B/E4B/12B (safetensors) audio_token plus top-level audio_config no, detection tests only
LFM3-Omni-2B (safetensors) processor_config.json audio_token no, detection tests only
Qwen3-Omni on MLX MLX audio probe (_classify_mlx_audio_type) no, detection tests only

Verified end to end

MacBook Pro M5, macOS 26, Unsloth Studio from this branch at f60f99472d (isolated install), Chromium. The mic was scripted: getUserMedia was fed a macOS say WAV, so the clip is real speech and the actual mic button, recording bar and send path all ran.

model spoken question how it was sent reply
unsloth/gemma-4-E2B-it-GGUF Q4_K_M "What is the capital of France? Answer in one word." Stop, then Send with an empty text box Paris
LiquidAI/LFM3-Omni-2B-GGUF Q8_0 "Which planet is the largest in our solar system? Answer in one word." the recording bar's send (stop-and-send) Jupiter

The stored Gemma 4 user message has no text and one audio part (wav, about 180 KB), so the reply came from the audio. Before the backend fix, the Gemma 4 list row read has_audio_input: false while status read true; after it, both read true, and the same holds for the LFM3-Omni GGUF.

The commits after f60f99472d only add guards on edge cases (cancel, attachment room, a model switch mid-recording, a browser without MediaRecorder, a device-rate audio context). They are covered by the unit tests below and were not re-run in the browser.

setting recording attached reply
setting recording attached reply

LFM3-Omni GGUF via stop-and-send: lfm3

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 saved model pick 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 maps has_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 to maxBytes; bytesFor uses the actual rate; support without MediaRecorder.
  • studio/backend/tests/test_models_list_gguf_audio_input.py (3): the GGUF list row carries has_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.
  • At 9ae4449120: npm run typecheck clean, npm test 14,964 pass / 0 fail.

UI before / after

Settings > Voice > Dictation, merge base 781b72f0e vs head 9e6a976f1, 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.

Settings Voice tab before and after

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.
@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

Codex review on the fork mirror (LeoBorcherding#754) found no major issues at 9ae4449120, this PR's head: result.

LeoBorcherding added a commit to LeoBorcherding/unsloth that referenced this pull request Nov 8, 2026
…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T15:00:33.105407Z c9d75dc Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 9, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: c9d75dc44e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 9, 2026
@danielhanchen
danielhanchen merged commit c21ee57 into unslothai:main Nov 9, 2026
danielhanchen added a commit that referenced this pull request Nov 9, 2026
…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.
danielhanchen added a commit to LeoBorcherding/unsloth that referenced this pull request Nov 13, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Direct Microphone Input for Audio-Accepting Models

2 participants