Boopster commited on
Commit
6d2637d
·
1 Parent(s): bc548fc

refactor: update `init_conversation_logging` to accept a `MiniMinderDB` instance and add background pre-loading for the wakeword detector's ONNX model.

Browse files
src/reachy_mini_conversation_app/console.py CHANGED
@@ -84,6 +84,7 @@ class LocalStream:
84
  self._is_session_active: bool = False # Session starts inactive to save tokens
85
  # Wake word detector - runs locally when session is inactive
86
  self._wakeword_detector = WakewordDetector()
 
87
  # Cooldown timestamp: wakeword detection paused until this time
88
  import time as _time
89
 
 
84
  self._is_session_active: bool = False # Session starts inactive to save tokens
85
  # Wake word detector - runs locally when session is inactive
86
  self._wakeword_detector = WakewordDetector()
87
+ self._wakeword_detector.eager_load() # start ONNX model load in background
88
  # Cooldown timestamp: wakeword detection paused until this time
89
  import time as _time
90
 
src/reachy_mini_conversation_app/main.py CHANGED
@@ -122,7 +122,7 @@ def run(
122
  enable_session_enrichment,
123
  )
124
 
125
- session_id = init_conversation_logging(db_dir / "mini_minder.db")
126
  logger.info("Conversation logging active: session=%s", session_id[:8])
127
 
128
  # One-time cleanup of old conversation logs (7-day retention)
 
122
  enable_session_enrichment,
123
  )
124
 
125
+ session_id = init_conversation_logging(minder_db)
126
  logger.info("Conversation logging active: session=%s", session_id[:8])
127
 
128
  # One-time cleanup of old conversation logs (7-day retention)
src/reachy_mini_conversation_app/stream_api.py CHANGED
@@ -74,17 +74,16 @@ _conversation_logger: Optional[ConversationLogger] = None
74
  _current_session_id: Optional[str] = None
75
 
76
 
77
- def init_conversation_logging(db_path: str | Path) -> str:
78
  """Initialize conversation logging with a new session.
79
 
80
  Args:
81
- db_path: Path to the SQLite database.
82
 
83
  Returns:
84
  The new session ID.
85
  """
86
  global _conversation_logger, _current_session_id
87
- db = MiniMinderDB(db_path)
88
  _conversation_logger = ConversationLogger(db)
89
  _current_session_id = str(uuid.uuid4())
90
  logger.info("Conversation logging initialized: session=%s", _current_session_id[:8])
 
74
  _current_session_id: Optional[str] = None
75
 
76
 
77
+ def init_conversation_logging(db: MiniMinderDB) -> str:
78
  """Initialize conversation logging with a new session.
79
 
80
  Args:
81
+ db: Existing MiniMinderDB instance to use for storage.
82
 
83
  Returns:
84
  The new session ID.
85
  """
86
  global _conversation_logger, _current_session_id
 
87
  _conversation_logger = ConversationLogger(db)
88
  _current_session_id = str(uuid.uuid4())
89
  logger.info("Conversation logging initialized: session=%s", _current_session_id[:8])
src/reachy_mini_conversation_app/wakeword_detector.py CHANGED
@@ -124,6 +124,21 @@ class WakewordDetector:
124
  logger.exception("Failed to initialise WakewordDetector")
125
  return False
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  # ------------------------------------------------------------------
128
  # Audio capture (diagnostics)
129
  # ------------------------------------------------------------------
 
124
  logger.exception("Failed to initialise WakewordDetector")
125
  return False
126
 
127
+ def eager_load(self) -> None:
128
+ """Start loading the ONNX model in a background thread.
129
+
130
+ Call this early during app boot so the model is ready by the
131
+ time the first audio frames arrive (~5s load time overlaps
132
+ with SDK/media init instead of blocking first ``feed()``).
133
+ """
134
+ import threading
135
+
136
+ def _load() -> None:
137
+ self._ensure_model()
138
+
139
+ t = threading.Thread(target=_load, daemon=True, name="wakeword-preload")
140
+ t.start()
141
+
142
  # ------------------------------------------------------------------
143
  # Audio capture (diagnostics)
144
  # ------------------------------------------------------------------