"""Score one pause with the int8 ONNX model. pip install onnxruntime soundfile numpy""" import numpy as np, onnxruntime as ort, soundfile as sf, sys SR, CTX = 16000, 8 * 16000 sess = ort.InferenceSession("eot.int8.onnx", providers=["CPUExecutionProvider"]) def p_done(audio_16k_mono: np.ndarray, decision_time_s: float) -> float: """P(the speaker has finished their turn), given audio up to `decision_time_s`. Call it ~200 ms after the speaker's last word, which is the point the model was trained on.""" e = int(decision_time_s * SR); w = audio_16k_mono[max(0, e - CTX):e].astype(np.float32) w = np.concatenate([np.zeros(CTX - len(w), np.float32), w])[None] # left-pad to exactly 8 s return float(sess.run(None, {"audio": w})[0].reshape(-1)[0]) if __name__ == "__main__": x, sr = sf.read(sys.argv[1], dtype="float32", always_2d=True); assert sr == SR, "resample to 16 kHz first" print(f"P(done) = {p_done(x.mean(1), float(sys.argv[2])):.3f}")