"""make_examples.py - write a few 16 kHz mono example recordings for the Space's Examples panel. python make_examples.py --audio-dir /path/to/wav [--files 25.IA.July.2023.wav ...] The examples are re-encoded at 16 kHz (the pipeline's working rate), which keeps each file under 4 MB; the app's ground-truth lookup works because the file names are unchanged. """ import argparse import os import sys import soundfile as sf HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) import acoustic as ac # noqa: E402 DEFAULT = ["25.IA.July.2023.wav", "49.IA.Mar.2023.wav", "51.NZ.Jan.2023.wav", "F1.IA.Oct.2023.wav"] def main(): ap = argparse.ArgumentParser() ap.add_argument("--audio-dir", required=True) ap.add_argument("--files", nargs="*", default=DEFAULT) ap.add_argument("--out", default=os.path.join(HERE, "examples")) a = ap.parse_args() os.makedirs(a.out, exist_ok=True) for f in a.files: y, sr = ac.load_audio(os.path.join(a.audio_dir, f), ac.SR) sf.write(os.path.join(a.out, f), y, sr, subtype="PCM_16") print("wrote", f, f"{os.path.getsize(os.path.join(a.out, f))/1e6:.2f} MB") if __name__ == "__main__": main()