import soundfile as sf, librosa, numpy as np, json, re from voices import asr, transcribe, cer rec = asr() lines = [l.strip() for l in open("/home/claude/agent1/tts/lines.txt", encoding="utf-8") if l.strip()] D = {'70':'هفتاد','10':'ده','15':'پانزده','5':'پنج','30':'سی','3':'سه','7':'هفت'} best = [] for i, t in enumerate(lines): res = [] for s in (1, 2, 3, 4, 5, 6): import os if not os.path.exists(f"/home/claude/agent1/tts/out/s{s}/{i:02d}.wav"): continue a, sr = sf.read(f"/home/claude/agent1/tts/out/s{s}/{i:02d}.wav", dtype="float32") a16 = librosa.resample(a, orig_sr=sr, target_sr=16000) a16 = np.concatenate([np.zeros(4000, np.float32), a16, np.zeros(16000, np.float32)]) h = re.sub(r'\d+', lambda m: D.get(m.group(), m.group()), transcribe(rec, a16, 16000)) res.append((round(cer(t, h), 3), round(len(a)/sr, 2), s, h)) res.sort(key=lambda r: (r[0], r[1])) best.append({"i": i, "seed": res[0][2], "cer": res[0][0]}) print(i, [(r[2], r[0], r[1]) for r in res], "|", res[0][3]) print("mean best CER", round(float(np.mean([b["cer"] for b in best])), 3)) json.dump(best, open("best.json", "w"))