From 3f8f8bbe66a072e2cab080b37cfbb709d0f1f9bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Paluch?= Date: Tue, 17 Nov 2026 12:16:33 +0100 Subject: [PATCH] =?UTF-8?q?TTS:=20dwa=20g=C5=82osy=20(PL=20gosia=20/=20EN?= =?UTF-8?q?=20ryan)=20wybierane=20po=20j=C4=99zyku=20wypowiedzi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonPlugins/PI_XCoPilot.py | 24 +++++++++++++++++++++--- PythonPlugins/config.example.json | 3 ++- README.md | 3 ++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/PythonPlugins/PI_XCoPilot.py b/PythonPlugins/PI_XCoPilot.py index 5a15cc6..5c15fa2 100644 --- a/PythonPlugins/PI_XCoPilot.py +++ b/PythonPlugins/PI_XCoPilot.py @@ -100,7 +100,9 @@ DEFAULT_CONFIG = { "whisper_language": "auto", "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", + "piper_model": "", # stary klucz (fallback); normalnie uzywa _pl / _en ponizej + "piper_model_pl": "/home/pali112/models/pl_PL-gosia-medium.onnx", + "piper_model_en": "/home/pali112/models/en_US-ryan-high.onnx", "play_cmd": ["pw-play"], "tts_enabled": True, } @@ -852,9 +854,22 @@ class XCoPilot: finally: self._speak_lock.release() + def _detect_lang(self, text): + """Zwraca 'pl' jesli tekst zawiera polskie znaki, inaczej 'en'.""" + if any(ch in text for ch in "ąćęłńóśźżĄĆĘŁŃÓŚŹŻ"): + return "pl" + return "en" + def _speak_locked(self, text): piper = self.config.get("piper", "/opt/piper-tts/piper") - model = self.config.get("piper_model", "") + # Wybierz glos wg jezyka wypowiedzi: pl -> gosia, en -> ryan. + if self._detect_lang(text) == "pl": + model = self.config.get("piper_model_pl") or self.config.get("piper_model", "") + else: + model = self.config.get("piper_model_en") or self.config.get("piper_model", "") + if not model: + xp.log("[XCoPilot] TTS: brak modelu piper (piper_model_pl/_en).") + return import tempfile wav = tempfile.mktemp(suffix=".wav", prefix="xcopilot_tts_") env = self._clean_env() @@ -988,7 +1003,10 @@ class XCoPilot: _, self.config["voice_enabled"] = imgui.checkbox("Glos wlaczony (STT)", self.config["voice_enabled"]) _, self.config["tts_enabled"] = imgui.checkbox("Odczytywanie odpowiedzi (TTS)", self.config["tts_enabled"]) _, self.config["whisper_model"] = imgui.input_text("Model whisper", self.config["whisper_model"], 512) - _, self.config["piper_model"] = imgui.input_text("Model piper", self.config["piper_model"], 512) + _, self.config["piper_model_pl"] = imgui.input_text( + "Glos PL (gosia)", self.config["piper_model_pl"], 512) + _, self.config["piper_model_en"] = imgui.input_text( + "Glos EN (ryan)", self.config["piper_model_en"], 512) imgui.separator() imgui.text("System prompt (osobowosc i format JSON):") diff --git a/PythonPlugins/config.example.json b/PythonPlugins/config.example.json index 85a27f0..94e5994 100644 --- a/PythonPlugins/config.example.json +++ b/PythonPlugins/config.example.json @@ -14,7 +14,8 @@ "whisper_language": "auto", "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", + "piper_model_pl": "/home/pali112/models/pl_PL-gosia-medium.onnx", + "piper_model_en": "/home/pali112/models/en_US-ryan-high.onnx", "play_cmd": ["pw-play"], "tts_enabled": true } diff --git a/README.md b/README.md index 173af22..15eb8e3 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,8 @@ Gdy w `config.json` ustawisz `allow_raw_actions: true`, AI może też bezpośred | `controls_file` | Ścieżka `controls.json` (puste = obok wtyczki) | | `allow_raw_actions` | Pozwól AI na surowe `dref`/`command` | | `voice_enabled` / `tts_enabled` | Głos wejściowy / wyjściowy | -| `whisper_model`, `piper_model` | Ścieżki modeli STT/TTS | +| `whisper_model` | Ścieżka modelu STT (whisper) | +| `piper_model_pl` / `piper_model_en` | Głos TTS: polski (`pl_PL-gosia-medium`) i angielski (`en_US-ryan-high`). Wybierany automatycznie po języku wypowiedzi co-pilota. | | `voice_ptt_mode` | `hold` (przytrzymaj) lub `toggle` | ## Push-to-talk