fix(live-dictate): talk to whisper.cpp's HTTP API instead of Lemonade realtime

Live dictation sent the OpenAI realtime protocol to ws://host/v1/realtime,
which only Lemonade-style servers implement.  Against the local
whisper-server on port 13305 every connection failed with
"websocket-received-error-http-response 404".

Retarget the module at whisper.cpp's native POST /inference endpoint:

- capture 16 kHz mono PCM16 with FFmpeg (now with binary process coding,
  which the old version lacked and which would have corrupted the audio)
- cut the stream into utterances with an energy-based VAD: speech starts
  above live-dictate-silence-threshold, flushes after a configurable
  silence window, with pre-roll and a max-utterance cap
- wrap each utterance in a WAV header and post it with curl, one request
  at a time so transcripts are inserted in spoken order
- insert text at the dictation marker with correct spacing, keep the
  mode-line indicator and follow-cursor behaviour
- warn when the microphone delivers pure digital silence (OS permission)

New defcustoms: live-dictate-language, -prompt, -silence-threshold,
-silence-duration, -min-utterance, -max-utterance, -preroll.

Comments in config-mac.el and packages.el updated; websocket is no
longer needed by dictation.
This commit is contained in:
Willem van den Ende
2026-11-05 12:14:30 +00:00
parent 183036a333
commit 580b213793
3 changed files with 335 additions and 229 deletions
+5 -7
View File
@@ -236,9 +236,8 @@ Returns answer with org-roam links to sources."
;;; Speech-to-text (whisper.el + streaming dictation)
;;
;; Ported from config-linux.el so both machines have the same capabilities.
;; The pieces are already cross-platform: `whisper' and `websocket' are
;; declared in shared packages.el, and lisp/live-dictate.el picks avfoundation
;; for FFmpeg input on darwin by itself.
;; `whisper' is declared in shared packages.el, and lisp/live-dictate.el
;; picks avfoundation for FFmpeg input on darwin by itself.
;;
;; Backend on this machine: homebrew's whisper.cpp server, started by hand:
;;
@@ -247,10 +246,9 @@ Returns answer with org-roam links to sources."
;;
;; Mode `remote' POSTs multipart (file, response_format=json, language) to
;; <baseurl>/inference and parses the {"text": ...} reply -- whisper.cpp's
;; native API. For a Lemonade-style OpenAI-compatible backend instead, use
;; `whisper-server-mode' 'openai with `whisper-openai-api-baseurl'; that is
;; also what `live-dictate' (SPC A d) requires, since it streams over
;; ws://host/v1/realtime, which whisper.cpp cannot serve.
;; native API. `live-dictate' (SPC A d) uses the same endpoint: it cuts the
;; microphone stream into utterances with a client-side VAD and posts each
;; one as a WAV, so no WebSocket or Lemonade server is needed.
(add-load-path! "lisp")
(autoload #'live-dictate "live-dictate" nil t)