# -*- coding: utf-8 -*- """Diagnose: schneidet das Modell selbst vorne/hinten ab, oder mein Trim? Misst Stille-Anteil am Anfang/Ende des ROHEN Outputs (vor jedem Trim).""" import os, time, numpy as np, soundfile as sf, librosa from pocket_tts import TTSModel BASE = r"F:\Coding Stuff\mission-control-2\client\lucy-tts" OUT = os.path.join(BASE, "out_diag"); os.makedirs(OUT, exist_ok=True) y, _ = librosa.load(os.path.join(BASE, "ref.mp3"), sr=24000, mono=True) yt, _ = librosa.effects.trim(y, top_db=30); ref = os.path.join(BASE, "ref.wav") sf.write(ref, yt[:int(18*24000)], 24000) SENT = { "kurz": "Hallo Commander, ich höre dich.", "lang": "Natürlich kümmere ich mich darum, Commander. Ich starte den Dienst neu, prüfe die Protokolle und melde mich, sobald alles wieder läuft.", } def lead_tail_silence(a, sr): """Wie viel ms am Anfang/Ende liegen unter -40dB vom Peak (= 'Stille')?""" a = np.abs(np.asarray(a, dtype=np.float32).reshape(-1)) if a.size == 0: return 0.0, 0.0, 0.0 peak = a.max() + 1e-9 thr = peak * (10 ** (-40/20)) # -40 dB above = np.where(a > thr)[0] if above.size == 0: return a.size/sr*1000, a.size/sr*1000, 0.0 lead = above[0] / sr * 1000 tail = (a.size - 1 - above[-1]) / sr * 1000 return lead, tail, a.size/sr*1000 m = TTSModel.load_model(language="german_24l", lsd_decode_steps=4) vs = m.get_state_for_audio_prompt(ref) sr = m.sample_rate for name, text in SENT.items(): for feos in [None, 4, 8]: a = m.generate_audio(vs, text, frames_after_eos=feos) a = a.numpy() if hasattr(a, "numpy") else np.asarray(a) a = a.reshape(-1) lead, tail, total = lead_tail_silence(a, sr) sf.write(os.path.join(OUT, f"raw_{name}_feos{feos}.wav"), a, sr) print(f"[{name:5} feos={str(feos):4}] total={total:7.1f}ms lead_sil={lead:6.1f}ms tail_sil={tail:6.1f}ms peak={np.abs(a).max():.3f}", flush=True) print("DIAG_DONE", flush=True)