TTS: pw-play zamiast aplay + szczegółowy logging odtwarzania

This commit is contained in:
pali112 committed 2026-10-20 17:45:01 +02:00
1 parent bdf1a1fdd5
commit 32fe481e28
1 file changed
+18 -11
+18 -11
View File
@@ -68,7 +68,7 @@ DEFAULT_CONFIG = {
"record_cmd": ["pw-record", "--format=s16", "--rate=16000", "--channels=1"], "record_cmd": ["pw-record", "--format=s16", "--rate=16000", "--channels=1"],
"piper": "/opt/piper-tts/piper", "piper": "/opt/piper-tts/piper",
"piper_model": "/home/pali112/.local/share/piper-voices/en_US-lessac-medium.onnx", "piper_model": "/home/pali112/.local/share/piper-voices/en_US-lessac-medium.onnx",
"play_cmd": ["aplay", "-q"], "play_cmd": ["pw-play"],
"tts_enabled": True, "tts_enabled": True,
# --- Plan lotu --- # --- Plan lotu ---
# Fallback dla samolotow z wlasnym FMC (Toliss/Zibo), ktore nie zapisuja # Fallback dla samolotow z wlasnym FMC (Toliss/Zibo), ktore nie zapisuja
@@ -628,8 +628,9 @@ class XSayATC:
return "" return ""
def _speak(self, text): 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): if not self.config.get("tts_enabled", True):
xp.log("[XSayATC] TTS wylaczone.")
return return
text = (text or "").strip() text = (text or "").strip()
if not text: if not text:
@@ -639,19 +640,25 @@ class XSayATC:
import tempfile import tempfile
wav = tempfile.mktemp(suffix=".wav", prefix="xsayatc_tts_") wav = tempfile.mktemp(suffix=".wav", prefix="xsayatc_tts_")
try: try:
# piper czyta tekst ze stdin, zapisuje WAV xp.log(f"[XSayATC] TTS: piper -> {wav}")
with open(wav, "wb") as out: p = subprocess.Popen(
p = subprocess.Popen( [piper, "-m", model, "-f", wav],
[piper, "-m", model, "-f", wav], stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) _out, err = p.communicate(input=text.encode("utf-8"), timeout=60)
p.communicate(input=text.encode("utf-8"), timeout=60) if err:
if os.path.exists(wav): xp.log(f"[XSayATC] TTS piper stderr: {err.decode('utf-8', 'ignore')[:200]}")
play_cmd = list(self.config.get("play_cmd", ["aplay", "-q"])) if os.path.exists(wav) and os.path.getsize(wav) > 0:
subprocess.run(play_cmd + [wav], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=60) 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: try:
os.remove(wav) os.remove(wav)
except Exception: except Exception:
pass pass
else:
xp.log(f"[XSayATC] TTS: brak pliku WAV (rozmiar 0 lub nie istnieje)")
except Exception as e: except Exception as e:
xp.log(f"[XSayATC] Blad TTS: {e}") xp.log(f"[XSayATC] Blad TTS: {e}")