Spaces:
Running
Running
Commit ·
814aa21
1
Parent(s): 4292e84
enhancement #23: removing remaining asyncio ref
Browse files
src/reachy_mini_conversation_demo/audio/head_wobbler.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
import base64
|
| 3 |
import logging
|
| 4 |
import queue
|
| 5 |
import threading
|
| 6 |
import time
|
| 7 |
-
from asyncio import QueueEmpty
|
| 8 |
from typing import Optional
|
| 9 |
|
| 10 |
import numpy as np
|
|
@@ -31,22 +31,13 @@ class HeadWobbler:
|
|
| 31 |
self._stop_event = threading.Event()
|
| 32 |
self._thread: Optional[threading.Thread] = None
|
| 33 |
|
| 34 |
-
def bind_loops(
|
| 35 |
-
self,
|
| 36 |
-
consumer_loop: asyncio.AbstractEventLoop,
|
| 37 |
-
movement_loop: asyncio.AbstractEventLoop,
|
| 38 |
-
) -> None:
|
| 39 |
-
"""Bind the event loops for thread-safe communication."""
|
| 40 |
-
self._consumer_loop = consumer_loop
|
| 41 |
-
self._movement_loop = movement_loop
|
| 42 |
-
|
| 43 |
def feed(self, delta_b64: str) -> None:
|
| 44 |
"""Thread-safe: push audio into the consumer queue."""
|
| 45 |
buf = np.frombuffer(base64.b64decode(delta_b64), dtype=np.int16).reshape(1, -1)
|
| 46 |
self.audio_queue.put((SAMPLE_RATE, buf))
|
| 47 |
|
| 48 |
def start(self) -> None:
|
| 49 |
-
"""Start the head wobbler loop in
|
| 50 |
self._thread = threading.Thread(target=self.working_loop, daemon=True)
|
| 51 |
self._thread.start()
|
| 52 |
logger.info("Head wobbler started")
|
|
@@ -114,6 +105,7 @@ class HeadWobbler:
|
|
| 114 |
i += 1
|
| 115 |
logger.debug("Head wobbler thread exited")
|
| 116 |
|
|
|
|
| 117 |
def drain_audio_queue(self) -> None:
|
| 118 |
"""Empty the audio queue."""
|
| 119 |
try:
|
|
@@ -121,6 +113,7 @@ class HeadWobbler:
|
|
| 121 |
self.audio_queue.get_nowait()
|
| 122 |
except QueueEmpty:
|
| 123 |
pass
|
|
|
|
| 124 |
|
| 125 |
def reset(self) -> None:
|
| 126 |
"""Reset the internal state."""
|
|
|
|
| 1 |
+
"""Moves head given audio samples."""
|
| 2 |
+
|
| 3 |
import base64
|
| 4 |
import logging
|
| 5 |
import queue
|
| 6 |
import threading
|
| 7 |
import time
|
|
|
|
| 8 |
from typing import Optional
|
| 9 |
|
| 10 |
import numpy as np
|
|
|
|
| 31 |
self._stop_event = threading.Event()
|
| 32 |
self._thread: Optional[threading.Thread] = None
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
def feed(self, delta_b64: str) -> None:
|
| 35 |
"""Thread-safe: push audio into the consumer queue."""
|
| 36 |
buf = np.frombuffer(base64.b64decode(delta_b64), dtype=np.int16).reshape(1, -1)
|
| 37 |
self.audio_queue.put((SAMPLE_RATE, buf))
|
| 38 |
|
| 39 |
def start(self) -> None:
|
| 40 |
+
"""Start the head wobbler loop in a thread."""
|
| 41 |
self._thread = threading.Thread(target=self.working_loop, daemon=True)
|
| 42 |
self._thread.start()
|
| 43 |
logger.info("Head wobbler started")
|
|
|
|
| 105 |
i += 1
|
| 106 |
logger.debug("Head wobbler thread exited")
|
| 107 |
|
| 108 |
+
'''
|
| 109 |
def drain_audio_queue(self) -> None:
|
| 110 |
"""Empty the audio queue."""
|
| 111 |
try:
|
|
|
|
| 113 |
self.audio_queue.get_nowait()
|
| 114 |
except QueueEmpty:
|
| 115 |
pass
|
| 116 |
+
'''
|
| 117 |
|
| 118 |
def reset(self) -> None:
|
| 119 |
"""Reset the internal state."""
|
src/reachy_mini_conversation_demo/camera_worker.py
CHANGED
|
@@ -82,7 +82,7 @@ class CameraWorker:
|
|
| 82 |
logger.info(f"Head tracking {'enabled' if enabled else 'disabled'}")
|
| 83 |
|
| 84 |
def start(self) -> None:
|
| 85 |
-
"""Start the camera worker loop in
|
| 86 |
self._thread = threading.Thread(target=self.working_loop, daemon=True)
|
| 87 |
self._thread.start()
|
| 88 |
logger.info("Camera worker started")
|
|
|
|
| 82 |
logger.info(f"Head tracking {'enabled' if enabled else 'disabled'}")
|
| 83 |
|
| 84 |
def start(self) -> None:
|
| 85 |
+
"""Start the camera worker loop in a thread."""
|
| 86 |
self._thread = threading.Thread(target=self.working_loop, daemon=True)
|
| 87 |
self._thread.start()
|
| 88 |
logger.info("Camera worker started")
|
src/reachy_mini_conversation_demo/moves.py
CHANGED
|
@@ -399,7 +399,7 @@ class MovementManager:
|
|
| 399 |
self.current_robot.set_target(head=neutral_head_pose, antennas=(0.0, 0.0))
|
| 400 |
|
| 401 |
def start(self) -> None:
|
| 402 |
-
"""Start the move worker loop in
|
| 403 |
self._thread = threading.Thread(target=self.working_loop, daemon=True)
|
| 404 |
self._thread.start()
|
| 405 |
logger.info("Move worker started")
|
|
|
|
| 399 |
self.current_robot.set_target(head=neutral_head_pose, antennas=(0.0, 0.0))
|
| 400 |
|
| 401 |
def start(self) -> None:
|
| 402 |
+
"""Start the move worker loop in a thread."""
|
| 403 |
self._thread = threading.Thread(target=self.working_loop, daemon=True)
|
| 404 |
self._thread.start()
|
| 405 |
logger.info("Move worker started")
|