feat: enable /voice mode with native audio binaries#92
Conversation
Restore voice input by: - Copying official cpal-based audio-capture.node binaries (6 platforms) - Replacing SoX subprocess stub with native .node loader - Adding VOICE_MODE to default build features All voice source files in src/ already match the official CLI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR enables VOICE_MODE functionality by replacing a non-functional child_process/SoX audio capture implementation with a native N-API module loader. Build configuration defaults are updated to include VOICE_MODE, and platform-specific native binaries with vendor-sourced module loading are introduced. Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant Wrapper as audio-capture-src<br/>(Wrapper Module)
participant Loader as Module Loader
participant Native as audio-capture.node<br/>(Native Addon)
App->>Wrapper: startNativeRecording(onData, onEnd)
Wrapper->>Loader: loadModule()
Loader->>Loader: Check env AUDIO_CAPTURE_NODE_PATH
alt Path provided
Loader->>Native: require(envPath)
else Fallback to vendor paths
Loader->>Native: require(platform/arch path)
end
Native-->>Loader: Module loaded & cached
Loader-->>Wrapper: cachedModule
Wrapper->>Native: startNativeRecording()
Native-->>Wrapper: true (started)
Wrapper-->>App: true (started)
Native->>Native: Capture audio frames
Native->>Wrapper: onData(audioBuffer)
Wrapper->>App: onData(audioBuffer)
App->>Wrapper: stopNativeRecording()
Wrapper->>Native: stopNativeRecording()
Native->>Wrapper: onEnd()
Wrapper->>App: onEnd()
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
vendor/audio-capture-src/index.ts (1)
58-61: Missingprocess.cwd()fallback compared to package version.The package version at
packages/audio-capture-napi/src/index.tsincludes a third fallback path usingprocess.cwd():`${process.cwd()}/vendor/audio-capture/${platformDir}/audio-capture.node`This fallback is documented as necessary "when loaded from a workspace package." If this vendor loader is intended to work in dev/workspace scenarios, consider adding the same fallback for consistency.
💡 Proposed fix to add process.cwd() fallback
const fallbacks = [ `./vendor/audio-capture/${platformDir}/audio-capture.node`, `../audio-capture/${platformDir}/audio-capture.node`, + `${process.cwd()}/vendor/audio-capture/${platformDir}/audio-capture.node`, ]🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@vendor/audio-capture-src/index.ts` around lines 58 - 61, The fallback list in vendor/audio-capture-src/index.ts (the const fallbacks using platformDir) is missing the workspace-aware fallback; add the same third entry used in packages/audio-capture-napi/src/index.ts — a path built with process.cwd() like `${process.cwd()}/vendor/audio-capture/${platformDir}/audio-capture.node` — so the loader will resolve when run from a workspace/dev environment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@vendor/audio-capture-src/index.ts`:
- Around line 58-61: The fallback list in vendor/audio-capture-src/index.ts (the
const fallbacks using platformDir) is missing the workspace-aware fallback; add
the same third entry used in packages/audio-capture-napi/src/index.ts — a path
built with process.cwd() like
`${process.cwd()}/vendor/audio-capture/${platformDir}/audio-capture.node` — so
the loader will resolve when run from a workspace/dev environment.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6867bfe6-839f-4eea-bc5b-c120ca693948
📒 Files selected for processing (11)
DEV-LOG.mdbuild.tspackages/audio-capture-napi/src/index.tsscripts/dev.tsvendor/audio-capture-src/index.tsvendor/audio-capture/arm64-darwin/audio-capture.nodevendor/audio-capture/arm64-linux/audio-capture.nodevendor/audio-capture/arm64-win32/audio-capture.nodevendor/audio-capture/x64-darwin/audio-capture.nodevendor/audio-capture/x64-linux/audio-capture.nodevendor/audio-capture/x64-win32/audio-capture.node
|
@amDosion 有个问题, 我们很多人是没有 anthropic 官方端口的, 那么能否判断 base url 决定使用适配器呢 |
可以利用兼容的,很多国产模型就是支持 anthropic 官方端口,要么就是改客户端(改客户端可以支持任意模型切换),客户端内部有校验(代码中有体现出来),目前有人已经改出来了,目前我还没有试验. |
|
我觉得还是改客户端好些, 抽象一个兼容层, 可以替换为其他实现. 刚刚还有个人发 issues 说百炼不支持 anthropic 缓存, 那没活 |



Summary
audio-capture.node二进制(6 平台,含 Windows x64)packages/audio-capture-napi/src/index.ts的 SoX 子进程 stub 为原生.node加载器scripts/dev.ts+build.ts加"VOICE_MODE"编译开关DEV-LOG.md追加 Voice Mode 章节Why
/voice命令不显示且报native audio module could not be loaded。原因:feature('VOICE_MODE')编译时为 false → 命令未注册audio-capture-napi是 SoX stub → Windows 硬编码return false.node二进制文件src/下所有 voice 源码已与官方一致(0 行差异),只需补 vendor 文件 + 开开关。Test plan
bun run dev→/voice命令可见(需/login登录 claude.ai)isNativeAudioAvailable()返回true(Windows x64)bun run build→ 产物包含 voice 代码🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Documentation