TTS: czyste środowisko (LD_LIBRARY_PATH=/opt/piper-tts) — naprawa konfliktu libespeak-ng ze Steam Runtime
This commit is contained in:
1 parent
32fe481e28
commit
ed073df1bc
1 file changed
+16
-2
@@ -627,6 +627,18 @@ class XSayATC:
|
|||||||
xp.log(f"[XSayATC] Blad whisper: {e}")
|
xp.log(f"[XSayATC] Blad whisper: {e}")
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def _clean_env(self):
|
||||||
|
"""Zwraca srodowisko bez LD_LIBRARY_PATH/LD_PRELOAD ze Steam, zeby
|
||||||
|
piper/pw-play uzywaly wlasnych bibliotek (inaczej Steam Runtime podklada
|
||||||
|
stara libespeak-ng i piper zwraca pusty plik)."""
|
||||||
|
env = dict(os.environ)
|
||||||
|
env.pop("LD_PRELOAD", None)
|
||||||
|
# Zostawiamy tylko sciezki systemowe, nie Steam Runtime.
|
||||||
|
ld = env.pop("LD_LIBRARY_PATH", "")
|
||||||
|
# Dopisujemy /opt/piper-tts na poczatek, by piper znalazl swoje libs.
|
||||||
|
env["LD_LIBRARY_PATH"] = "/opt/piper-tts"
|
||||||
|
return env
|
||||||
|
|
||||||
def _speak(self, text):
|
def _speak(self, text):
|
||||||
"""Synteza mowy (piper) i odtworzenie. 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):
|
||||||
@@ -639,18 +651,20 @@ class XSayATC:
|
|||||||
model = self.config.get("piper_model", "")
|
model = self.config.get("piper_model", "")
|
||||||
import tempfile
|
import tempfile
|
||||||
wav = tempfile.mktemp(suffix=".wav", prefix="xsayatc_tts_")
|
wav = tempfile.mktemp(suffix=".wav", prefix="xsayatc_tts_")
|
||||||
|
env = self._clean_env()
|
||||||
try:
|
try:
|
||||||
xp.log(f"[XSayATC] TTS: piper -> {wav}")
|
xp.log(f"[XSayATC] TTS: piper -> {wav}")
|
||||||
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.PIPE,
|
||||||
|
env=env)
|
||||||
_out, err = p.communicate(input=text.encode("utf-8"), timeout=60)
|
_out, err = p.communicate(input=text.encode("utf-8"), timeout=60)
|
||||||
if err:
|
if err:
|
||||||
xp.log(f"[XSayATC] TTS piper stderr: {err.decode('utf-8', 'ignore')[:200]}")
|
xp.log(f"[XSayATC] TTS piper stderr: {err.decode('utf-8', 'ignore')[:200]}")
|
||||||
if os.path.exists(wav) and os.path.getsize(wav) > 0:
|
if os.path.exists(wav) and os.path.getsize(wav) > 0:
|
||||||
play_cmd = list(self.config.get("play_cmd", ["pw-play"]))
|
play_cmd = list(self.config.get("play_cmd", ["pw-play"]))
|
||||||
xp.log(f"[XSayATC] TTS: odtwarzam: {play_cmd} {wav}")
|
xp.log(f"[XSayATC] TTS: odtwarzam: {play_cmd} {wav}")
|
||||||
r = subprocess.run(play_cmd + [wav], stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, timeout=60)
|
r = subprocess.run(play_cmd + [wav], stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, timeout=60, env=env)
|
||||||
if r.returncode != 0:
|
if r.returncode != 0:
|
||||||
xp.log(f"[XSayATC] TTS odtwarzanie kod={r.returncode} stderr={r.stderr.decode('utf-8','ignore')[:200]}")
|
xp.log(f"[XSayATC] TTS odtwarzanie kod={r.returncode} stderr={r.stderr.decode('utf-8','ignore')[:200]}")
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in new issue
Block a user