Reachy Mini documentation
音の到来方向(DoA)
はじめに
Reachy Mini (Wireless)
Reachy Mini Lite
シミュレーション
ソフトウェアガイド
SDKの概要インストールコアコンセプトクイックスタートガイドJavaScript SDK & Web アプリアプリの構築と公開Wake & Sleep ライフサイクルAI 統合Python SDKREST APIメディアアーキテクチャクラウドバックエンドコンシューマーGStreamer のインストールテレメトリ
ヘルプとサポート
例
最小限のデモ参照ヘッドトラッキングシーケンスGoto Interpolation PlaygroundIMUコンプライアンスモードのデモ記録された移動Rerun Viewer写真を撮るジョイスティックコントローラーヘッドポジションGUI音の到来方向サウンド再生音声録音サウンドTTS(頭の揺れ付き)カスタムメディアマネージャー
統合
API
音の到来方向(DoA)
この例では、マイクアレイを使用して音声の到来方向(DoA)を検出する方法を示します。ロボットはFastAPIエンドポイントからDoA情報を取得し、音源の位置を計算して世界座標系に変換し、話者の方を自動的に向きます。
仕組み:
/api/state/doaエンドポイントを継続的にポーリングして、音声の方向を取得します- 音声の検出時に、音源の3D位置を計算します
- ヘッド座標からワールド座標へ位置を変換します
look_at_world()を使用して、ロボットに話者を見るよう指示します
機能:
- ロボットのIP(ローカルまたはワイヤレス)の自動検出
- 過度なヘッドムーブメントを回避するための閾値ベースのフィルタリング
- ヘッド座標からワールド座標へのリアルタイム変換
import time
import numpy as np
import requests
from reachy_mini import ReachyMini
def main() -> None:
"""Continuously monitor audio input and orient the head toward the speaker."""
with ReachyMini(log_level="DEBUG", automatic_body_yaw=True) as mini:
# Get the robot IP address
robot_ip = "localhost"
status = mini.client.get_status()
if status.wireless_version and status.wlan_ip:
robot_ip = status.wlan_ip
doa_url = f"http://{robot_ip}:8000/api/state/doa"
# One reused connection: a fresh handshake per poll times out over
# Wi-Fi contended by the WebRTC audio stream.
session = requests.Session()
last_doa = -1
THRESHOLD = 0.004 # ~2 degrees
while True:
# Get DoA from FastAPI endpoint
try:
response = session.get(doa_url, timeout=3.0)
response.raise_for_status()
doa_data = response.json()
if doa_data is None:
print(" No DoA data available (audio not initialized)")
time.sleep(0.5)
continue
angle = doa_data["angle"]
speech_detected = doa_data["speech_detected"]
print(f"DOA: angle={angle:.3f} rad, speech_detected={speech_detected}")
if speech_detected and np.abs(angle - last_doa) > THRESHOLD:
print(f" Speech detected at {angle:.1f} radians")
p_head = [np.sin(angle), np.cos(angle), 0.0]
print(
f" Pointing to x={p_head[0]:.2f}, y={p_head[1]:.2f}, z={p_head[2]:.2f}"
)
T_world_head = mini.get_current_head_pose()
R_world_head = T_world_head[:3, :3]
p_world = R_world_head @ p_head
print(
f" In world coordinates: x={p_world[0]:.2f}, y={p_world[1]:.2f}, z={p_world[2]:.2f}"
)
mini.look_at_world(p_world[0], p_world[1], p_world[2], duration=0.5)
last_doa = angle
else:
if not speech_detected:
print(" No speech detected")
else:
print(
f" Small change in DOA: {angle:.1f} rad (last was {last_doa:.1f} rad). Not moving."
)
time.sleep(0.5)
except requests.RequestException as e:
print(f" Error fetching DoA: {e}")
time.sleep(0.5)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("Exiting...")