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`.
|
- STT model and device are configured via the `stt` section in `config.json`.
|
||||||
- LLM model settings are locked; model downloads to `~/.cache/lel/models/`.
|
- LLM model settings are locked; model downloads to `~/.cache/lel/models/`.
|
||||||
- `-v/--verbose` enables verbose logs (including llama.cpp) with `llama::` prefix.
|
- `-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 the hotkey once to start recording.
|
||||||
- Press it again to stop and run STT.
|
- 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.
|
- Transcript contents are logged only when `logging.log_transcript` is enabled or `-v/--verbose` is used.
|
||||||
|
|
||||||
Wayland note:
|
Wayland note:
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@ class DesktopAdapter(Protocol):
|
||||||
def start_hotkey_listener(self, hotkey: str, callback: Callable[[], None]) -> None:
|
def start_hotkey_listener(self, hotkey: str, callback: Callable[[], None]) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def start_cancel_listener(self, callback: Callable[[], None]) -> None:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def inject_text(self, text: str, backend: str) -> None:
|
def inject_text(self, text: str, backend: str) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,9 @@ class WaylandAdapter:
|
||||||
def start_hotkey_listener(self, _hotkey: str, _callback: Callable[[], None]) -> None:
|
def start_hotkey_listener(self, _hotkey: str, _callback: Callable[[], None]) -> None:
|
||||||
raise SystemExit("Wayland hotkeys are not supported yet.")
|
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:
|
def inject_text(self, _text: str, _backend: str) -> None:
|
||||||
raise SystemExit("Wayland text injection is not supported yet.")
|
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 = threading.Thread(target=self._listen, args=(hotkey, callback), daemon=True)
|
||||||
thread.start()
|
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:
|
def inject_text(self, text: str, backend: str) -> None:
|
||||||
backend = (backend or "").strip().lower()
|
backend = (backend or "").strip().lower()
|
||||||
if backend in ("", "clipboard"):
|
if backend in ("", "clipboard"):
|
||||||
|
|
|
||||||
|
|
@ -231,6 +231,12 @@ class Daemon:
|
||||||
stream, record = payload
|
stream, record = payload
|
||||||
self._start_stop_worker(stream, record, trigger, process_audio)
|
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:
|
def shutdown(self, timeout: float = 5.0) -> bool:
|
||||||
self.request_shutdown()
|
self.request_shutdown()
|
||||||
self.stop_recording(trigger="shutdown", process_audio=False)
|
self.stop_recording(trigger="shutdown", process_audio=False)
|
||||||
|
|
@ -348,6 +354,7 @@ def main():
|
||||||
cfg.daemon.hotkey,
|
cfg.daemon.hotkey,
|
||||||
lambda: logging.info("hotkey pressed (dry-run)") if args.dry_run else daemon.toggle(),
|
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")
|
logging.info("ready")
|
||||||
try:
|
try:
|
||||||
desktop.run_tray(daemon.get_state, lambda: shutdown("quit requested"))
|
desktop.run_tray(daemon.get_state, lambda: shutdown("quit requested"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue