Microphone
robot.microphone reads raw audio from the robot's internal microphone array, tunes its DSP, and reports voice-activity/direction-of-arrival events. These examples assume you already have a connected robot — see Connection if you haven't set one up yet.
Setup
mkdir ~/example
cd ~/example
python -m venv .venv
# or: uv venv .venv
source .venv/bin/activate
pip install luxai-robot
# or: uv pip install luxai-robot
Connect
from luxai.robot.core import Robot
robot = Robot.connect_zmq(robot_id="QTRD000123")
print(f"connected to {robot.robot_id} ({robot.robot_type})")
See Connection for MQTT, WebRTC, and other connection options.
DSP tuning
# Read all readable Respeaker (internal mic array) tuning parameters
params = robot.microphone.get_int_tuning()
Logger.info("Internal mic tuning parameters:")
for name, value in params.items():
Logger.info(f" {name}: {value}")
# Enable AGC (automatic gain control) on the internal mic array
ok = robot.microphone.set_int_tuning(name="AGCONOFF", value=1.0)
Logger.info(f"set_int_tuning result: {ok}")
# Confirm the change was applied
params = robot.microphone.get_int_tuning()
Logger.info(f"AGCONOFF after set: {params.get('AGCONOFF')}")
Record to a WAV file
import time
import wave
from luxai.magpie.frames import AudioFrameRaw
def record_int_audio_ch0_to_wav(robot, duration_s=5.0, output_path="recording.wav"):
# Open a reader for internal mic channel 0 (processed/ASR channel)
reader = robot.microphone.stream.open_int_audio_ch0_reader(queue_size=10)
# Read the first frame to learn sample rate and bit depth
first_frame: AudioFrameRaw = reader.read(timeout=3.0)
if first_frame is None:
Logger.error("No audio frame received!")
return
sample_rate = first_frame.sample_rate
bit_depth = first_frame.bit_depth
channels = first_frame.channels
deadline = time.monotonic() + duration_s
with wave.open(output_path, "wb") as wf:
wf.setnchannels(channels)
wf.setsampwidth(bit_depth // 8)
wf.setframerate(sample_rate)
wf.writeframes(first_frame.data)
while time.monotonic() < deadline:
frame: AudioFrameRaw = reader.read(timeout=1.0)
if frame:
wf.writeframes(frame.data)
Logger.info(f"Recording saved to {output_path}")
Voice-activity events
from luxai.magpie.frames import DictFrame
def on_event(frame: DictFrame):
evt = frame.value
if evt.get("activity", False):
Logger.info(f"Voice detected — DOA: {evt.get('direction', 0)}°")
else:
Logger.info("Silence")
sub = robot.microphone.stream.on_int_event(on_event, queue_size=2)
Next steps
Continue with the Camera tutorial, or see the full robot.microphone namespace in the Python API Reference.