From 32fe481e28293538f8b8e047ea8d9d49db600672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Paluch?= Date: Tue, 20 Oct 2026 17:45:01 +0200 Subject: [PATCH] =?UTF-8?q?TTS:=20pw-play=20zamiast=20aplay=20+=20szczeg?= =?UTF-8?q?=C3=B3=C5=82owy=20logging=20odtwarzania?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonPlugins/PI_XSayATC.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/PythonPlugins/PI_XSayATC.py b/PythonPlugins/PI_XSayATC.py index 82e52eb..b40a669 100644 --- a/PythonPlugins/PI_XSayATC.py +++ b/PythonPlugins/PI_XSayATC.py @@ -68,7 +68,7 @@ DEFAULT_CONFIG = { "record_cmd": ["pw-record", "--format=s16", "--rate=16000", "--channels=1"], "piper": "/opt/piper-tts/piper", "piper_model": "/home/pali112/.local/share/piper-voices/en_US-lessac-medium.onnx", - "play_cmd": ["aplay", "-q"], + "play_cmd": ["pw-play"], "tts_enabled": True, # --- Plan lotu --- # Fallback dla samolotow z wlasnym FMC (Toliss/Zibo), ktore nie zapisuja @@ -628,8 +628,9 @@ class XSayATC: return "" def _speak(self, text): - """Synteza mowy (piper) i odtworzenie (aplay). Watek roboczy.""" + """Synteza mowy (piper) i odtworzenie. Watek roboczy.""" if not self.config.get("tts_enabled", True): + xp.log("[XSayATC] TTS wylaczone.") return text = (text or "").strip() if not text: @@ -639,19 +640,25 @@ class XSayATC: import tempfile wav = tempfile.mktemp(suffix=".wav", prefix="xsayatc_tts_") try: - # piper czyta tekst ze stdin, zapisuje WAV - with open(wav, "wb") as out: - p = subprocess.Popen( - [piper, "-m", model, "-f", wav], - stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - p.communicate(input=text.encode("utf-8"), timeout=60) - if os.path.exists(wav): - play_cmd = list(self.config.get("play_cmd", ["aplay", "-q"])) - subprocess.run(play_cmd + [wav], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=60) + xp.log(f"[XSayATC] TTS: piper -> {wav}") + p = subprocess.Popen( + [piper, "-m", model, "-f", wav], + stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) + _out, err = p.communicate(input=text.encode("utf-8"), timeout=60) + if err: + xp.log(f"[XSayATC] TTS piper stderr: {err.decode('utf-8', 'ignore')[:200]}") + if os.path.exists(wav) and os.path.getsize(wav) > 0: + play_cmd = list(self.config.get("play_cmd", ["pw-play"])) + xp.log(f"[XSayATC] TTS: odtwarzam: {play_cmd} {wav}") + r = subprocess.run(play_cmd + [wav], stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, timeout=60) + if r.returncode != 0: + xp.log(f"[XSayATC] TTS odtwarzanie kod={r.returncode} stderr={r.stderr.decode('utf-8','ignore')[:200]}") try: os.remove(wav) except Exception: pass + else: + xp.log(f"[XSayATC] TTS: brak pliku WAV (rozmiar 0 lub nie istnieje)") except Exception as e: xp.log(f"[XSayATC] Blad TTS: {e}")