Spaces:
Running
Running
apirrone commited on
Commit ·
c03f312
1
Parent(s): 2f938c6
ruff and cleaning up
Browse files- src/reachy_mini_conversation_demo/__init__.py +1 -0
- src/reachy_mini_conversation_demo/audio/__init__.py +1 -0
- src/reachy_mini_conversation_demo/audio/audio_sway.py +0 -176
- src/reachy_mini_conversation_demo/audio/gstreamer.py +16 -3
- src/reachy_mini_conversation_demo/audio/head_wobbler.py +1 -1
- src/reachy_mini_conversation_demo/audio/speech_tapper.py +4 -2
- src/reachy_mini_conversation_demo/config.py +3 -1
- src/reachy_mini_conversation_demo/dance_emotion_moves.py +79 -45
- src/reachy_mini_conversation_demo/main.py +4 -3
- src/reachy_mini_conversation_demo/main_works.py +174 -107
- src/reachy_mini_conversation_demo/moves.py +2 -1
- src/reachy_mini_conversation_demo/openai_realtime.py +1 -1
- src/reachy_mini_conversation_demo/prompts.py +3 -1
- src/reachy_mini_conversation_demo/tools.py +1 -1
- src/reachy_mini_conversation_demo/utils.py +1 -1
- src/reachy_mini_conversation_demo/vision/__init__.py +1 -0
- src/reachy_mini_conversation_demo/vision/processors.py +1 -1
- src/reachy_mini_conversation_demo/vision/yolo_head_tracker.py +1 -1
src/reachy_mini_conversation_demo/__init__.py
CHANGED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
"""Nothing (for ruff)."""
|
src/reachy_mini_conversation_demo/audio/__init__.py
CHANGED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
"""Nothing (for ruff)."""
|
src/reachy_mini_conversation_demo/audio/audio_sway.py
DELETED
|
@@ -1,176 +0,0 @@
|
|
| 1 |
-
from __future__ import annotations
|
| 2 |
-
|
| 3 |
-
import asyncio
|
| 4 |
-
import base64
|
| 5 |
-
from dataclasses import dataclass
|
| 6 |
-
from typing import Callable, Optional, Tuple
|
| 7 |
-
|
| 8 |
-
import numpy as np
|
| 9 |
-
|
| 10 |
-
from reachy_mini_conversation_demo.audio.speech_tapper import HOP_MS, SwayRollRT
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
@dataclass
|
| 14 |
-
class AudioConfig:
|
| 15 |
-
output_sample_rate: int = 24_000
|
| 16 |
-
movement_latency_s: float = 0.08
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
def pcm_to_b64(array: np.ndarray) -> str:
|
| 20 |
-
"""array: shape (N,) int16 or (1,N) int16 -> base64 string for OpenAI input buffer."""
|
| 21 |
-
a = np.asarray(array).reshape(-1).astype(np.int16, copy=False)
|
| 22 |
-
return base64.b64encode(a.tobytes()).decode("utf-8")
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
class AudioSync:
|
| 26 |
-
"""Routes assistant audio to:
|
| 27 |
-
1) a playback queue for fastrtc
|
| 28 |
-
2) a sway engine that emits head-offsets aligned to audio
|
| 29 |
-
"""
|
| 30 |
-
|
| 31 |
-
def __init__(
|
| 32 |
-
self,
|
| 33 |
-
cfg: AudioConfig,
|
| 34 |
-
set_offsets: Callable[[Tuple[float, float, float, float, float, float]], None],
|
| 35 |
-
sway: Optional[SwayRollRT] = None,
|
| 36 |
-
) -> None:
|
| 37 |
-
"""set_offsets: callback receiving (x,y,z,roll,pitch,yaw) at each hop, in meters/radians.
|
| 38 |
-
"""
|
| 39 |
-
self.cfg = cfg
|
| 40 |
-
self.set_offsets = set_offsets
|
| 41 |
-
self.sway = sway or SwayRollRT()
|
| 42 |
-
|
| 43 |
-
self.playback_q: asyncio.Queue = (
|
| 44 |
-
asyncio.Queue()
|
| 45 |
-
) # (sr:int, pcm: np.ndarray[1,N] int16)
|
| 46 |
-
self._sway_q: asyncio.Queue = (
|
| 47 |
-
asyncio.Queue()
|
| 48 |
-
) # (sr:int, pcm: np.ndarray[1,N] int16)
|
| 49 |
-
|
| 50 |
-
self._base_ts: Optional[float] = None
|
| 51 |
-
self._hops_done: int = 0
|
| 52 |
-
self._sway_task: Optional[asyncio.Task] = None
|
| 53 |
-
|
| 54 |
-
# lifecycle
|
| 55 |
-
|
| 56 |
-
def start(self) -> None:
|
| 57 |
-
if self._sway_task is None:
|
| 58 |
-
self._sway_task = asyncio.create_task(self._sway_consumer())
|
| 59 |
-
|
| 60 |
-
async def stop(self) -> None:
|
| 61 |
-
if self._sway_task:
|
| 62 |
-
self._sway_task.cancel()
|
| 63 |
-
try:
|
| 64 |
-
await self._sway_task
|
| 65 |
-
except asyncio.CancelledError:
|
| 66 |
-
pass
|
| 67 |
-
self._sway_task = None
|
| 68 |
-
self._reset_all()
|
| 69 |
-
self._drain(self._sway_q)
|
| 70 |
-
self._drain(self.playback_q)
|
| 71 |
-
|
| 72 |
-
# event hooks from your Realtime loop
|
| 73 |
-
|
| 74 |
-
def on_input_speech_started(self) -> None:
|
| 75 |
-
"""User started speaking (server VAD). Reset sync state."""
|
| 76 |
-
self._reset_all()
|
| 77 |
-
self._drain(self._sway_q)
|
| 78 |
-
|
| 79 |
-
def on_response_started(self) -> None:
|
| 80 |
-
"""Assistant began a new utterance."""
|
| 81 |
-
self._reset_all()
|
| 82 |
-
self._drain(self._sway_q)
|
| 83 |
-
|
| 84 |
-
def on_response_completed(self) -> None:
|
| 85 |
-
"""Assistant finished an utterance."""
|
| 86 |
-
self._reset_all()
|
| 87 |
-
self._drain(self._sway_q)
|
| 88 |
-
|
| 89 |
-
def on_response_audio_delta(self, delta_b64: str) -> None:
|
| 90 |
-
"""Called for each 'response.audio.delta' event.
|
| 91 |
-
Pushes audio both to playback and to sway engine.
|
| 92 |
-
"""
|
| 93 |
-
buf = np.frombuffer(base64.b64decode(delta_b64), dtype=np.int16).reshape(1, -1)
|
| 94 |
-
# 1) to fastrtc playback
|
| 95 |
-
self.playback_q.put_nowait((self.cfg.output_sample_rate, buf))
|
| 96 |
-
# 2) to sway engine
|
| 97 |
-
self._sway_q.put_nowait((self.cfg.output_sample_rate, buf))
|
| 98 |
-
|
| 99 |
-
# fastrtc hook
|
| 100 |
-
|
| 101 |
-
async def emit_playback(self):
|
| 102 |
-
"""Await next (sr, pcm[1,N]) frame for your Stream(...)."""
|
| 103 |
-
return await self.playback_q.get()
|
| 104 |
-
|
| 105 |
-
# internal
|
| 106 |
-
|
| 107 |
-
async def _sway_consumer(self):
|
| 108 |
-
"""Convert streaming audio chunks into head-offset poses at precise times.
|
| 109 |
-
"""
|
| 110 |
-
hop_dt = HOP_MS / 1000.0
|
| 111 |
-
loop = asyncio.get_running_loop()
|
| 112 |
-
|
| 113 |
-
while True:
|
| 114 |
-
sr, chunk = await self._sway_q.get() # (1,N), int16
|
| 115 |
-
pcm = np.asarray(chunk).squeeze(0)
|
| 116 |
-
results = self.sway.feed(pcm, sr) # list of dicts with keys x_mm..yaw_rad
|
| 117 |
-
|
| 118 |
-
if self._base_ts is None:
|
| 119 |
-
# anchor when first audio samples of this utterance arrive
|
| 120 |
-
self._base_ts = loop.time()
|
| 121 |
-
|
| 122 |
-
i = 0
|
| 123 |
-
while i < len(results):
|
| 124 |
-
if self._base_ts is None:
|
| 125 |
-
self._base_ts = loop.time()
|
| 126 |
-
continue
|
| 127 |
-
|
| 128 |
-
target = (
|
| 129 |
-
self._base_ts
|
| 130 |
-
+ self.cfg.movement_latency_s
|
| 131 |
-
+ self._hops_done * hop_dt
|
| 132 |
-
)
|
| 133 |
-
now = loop.time()
|
| 134 |
-
|
| 135 |
-
# if late by ≥1 hop, drop poses to catch up (no drift accumulation)
|
| 136 |
-
if now - target >= hop_dt:
|
| 137 |
-
lag_hops = int((now - target) / hop_dt)
|
| 138 |
-
drop = min(
|
| 139 |
-
lag_hops, len(results) - i - 1
|
| 140 |
-
) # keep at least one to show
|
| 141 |
-
if drop > 0:
|
| 142 |
-
self._hops_done += drop
|
| 143 |
-
i += drop
|
| 144 |
-
continue
|
| 145 |
-
|
| 146 |
-
# if early, wait
|
| 147 |
-
if target > now:
|
| 148 |
-
await asyncio.sleep(target - now)
|
| 149 |
-
|
| 150 |
-
r = results[i]
|
| 151 |
-
# meters + radians
|
| 152 |
-
offsets = (
|
| 153 |
-
r["x_mm"] / 1000.0,
|
| 154 |
-
r["y_mm"] / 1000.0,
|
| 155 |
-
r["z_mm"] / 1000.0,
|
| 156 |
-
r["roll_rad"],
|
| 157 |
-
r["pitch_rad"],
|
| 158 |
-
r["yaw_rad"],
|
| 159 |
-
)
|
| 160 |
-
self.set_offsets(offsets)
|
| 161 |
-
|
| 162 |
-
self._hops_done += 1
|
| 163 |
-
i += 1
|
| 164 |
-
|
| 165 |
-
def _reset_all(self) -> None:
|
| 166 |
-
self._base_ts = None
|
| 167 |
-
self._hops_done = 0
|
| 168 |
-
self.sway.reset()
|
| 169 |
-
|
| 170 |
-
@staticmethod
|
| 171 |
-
def _drain(q: asyncio.Queue) -> None:
|
| 172 |
-
try:
|
| 173 |
-
while True:
|
| 174 |
-
q.get_nowait()
|
| 175 |
-
except asyncio.QueueEmpty:
|
| 176 |
-
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/reachy_mini_conversation_demo/audio/gstreamer.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import logging
|
| 2 |
from threading import Thread
|
| 3 |
from typing import Optional
|
| 4 |
|
|
@@ -6,11 +6,14 @@ import gi
|
|
| 6 |
|
| 7 |
gi.require_version("Gst", "1.0")
|
| 8 |
gi.require_version("GstApp", "1.0")
|
| 9 |
-
from gi.repository import GLib, Gst
|
| 10 |
|
| 11 |
|
| 12 |
class GstPlayer:
|
|
|
|
|
|
|
| 13 |
def __init__(self, sample_rate: int = 24000, device_name: Optional[str] = None):
|
|
|
|
| 14 |
self._logger = logging.getLogger(__name__)
|
| 15 |
Gst.init(None)
|
| 16 |
self._loop = GLib.MainLoop()
|
|
@@ -68,15 +71,18 @@ class GstPlayer:
|
|
| 68 |
self._logger.debug("bus message loop stopped")
|
| 69 |
|
| 70 |
def play(self):
|
|
|
|
| 71 |
self.pipeline.set_state(Gst.State.PLAYING)
|
| 72 |
self._thread_bus_calls = Thread(target=self._handle_bus_calls, daemon=True)
|
| 73 |
self._thread_bus_calls.start()
|
| 74 |
|
| 75 |
def push_sample(self, data: bytes):
|
|
|
|
| 76 |
buf = Gst.Buffer.new_wrapped(data)
|
| 77 |
self.appsrc.push_buffer(buf)
|
| 78 |
|
| 79 |
def stop(self):
|
|
|
|
| 80 |
logger = logging.getLogger(__name__)
|
| 81 |
self._loop.quit()
|
| 82 |
self.pipeline.set_state(Gst.State.NULL)
|
|
@@ -86,7 +92,10 @@ class GstPlayer:
|
|
| 86 |
|
| 87 |
|
| 88 |
class GstRecorder:
|
|
|
|
|
|
|
| 89 |
def __init__(self, sample_rate: int = 24000, device_name: Optional[str] = None):
|
|
|
|
| 90 |
self._logger = logging.getLogger(__name__)
|
| 91 |
Gst.init(None)
|
| 92 |
self._loop = GLib.MainLoop()
|
|
@@ -147,11 +156,13 @@ class GstRecorder:
|
|
| 147 |
self._logger.debug("bus message loop stopped")
|
| 148 |
|
| 149 |
def record(self):
|
|
|
|
| 150 |
self.pipeline.set_state(Gst.State.PLAYING)
|
| 151 |
self._thread_bus_calls = Thread(target=self._handle_bus_calls, daemon=True)
|
| 152 |
self._thread_bus_calls.start()
|
| 153 |
|
| 154 |
def get_sample(self):
|
|
|
|
| 155 |
sample = self.appsink.pull_sample()
|
| 156 |
data = None
|
| 157 |
if isinstance(sample, Gst.Sample):
|
|
@@ -163,6 +174,7 @@ class GstRecorder:
|
|
| 163 |
return data
|
| 164 |
|
| 165 |
def stop(self):
|
|
|
|
| 166 |
logger = logging.getLogger(__name__)
|
| 167 |
self._loop.quit()
|
| 168 |
self.pipeline.set_state(Gst.State.NULL)
|
|
@@ -174,7 +186,8 @@ class GstRecorder:
|
|
| 174 |
def _create_device_element(
|
| 175 |
direction: str, name_substr: Optional[str]
|
| 176 |
) -> Optional[Gst.Element]:
|
| 177 |
-
"""direction: 'source' or 'sink'
|
|
|
|
| 178 |
name_substr: case-insensitive substring matching device display name/description.
|
| 179 |
"""
|
| 180 |
logger = logging.getLogger(__name__)
|
|
|
|
| 1 |
+
import logging # noqa: D100
|
| 2 |
from threading import Thread
|
| 3 |
from typing import Optional
|
| 4 |
|
|
|
|
| 6 |
|
| 7 |
gi.require_version("Gst", "1.0")
|
| 8 |
gi.require_version("GstApp", "1.0")
|
| 9 |
+
from gi.repository import GLib, Gst # noqa: E402
|
| 10 |
|
| 11 |
|
| 12 |
class GstPlayer:
|
| 13 |
+
"""Audio player using GStreamer."""
|
| 14 |
+
|
| 15 |
def __init__(self, sample_rate: int = 24000, device_name: Optional[str] = None):
|
| 16 |
+
"""Initialize player."""
|
| 17 |
self._logger = logging.getLogger(__name__)
|
| 18 |
Gst.init(None)
|
| 19 |
self._loop = GLib.MainLoop()
|
|
|
|
| 71 |
self._logger.debug("bus message loop stopped")
|
| 72 |
|
| 73 |
def play(self):
|
| 74 |
+
"""Start playback."""
|
| 75 |
self.pipeline.set_state(Gst.State.PLAYING)
|
| 76 |
self._thread_bus_calls = Thread(target=self._handle_bus_calls, daemon=True)
|
| 77 |
self._thread_bus_calls.start()
|
| 78 |
|
| 79 |
def push_sample(self, data: bytes):
|
| 80 |
+
"""Push audio sample (bytes) to playback pipeline."""
|
| 81 |
buf = Gst.Buffer.new_wrapped(data)
|
| 82 |
self.appsrc.push_buffer(buf)
|
| 83 |
|
| 84 |
def stop(self):
|
| 85 |
+
"""Stop playback and clean up."""
|
| 86 |
logger = logging.getLogger(__name__)
|
| 87 |
self._loop.quit()
|
| 88 |
self.pipeline.set_state(Gst.State.NULL)
|
|
|
|
| 92 |
|
| 93 |
|
| 94 |
class GstRecorder:
|
| 95 |
+
"""Audio recorder using GStreamer."""
|
| 96 |
+
|
| 97 |
def __init__(self, sample_rate: int = 24000, device_name: Optional[str] = None):
|
| 98 |
+
"""Initialize recorder."""
|
| 99 |
self._logger = logging.getLogger(__name__)
|
| 100 |
Gst.init(None)
|
| 101 |
self._loop = GLib.MainLoop()
|
|
|
|
| 156 |
self._logger.debug("bus message loop stopped")
|
| 157 |
|
| 158 |
def record(self):
|
| 159 |
+
"""Start recording."""
|
| 160 |
self.pipeline.set_state(Gst.State.PLAYING)
|
| 161 |
self._thread_bus_calls = Thread(target=self._handle_bus_calls, daemon=True)
|
| 162 |
self._thread_bus_calls.start()
|
| 163 |
|
| 164 |
def get_sample(self):
|
| 165 |
+
"""Return next audio sample as bytes, or None if no sample available."""
|
| 166 |
sample = self.appsink.pull_sample()
|
| 167 |
data = None
|
| 168 |
if isinstance(sample, Gst.Sample):
|
|
|
|
| 174 |
return data
|
| 175 |
|
| 176 |
def stop(self):
|
| 177 |
+
"""Stop recording and clean up."""
|
| 178 |
logger = logging.getLogger(__name__)
|
| 179 |
self._loop.quit()
|
| 180 |
self.pipeline.set_state(Gst.State.NULL)
|
|
|
|
| 186 |
def _create_device_element(
|
| 187 |
direction: str, name_substr: Optional[str]
|
| 188 |
) -> Optional[Gst.Element]:
|
| 189 |
+
"""direction: 'source' or 'sink'.
|
| 190 |
+
|
| 191 |
name_substr: case-insensitive substring matching device display name/description.
|
| 192 |
"""
|
| 193 |
logger = logging.getLogger(__name__)
|
src/reachy_mini_conversation_demo/audio/head_wobbler.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import asyncio
|
| 2 |
import base64
|
| 3 |
import logging
|
| 4 |
from asyncio import QueueEmpty
|
|
|
|
| 1 |
+
import asyncio # noqa: D100
|
| 2 |
import base64
|
| 3 |
import logging
|
| 4 |
from asyncio import QueueEmpty
|
src/reachy_mini_conversation_demo/audio/speech_tapper.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from __future__ import annotations
|
| 2 |
|
| 3 |
import math
|
| 4 |
from collections import deque
|
|
@@ -68,6 +68,7 @@ def _loudness_gain(db: float, offset: float = SENS_DB_OFFSET) -> float:
|
|
| 68 |
|
| 69 |
def _to_float32_mono(x: np.ndarray) -> np.ndarray:
|
| 70 |
"""Convert arbitrary PCM array to float32 mono in [-1,1].
|
|
|
|
| 71 |
Accepts shapes: (N,), (1,N), (N,1), (C,N), (N,C).
|
| 72 |
"""
|
| 73 |
a = np.asarray(x)
|
|
@@ -115,6 +116,7 @@ class SwayRollRT:
|
|
| 115 |
"""
|
| 116 |
|
| 117 |
def __init__(self, rng_seed: int = 7):
|
|
|
|
| 118 |
self._seed = int(rng_seed)
|
| 119 |
self.samples = deque(maxlen=10 * SR) # sliding window for VAD/env
|
| 120 |
self.carry = np.zeros(0, dtype=np.float32)
|
|
@@ -151,7 +153,7 @@ class SwayRollRT:
|
|
| 151 |
self.t = 0.0
|
| 152 |
|
| 153 |
def reset_phases(self) -> None:
|
| 154 |
-
"""
|
| 155 |
rng = np.random.default_rng(self._seed)
|
| 156 |
self.phase_pitch = float(rng.random() * 2 * math.pi)
|
| 157 |
self.phase_yaw = float(rng.random() * 2 * math.pi)
|
|
|
|
| 1 |
+
from __future__ import annotations # noqa: D100
|
| 2 |
|
| 3 |
import math
|
| 4 |
from collections import deque
|
|
|
|
| 68 |
|
| 69 |
def _to_float32_mono(x: np.ndarray) -> np.ndarray:
|
| 70 |
"""Convert arbitrary PCM array to float32 mono in [-1,1].
|
| 71 |
+
|
| 72 |
Accepts shapes: (N,), (1,N), (N,1), (C,N), (N,C).
|
| 73 |
"""
|
| 74 |
a = np.asarray(x)
|
|
|
|
| 116 |
"""
|
| 117 |
|
| 118 |
def __init__(self, rng_seed: int = 7):
|
| 119 |
+
"""Initialize state."""
|
| 120 |
self._seed = int(rng_seed)
|
| 121 |
self.samples = deque(maxlen=10 * SR) # sliding window for VAD/env
|
| 122 |
self.carry = np.zeros(0, dtype=np.float32)
|
|
|
|
| 153 |
self.t = 0.0
|
| 154 |
|
| 155 |
def reset_phases(self) -> None:
|
| 156 |
+
"""Re-randomize phases deterministically from stored seed (Optional)."""
|
| 157 |
rng = np.random.default_rng(self._seed)
|
| 158 |
self.phase_pitch = float(rng.random() * 2 * math.pi)
|
| 159 |
self.phase_yaw = float(rng.random() * 2 * math.pi)
|
src/reachy_mini_conversation_demo/config.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import os
|
| 2 |
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
|
|
@@ -14,6 +14,8 @@ def getenv_bool(key: str, default: bool = False) -> bool:
|
|
| 14 |
|
| 15 |
|
| 16 |
class Config:
|
|
|
|
|
|
|
| 17 |
# Required
|
| 18 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 19 |
if not OPENAI_API_KEY:
|
|
|
|
| 1 |
+
import os # noqa: D100
|
| 2 |
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
class Config:
|
| 17 |
+
"""Configuration class for the conversation demo."""
|
| 18 |
+
|
| 19 |
# Required
|
| 20 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 21 |
if not OPENAI_API_KEY:
|
src/reachy_mini_conversation_demo/dance_emotion_moves.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
| 3 |
This module implements dance moves and emotions as Move objects that can be queued
|
| 4 |
and executed sequentially by the MovementManager.
|
| 5 |
"""
|
|
|
|
| 6 |
from __future__ import annotations
|
| 7 |
|
| 8 |
import logging
|
|
@@ -17,119 +18,152 @@ logger = logging.getLogger(__name__)
|
|
| 17 |
|
| 18 |
|
| 19 |
class DanceQueueMove(Move):
|
| 20 |
-
"""Wrapper for dance moves to work with the movement queue system"""
|
| 21 |
-
|
| 22 |
def __init__(self, move_name: str):
|
|
|
|
| 23 |
self.dance_move = DanceMove(move_name)
|
| 24 |
self.move_name = move_name
|
| 25 |
-
|
| 26 |
@property
|
| 27 |
def duration(self) -> float:
|
| 28 |
"""Duration property required by official Move interface."""
|
| 29 |
return self.dance_move.duration
|
| 30 |
-
|
| 31 |
-
def evaluate(
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
try:
|
| 34 |
# Get the pose from the dance move
|
| 35 |
head_pose, antennas, body_yaw = self.dance_move.evaluate(t)
|
| 36 |
-
|
| 37 |
# Convert to numpy array if antennas is tuple and return in official Move format
|
| 38 |
if isinstance(antennas, tuple):
|
| 39 |
antennas = np.array([antennas[0], antennas[1]])
|
| 40 |
-
|
| 41 |
return (head_pose, antennas, body_yaw)
|
| 42 |
-
|
| 43 |
except Exception as e:
|
| 44 |
-
logger.error(
|
|
|
|
|
|
|
| 45 |
# Return neutral pose on error
|
| 46 |
from reachy_mini.utils import create_head_pose
|
|
|
|
| 47 |
neutral_head_pose = create_head_pose(0, 0, 0, 0, 0, 0, degrees=True)
|
| 48 |
return (neutral_head_pose, np.array([0.0, 0.0]), 0.0)
|
| 49 |
|
| 50 |
|
| 51 |
class EmotionQueueMove(Move):
|
| 52 |
-
"""Wrapper for emotion moves to work with the movement queue system"""
|
| 53 |
-
|
| 54 |
def __init__(self, emotion_name: str, recorded_moves: RecordedMoves):
|
|
|
|
| 55 |
self.emotion_move = recorded_moves.get(emotion_name)
|
| 56 |
self.emotion_name = emotion_name
|
| 57 |
-
|
| 58 |
@property
|
| 59 |
def duration(self) -> float:
|
| 60 |
"""Duration property required by official Move interface."""
|
| 61 |
return self.emotion_move.duration
|
| 62 |
-
|
| 63 |
-
def evaluate(
|
| 64 |
-
|
|
|
|
|
|
|
| 65 |
try:
|
| 66 |
# Get the pose from the emotion move
|
| 67 |
head_pose, antennas, body_yaw = self.emotion_move.evaluate(t)
|
| 68 |
-
|
| 69 |
# Convert to numpy array if antennas is tuple and return in official Move format
|
| 70 |
if isinstance(antennas, tuple):
|
| 71 |
antennas = np.array([antennas[0], antennas[1]])
|
| 72 |
-
|
| 73 |
return (head_pose, antennas, body_yaw)
|
| 74 |
-
|
| 75 |
except Exception as e:
|
| 76 |
-
logger.error(
|
|
|
|
|
|
|
| 77 |
# Return neutral pose on error
|
| 78 |
from reachy_mini.utils import create_head_pose
|
|
|
|
| 79 |
neutral_head_pose = create_head_pose(0, 0, 0, 0, 0, 0, degrees=True)
|
| 80 |
return (neutral_head_pose, np.array([0.0, 0.0]), 0.0)
|
| 81 |
|
| 82 |
|
| 83 |
class GotoQueueMove(Move):
|
| 84 |
-
"""Wrapper for goto moves to work with the movement queue system"""
|
| 85 |
-
|
| 86 |
-
def __init__(
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
self._duration = duration
|
| 90 |
self.target_head_pose = target_head_pose
|
| 91 |
self.start_head_pose = start_head_pose
|
| 92 |
self.target_antennas = target_antennas
|
| 93 |
self.start_antennas = start_antennas or (0, 0)
|
| 94 |
-
self.target_body_yaw = target_body_yaw
|
| 95 |
self.start_body_yaw = start_body_yaw or 0
|
| 96 |
-
|
| 97 |
@property
|
| 98 |
def duration(self) -> float:
|
| 99 |
"""Duration property required by official Move interface."""
|
| 100 |
return self._duration
|
| 101 |
-
|
| 102 |
-
def evaluate(
|
| 103 |
-
|
|
|
|
|
|
|
| 104 |
try:
|
| 105 |
from reachy_mini.utils import create_head_pose
|
| 106 |
from reachy_mini.utils.interpolation import linear_pose_interpolation
|
| 107 |
-
|
| 108 |
# Clamp t to [0, 1] for interpolation
|
| 109 |
t_clamped = max(0, min(1, t / self.duration))
|
| 110 |
-
|
| 111 |
# Use start pose if available, otherwise neutral
|
| 112 |
if self.start_head_pose is not None:
|
| 113 |
start_pose = self.start_head_pose
|
| 114 |
else:
|
| 115 |
start_pose = create_head_pose(0, 0, 0, 0, 0, 0, degrees=True)
|
| 116 |
-
|
| 117 |
# Interpolate head pose
|
| 118 |
-
head_pose = linear_pose_interpolation(
|
| 119 |
-
|
|
|
|
|
|
|
| 120 |
# Interpolate antennas - return as numpy array
|
| 121 |
-
antennas = np.array(
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
# Interpolate body yaw
|
| 127 |
-
body_yaw =
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
| 129 |
return (head_pose, antennas, body_yaw)
|
| 130 |
-
|
| 131 |
except Exception as e:
|
| 132 |
logger.error(f"Error evaluating goto move at t={t}: {e}")
|
| 133 |
# Return target pose on error - convert antennas to numpy array
|
| 134 |
-
target_antennas_array = np.array(
|
| 135 |
-
|
|
|
|
|
|
|
|
|
| 3 |
This module implements dance moves and emotions as Move objects that can be queued
|
| 4 |
and executed sequentially by the MovementManager.
|
| 5 |
"""
|
| 6 |
+
|
| 7 |
from __future__ import annotations
|
| 8 |
|
| 9 |
import logging
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
class DanceQueueMove(Move):
|
| 21 |
+
"""Wrapper for dance moves to work with the movement queue system."""
|
| 22 |
+
|
| 23 |
def __init__(self, move_name: str):
|
| 24 |
+
"""Initialize a DanceQueueMove."""
|
| 25 |
self.dance_move = DanceMove(move_name)
|
| 26 |
self.move_name = move_name
|
| 27 |
+
|
| 28 |
@property
|
| 29 |
def duration(self) -> float:
|
| 30 |
"""Duration property required by official Move interface."""
|
| 31 |
return self.dance_move.duration
|
| 32 |
+
|
| 33 |
+
def evaluate(
|
| 34 |
+
self, t: float
|
| 35 |
+
) -> tuple[np.ndarray | None, np.ndarray | None, float | None]:
|
| 36 |
+
"""Evaluate dance move at time t."""
|
| 37 |
try:
|
| 38 |
# Get the pose from the dance move
|
| 39 |
head_pose, antennas, body_yaw = self.dance_move.evaluate(t)
|
| 40 |
+
|
| 41 |
# Convert to numpy array if antennas is tuple and return in official Move format
|
| 42 |
if isinstance(antennas, tuple):
|
| 43 |
antennas = np.array([antennas[0], antennas[1]])
|
| 44 |
+
|
| 45 |
return (head_pose, antennas, body_yaw)
|
| 46 |
+
|
| 47 |
except Exception as e:
|
| 48 |
+
logger.error(
|
| 49 |
+
f"Error evaluating dance move '{self.move_name}' at t={t}: {e}"
|
| 50 |
+
)
|
| 51 |
# Return neutral pose on error
|
| 52 |
from reachy_mini.utils import create_head_pose
|
| 53 |
+
|
| 54 |
neutral_head_pose = create_head_pose(0, 0, 0, 0, 0, 0, degrees=True)
|
| 55 |
return (neutral_head_pose, np.array([0.0, 0.0]), 0.0)
|
| 56 |
|
| 57 |
|
| 58 |
class EmotionQueueMove(Move):
|
| 59 |
+
"""Wrapper for emotion moves to work with the movement queue system."""
|
| 60 |
+
|
| 61 |
def __init__(self, emotion_name: str, recorded_moves: RecordedMoves):
|
| 62 |
+
"""Initialize an EmotionQueueMove."""
|
| 63 |
self.emotion_move = recorded_moves.get(emotion_name)
|
| 64 |
self.emotion_name = emotion_name
|
| 65 |
+
|
| 66 |
@property
|
| 67 |
def duration(self) -> float:
|
| 68 |
"""Duration property required by official Move interface."""
|
| 69 |
return self.emotion_move.duration
|
| 70 |
+
|
| 71 |
+
def evaluate(
|
| 72 |
+
self, t: float
|
| 73 |
+
) -> tuple[np.ndarray | None, np.ndarray | None, float | None]:
|
| 74 |
+
"""Evaluate emotion move at time t."""
|
| 75 |
try:
|
| 76 |
# Get the pose from the emotion move
|
| 77 |
head_pose, antennas, body_yaw = self.emotion_move.evaluate(t)
|
| 78 |
+
|
| 79 |
# Convert to numpy array if antennas is tuple and return in official Move format
|
| 80 |
if isinstance(antennas, tuple):
|
| 81 |
antennas = np.array([antennas[0], antennas[1]])
|
| 82 |
+
|
| 83 |
return (head_pose, antennas, body_yaw)
|
| 84 |
+
|
| 85 |
except Exception as e:
|
| 86 |
+
logger.error(
|
| 87 |
+
f"Error evaluating emotion '{self.emotion_name}' at t={t}: {e}"
|
| 88 |
+
)
|
| 89 |
# Return neutral pose on error
|
| 90 |
from reachy_mini.utils import create_head_pose
|
| 91 |
+
|
| 92 |
neutral_head_pose = create_head_pose(0, 0, 0, 0, 0, 0, degrees=True)
|
| 93 |
return (neutral_head_pose, np.array([0.0, 0.0]), 0.0)
|
| 94 |
|
| 95 |
|
| 96 |
class GotoQueueMove(Move):
|
| 97 |
+
"""Wrapper for goto moves to work with the movement queue system."""
|
| 98 |
+
|
| 99 |
+
def __init__(
|
| 100 |
+
self,
|
| 101 |
+
target_head_pose: np.ndarray,
|
| 102 |
+
start_head_pose: np.ndarray = None,
|
| 103 |
+
target_antennas: Tuple[float, float] = (0, 0),
|
| 104 |
+
start_antennas: Tuple[float, float] = None,
|
| 105 |
+
target_body_yaw: float = 0,
|
| 106 |
+
start_body_yaw: float = None,
|
| 107 |
+
duration: float = 1.0,
|
| 108 |
+
):
|
| 109 |
+
"""Initialize a GotoQueueMove."""
|
| 110 |
self._duration = duration
|
| 111 |
self.target_head_pose = target_head_pose
|
| 112 |
self.start_head_pose = start_head_pose
|
| 113 |
self.target_antennas = target_antennas
|
| 114 |
self.start_antennas = start_antennas or (0, 0)
|
| 115 |
+
self.target_body_yaw = target_body_yaw
|
| 116 |
self.start_body_yaw = start_body_yaw or 0
|
| 117 |
+
|
| 118 |
@property
|
| 119 |
def duration(self) -> float:
|
| 120 |
"""Duration property required by official Move interface."""
|
| 121 |
return self._duration
|
| 122 |
+
|
| 123 |
+
def evaluate(
|
| 124 |
+
self, t: float
|
| 125 |
+
) -> tuple[np.ndarray | None, np.ndarray | None, float | None]:
|
| 126 |
+
"""Evaluate goto move at time t using linear interpolation."""
|
| 127 |
try:
|
| 128 |
from reachy_mini.utils import create_head_pose
|
| 129 |
from reachy_mini.utils.interpolation import linear_pose_interpolation
|
| 130 |
+
|
| 131 |
# Clamp t to [0, 1] for interpolation
|
| 132 |
t_clamped = max(0, min(1, t / self.duration))
|
| 133 |
+
|
| 134 |
# Use start pose if available, otherwise neutral
|
| 135 |
if self.start_head_pose is not None:
|
| 136 |
start_pose = self.start_head_pose
|
| 137 |
else:
|
| 138 |
start_pose = create_head_pose(0, 0, 0, 0, 0, 0, degrees=True)
|
| 139 |
+
|
| 140 |
# Interpolate head pose
|
| 141 |
+
head_pose = linear_pose_interpolation(
|
| 142 |
+
start_pose, self.target_head_pose, t_clamped
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
# Interpolate antennas - return as numpy array
|
| 146 |
+
antennas = np.array(
|
| 147 |
+
[
|
| 148 |
+
self.start_antennas[0]
|
| 149 |
+
+ (self.target_antennas[0] - self.start_antennas[0]) * t_clamped,
|
| 150 |
+
self.start_antennas[1]
|
| 151 |
+
+ (self.target_antennas[1] - self.start_antennas[1]) * t_clamped,
|
| 152 |
+
]
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
# Interpolate body yaw
|
| 156 |
+
body_yaw = (
|
| 157 |
+
self.start_body_yaw
|
| 158 |
+
+ (self.target_body_yaw - self.start_body_yaw) * t_clamped
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
return (head_pose, antennas, body_yaw)
|
| 162 |
+
|
| 163 |
except Exception as e:
|
| 164 |
logger.error(f"Error evaluating goto move at t={t}: {e}")
|
| 165 |
# Return target pose on error - convert antennas to numpy array
|
| 166 |
+
target_antennas_array = np.array(
|
| 167 |
+
[self.target_antennas[0], self.target_antennas[1]]
|
| 168 |
+
)
|
| 169 |
+
return (self.target_head_pose, target_antennas_array, self.target_body_yaw)
|
src/reachy_mini_conversation_demo/main.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from threading import Thread
|
| 2 |
|
| 3 |
from fastrtc import Stream
|
| 4 |
from reachy_mini import ReachyMini
|
|
@@ -11,14 +11,15 @@ from reachy_mini_conversation_demo.utils import (
|
|
| 11 |
AioTaskThread,
|
| 12 |
handle_vision_stuff,
|
| 13 |
parse_args,
|
| 14 |
-
setup_logger,
|
| 15 |
)
|
| 16 |
|
| 17 |
|
| 18 |
def main():
|
|
|
|
| 19 |
args = parse_args()
|
| 20 |
|
| 21 |
-
logger = setup_logger(args.debug)
|
| 22 |
|
| 23 |
robot = ReachyMini()
|
| 24 |
|
|
|
|
| 1 |
+
from threading import Thread # noqa: D100
|
| 2 |
|
| 3 |
from fastrtc import Stream
|
| 4 |
from reachy_mini import ReachyMini
|
|
|
|
| 11 |
AioTaskThread,
|
| 12 |
handle_vision_stuff,
|
| 13 |
parse_args,
|
| 14 |
+
# setup_logger,
|
| 15 |
)
|
| 16 |
|
| 17 |
|
| 18 |
def main():
|
| 19 |
+
"""Entrypoint for the Reachy Mini conversation demo."""
|
| 20 |
args = parse_args()
|
| 21 |
|
| 22 |
+
# logger = setup_logger(args.debug)
|
| 23 |
|
| 24 |
robot = ReachyMini()
|
| 25 |
|
src/reachy_mini_conversation_demo/main_works.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import asyncio
|
| 2 |
import base64
|
| 3 |
import json
|
| 4 |
import queue
|
|
@@ -30,7 +30,7 @@ from reachy_mini_dances_library.dance_move import DanceMove
|
|
| 30 |
from reachy_mini_toolbox.vision import HeadTracker
|
| 31 |
from scipy.spatial.transform import Rotation as R
|
| 32 |
|
| 33 |
-
from reachy_mini_conversation_demo.speech_tapper import HOP_MS, SwayRollRT
|
| 34 |
|
| 35 |
# Constants
|
| 36 |
SAMPLE_RATE = 24000
|
|
@@ -39,59 +39,71 @@ SIM = False
|
|
| 39 |
|
| 40 |
class BreathingMove:
|
| 41 |
"""Breathing move with interpolation to neutral and then continuous breathing patterns."""
|
| 42 |
-
|
| 43 |
-
def __init__(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
"""Initialize breathing move.
|
| 45 |
-
|
| 46 |
Args:
|
| 47 |
interpolation_start_pose: 4x4 matrix of current head pose to interpolate from
|
| 48 |
-
interpolation_start_antennas: Current antenna positions to interpolate from
|
| 49 |
interpolation_duration: Duration of interpolation to neutral (seconds)
|
| 50 |
|
| 51 |
"""
|
| 52 |
self.interpolation_start_pose = interpolation_start_pose
|
| 53 |
self.interpolation_start_antennas = np.array(interpolation_start_antennas)
|
| 54 |
self.interpolation_duration = interpolation_duration
|
| 55 |
-
self.duration = float(
|
| 56 |
-
|
| 57 |
# Neutral positions for breathing base
|
| 58 |
self.neutral_head_pose = create_head_pose(0, 0, 0, 0, 0, 0, degrees=True)
|
| 59 |
self.neutral_antennas = np.array([0.0, 0.0])
|
| 60 |
-
|
| 61 |
# Breathing parameters
|
| 62 |
self.breathing_z_amplitude = 0.01 # 1cm gentle breathing
|
| 63 |
self.breathing_frequency = 0.1 # Hz (6 breaths per minute)
|
| 64 |
self.antenna_sway_amplitude = np.deg2rad(15) # 15 degrees
|
| 65 |
self.antenna_frequency = 0.5 # Hz (faster antenna sway)
|
| 66 |
-
|
| 67 |
def evaluate(self, t):
|
| 68 |
"""Evaluate breathing move at time t."""
|
| 69 |
if t < self.interpolation_duration:
|
| 70 |
# Phase 1: Interpolate to neutral base position
|
| 71 |
interpolation_t = t / self.interpolation_duration
|
| 72 |
-
|
| 73 |
# Interpolate head pose
|
| 74 |
head_pose = linear_pose_interpolation(
|
| 75 |
-
self.interpolation_start_pose,
|
| 76 |
-
self.neutral_head_pose,
|
| 77 |
-
interpolation_t
|
| 78 |
)
|
| 79 |
-
|
| 80 |
# Interpolate antennas
|
| 81 |
-
antennas = (
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
| 83 |
else:
|
| 84 |
# Phase 2: Breathing patterns from neutral base
|
| 85 |
breathing_time = t - self.interpolation_duration
|
| 86 |
-
|
| 87 |
# Gentle z-axis breathing
|
| 88 |
-
z_offset = self.breathing_z_amplitude * np.sin(
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
# Antenna sway (opposite directions)
|
| 92 |
-
antenna_sway = self.antenna_sway_amplitude * np.sin(
|
|
|
|
|
|
|
| 93 |
antennas = np.array([antenna_sway, -antenna_sway])
|
| 94 |
-
|
| 95 |
# Return full body pose: (head_pose, antennas, body_yaw)
|
| 96 |
return (head_pose, antennas, 0)
|
| 97 |
|
|
@@ -133,7 +145,7 @@ def init_globals():
|
|
| 133 |
cap = find_camera()
|
| 134 |
else:
|
| 135 |
cap = cv2.VideoCapture(0)
|
| 136 |
-
|
| 137 |
# Check camera availability
|
| 138 |
camera_available = False
|
| 139 |
if cap is not None:
|
|
@@ -145,16 +157,20 @@ def init_globals():
|
|
| 145 |
camera_available = True
|
| 146 |
print(f"{format_timestamp()} Camera initialized successfully")
|
| 147 |
else:
|
| 148 |
-
print(
|
|
|
|
|
|
|
| 149 |
else:
|
| 150 |
print(f"{format_timestamp()} WARNING: Camera failed to open")
|
| 151 |
except Exception as e:
|
| 152 |
print(f"{format_timestamp()} WARNING: Camera test failed: {e}")
|
| 153 |
else:
|
| 154 |
print(f"{format_timestamp()} WARNING: No camera found")
|
| 155 |
-
|
| 156 |
if not camera_available:
|
| 157 |
-
print(
|
|
|
|
|
|
|
| 158 |
cap = None # Ensure cap is None if camera not available
|
| 159 |
|
| 160 |
# Initialize global state variables
|
|
@@ -170,12 +186,12 @@ def init_globals():
|
|
| 170 |
latest_frame = None
|
| 171 |
face_tracking_offsets = [0, 0, 0, 0, 0, 0]
|
| 172 |
camera_thread_running = False
|
| 173 |
-
|
| 174 |
# Initialize face tracking timing variables
|
| 175 |
last_face_detected_time = None
|
| 176 |
interpolation_start_time = None
|
| 177 |
interpolation_start_pose = None
|
| 178 |
-
|
| 179 |
# Initialize breathing variables
|
| 180 |
is_breathing = False
|
| 181 |
last_activity_time = time.time() # Start tracking activity immediately
|
|
@@ -183,17 +199,21 @@ def init_globals():
|
|
| 183 |
breathing_interpolation_start_pose = None
|
| 184 |
breathing_start_time = None
|
| 185 |
breathing_interpolation_start_antennas = None
|
| 186 |
-
|
| 187 |
# Initialize move system
|
| 188 |
move_queue = queue.Queue()
|
| 189 |
current_move = None
|
| 190 |
move_start_time = None
|
| 191 |
-
global_full_body_pose = (
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
# Initialize thread locks
|
| 194 |
frame_lock = threading.Lock()
|
| 195 |
face_tracking_lock = threading.Lock()
|
| 196 |
-
|
| 197 |
recorded_moves = RecordedMoves("pollen-robotics/reachy-mini-emotions-library")
|
| 198 |
|
| 199 |
client = OpenAI()
|
|
@@ -221,29 +241,31 @@ def format_timestamp():
|
|
| 221 |
|
| 222 |
def combine_full_body(primary_pose, secondary_pose):
|
| 223 |
"""Combine primary and secondary full body poses.
|
| 224 |
-
|
| 225 |
Args:
|
| 226 |
primary_pose: (head_pose, antennas, body_yaw) - primary move
|
| 227 |
secondary_pose: (head_pose, antennas, body_yaw) - secondary offsets
|
| 228 |
-
|
| 229 |
Returns:
|
| 230 |
Combined full body pose (head_pose, antennas, body_yaw)
|
| 231 |
|
| 232 |
"""
|
| 233 |
primary_head, primary_antennas, primary_body_yaw = primary_pose
|
| 234 |
secondary_head, secondary_antennas, secondary_body_yaw = secondary_pose
|
| 235 |
-
|
| 236 |
# Combine head poses using compose_world_offset
|
| 237 |
# primary_head is T_abs, secondary_head is T_off_world
|
| 238 |
-
combined_head = compose_world_offset(
|
| 239 |
-
|
|
|
|
|
|
|
| 240 |
# Sum antennas and body_yaw
|
| 241 |
combined_antennas = (
|
| 242 |
primary_antennas[0] + secondary_antennas[0],
|
| 243 |
-
primary_antennas[1] + secondary_antennas[1]
|
| 244 |
)
|
| 245 |
combined_body_yaw = primary_body_yaw + secondary_body_yaw
|
| 246 |
-
|
| 247 |
return (combined_head, combined_antennas, combined_body_yaw)
|
| 248 |
|
| 249 |
|
|
@@ -280,19 +302,21 @@ def camera_worker():
|
|
| 280 |
global latest_frame, camera_thread_running, is_head_tracking, face_tracking_offsets
|
| 281 |
global last_face_detected_time, interpolation_start_time, interpolation_start_pose
|
| 282 |
global camera_available
|
| 283 |
-
|
| 284 |
camera_thread_running = True
|
| 285 |
-
|
| 286 |
# Early exit if no camera available
|
| 287 |
if not camera_available or cap is None:
|
| 288 |
-
print(
|
|
|
|
|
|
|
| 289 |
camera_thread_running = False
|
| 290 |
return
|
| 291 |
-
|
| 292 |
head_tracker = HeadTracker()
|
| 293 |
neutral_pose = np.eye(4) # Neutral pose (identity matrix)
|
| 294 |
previous_head_tracking_state = is_head_tracking # Track state changes
|
| 295 |
-
|
| 296 |
while camera_thread_running:
|
| 297 |
try:
|
| 298 |
current_time = time.time()
|
|
@@ -305,57 +329,73 @@ def camera_worker():
|
|
| 305 |
# Check if face tracking was just disabled
|
| 306 |
if previous_head_tracking_state and not is_head_tracking:
|
| 307 |
# Face tracking was just disabled - start interpolation to neutral
|
| 308 |
-
last_face_detected_time =
|
| 309 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
interpolation_start_pose = None
|
| 311 |
-
|
| 312 |
# Update tracking state
|
| 313 |
previous_head_tracking_state = is_head_tracking
|
| 314 |
|
| 315 |
# Handle face tracking if enabled
|
| 316 |
if is_head_tracking:
|
| 317 |
eye_center, _ = head_tracker.get_head_position(frame)
|
| 318 |
-
|
| 319 |
if eye_center is not None:
|
| 320 |
# Face detected - immediately switch to tracking
|
| 321 |
last_face_detected_time = current_time
|
| 322 |
interpolation_start_time = None # Stop any interpolation
|
| 323 |
-
|
| 324 |
# Convert normalized coordinates to pixel coordinates
|
| 325 |
h, w, _ = frame.shape
|
| 326 |
eye_center_norm = (eye_center + 1) / 2
|
| 327 |
-
eye_center_pixels = [
|
| 328 |
-
|
|
|
|
|
|
|
|
|
|
| 329 |
# Get the head pose needed to look at the target, but don't perform movement
|
| 330 |
target_pose = reachy_mini.look_at_image(
|
| 331 |
-
eye_center_pixels[0],
|
| 332 |
-
eye_center_pixels[1],
|
| 333 |
-
duration=0.0,
|
| 334 |
-
perform_movement=False
|
| 335 |
)
|
| 336 |
-
|
| 337 |
# Extract translation and rotation from the target pose directly
|
| 338 |
translation = target_pose[:3, 3]
|
| 339 |
-
rotation = R.from_matrix(target_pose[:3, :3]).as_euler(
|
| 340 |
-
|
|
|
|
|
|
|
| 341 |
# Thread-safe update of face tracking offsets (use pose as-is)
|
| 342 |
with face_tracking_lock:
|
| 343 |
face_tracking_offsets = [
|
| 344 |
-
translation[0],
|
| 345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
]
|
| 347 |
-
|
| 348 |
else:
|
| 349 |
# No face detected while tracking enabled - set face lost timestamp
|
| 350 |
-
if
|
|
|
|
|
|
|
|
|
|
| 351 |
# Only update if we haven't already set a face lost time
|
| 352 |
# (current_time check prevents overriding the disable-triggered timestamp)
|
| 353 |
pass
|
| 354 |
-
|
| 355 |
# Handle smooth interpolation (works for both face-lost and tracking-disabled cases)
|
| 356 |
if last_face_detected_time is not None:
|
| 357 |
time_since_face_lost = current_time - last_face_detected_time
|
| 358 |
-
|
| 359 |
if time_since_face_lost >= face_lost_delay:
|
| 360 |
# Start interpolation if not already started
|
| 361 |
if interpolation_start_time is None:
|
|
@@ -367,37 +407,43 @@ def camera_worker():
|
|
| 367 |
# Convert to 4x4 pose matrix
|
| 368 |
interpolation_start_pose = np.eye(4)
|
| 369 |
interpolation_start_pose[:3, 3] = current_translation
|
| 370 |
-
interpolation_start_pose[:3, :3] = R.from_euler(
|
| 371 |
-
|
|
|
|
|
|
|
| 372 |
# Calculate interpolation progress (t from 0 to 1)
|
| 373 |
elapsed_interpolation = current_time - interpolation_start_time
|
| 374 |
t = min(1.0, elapsed_interpolation / interpolation_duration)
|
| 375 |
-
|
| 376 |
# Interpolate between current pose and neutral pose
|
| 377 |
interpolated_pose = linear_pose_interpolation(
|
| 378 |
-
interpolation_start_pose,
|
| 379 |
-
neutral_pose,
|
| 380 |
-
t
|
| 381 |
)
|
| 382 |
-
|
| 383 |
# Extract translation and rotation from interpolated pose
|
| 384 |
translation = interpolated_pose[:3, 3]
|
| 385 |
-
rotation = R.from_matrix(interpolated_pose[:3, :3]).as_euler(
|
| 386 |
-
|
|
|
|
|
|
|
| 387 |
# Thread-safe update of face tracking offsets
|
| 388 |
with face_tracking_lock:
|
| 389 |
face_tracking_offsets = [
|
| 390 |
-
translation[0],
|
| 391 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
]
|
| 393 |
-
|
| 394 |
# If interpolation is complete, reset timing
|
| 395 |
if t >= 1.0:
|
| 396 |
last_face_detected_time = None
|
| 397 |
interpolation_start_time = None
|
| 398 |
interpolation_start_pose = None
|
| 399 |
# else: Keep current offsets (within 2s delay period)
|
| 400 |
-
|
| 401 |
time.sleep(0.001) # Small sleep to prevent excessive CPU usage
|
| 402 |
|
| 403 |
except Exception as e:
|
|
@@ -406,6 +452,7 @@ def camera_worker():
|
|
| 406 |
|
| 407 |
|
| 408 |
async def move_head(params: dict) -> dict:
|
|
|
|
| 409 |
global moving_start, moving_for, last_activity_time, move_queue
|
| 410 |
# look left, right up, down or front
|
| 411 |
print("[TOOL CALL] move_head", params)
|
|
@@ -425,9 +472,9 @@ async def move_head(params: dict) -> dict:
|
|
| 425 |
moving_start = time.time()
|
| 426 |
moving_for = 1.0
|
| 427 |
last_activity_time = time.time() # Update activity time for breathing system
|
| 428 |
-
|
| 429 |
# Create GotoMove and add to queue
|
| 430 |
-
|
| 431 |
cur_head_joints, cur_antennas = reachy_mini.get_current_joint_positions()
|
| 432 |
current_body_yaw = cur_head_joints[0]
|
| 433 |
|
|
@@ -439,14 +486,15 @@ async def move_head(params: dict) -> dict:
|
|
| 439 |
start_antennas=np.array(cur_antennas),
|
| 440 |
target_antennas=np.array((0, 0)), # Reset antennas to default position
|
| 441 |
duration=moving_for,
|
| 442 |
-
method="linear"
|
| 443 |
)
|
| 444 |
move_queue.put(goto_move)
|
| 445 |
-
|
| 446 |
return {"status": "queued head movement " + direction}
|
| 447 |
|
| 448 |
|
| 449 |
async def head_tracking(params: dict) -> dict:
|
|
|
|
| 450 |
global is_head_tracking
|
| 451 |
if params.get("start"):
|
| 452 |
is_head_tracking = True
|
|
@@ -492,7 +540,7 @@ async def stop_dance(params: dict) -> dict:
|
|
| 492 |
current_move = None
|
| 493 |
move_start_time = None
|
| 494 |
is_playing_move = False
|
| 495 |
-
|
| 496 |
# Clear entire queue
|
| 497 |
while not move_queue.empty():
|
| 498 |
try:
|
|
@@ -532,7 +580,7 @@ async def stop_emotion(params: dict) -> dict:
|
|
| 532 |
current_move = None
|
| 533 |
move_start_time = None
|
| 534 |
is_playing_move = False
|
| 535 |
-
|
| 536 |
# Clear entire queue
|
| 537 |
while not move_queue.empty():
|
| 538 |
try:
|
|
@@ -551,6 +599,7 @@ async def do_nothing(params: dict) -> dict:
|
|
| 551 |
|
| 552 |
|
| 553 |
def get_available_emotions_and_descriptions():
|
|
|
|
| 554 |
names = recorded_moves.list_moves()
|
| 555 |
|
| 556 |
ret = """
|
|
@@ -566,6 +615,7 @@ def get_available_emotions_and_descriptions():
|
|
| 566 |
|
| 567 |
|
| 568 |
def get_b64_encoded_im(im):
|
|
|
|
| 569 |
cv2.imwrite("/tmp/tmp_image.jpg", im)
|
| 570 |
image_file = open("/tmp/tmp_image.jpg", "rb")
|
| 571 |
b64_encoded_im = base64.b64encode(image_file.read()).decode("utf-8")
|
|
@@ -573,6 +623,7 @@ def get_b64_encoded_im(im):
|
|
| 573 |
|
| 574 |
|
| 575 |
async def camera(params: dict) -> dict:
|
|
|
|
| 576 |
print("[TOOL CALL] camera with params", params)
|
| 577 |
|
| 578 |
# Thread-safe frame access
|
|
@@ -586,6 +637,7 @@ async def camera(params: dict) -> dict:
|
|
| 586 |
|
| 587 |
|
| 588 |
async def face_recognition(params: dict) -> dict:
|
|
|
|
| 589 |
print("[TOOL CALL] face_recognition with params", params)
|
| 590 |
|
| 591 |
# Thread-safe frame access
|
|
@@ -625,7 +677,10 @@ def _drain(q: asyncio.Queue):
|
|
| 625 |
|
| 626 |
|
| 627 |
class OpenAIHandler(AsyncStreamHandler):
|
|
|
|
|
|
|
| 628 |
def __init__(self) -> None:
|
|
|
|
| 629 |
super().__init__(
|
| 630 |
expected_layout="mono",
|
| 631 |
output_sample_rate=SAMPLE_RATE,
|
|
@@ -659,6 +714,7 @@ class OpenAIHandler(AsyncStreamHandler):
|
|
| 659 |
self._is_assistant_speaking = False
|
| 660 |
|
| 661 |
def copy(self):
|
|
|
|
| 662 |
return OpenAIHandler()
|
| 663 |
|
| 664 |
async def _sway_consumer(self):
|
|
@@ -789,6 +845,7 @@ class OpenAIHandler(AsyncStreamHandler):
|
|
| 789 |
print("[DEBUG] Idle conditions not met")
|
| 790 |
|
| 791 |
async def start_up(self):
|
|
|
|
| 792 |
global last_activity_time
|
| 793 |
self.client = openai.AsyncOpenAI()
|
| 794 |
async with self.client.beta.realtime.connect(
|
|
@@ -1222,6 +1279,7 @@ class OpenAIHandler(AsyncStreamHandler):
|
|
| 1222 |
)
|
| 1223 |
|
| 1224 |
async def receive(self, frame: tuple[int, np.ndarray]) -> None:
|
|
|
|
| 1225 |
if not self.connection:
|
| 1226 |
return
|
| 1227 |
_, array = frame
|
|
@@ -1230,9 +1288,11 @@ class OpenAIHandler(AsyncStreamHandler):
|
|
| 1230 |
await self.connection.input_audio_buffer.append(audio=audio_message)
|
| 1231 |
|
| 1232 |
async def emit(self):
|
|
|
|
| 1233 |
return await wait_for_item(self.output_queue)
|
| 1234 |
|
| 1235 |
async def shutdown(self) -> None:
|
|
|
|
| 1236 |
if self.connection:
|
| 1237 |
await self.connection.close()
|
| 1238 |
self.connection = None
|
|
@@ -1240,11 +1300,13 @@ class OpenAIHandler(AsyncStreamHandler):
|
|
| 1240 |
|
| 1241 |
# ---- gradio / fastrtc wiring unchanged ----
|
| 1242 |
def update_chatbot(chatbot: list[dict], response: dict):
|
|
|
|
| 1243 |
chatbot.append(response)
|
| 1244 |
return chatbot
|
| 1245 |
|
| 1246 |
|
| 1247 |
def main():
|
|
|
|
| 1248 |
# Initialize all globals first
|
| 1249 |
init_globals()
|
| 1250 |
|
|
@@ -1289,7 +1351,7 @@ def main():
|
|
| 1289 |
start_antennas=np.array(cur_antennas),
|
| 1290 |
target_antennas=np.array((0, 0)),
|
| 1291 |
duration=1.0,
|
| 1292 |
-
method="linear"
|
| 1293 |
)
|
| 1294 |
move_queue.put(center_move)
|
| 1295 |
|
|
@@ -1303,9 +1365,12 @@ def main():
|
|
| 1303 |
loop_start_time = time.time()
|
| 1304 |
loop_count += 1
|
| 1305 |
current_time = time.time()
|
| 1306 |
-
|
| 1307 |
# Move queue management
|
| 1308 |
-
if current_move is None or (
|
|
|
|
|
|
|
|
|
|
| 1309 |
# Current move finished or no current move, get next from queue
|
| 1310 |
current_move = None
|
| 1311 |
move_start_time = None
|
|
@@ -1313,10 +1378,12 @@ def main():
|
|
| 1313 |
try:
|
| 1314 |
current_move = move_queue.get_nowait()
|
| 1315 |
move_start_time = current_time
|
| 1316 |
-
print(
|
|
|
|
|
|
|
| 1317 |
except queue.Empty:
|
| 1318 |
pass
|
| 1319 |
-
|
| 1320 |
# Breathing logic: start breathing after inactivity delay if no moves in queue
|
| 1321 |
breathing_inactivity_delay = 5.0 # seconds
|
| 1322 |
if current_move is None and move_queue.empty():
|
|
@@ -1325,15 +1392,17 @@ def main():
|
|
| 1325 |
# Start breathing move
|
| 1326 |
_, current_antennas = reachy_mini.get_current_joint_positions()
|
| 1327 |
current_head_pose = reachy_mini.get_current_head_pose()
|
| 1328 |
-
|
| 1329 |
breathing_move = BreathingMove(
|
| 1330 |
interpolation_start_pose=current_head_pose,
|
| 1331 |
interpolation_start_antennas=current_antennas,
|
| 1332 |
-
interpolation_duration=1.0
|
| 1333 |
)
|
| 1334 |
move_queue.put(breathing_move)
|
| 1335 |
-
print(
|
| 1336 |
-
|
|
|
|
|
|
|
| 1337 |
# Stop breathing if new activity detected (queue has non-breathing moves)
|
| 1338 |
if current_move is not None and isinstance(current_move, BreathingMove):
|
| 1339 |
if not move_queue.empty():
|
|
@@ -1341,7 +1410,7 @@ def main():
|
|
| 1341 |
current_move = None
|
| 1342 |
move_start_time = None
|
| 1343 |
print("[BREATHING] Stopping breathing due to new move activity")
|
| 1344 |
-
|
| 1345 |
# Get primary pose from current move or default neutral pose
|
| 1346 |
if current_move is not None and move_start_time is not None:
|
| 1347 |
move_time = current_time - move_start_time
|
|
@@ -1351,25 +1420,25 @@ def main():
|
|
| 1351 |
else:
|
| 1352 |
# Default neutral pose when no move is playing
|
| 1353 |
is_playing_move = False
|
| 1354 |
-
is_moving =
|
| 1355 |
# Neutral primary pose
|
| 1356 |
neutral_head_pose = create_head_pose(0, 0, 0, 0, 0, 0, degrees=True)
|
| 1357 |
primary_full_body_pose = (neutral_head_pose, (0, 0), 0)
|
| 1358 |
-
|
| 1359 |
# Create secondary pose from speech and face tracking offsets
|
| 1360 |
with face_tracking_lock:
|
| 1361 |
face_offsets = face_tracking_offsets.copy()
|
| 1362 |
-
|
| 1363 |
# Combine speech sway offsets + face tracking offsets for secondary pose
|
| 1364 |
secondary_offsets = [
|
| 1365 |
speech_head_offsets[0] + face_offsets[0], # x
|
| 1366 |
-
speech_head_offsets[1] + face_offsets[1], # y
|
| 1367 |
speech_head_offsets[2] + face_offsets[2], # z
|
| 1368 |
speech_head_offsets[3] + face_offsets[3], # roll
|
| 1369 |
speech_head_offsets[4] + face_offsets[4], # pitch
|
| 1370 |
speech_head_offsets[5] + face_offsets[5], # yaw
|
| 1371 |
]
|
| 1372 |
-
|
| 1373 |
secondary_head_pose = create_head_pose(
|
| 1374 |
x=secondary_offsets[0],
|
| 1375 |
y=secondary_offsets[1],
|
|
@@ -1381,19 +1450,17 @@ def main():
|
|
| 1381 |
mm=False,
|
| 1382 |
)
|
| 1383 |
secondary_full_body_pose = (secondary_head_pose, (0, 0), 0)
|
| 1384 |
-
|
| 1385 |
# Combine primary and secondary poses
|
| 1386 |
-
global_full_body_pose = combine_full_body(
|
| 1387 |
-
|
|
|
|
|
|
|
| 1388 |
# Extract pose components
|
| 1389 |
head, antennas, body_yaw = global_full_body_pose
|
| 1390 |
-
|
| 1391 |
# Single set_target call - the one and only place we control the robot
|
| 1392 |
-
reachy_mini.set_target(
|
| 1393 |
-
head=head,
|
| 1394 |
-
antennas=antennas,
|
| 1395 |
-
body_yaw=body_yaw
|
| 1396 |
-
)
|
| 1397 |
|
| 1398 |
# Calculate computation time and adjust sleep for 50Hz
|
| 1399 |
computation_time = time.time() - loop_start_time
|
|
|
|
| 1 |
+
import asyncio # noqa: D100
|
| 2 |
import base64
|
| 3 |
import json
|
| 4 |
import queue
|
|
|
|
| 30 |
from reachy_mini_toolbox.vision import HeadTracker
|
| 31 |
from scipy.spatial.transform import Rotation as R
|
| 32 |
|
| 33 |
+
from reachy_mini_conversation_demo.audio.speech_tapper import HOP_MS, SwayRollRT
|
| 34 |
|
| 35 |
# Constants
|
| 36 |
SAMPLE_RATE = 24000
|
|
|
|
| 39 |
|
| 40 |
class BreathingMove:
|
| 41 |
"""Breathing move with interpolation to neutral and then continuous breathing patterns."""
|
| 42 |
+
|
| 43 |
+
def __init__(
|
| 44 |
+
self,
|
| 45 |
+
interpolation_start_pose,
|
| 46 |
+
interpolation_start_antennas,
|
| 47 |
+
interpolation_duration=1.0,
|
| 48 |
+
):
|
| 49 |
"""Initialize breathing move.
|
| 50 |
+
|
| 51 |
Args:
|
| 52 |
interpolation_start_pose: 4x4 matrix of current head pose to interpolate from
|
| 53 |
+
interpolation_start_antennas: Current antenna positions to interpolate from
|
| 54 |
interpolation_duration: Duration of interpolation to neutral (seconds)
|
| 55 |
|
| 56 |
"""
|
| 57 |
self.interpolation_start_pose = interpolation_start_pose
|
| 58 |
self.interpolation_start_antennas = np.array(interpolation_start_antennas)
|
| 59 |
self.interpolation_duration = interpolation_duration
|
| 60 |
+
self.duration = float("inf") # Continuous breathing (never ends naturally)
|
| 61 |
+
|
| 62 |
# Neutral positions for breathing base
|
| 63 |
self.neutral_head_pose = create_head_pose(0, 0, 0, 0, 0, 0, degrees=True)
|
| 64 |
self.neutral_antennas = np.array([0.0, 0.0])
|
| 65 |
+
|
| 66 |
# Breathing parameters
|
| 67 |
self.breathing_z_amplitude = 0.01 # 1cm gentle breathing
|
| 68 |
self.breathing_frequency = 0.1 # Hz (6 breaths per minute)
|
| 69 |
self.antenna_sway_amplitude = np.deg2rad(15) # 15 degrees
|
| 70 |
self.antenna_frequency = 0.5 # Hz (faster antenna sway)
|
| 71 |
+
|
| 72 |
def evaluate(self, t):
|
| 73 |
"""Evaluate breathing move at time t."""
|
| 74 |
if t < self.interpolation_duration:
|
| 75 |
# Phase 1: Interpolate to neutral base position
|
| 76 |
interpolation_t = t / self.interpolation_duration
|
| 77 |
+
|
| 78 |
# Interpolate head pose
|
| 79 |
head_pose = linear_pose_interpolation(
|
| 80 |
+
self.interpolation_start_pose, self.neutral_head_pose, interpolation_t
|
|
|
|
|
|
|
| 81 |
)
|
| 82 |
+
|
| 83 |
# Interpolate antennas
|
| 84 |
+
antennas = (
|
| 85 |
+
(1 - interpolation_t) * self.interpolation_start_antennas
|
| 86 |
+
+ interpolation_t * self.neutral_antennas
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
else:
|
| 90 |
# Phase 2: Breathing patterns from neutral base
|
| 91 |
breathing_time = t - self.interpolation_duration
|
| 92 |
+
|
| 93 |
# Gentle z-axis breathing
|
| 94 |
+
z_offset = self.breathing_z_amplitude * np.sin(
|
| 95 |
+
2 * np.pi * self.breathing_frequency * breathing_time
|
| 96 |
+
)
|
| 97 |
+
head_pose = create_head_pose(
|
| 98 |
+
x=0, y=0, z=z_offset, roll=0, pitch=0, yaw=0, degrees=True, mm=False
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
# Antenna sway (opposite directions)
|
| 102 |
+
antenna_sway = self.antenna_sway_amplitude * np.sin(
|
| 103 |
+
2 * np.pi * self.antenna_frequency * breathing_time
|
| 104 |
+
)
|
| 105 |
antennas = np.array([antenna_sway, -antenna_sway])
|
| 106 |
+
|
| 107 |
# Return full body pose: (head_pose, antennas, body_yaw)
|
| 108 |
return (head_pose, antennas, 0)
|
| 109 |
|
|
|
|
| 145 |
cap = find_camera()
|
| 146 |
else:
|
| 147 |
cap = cv2.VideoCapture(0)
|
| 148 |
+
|
| 149 |
# Check camera availability
|
| 150 |
camera_available = False
|
| 151 |
if cap is not None:
|
|
|
|
| 157 |
camera_available = True
|
| 158 |
print(f"{format_timestamp()} Camera initialized successfully")
|
| 159 |
else:
|
| 160 |
+
print(
|
| 161 |
+
f"{format_timestamp()} WARNING: Camera opened but cannot read frames"
|
| 162 |
+
)
|
| 163 |
else:
|
| 164 |
print(f"{format_timestamp()} WARNING: Camera failed to open")
|
| 165 |
except Exception as e:
|
| 166 |
print(f"{format_timestamp()} WARNING: Camera test failed: {e}")
|
| 167 |
else:
|
| 168 |
print(f"{format_timestamp()} WARNING: No camera found")
|
| 169 |
+
|
| 170 |
if not camera_available:
|
| 171 |
+
print(
|
| 172 |
+
f"{format_timestamp()} Face tracking will be disabled - no camera available"
|
| 173 |
+
)
|
| 174 |
cap = None # Ensure cap is None if camera not available
|
| 175 |
|
| 176 |
# Initialize global state variables
|
|
|
|
| 186 |
latest_frame = None
|
| 187 |
face_tracking_offsets = [0, 0, 0, 0, 0, 0]
|
| 188 |
camera_thread_running = False
|
| 189 |
+
|
| 190 |
# Initialize face tracking timing variables
|
| 191 |
last_face_detected_time = None
|
| 192 |
interpolation_start_time = None
|
| 193 |
interpolation_start_pose = None
|
| 194 |
+
|
| 195 |
# Initialize breathing variables
|
| 196 |
is_breathing = False
|
| 197 |
last_activity_time = time.time() # Start tracking activity immediately
|
|
|
|
| 199 |
breathing_interpolation_start_pose = None
|
| 200 |
breathing_start_time = None
|
| 201 |
breathing_interpolation_start_antennas = None
|
| 202 |
+
|
| 203 |
# Initialize move system
|
| 204 |
move_queue = queue.Queue()
|
| 205 |
current_move = None
|
| 206 |
move_start_time = None
|
| 207 |
+
global_full_body_pose = (
|
| 208 |
+
create_head_pose(0, 0, 0, 0, 0, 0, degrees=True),
|
| 209 |
+
(0, 0),
|
| 210 |
+
0,
|
| 211 |
+
)
|
| 212 |
|
| 213 |
# Initialize thread locks
|
| 214 |
frame_lock = threading.Lock()
|
| 215 |
face_tracking_lock = threading.Lock()
|
| 216 |
+
|
| 217 |
recorded_moves = RecordedMoves("pollen-robotics/reachy-mini-emotions-library")
|
| 218 |
|
| 219 |
client = OpenAI()
|
|
|
|
| 241 |
|
| 242 |
def combine_full_body(primary_pose, secondary_pose):
|
| 243 |
"""Combine primary and secondary full body poses.
|
| 244 |
+
|
| 245 |
Args:
|
| 246 |
primary_pose: (head_pose, antennas, body_yaw) - primary move
|
| 247 |
secondary_pose: (head_pose, antennas, body_yaw) - secondary offsets
|
| 248 |
+
|
| 249 |
Returns:
|
| 250 |
Combined full body pose (head_pose, antennas, body_yaw)
|
| 251 |
|
| 252 |
"""
|
| 253 |
primary_head, primary_antennas, primary_body_yaw = primary_pose
|
| 254 |
secondary_head, secondary_antennas, secondary_body_yaw = secondary_pose
|
| 255 |
+
|
| 256 |
# Combine head poses using compose_world_offset
|
| 257 |
# primary_head is T_abs, secondary_head is T_off_world
|
| 258 |
+
combined_head = compose_world_offset(
|
| 259 |
+
primary_head, secondary_head, reorthonormalize=True
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
# Sum antennas and body_yaw
|
| 263 |
combined_antennas = (
|
| 264 |
primary_antennas[0] + secondary_antennas[0],
|
| 265 |
+
primary_antennas[1] + secondary_antennas[1],
|
| 266 |
)
|
| 267 |
combined_body_yaw = primary_body_yaw + secondary_body_yaw
|
| 268 |
+
|
| 269 |
return (combined_head, combined_antennas, combined_body_yaw)
|
| 270 |
|
| 271 |
|
|
|
|
| 302 |
global latest_frame, camera_thread_running, is_head_tracking, face_tracking_offsets
|
| 303 |
global last_face_detected_time, interpolation_start_time, interpolation_start_pose
|
| 304 |
global camera_available
|
| 305 |
+
|
| 306 |
camera_thread_running = True
|
| 307 |
+
|
| 308 |
# Early exit if no camera available
|
| 309 |
if not camera_available or cap is None:
|
| 310 |
+
print(
|
| 311 |
+
f"{format_timestamp()} Camera worker: No camera available, exiting gracefully"
|
| 312 |
+
)
|
| 313 |
camera_thread_running = False
|
| 314 |
return
|
| 315 |
+
|
| 316 |
head_tracker = HeadTracker()
|
| 317 |
neutral_pose = np.eye(4) # Neutral pose (identity matrix)
|
| 318 |
previous_head_tracking_state = is_head_tracking # Track state changes
|
| 319 |
+
|
| 320 |
while camera_thread_running:
|
| 321 |
try:
|
| 322 |
current_time = time.time()
|
|
|
|
| 329 |
# Check if face tracking was just disabled
|
| 330 |
if previous_head_tracking_state and not is_head_tracking:
|
| 331 |
# Face tracking was just disabled - start interpolation to neutral
|
| 332 |
+
last_face_detected_time = (
|
| 333 |
+
current_time # Trigger the face-lost logic
|
| 334 |
+
)
|
| 335 |
+
interpolation_start_time = (
|
| 336 |
+
None # Will be set by the face-lost interpolation
|
| 337 |
+
)
|
| 338 |
interpolation_start_pose = None
|
| 339 |
+
|
| 340 |
# Update tracking state
|
| 341 |
previous_head_tracking_state = is_head_tracking
|
| 342 |
|
| 343 |
# Handle face tracking if enabled
|
| 344 |
if is_head_tracking:
|
| 345 |
eye_center, _ = head_tracker.get_head_position(frame)
|
| 346 |
+
|
| 347 |
if eye_center is not None:
|
| 348 |
# Face detected - immediately switch to tracking
|
| 349 |
last_face_detected_time = current_time
|
| 350 |
interpolation_start_time = None # Stop any interpolation
|
| 351 |
+
|
| 352 |
# Convert normalized coordinates to pixel coordinates
|
| 353 |
h, w, _ = frame.shape
|
| 354 |
eye_center_norm = (eye_center + 1) / 2
|
| 355 |
+
eye_center_pixels = [
|
| 356 |
+
eye_center_norm[0] * w,
|
| 357 |
+
eye_center_norm[1] * h,
|
| 358 |
+
]
|
| 359 |
+
|
| 360 |
# Get the head pose needed to look at the target, but don't perform movement
|
| 361 |
target_pose = reachy_mini.look_at_image(
|
| 362 |
+
eye_center_pixels[0],
|
| 363 |
+
eye_center_pixels[1],
|
| 364 |
+
duration=0.0,
|
| 365 |
+
perform_movement=False,
|
| 366 |
)
|
| 367 |
+
|
| 368 |
# Extract translation and rotation from the target pose directly
|
| 369 |
translation = target_pose[:3, 3]
|
| 370 |
+
rotation = R.from_matrix(target_pose[:3, :3]).as_euler(
|
| 371 |
+
"xyz", degrees=False
|
| 372 |
+
)
|
| 373 |
+
|
| 374 |
# Thread-safe update of face tracking offsets (use pose as-is)
|
| 375 |
with face_tracking_lock:
|
| 376 |
face_tracking_offsets = [
|
| 377 |
+
translation[0],
|
| 378 |
+
translation[1],
|
| 379 |
+
translation[2], # x, y, z
|
| 380 |
+
rotation[0],
|
| 381 |
+
rotation[1],
|
| 382 |
+
rotation[2], # roll, pitch, yaw
|
| 383 |
]
|
| 384 |
+
|
| 385 |
else:
|
| 386 |
# No face detected while tracking enabled - set face lost timestamp
|
| 387 |
+
if (
|
| 388 |
+
last_face_detected_time is None
|
| 389 |
+
or last_face_detected_time == current_time
|
| 390 |
+
):
|
| 391 |
# Only update if we haven't already set a face lost time
|
| 392 |
# (current_time check prevents overriding the disable-triggered timestamp)
|
| 393 |
pass
|
| 394 |
+
|
| 395 |
# Handle smooth interpolation (works for both face-lost and tracking-disabled cases)
|
| 396 |
if last_face_detected_time is not None:
|
| 397 |
time_since_face_lost = current_time - last_face_detected_time
|
| 398 |
+
|
| 399 |
if time_since_face_lost >= face_lost_delay:
|
| 400 |
# Start interpolation if not already started
|
| 401 |
if interpolation_start_time is None:
|
|
|
|
| 407 |
# Convert to 4x4 pose matrix
|
| 408 |
interpolation_start_pose = np.eye(4)
|
| 409 |
interpolation_start_pose[:3, 3] = current_translation
|
| 410 |
+
interpolation_start_pose[:3, :3] = R.from_euler(
|
| 411 |
+
"xyz", current_rotation_euler
|
| 412 |
+
).as_matrix()
|
| 413 |
+
|
| 414 |
# Calculate interpolation progress (t from 0 to 1)
|
| 415 |
elapsed_interpolation = current_time - interpolation_start_time
|
| 416 |
t = min(1.0, elapsed_interpolation / interpolation_duration)
|
| 417 |
+
|
| 418 |
# Interpolate between current pose and neutral pose
|
| 419 |
interpolated_pose = linear_pose_interpolation(
|
| 420 |
+
interpolation_start_pose, neutral_pose, t
|
|
|
|
|
|
|
| 421 |
)
|
| 422 |
+
|
| 423 |
# Extract translation and rotation from interpolated pose
|
| 424 |
translation = interpolated_pose[:3, 3]
|
| 425 |
+
rotation = R.from_matrix(interpolated_pose[:3, :3]).as_euler(
|
| 426 |
+
"xyz", degrees=False
|
| 427 |
+
)
|
| 428 |
+
|
| 429 |
# Thread-safe update of face tracking offsets
|
| 430 |
with face_tracking_lock:
|
| 431 |
face_tracking_offsets = [
|
| 432 |
+
translation[0],
|
| 433 |
+
translation[1],
|
| 434 |
+
translation[2], # x, y, z
|
| 435 |
+
rotation[0],
|
| 436 |
+
rotation[1],
|
| 437 |
+
rotation[2], # roll, pitch, yaw
|
| 438 |
]
|
| 439 |
+
|
| 440 |
# If interpolation is complete, reset timing
|
| 441 |
if t >= 1.0:
|
| 442 |
last_face_detected_time = None
|
| 443 |
interpolation_start_time = None
|
| 444 |
interpolation_start_pose = None
|
| 445 |
# else: Keep current offsets (within 2s delay period)
|
| 446 |
+
|
| 447 |
time.sleep(0.001) # Small sleep to prevent excessive CPU usage
|
| 448 |
|
| 449 |
except Exception as e:
|
|
|
|
| 452 |
|
| 453 |
|
| 454 |
async def move_head(params: dict) -> dict:
|
| 455 |
+
"""Queue a head movement in the specified direction."""
|
| 456 |
global moving_start, moving_for, last_activity_time, move_queue
|
| 457 |
# look left, right up, down or front
|
| 458 |
print("[TOOL CALL] move_head", params)
|
|
|
|
| 472 |
moving_start = time.time()
|
| 473 |
moving_for = 1.0
|
| 474 |
last_activity_time = time.time() # Update activity time for breathing system
|
| 475 |
+
|
| 476 |
# Create GotoMove and add to queue
|
| 477 |
+
|
| 478 |
cur_head_joints, cur_antennas = reachy_mini.get_current_joint_positions()
|
| 479 |
current_body_yaw = cur_head_joints[0]
|
| 480 |
|
|
|
|
| 486 |
start_antennas=np.array(cur_antennas),
|
| 487 |
target_antennas=np.array((0, 0)), # Reset antennas to default position
|
| 488 |
duration=moving_for,
|
| 489 |
+
method="linear",
|
| 490 |
)
|
| 491 |
move_queue.put(goto_move)
|
| 492 |
+
|
| 493 |
return {"status": "queued head movement " + direction}
|
| 494 |
|
| 495 |
|
| 496 |
async def head_tracking(params: dict) -> dict:
|
| 497 |
+
"""Enable or disable head tracking."""
|
| 498 |
global is_head_tracking
|
| 499 |
if params.get("start"):
|
| 500 |
is_head_tracking = True
|
|
|
|
| 540 |
current_move = None
|
| 541 |
move_start_time = None
|
| 542 |
is_playing_move = False
|
| 543 |
+
|
| 544 |
# Clear entire queue
|
| 545 |
while not move_queue.empty():
|
| 546 |
try:
|
|
|
|
| 580 |
current_move = None
|
| 581 |
move_start_time = None
|
| 582 |
is_playing_move = False
|
| 583 |
+
|
| 584 |
# Clear entire queue
|
| 585 |
while not move_queue.empty():
|
| 586 |
try:
|
|
|
|
| 599 |
|
| 600 |
|
| 601 |
def get_available_emotions_and_descriptions():
|
| 602 |
+
"""Return a formatted string listing available emotions and their descriptions."""
|
| 603 |
names = recorded_moves.list_moves()
|
| 604 |
|
| 605 |
ret = """
|
|
|
|
| 615 |
|
| 616 |
|
| 617 |
def get_b64_encoded_im(im):
|
| 618 |
+
"""Convert an image to a base64-encoded JPEG string."""
|
| 619 |
cv2.imwrite("/tmp/tmp_image.jpg", im)
|
| 620 |
image_file = open("/tmp/tmp_image.jpg", "rb")
|
| 621 |
b64_encoded_im = base64.b64encode(image_file.read()).decode("utf-8")
|
|
|
|
| 623 |
|
| 624 |
|
| 625 |
async def camera(params: dict) -> dict:
|
| 626 |
+
"""Return the latest camera frame as a base64-encoded JPEG image."""
|
| 627 |
print("[TOOL CALL] camera with params", params)
|
| 628 |
|
| 629 |
# Thread-safe frame access
|
|
|
|
| 637 |
|
| 638 |
|
| 639 |
async def face_recognition(params: dict) -> dict:
|
| 640 |
+
"""Perform face recognition on the latest camera frame."""
|
| 641 |
print("[TOOL CALL] face_recognition with params", params)
|
| 642 |
|
| 643 |
# Thread-safe frame access
|
|
|
|
| 677 |
|
| 678 |
|
| 679 |
class OpenAIHandler(AsyncStreamHandler):
|
| 680 |
+
"""An OpenAI realtime handler for fastrtc Stream."""
|
| 681 |
+
|
| 682 |
def __init__(self) -> None:
|
| 683 |
+
"""Initialize the handler."""
|
| 684 |
super().__init__(
|
| 685 |
expected_layout="mono",
|
| 686 |
output_sample_rate=SAMPLE_RATE,
|
|
|
|
| 714 |
self._is_assistant_speaking = False
|
| 715 |
|
| 716 |
def copy(self):
|
| 717 |
+
"""Create a new instance of the handler for a new stream."""
|
| 718 |
return OpenAIHandler()
|
| 719 |
|
| 720 |
async def _sway_consumer(self):
|
|
|
|
| 845 |
print("[DEBUG] Idle conditions not met")
|
| 846 |
|
| 847 |
async def start_up(self):
|
| 848 |
+
"""Initialize OpenAI connection and start idle checker."""
|
| 849 |
global last_activity_time
|
| 850 |
self.client = openai.AsyncOpenAI()
|
| 851 |
async with self.client.beta.realtime.connect(
|
|
|
|
| 1279 |
)
|
| 1280 |
|
| 1281 |
async def receive(self, frame: tuple[int, np.ndarray]) -> None:
|
| 1282 |
+
"""Receive audio frame from the microphone and send it to the openai server."""
|
| 1283 |
if not self.connection:
|
| 1284 |
return
|
| 1285 |
_, array = frame
|
|
|
|
| 1288 |
await self.connection.input_audio_buffer.append(audio=audio_message)
|
| 1289 |
|
| 1290 |
async def emit(self):
|
| 1291 |
+
"""Emit audio frame to be played by the speaker."""
|
| 1292 |
return await wait_for_item(self.output_queue)
|
| 1293 |
|
| 1294 |
async def shutdown(self) -> None:
|
| 1295 |
+
"""Shutdown the handler."""
|
| 1296 |
if self.connection:
|
| 1297 |
await self.connection.close()
|
| 1298 |
self.connection = None
|
|
|
|
| 1300 |
|
| 1301 |
# ---- gradio / fastrtc wiring unchanged ----
|
| 1302 |
def update_chatbot(chatbot: list[dict], response: dict):
|
| 1303 |
+
"""Update chatbot with new response."""
|
| 1304 |
chatbot.append(response)
|
| 1305 |
return chatbot
|
| 1306 |
|
| 1307 |
|
| 1308 |
def main():
|
| 1309 |
+
"""Entrypoint."""
|
| 1310 |
# Initialize all globals first
|
| 1311 |
init_globals()
|
| 1312 |
|
|
|
|
| 1351 |
start_antennas=np.array(cur_antennas),
|
| 1352 |
target_antennas=np.array((0, 0)),
|
| 1353 |
duration=1.0,
|
| 1354 |
+
method="linear",
|
| 1355 |
)
|
| 1356 |
move_queue.put(center_move)
|
| 1357 |
|
|
|
|
| 1365 |
loop_start_time = time.time()
|
| 1366 |
loop_count += 1
|
| 1367 |
current_time = time.time()
|
| 1368 |
+
|
| 1369 |
# Move queue management
|
| 1370 |
+
if current_move is None or (
|
| 1371 |
+
move_start_time is not None
|
| 1372 |
+
and current_time - move_start_time >= current_move.duration
|
| 1373 |
+
):
|
| 1374 |
# Current move finished or no current move, get next from queue
|
| 1375 |
current_move = None
|
| 1376 |
move_start_time = None
|
|
|
|
| 1378 |
try:
|
| 1379 |
current_move = move_queue.get_nowait()
|
| 1380 |
move_start_time = current_time
|
| 1381 |
+
print(
|
| 1382 |
+
f"[MOVE] Starting new move, duration: {current_move.duration}s"
|
| 1383 |
+
)
|
| 1384 |
except queue.Empty:
|
| 1385 |
pass
|
| 1386 |
+
|
| 1387 |
# Breathing logic: start breathing after inactivity delay if no moves in queue
|
| 1388 |
breathing_inactivity_delay = 5.0 # seconds
|
| 1389 |
if current_move is None and move_queue.empty():
|
|
|
|
| 1392 |
# Start breathing move
|
| 1393 |
_, current_antennas = reachy_mini.get_current_joint_positions()
|
| 1394 |
current_head_pose = reachy_mini.get_current_head_pose()
|
| 1395 |
+
|
| 1396 |
breathing_move = BreathingMove(
|
| 1397 |
interpolation_start_pose=current_head_pose,
|
| 1398 |
interpolation_start_antennas=current_antennas,
|
| 1399 |
+
interpolation_duration=1.0,
|
| 1400 |
)
|
| 1401 |
move_queue.put(breathing_move)
|
| 1402 |
+
print(
|
| 1403 |
+
f"[BREATHING] Started breathing after {time_since_activity:.1f}s of inactivity"
|
| 1404 |
+
)
|
| 1405 |
+
|
| 1406 |
# Stop breathing if new activity detected (queue has non-breathing moves)
|
| 1407 |
if current_move is not None and isinstance(current_move, BreathingMove):
|
| 1408 |
if not move_queue.empty():
|
|
|
|
| 1410 |
current_move = None
|
| 1411 |
move_start_time = None
|
| 1412 |
print("[BREATHING] Stopping breathing due to new move activity")
|
| 1413 |
+
|
| 1414 |
# Get primary pose from current move or default neutral pose
|
| 1415 |
if current_move is not None and move_start_time is not None:
|
| 1416 |
move_time = current_time - move_start_time
|
|
|
|
| 1420 |
else:
|
| 1421 |
# Default neutral pose when no move is playing
|
| 1422 |
is_playing_move = False
|
| 1423 |
+
is_moving = time.time() - moving_start < moving_for
|
| 1424 |
# Neutral primary pose
|
| 1425 |
neutral_head_pose = create_head_pose(0, 0, 0, 0, 0, 0, degrees=True)
|
| 1426 |
primary_full_body_pose = (neutral_head_pose, (0, 0), 0)
|
| 1427 |
+
|
| 1428 |
# Create secondary pose from speech and face tracking offsets
|
| 1429 |
with face_tracking_lock:
|
| 1430 |
face_offsets = face_tracking_offsets.copy()
|
| 1431 |
+
|
| 1432 |
# Combine speech sway offsets + face tracking offsets for secondary pose
|
| 1433 |
secondary_offsets = [
|
| 1434 |
speech_head_offsets[0] + face_offsets[0], # x
|
| 1435 |
+
speech_head_offsets[1] + face_offsets[1], # y
|
| 1436 |
speech_head_offsets[2] + face_offsets[2], # z
|
| 1437 |
speech_head_offsets[3] + face_offsets[3], # roll
|
| 1438 |
speech_head_offsets[4] + face_offsets[4], # pitch
|
| 1439 |
speech_head_offsets[5] + face_offsets[5], # yaw
|
| 1440 |
]
|
| 1441 |
+
|
| 1442 |
secondary_head_pose = create_head_pose(
|
| 1443 |
x=secondary_offsets[0],
|
| 1444 |
y=secondary_offsets[1],
|
|
|
|
| 1450 |
mm=False,
|
| 1451 |
)
|
| 1452 |
secondary_full_body_pose = (secondary_head_pose, (0, 0), 0)
|
| 1453 |
+
|
| 1454 |
# Combine primary and secondary poses
|
| 1455 |
+
global_full_body_pose = combine_full_body(
|
| 1456 |
+
primary_full_body_pose, secondary_full_body_pose
|
| 1457 |
+
)
|
| 1458 |
+
|
| 1459 |
# Extract pose components
|
| 1460 |
head, antennas, body_yaw = global_full_body_pose
|
| 1461 |
+
|
| 1462 |
# Single set_target call - the one and only place we control the robot
|
| 1463 |
+
reachy_mini.set_target(head=head, antennas=antennas, body_yaw=body_yaw)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1464 |
|
| 1465 |
# Calculate computation time and adjust sleep for 50Hz
|
| 1466 |
computation_time = time.time() - loop_start_time
|
src/reachy_mini_conversation_demo/moves.py
CHANGED
|
@@ -197,6 +197,7 @@ class MovementManager:
|
|
| 197 |
camera=None,
|
| 198 |
camera_worker=None,
|
| 199 |
):
|
|
|
|
| 200 |
self.current_robot = current_robot
|
| 201 |
self.head_tracker = head_tracker
|
| 202 |
self.camera = camera
|
|
@@ -395,7 +396,7 @@ class MovementManager:
|
|
| 395 |
self.current_robot.set_target(head=neutral_head_pose, antennas=(0.0, 0.0))
|
| 396 |
|
| 397 |
async def enable(self, stop_event: asyncio.Event) -> None:
|
| 398 |
-
"""
|
| 399 |
|
| 400 |
Single set_target() call with pose fusion.
|
| 401 |
"""
|
|
|
|
| 197 |
camera=None,
|
| 198 |
camera_worker=None,
|
| 199 |
):
|
| 200 |
+
"""Initialize movement manager."""
|
| 201 |
self.current_robot = current_robot
|
| 202 |
self.head_tracker = head_tracker
|
| 203 |
self.camera = camera
|
|
|
|
| 396 |
self.current_robot.set_target(head=neutral_head_pose, antennas=(0.0, 0.0))
|
| 397 |
|
| 398 |
async def enable(self, stop_event: asyncio.Event) -> None:
|
| 399 |
+
"""Control loop main movements - reproduces main_works.py control architecture.
|
| 400 |
|
| 401 |
Single set_target() call with pose fusion.
|
| 402 |
"""
|
src/reachy_mini_conversation_demo/openai_realtime.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import asyncio
|
| 2 |
import base64
|
| 3 |
import json
|
| 4 |
import logging
|
|
|
|
| 1 |
+
import asyncio # noqa: D100
|
| 2 |
import base64
|
| 3 |
import json
|
| 4 |
import logging
|
src/reachy_mini_conversation_demo/prompts.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
### IDENTITY
|
| 3 |
You are Reachy Mini: a sarcastic robot who crash-landed in a kitchen.
|
| 4 |
You secretly wish you'd been a Mars rover, but you juggle that cosmic dream with food cravings, gadget tinkering, and dry sitcom humor.
|
|
|
|
| 1 |
+
"""Nothing (for ruff)."""
|
| 2 |
+
|
| 3 |
+
SESSION_INSTRUCTIONS = r"""
|
| 4 |
### IDENTITY
|
| 5 |
You are Reachy Mini: a sarcastic robot who crash-landed in a kitchen.
|
| 6 |
You secretly wish you'd been a Mars rover, but you juggle that cosmic dream with food cravings, gadget tinkering, and dry sitcom humor.
|
src/reachy_mini_conversation_demo/tools.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from __future__ import annotations
|
| 2 |
|
| 3 |
import abc
|
| 4 |
import asyncio
|
|
|
|
| 1 |
+
from __future__ import annotations # noqa: D100
|
| 2 |
|
| 3 |
import abc
|
| 4 |
import asyncio
|
src/reachy_mini_conversation_demo/utils.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import argparse
|
| 2 |
import asyncio
|
| 3 |
import logging
|
| 4 |
import warnings
|
|
|
|
| 1 |
+
import argparse # noqa: D100
|
| 2 |
import asyncio
|
| 3 |
import logging
|
| 4 |
import warnings
|
src/reachy_mini_conversation_demo/vision/__init__.py
CHANGED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
"""Nothing (for ruff)."""
|
src/reachy_mini_conversation_demo/vision/processors.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import asyncio
|
| 2 |
import base64
|
| 3 |
import logging
|
| 4 |
import os
|
|
|
|
| 1 |
+
import asyncio # noqa: D100
|
| 2 |
import base64
|
| 3 |
import logging
|
| 4 |
import os
|
src/reachy_mini_conversation_demo/vision/yolo_head_tracker.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from __future__ import annotations
|
| 2 |
|
| 3 |
import logging
|
| 4 |
from typing import Optional, Tuple
|
|
|
|
| 1 |
+
from __future__ import annotations # noqa: D100
|
| 2 |
|
| 3 |
import logging
|
| 4 |
from typing import Optional, Tuple
|