From 919cc6b2c997cd0bd0775236c9ecac30231fde1a Mon Sep 17 00:00:00 2001 From: miro Date: Sun, 15 Dec 2024 19:45:14 +0000 Subject: [PATCH] error handling --- ovos_tts_plugin_piper/__init__.py | 8 ++++++-- ovos_tts_plugin_piper/download.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ovos_tts_plugin_piper/__init__.py b/ovos_tts_plugin_piper/__init__.py index 9db02d0..c89e635 100644 --- a/ovos_tts_plugin_piper/__init__.py +++ b/ovos_tts_plugin_piper/__init__.py @@ -18,7 +18,7 @@ from ovos_utils.lang import standardize_lang_tag from ovos_utils.log import LOG -from ovos_tts_plugin_piper.download import LANG2VOICES, SHORTNAMES, get_voice_files, get_lang_voices, get_default_voice +from ovos_tts_plugin_piper.download import LANG2VOICES, SHORTNAMES, VoiceNotFoundError, get_voice_files, get_lang_voices, get_default_voice from ovos_tts_plugin_piper.piper import PiperVoice, PiperConfig @@ -89,7 +89,11 @@ def get_model(self, lang=None, voice=None, speaker=None): if voice in PiperTTSPlugin.engines: return PiperTTSPlugin.engines[voice], speaker - model, model_config = get_voice_files(voice) + try: + model, model_config = get_voice_files(voice) + except VoiceNotFoundError as e: + LOG.error(f"Voice files for '{voice}' not found: {e}") + raise with open(model_config, "r", encoding="utf-8") as config_file: config_dict = json.load(config_file) diff --git a/ovos_tts_plugin_piper/download.py b/ovos_tts_plugin_piper/download.py index 225e911..8af14a2 100644 --- a/ovos_tts_plugin_piper/download.py +++ b/ovos_tts_plugin_piper/download.py @@ -50,7 +50,7 @@ def get_available_voices(update_voices: bool = False) -> Dict[str, Any]: shutil.copyfileobj(response, download_file) except Exception as e: LOG.error(f"Failed to download {voices_url}: {e}") - raise e + # Prefer downloaded file to embedded voices_embedded = _DIR / "voices.json" voices_path = voices_download if voices_download.exists() else voices_embedded