"""Baseline 3.8.6 TFLite keyword scores (1.5 s window every 100 ms) on the Vietnamese dev FA lists. python baseline_fa_cache.py LIST WORKERS Writes vita_fa2/cache/baseline386/.npy (float16, one score per 100 ms). Skips files already done. Uses the same scorer as the 514-clip benchmark (scripts/bench_wuw_testset.py). """ import os import subprocess import sys from multiprocessing import get_context from pathlib import Path import numpy as np sys.path.insert(0, "/home/user/Downloads/vita-wakeword-handoff/scripts") REL = os.environ.get("COMPANY_REL", "/home/user/Downloads/wuw/3.8.6_en") OUT = Path(os.environ.get("COMPANY_OUT", "/data/ext/vita_fa2/cache/baseline386")) M = None def init(): global M os.environ.setdefault("OMP_NUM_THREADS", "1") import bench_wuw_testset as B M = (B, B.make(("tflite", "c", REL))) def job(path): B, m = M out = OUT / (Path(path).stem + ".npy") if out.exists(): return path, -1.0 cmd = ["ffmpeg", "-v", "error", "-i", path, "-f", "f32le", "-ac", "1", "-ar", "16000", "-"] try: audio = np.frombuffer(subprocess.run(cmd, capture_output=True, check=True).stdout, dtype=np.float32) s = B.blocked(m, audio).astype(np.float16) except Exception as e: print("FAIL", path, type(e).__name__, flush=True) return path, 0.0 tmp = out.with_suffix(".tmp.npy") np.save(tmp, s) tmp.rename(out) return path, len(audio) / 16000 / 3600 def main(): files = [l.strip() for l in open(sys.argv[1]) if l.strip()] OUT.mkdir(parents=True, exist_ok=True) done = 0.0 with get_context("spawn").Pool(int(sys.argv[2]), initializer=init, maxtasksperchild=20) as p: for i, (path, h) in enumerate(p.imap_unordered(job, files), 1): done += max(h, 0) if i % 10 == 0 or i == len(files): print(f"{i}/{len(files)} files, {done:.1f} h new", flush=True) print("DONE", flush=True) if __name__ == "__main__": main()