Randoloot/tests/audio/freighter_assets_test.py
2026-10-18 15:11:06 +02:00

27 lines
1.2 KiB
Python

"""Technical QA for authored frigate audio (Python + numpy)."""
from pathlib import Path
import wave
import numpy as np
ROOT = Path(__file__).resolve().parents[2]
files = list((ROOT / "assets/sounds/freighter").glob("*.wav"))
assert len(files) == 13
seams = []
for path in files:
with wave.open(str(path)) as stream:
assert stream.getnchannels() == 2
assert stream.getsampwidth() == 2
assert stream.getframerate() == 48000
signal = np.frombuffer(stream.readframes(stream.getnframes()),dtype="<i2").reshape(-1,2)/32768.0
assert np.isfinite(signal).all()
assert np.max(np.abs(signal)) < .9, path.name
assert np.max(np.abs(signal.mean(axis=0))) < .01, path.name
if path.stem.endswith("loop"):
difference = float(np.max(np.abs(signal[0]-signal[-1])))
assert difference < .05, (path.name,difference)
seams.append((path.name,round(difference,6)))
with wave.open(str(ROOT / "artifacts/freighter_ambience_demo.wav")) as stream:
assert stream.getnchannels() == 2
assert stream.getnframes()/stream.getframerate() == 34
print("AUDIO ASSET QA PASS: 13 stereo PCM16 WAV files at 48 kHz; no clipping/DC; loop seam deltas:",seams)