TTS: pw-play zamiast aplay + szczegółowy logging odtwarzania
This commit is contained in:
1 parent
bdf1a1fdd5
commit
32fe481e28
1 file changed
+18
-11
+18
-11
@@ -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}")
|
||||
|
||||
|
||||
Reference in new issue
Block a user