Switch to sounddevice recording

This commit is contained in:
Thales Maciel 2026-02-24 10:25:21 -03:00
parent afdf088d17
commit b6c0fc0793
No known key found for this signature in database
GPG key ID: 33112E6833C34679
9 changed files with 250 additions and 468 deletions

View file

@ -15,7 +15,6 @@ from stt import FasterWhisperSTT, STTConfig
from aiprocess import AIConfig, build_processor
from context import I3Provider
from inject import inject
from history import HistoryStore
from x11_hotkey import listen
from tray import run_tray
from settings_window import open_settings_window
@ -32,8 +31,6 @@ class State:
class Daemon:
def __init__(self, cfg: Config):
self.cfg = cfg
self.history = HistoryStore()
self.history.prune(1000)
self.lock = threading.Lock()
self.state = State.IDLE
self.proc = None
@ -75,7 +72,7 @@ class Daemon:
def _start_recording_locked(self):
try:
proc, record = start_recording(self.cfg.recording.get("input", "pulse:default"))
proc, record = start_recording(self.cfg.recording.get("input", ""))
except Exception as exc:
logging.error("record start failed: %s", exc)
return
@ -100,8 +97,6 @@ class Daemon:
self.record = record
self.state = State.RECORDING
logging.info("recording started (%s)", record.wav_path)
run_id = self.history.add_run("record", "started", self.cfg, self._context_json(self.context))
self.history.add_artifact(run_id, "audio", {"path": record.wav_path}, record.wav_path)
if self.timer:
self.timer.cancel()
self.timer = threading.Timer(300, self._timeout_stop)
@ -130,7 +125,7 @@ class Daemon:
logging.info("stopping recording (user)")
try:
stop_recording(proc)
stop_recording(proc, record)
except Exception as exc:
logging.error("record stop failed: %s", exc)
self.set_state(State.IDLE)
@ -156,9 +151,6 @@ class Daemon:
return
logging.info("stt: %s", text)
run_id = self.history.add_run("stt", "ok", self.cfg, self._context_json(self.context))
self.history.add_artifact(run_id, "input", {"wav_path": record.wav_path, "language": "en"})
self.history.add_artifact(run_id, "output", {"text": text})
ai_enabled = self.cfg.ai_cleanup.get("enabled", False)
ai_prompt_file = ""
@ -180,17 +172,6 @@ class Daemon:
)
ai_input = text
text = processor.process(ai_input) or text
run_id = self.history.add_run("ai", "ok", self.cfg, self._context_json(self.context))
self.history.add_artifact(
run_id,
"input",
{
"text": ai_input,
"model": self.cfg.ai_cleanup.get("model", ""),
"temperature": self.cfg.ai_cleanup.get("temperature", 0.0),
},
)
self.history.add_artifact(run_id, "output", {"text": text})
except Exception as exc:
logging.error("ai process failed: %s", exc)
@ -206,8 +187,6 @@ class Daemon:
return
backend = self.cfg.injection.get("backend", "clipboard")
inject(text, backend)
run_id = self.history.add_run("inject", "ok", self.cfg, self._context_json(self.context))
self.history.add_artifact(run_id, "input", {"text": text, "backend": backend})
except Exception as exc:
logging.error("output failed: %s", exc)
finally:
@ -263,7 +242,7 @@ def main():
open_settings_window(cfg, config_path)
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from gi.repository import Gtk # type: ignore[import-not-found]
Gtk.main()
return