Test 1: add playback step — record-play loop complete

This commit is contained in:
2026-06-11 14:38:41 +00:00
parent 431fe7cfbc
commit a301345ec4
+11 -3
View File
@@ -1,9 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""Record 5s from the USB Speaker Phone with a live RMS meter, save out.wav. """Record 5s from the USB Speaker Phone with a live RMS meter, save out.wav, play it back.
Pass criteria for the record stage: Pass criteria (per spec):
- Playback is recognisable as what was said into the mic.
- Level meter visibly responds to speech and to silence. - Level meter visibly responds to speech and to silence.
- out.wav is written and non-empty. - No clipping, dropouts, or sustained PortAudio under/overrun warnings.
""" """
import os import os
os.environ.setdefault("PA_ALSA_PLUGHW", "1") os.environ.setdefault("PA_ALSA_PLUGHW", "1")
@@ -73,11 +74,18 @@ def record(device: int) -> np.ndarray:
return buf return buf
def play(device: int, audio: np.ndarray) -> None:
print(f"Playing back through device {device}")
sd.play(audio, samplerate=SAMPLE_RATE, device=device)
sd.wait()
def main() -> int: def main() -> int:
device = find_usb_device() device = find_usb_device()
audio = record(device) audio = record(device)
sf.write(OUT_WAV, audio, SAMPLE_RATE) sf.write(OUT_WAV, audio, SAMPLE_RATE)
print(f"Wrote {OUT_WAV} ({audio.shape[0]} frames @ {SAMPLE_RATE} Hz)") print(f"Wrote {OUT_WAV} ({audio.shape[0]} frames @ {SAMPLE_RATE} Hz)")
play(device, audio)
return 0 return 0