From ff6736d6ae7a1274587394fba34da34bb2cb1d8a Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sun, 27 Sep 2026 19:56:28 +0200 Subject: Speak announcements with Kokoro, leading silence against clipped first word Co-Authored-By: Claude Opus 5.5 --- cal-notif | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/cal-notif b/cal-notif index 3726200..d577d13 100755 --- a/cal-notif +++ b/cal-notif @@ -296,13 +296,40 @@ def announce(occ, now, vcfg): # ---- voice ---- +def say(text, vcfg): + import numpy as np + from kokoro_onnx import Kokoro + k = Kokoro(vcfg["model"], vcfg["voices"]) + style = sum(w * k.get_voice_style(n) for n, w in vcfg["blend"].items()) + audio, sr = k.create(text, voice=style, lang=vcfg["lang"]) + # A new playback stream wakes the suspended sink and loses its first + # ~0.2 s: lead with silence so it eats that, not the first word. + lead = bytes(int(sr * vcfg["lead_silence"]) * 2) + pcm = (np.clip(audio, -1, 1) * 32767).astype(" 2: + say(" ".join(sys.argv[2:]), load_config()["voice"]) + else: + sys.exit(__doc__) if __name__ == "__main__": -- cgit v1.2.3