feat(opencode): add voice input#29663
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicates FoundBased on my search, here are related PRs that might be addressing similar functionality:
|
067e4b2 to
6153ca0
Compare
6153ca0 to
e332505
Compare
|
rebase note: voice config use ConfigV1 schema |
|
Not technically related to the PR in any way, I just love how by 2026 we developed the urge/necessity to justify pull requests by starting them with "written by a human". |
e332505 to
13f906d
Compare
|
https://github.com/XiaomiMiMo/MiMo-Code/blob/9753077419087cb8725814c32a9077385eb48399/packages/opencode/src/cli/cmd/tui/util/voice.ts#L326 |
Issue for this PR
Closes #18226
Closes #4695
Type of change
What does this PR do?
THIS PR WAS WRITTEN BY A HUMAN. I know this is a big PR. THIS IS NOT AI SLOP.
This PR adds voice input to OpenCode. Users can record audio in the Web/App and TUI interfaces and have it transcribed directly into the prompt input. The design follows OpenCode's existing frontend/backend separation — all transcription logic lives on the server, and clients (Web/App and TUI) only handle audio recording and call the server via the SDK/API.
Core voice module (
packages/opencode/src/voice/)Voiceservice built on Effect, supporting two transcription backends:MiMo-V2.5,Gemini 3.5 Flash,Qwen3 Omni 30B A3B Instruct) for transcription./v1/audio/transcriptionsor a self-hosted service).ffmpeg— automatically converts non-wav/mp3 formats (webm, ogg, etc.) to mp3 before sending to the transcription service.AbortSignal.Configuration (
packages/opencode/src/config/config.ts)A new
voiceconfig block inopencode.json, withtypeselecting the transcription backend:{ "voice": { "type": "lalm", "lalm": { "model": "opencode/mimo-v2.5-free" // "model": "opencode-go/mimo-v2.5" // "model": "opencode/gemini-3.5-flash" }, "whisper": { "url": "http://127.0.0.1:5000/v1/audio/transcriptions", "apiKey": "sk-abc123def456ghi789", "model": "whisper-1" } } }LALM only requires specifying a model that supports audio input (auth is handled by existing provider config). Whisper requires an additional API URL and key. See the docs for the full set of config options.
Practical experience: Gemini 3.5 Flash has the best transcription quality but is also the most expensive; MiMo V2.5 is good enough for me — surprisingly capable and very cheap; Qwen3 Omni 30B A3B Instruct is great for self-hosting, runnable via llama.cpp on a personal machine for privacy-preserving deployment.
HTTP API (
packages/opencode/src/server/routes/instance/httpapi/)POST /voice/transcribeendpoint, accepting base64 audio, optional context (e.g. text the user has already typed in the input), images, and request parameters that can override the project-level config above — consistent with the design of other prompt endpoints in the project.audio.transcribeendpoint.Web/App UI (
packages/app/src/components/prompt-input/voice.tsx)VoiceButtoncomponent with microphone/stop/loading states, wired into both v1 and v2 layouts.createVoiceInputhook manages the browser MediaRecorder lifecycle, calls transcription via the SDK, and handles retries. Recording data stays in memory (Blob), released on successful transcription, preserved on failure for retry.mod+shift+vkeyboard shortcut for voice input.TUI (
packages/opencode/src/cli/cmd/tui/)useVoicehook manages terminal audio recording via subprocesses (ffmpeg/arecord/sox/rec — auto-detected by platform). Temporary recording files are stored inos.tmpdir()(e.g./tmp/opencode-voice-<uuid>.mp3), cleaned up after successful transcription, preserved on failure for retry.<leader>vas the default keybinding.tui.jsonsupportsvoice.commandandvoice.mimefor custom recorder configuration.Documentation (
packages/web/src/content/docs/)config.mdxwith the fullvoiceconfig reference.tui.mdxwith TUI voice recorder configuration docs.Design considerations
generateTextinterface, while Whisper bypasses the Vercel AI SDK and builds the multipart form-data request directly through Effect'sHttpClient. This is because the Vercel AI SDK's Whisper transcription interface is still experimental — the API is unstable and cumbersome, so constructing the request ourselves is simpler and more reliable.When building conversation context, special filtering is applied: messages are traversed from back to front, and after a user message there are typically multiple assistant messages (from the agent's multi-turn tool calls, etc.). The code only pairs the first assistant message with actual text content, while skipping
synthetictext parts and summary messages. This is because in an agent loop, the last assistant message usually contains the final conclusion and is the most important one.smallOptionsto reduce the model's thinking level, avoiding unnecessary reasoning overhead. Special handling is applied for MiMo — it enables thinking by default, so it must be explicitly disabled inprovider/transform.ts.How did you verify your code works?
I've been using the voice input feature for over two months, transcribing thousands of requests during that time. I've been continuously rebasing against upstream and iterating on the code. I understand my code. I now feel the quality is high enough to merge back into the main branch.
My primary development environment is Linux. I've also done my best to test on a MacBook and a Windows VM, but there may be gaps — if you find platform compatibility issues, please point them out.
Screenshots / recordings
hi @thdxr now you can voice prompt this :)
demo-1.mp4
demo-2.mp4
demo-3.mp4
another project android IME using this opencode transcribe API https://voice.aquarium39.moe
demo-1.mp4
our company product using opencode as agent core, can easily implement the voice input feature.
demo-5.mp4
Checklist
If you do not follow this template your PR will be automatically rejected.