feat(desktop): add local voice dictation to the chat composer

Adds a microphone button beside the composer. Click to record, click to stop; the audio is resampled to 16 kHz mono PCM16 WAV, posted to the local server and transcribed by a SenseVoice worker process, and the text lands in the draft without being sent. If the draft changed or an IME is composing, the result is held behind an insert button instead of overwriting the user's text.

Server: a small provider registry behind /api/voice/* (catalog, preferences, prepare/cancel/status/remove, transcribe). The engine and model are downloaded at runtime to <config>/cc-haha/voice with pinned sha256/sha512, HuggingFace plus hf-mirror and npm plus npmmirror, HTTP Range resume, automatic retry after interruptions, and a partial file kept across cancels. Recognition runs in a separate worker process (sidecar --voice-worker), started on demand and reclaimed when idle.

Desktop: an independent Voice input settings tab with enable switch, model download progress and resume, language, microphone selection and a transcription test with a live waveform. Uses the shared Dropdown/Card/Button components; adds a danger-ghost Button variant. Preferences live in desktop-ui.json (schemaVersion 6); the microphone device id stays in localStorage.

Electron: main-window media permission handler limited to app pages, main frame and audio only, plus the audio-input entitlement and NSMicrophoneUsageDescription.

Scope: Electron desktop only. Not verified on Windows or Linux, with a real microphone, or in a signed and notarized package.
This commit is contained in:
程序员阿江(Relakkes)
2026-10-01 00:32:16 +08:00
parent 8d1548e62c
commit 6d75fac69e
94 changed files with 12839 additions and 20 deletions
@@ -11,6 +11,9 @@
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<!-- Chromium's audio service runs in a helper process and captures the microphone. -->
<key>com.apple.security.device.audio-input</key>
<true/>
<key>com.apple.security.inherit</key>
<true/>
</dict>
+3
View File
@@ -15,5 +15,8 @@
and server runtime to work under a notarized hardened-runtime build. -->
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<!-- Voice dictation records from the microphone via getUserMedia in the renderer. -->
<key>com.apple.security.device.audio-input</key>
<true/>
</dict>
</plist>