RemiFabre commited on
Commit
f88ddb5
·
1 Parent(s): 977318a

Refine listening idle behaviour

Browse files
src/reachy_mini_conversation_demo/moves.py CHANGED
@@ -227,6 +227,7 @@ class MovementManager:
227
  self._stop_event = threading.Event()
228
  self._thread: Optional[threading.Thread] = None
229
  self._state_lock = threading.RLock()
 
230
 
231
  def queue_move(self, move: Move) -> None:
232
  """Add a move to the primary move queue."""
@@ -276,10 +277,25 @@ class MovementManager:
276
  def is_idle(self):
277
  """Check if the robot is idle based on inactivity delay."""
278
  with self._state_lock:
 
 
279
  current_time = time.time()
280
  time_since_activity = current_time - self.state.last_activity_time
281
  return time_since_activity >= self.idle_inactivity_delay
282
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  def _manage_move_queue(self, current_time: float) -> None:
284
  """Manage the primary move queue (sequential execution)."""
285
  with self._state_lock:
@@ -481,11 +497,14 @@ class MovementManager:
481
 
482
  # 7. Extract pose components
483
  head, antennas, body_yaw = global_full_body_pose
 
 
 
484
 
485
  # 8. Single set_target call - the one and only place we control the robot
486
  try:
487
  self.current_robot.set_target(
488
- head=head, antennas=antennas, body_yaw=body_yaw
489
  )
490
  except Exception as e:
491
  logger.error(f"Failed to set robot target: {e}")
 
227
  self._stop_event = threading.Event()
228
  self._thread: Optional[threading.Thread] = None
229
  self._state_lock = threading.RLock()
230
+ self._is_listening = False
231
 
232
  def queue_move(self, move: Move) -> None:
233
  """Add a move to the primary move queue."""
 
277
  def is_idle(self):
278
  """Check if the robot is idle based on inactivity delay."""
279
  with self._state_lock:
280
+ if self._is_listening:
281
+ return False
282
  current_time = time.time()
283
  time_since_activity = current_time - self.state.last_activity_time
284
  return time_since_activity >= self.idle_inactivity_delay
285
 
286
+ def mark_user_activity(self) -> None:
287
+ """Record recent user activity to delay idle behaviours."""
288
+ with self._state_lock:
289
+ self.state.update_activity()
290
+
291
+ def set_listening(self, listening: bool) -> None:
292
+ """Toggle listening mode, freezing antennas when active."""
293
+ with self._state_lock:
294
+ if self._is_listening == listening:
295
+ return
296
+ self._is_listening = listening
297
+ self.state.update_activity()
298
+
299
  def _manage_move_queue(self, current_time: float) -> None:
300
  """Manage the primary move queue (sequential execution)."""
301
  with self._state_lock:
 
497
 
498
  # 7. Extract pose components
499
  head, antennas, body_yaw = global_full_body_pose
500
+ with self._state_lock:
501
+ listening = self._is_listening
502
+ antennas_cmd = (0.0, 0.0) if listening else antennas
503
 
504
  # 8. Single set_target call - the one and only place we control the robot
505
  try:
506
  self.current_robot.set_target(
507
+ head=head, antennas=antennas_cmd, body_yaw=body_yaw
508
  )
509
  except Exception as e:
510
  logger.error(f"Failed to set robot target: {e}")
src/reachy_mini_conversation_demo/openai_realtime.py CHANGED
@@ -71,9 +71,11 @@ class OpenaiRealtimeHandler(AsyncStreamHandler):
71
  if event.type == "input_audio_buffer.speech_started":
72
  self.clear_queue()
73
  self.deps.head_wobbler.reset()
 
74
  logger.debug("user speech started")
75
 
76
  if event.type == "input_audio_buffer.speech_stopped":
 
77
  logger.debug("user speech stopped")
78
 
79
  if event.type in ("response.audio.completed", "response.completed"):
 
71
  if event.type == "input_audio_buffer.speech_started":
72
  self.clear_queue()
73
  self.deps.head_wobbler.reset()
74
+ self.deps.movement_manager.set_listening(True)
75
  logger.debug("user speech started")
76
 
77
  if event.type == "input_audio_buffer.speech_stopped":
78
+ self.deps.movement_manager.set_listening(False)
79
  logger.debug("user speech stopped")
80
 
81
  if event.type in ("response.audio.completed", "response.completed"):