#!/usr/bin/env python3 """Check bundled soundscapes without synthesis dependencies.""" import array import hashlib import json import math import wave from pathlib import Path root = Path(__file__).resolve().parents[1] audio = root / 'assets/audio' manifest = json.loads((audio / 'ambience_manifest.json').read_text()) assert set(manifest['tracks']) == {'cottage', 'harbour', 'bridge', 'tower'} pubspec = (root / 'pubspec.yaml').read_text() for scene, track in manifest['tracks'].items(): path = audio / track['file'] assert 'assets/audio/' + path.name in pubspec assert hashlib.sha256(path.read_bytes()).hexdigest() == track['wavSha256'] with wave.open(str(path), 'rb') as reader: assert reader.getnchannels() == 1 and reader.getsampwidth() == 2 assert reader.getframerate() == track['sampleRate'] == 24000 assert reader.getnframes() == track['frames'] samples = array.array('h', reader.readframes(reader.getnframes())) rms = math.sqrt(sum(v * v for v in samples) / len(samples)) / 32768 peak = max(abs(v) for v in samples) / 32768 assert .05 < rms < .15 and peak < .73, 'Silent or clipped soundscape' assert abs(samples[-1] - samples[0]) <= 1, 'Discontinuous loop join' assert track['durationMs'] == len(samples) * 1000 // 24000 print(f'PASS {scene}: bundled PCM, checksum, level and loop join verified')