Add Esc cancel support
This commit is contained in:
parent
b3be444625
commit
f9224621fa
6 changed files with 19 additions and 0 deletions
|
|
@ -41,3 +41,4 @@ System packages (example names):
|
|||
- STT model and device are configured via the `stt` section in `config.json`.
|
||||
- LLM model settings are locked; model downloads to `~/.cache/lel/models/`.
|
||||
- `-v/--verbose` enables verbose logs (including llama.cpp) with `llama::` prefix.
|
||||
- Press `Esc` while recording to cancel without processing.
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ systemctl --user enable --now lel
|
|||
|
||||
- Press the hotkey once to start recording.
|
||||
- Press it again to stop and run STT.
|
||||
- Press `Esc` while recording to cancel without processing.
|
||||
- Transcript contents are logged only when `logging.log_transcript` is enabled or `-v/--verbose` is used.
|
||||
|
||||
Wayland note:
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ class DesktopAdapter(Protocol):
|
|||
def start_hotkey_listener(self, hotkey: str, callback: Callable[[], None]) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
def start_cancel_listener(self, callback: Callable[[], None]) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
def inject_text(self, text: str, backend: str) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ class WaylandAdapter:
|
|||
def start_hotkey_listener(self, _hotkey: str, _callback: Callable[[], None]) -> None:
|
||||
raise SystemExit("Wayland hotkeys are not supported yet.")
|
||||
|
||||
def start_cancel_listener(self, _callback: Callable[[], None]) -> None:
|
||||
raise SystemExit("Wayland hotkeys are not supported yet.")
|
||||
|
||||
def inject_text(self, _text: str, _backend: str) -> None:
|
||||
raise SystemExit("Wayland text injection is not supported yet.")
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,10 @@ class X11Adapter:
|
|||
thread = threading.Thread(target=self._listen, args=(hotkey, callback), daemon=True)
|
||||
thread.start()
|
||||
|
||||
def start_cancel_listener(self, callback: Callable[[], None]) -> None:
|
||||
thread = threading.Thread(target=self._listen, args=("Escape", callback), daemon=True)
|
||||
thread.start()
|
||||
|
||||
def inject_text(self, text: str, backend: str) -> None:
|
||||
backend = (backend or "").strip().lower()
|
||||
if backend in ("", "clipboard"):
|
||||
|
|
|
|||
|
|
@ -231,6 +231,12 @@ class Daemon:
|
|||
stream, record = payload
|
||||
self._start_stop_worker(stream, record, trigger, process_audio)
|
||||
|
||||
def cancel_recording(self):
|
||||
with self.lock:
|
||||
if self.state != State.RECORDING:
|
||||
return
|
||||
self.stop_recording(trigger="cancel", process_audio=False)
|
||||
|
||||
def shutdown(self, timeout: float = 5.0) -> bool:
|
||||
self.request_shutdown()
|
||||
self.stop_recording(trigger="shutdown", process_audio=False)
|
||||
|
|
@ -348,6 +354,7 @@ def main():
|
|||
cfg.daemon.hotkey,
|
||||
lambda: logging.info("hotkey pressed (dry-run)") if args.dry_run else daemon.toggle(),
|
||||
)
|
||||
desktop.start_cancel_listener(lambda: daemon.cancel_recording())
|
||||
logging.info("ready")
|
||||
try:
|
||||
desktop.run_tray(daemon.get_state, lambda: shutdown("quit requested"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue