Test 1: add playback step — record-play loop complete
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
#!/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.
|
||||
- out.wav is written and non-empty.
|
||||
- No clipping, dropouts, or sustained PortAudio under/overrun warnings.
|
||||
"""
|
||||
import os
|
||||
os.environ.setdefault("PA_ALSA_PLUGHW", "1")
|
||||
@@ -73,11 +74,18 @@ def record(device: int) -> np.ndarray:
|
||||
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:
|
||||
device = find_usb_device()
|
||||
audio = record(device)
|
||||
sf.write(OUT_WAV, audio, SAMPLE_RATE)
|
||||
print(f"Wrote {OUT_WAV} ({audio.shape[0]} frames @ {SAMPLE_RATE} Hz)")
|
||||
play(device, audio)
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user