Reachy Mini documentation
Sound Recording
Get Started
Reachy Mini (Wireless)
Getting startedHardwareUsageMedia Advanced ControlsResetInstall Daemon from BranchDevelopment WorkflowReflash the ISO
Reachy Mini Lite
Simulation
Software guide
SDK OverviewInstallationCore ConceptsQuickstart GuidePython SDKAI IntegrationsBuilding & Publishing AppsREST APIJavaScript SDK & Web AppsMedia ArchitectureGStreamer Installation
Help and support
Examples
Minimal demoLook atSequenceGoto Interpolation PlaygroundIMUCompliant Mode DemoRecorded MovesRerun ViewerTake PictureJoystick ControllerHead Position GUISound Direction of ArrivalSound PlaybackSound RecordingCustom Media Manager
API
Sound Recording
This example demonstrates how to record audio from Reachy Mini’s microphone array and save it to a WAV file. The script records for 5 seconds and saves the audio to recorded_audio.wav.
How it works:
- Starts audio recording using
start_recording() - Continuously retrieves audio samples using
get_audio_sample() - Collects samples until the desired duration is reached
- Stops recording and concatenates all samples
- Saves the audio data to a WAV file using
soundfile
Features:
- Configurable recording duration (default: 5 seconds)
- Automatic sample rate detection
- Timeout protection to prevent infinite loops
- Support for different media backends
Usage:
python sound_record.py --backend [default|local|webrtc]The recorded audio will be saved to recorded_audio.wav in the current directory.
import argparse
import time
import numpy as np
from reachy_mini import ReachyMini
from reachy_mini.media.audio_utils import save_audio_to_wav
TIMEOUT = 1
DURATION = 5 # seconds
OUTPUT_FILE = "recorded_audio.wav"
def main(backend: str) -> None:
"""Record audio for 5 seconds and save to a WAV file."""
with ReachyMini(log_level="INFO", media_backend=backend) as mini:
audio_samples = []
mini.media.start_recording()
# Wait to actually get an audio sample
print("Waiting for the microphone to be ready...")
start_time = time.time()
while (
mini.media.get_audio_sample() is None and time.time() - start_time < TIMEOUT
):
time.sleep(0.005)
if time.time() - start_time >= TIMEOUT:
print(f"Timeout: the microphone did not respond in {TIMEOUT} seconds.")
return
print(f"Recording for {DURATION} seconds...")
start_time = time.time()
while time.time() - start_time < DURATION:
sample = mini.media.get_audio_sample()
if sample is not None:
audio_samples.append(sample)
mini.media.stop_recording()
# Concatenate all samples and save
if audio_samples:
audio_data = np.concatenate(audio_samples, axis=0)
samplerate = mini.media.get_input_audio_samplerate()
save_audio_to_wav(audio_data, samplerate, OUTPUT_FILE)
print(f"Audio saved to {OUTPUT_FILE}")
else:
print("No audio data recorded.")
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Records audio from Reachy Mini's microphone."
)
parser.add_argument(
"--backend",
type=str,
choices=["default", "local", "webrtc"],
default="default",
help="Media backend to use.",
)
args = parser.parse_args()
main(backend=args.backend)