From 77c18e8b84aad83e57697218861fe50b52acd14a Mon Sep 17 00:00:00 2001 From: Oskar Kapala Date: Wed, 10 Jun 2026 14:01:30 +0200 Subject: [PATCH] =?UTF-8?q?fix(tts):=20Linux=20audio=20=E2=80=94=20pw-play?= =?UTF-8?q?/paplay=20first,=20warn=20on=20nonzero=20exit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Na Linuksie wybiera pierwszy dostępny odtwarzacz w kolejności: pw-play → paplay → aplay (wykrywa przez shutil.which). Gdy żaden nie istnieje: "[TTS: brak odtwarzacza audio]". Gdy odtwarzacz zwróci kod != 0: wypisuje ostrzeżenie ze stderr (wcześniej aplay milczał bez śladu przy cichej awarii). Co-Authored-By: Claude Sonnet 4.6 --- ipin_vr/tts.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ipin_vr/tts.py b/ipin_vr/tts.py index 89f41f6..c45edd2 100644 --- a/ipin_vr/tts.py +++ b/ipin_vr/tts.py @@ -1,8 +1,11 @@ import os +import shutil import subprocess import sys import tempfile +_LINUX_PLAYERS = ["pw-play", "paplay", "aplay"] + def speak(text: str, voice_path: str) -> None: with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tf: @@ -35,7 +38,11 @@ def speak(text: str, voice_path: str) -> None: def _play(wav_path: str) -> None: if sys.platform.startswith("linux"): - _run_player("aplay", wav_path) + player = next((p for p in _LINUX_PLAYERS if shutil.which(p)), None) + if player is None: + print("[TTS: brak odtwarzacza audio]") + return + _run_player(player, wav_path) elif sys.platform == "darwin": _run_player("afplay", wav_path) elif sys.platform == "win32": @@ -50,7 +57,10 @@ def _play(wav_path: str) -> None: def _run_player(player: str, wav_path: str) -> None: try: - subprocess.run([player, wav_path], capture_output=True, timeout=30) + proc = subprocess.run([player, wav_path], capture_output=True, timeout=30) + if proc.returncode != 0: + stderr = proc.stderr.decode(errors="replace").strip() + print(f"[TTS: {player} błąd {proc.returncode}: {stderr}]") except FileNotFoundError: print(f"[TTS off: {player} nie znaleziony]") except Exception as exc: