#!/usr/bin/env python3 """Calidad del modo en vivo contra una pasada de referencia, con el mismo motor HTTP. - referencia: el clip en pedazos de 30 s (el contexto completo que whisper soporta), sin apuro de tiempo real: es lo mejor que da el motor sobre ese audio. - en vivo: el mismo Transcriptor del servicio, alimentado de a 6 s (un segmento HLS). Los pedidos van de a uno (gpu02 es compartido). Uso: bench_http.py clip.wav salida.json [url] """ import json, sys, time, wave import numpy as np from orbisubs import SR, MotorHTTP, Transcriptor, armar_cues def leer_wav(p): with wave.open(p) as w: assert w.getframerate() == SR and w.getnchannels() == 1 return np.frombuffer(w.readframes(w.getnframes()), " 3 else "http://192.168.2.10:8004" audio = leer_wav(clip) dur = len(audio) / SR motor = MotorHTTP(url, timeout=60) ref, t_ref = [], [] for i in range(0, len(audio), 30 * SR): a = time.time() ref += [w[2] for w in motor(audio[i:i + 30 * SR], None)] t_ref.append(time.time() - a) tr = Transcriptor(motor, hold=1.0, max_buf=20.0) vivo, t_vivo, cues = [], [], [] for i in range(0, len(audio), 6 * SR): tr.agregar(i / SR, audio[i:i + 6 * SR]) conf, dt = tr.paso() t_vivo.append(dt) vivo += [w[2] for w in conf] cues += armar_cues(conf) r = {"audio_s": round(dur, 1), "ref_pedidos": len(t_ref), "ref_s_por_pedido": round(sum(t_ref) / len(t_ref), 2), "vivo_pedidos": len(t_vivo), "vivo_s_por_pedido": round(sum(t_vivo) / len(t_vivo), 2), "vivo_max_s": round(max(t_vivo), 2), "vivo_rtf": round(sum(t_vivo) / dur, 3), "referencia": "".join(ref).strip(), "vivo": "".join(vivo).strip(), "cues": [[round(a, 2), round(b, 2), t] for a, b, t in cues]} from bench import wer r["wer_vivo_vs_ref"] = round(wer(r["referencia"], r["vivo"]), 3) json.dump(r, open(out, "w"), ensure_ascii=False, indent=1) print(json.dumps({k: v for k, v in r.items() if k not in ("referencia", "vivo", "cues")})) if __name__ == "__main__": main()