Download source/tools/record-loopback.py from FormaLau/microduck-reachy-simulator: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/FormaLau/microduck-reachy-simulator/resolve/main/source/tools/record-loopback.py
- Command line
-
hf download hf://spaces/FormaLau/microduck-reachy-simulator/source/tools/record-loopback.py
-
curl -L -o record-loopback.py https://huggingface.co/spaces/FormaLau/microduck-reachy-simulator/resolve/main/source/tools/record-loopback.py
1.11 kB
| """Record the Windows speaker output, including the simulator's legacy TTS. | |
| Optional demo dependencies: pip install soundcard numpy imageio-ffmpeg | |
| The caller creates STOP in the output directory to finish capture. | |
| """ | |
| import json | |
| import pathlib | |
| import sys | |
| import time | |
| import wave | |
| import numpy as np | |
| import soundcard as sc | |
| out = pathlib.Path(sys.argv[1]).resolve() | |
| out.mkdir(parents=True, exist_ok=True) | |
| speaker = sc.default_speaker() | |
| microphone = sc.get_microphone(speaker.id, include_loopback=True) | |
| with microphone.recorder(samplerate=48000, channels=2, blocksize=48000) as capture: | |
| with wave.open(str(out / "speaker.wav"), "wb") as wav: | |
| wav.setnchannels(2) | |
| wav.setsampwidth(2) | |
| wav.setframerate(48000) | |
| (out / "audio-ready.json").write_text(json.dumps({"started": time.time(), "speaker": speaker.name})) | |
| print("Audio capture ready", flush=True) | |
| while not (out / "STOP").exists(): | |
| block = capture.record(numframes=4800) | |
| wav.writeframes((np.clip(block, -1, 1) * 32767).astype("<i2").tobytes()) | |
| print("Audio capture saved", flush=True) | |