From a4d25accc1ff3e9108f4807d3ef8f5091f421765 Mon Sep 17 00:00:00 2001 From: Artem Akymenko Date: Wed, 8 Jul 2026 15:57:18 +0000 Subject: [PATCH] refactor(pyqt): migrate from VOICES_INTERNAL to get_metadata API Replace direct VOICES_INTERNAL imports with get_metadata('kokoro').voices from tts_backend_registry in all PyQt modules: - abogen/pyqt/gui.py - abogen/pyqt/predownload_gui.py - abogen/pyqt/voice_formula_gui.py --- abogen/pyqt/gui.py | 4 ++-- abogen/pyqt/predownload_gui.py | 9 +++++---- abogen/pyqt/voice_formula_gui.py | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/abogen/pyqt/gui.py b/abogen/pyqt/gui.py index 866c004..ba8319e 100644 --- a/abogen/pyqt/gui.py +++ b/abogen/pyqt/gui.py @@ -82,11 +82,11 @@ from abogen.constants import ( GITHUB_URL, PROGRAM_DESCRIPTION, LANGUAGE_DESCRIPTIONS, - VOICES_INTERNAL, SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION, COLORS, SUBTITLE_FORMATS, ) +from abogen.tts_backend_registry import get_metadata import threading from abogen.pyqt.voice_formula_gui import VoiceFormulaDialog from abogen.voice_profiles import load_profiles @@ -1873,7 +1873,7 @@ class abogen(QWidget): for pname in load_profiles().keys(): self.voice_combo.addItem(profile_icon, pname, f"profile:{pname}") # re-add voices - for v in VOICES_INTERNAL: + for v in get_metadata("kokoro").voices: icon = QIcon() flag_path = get_resource_path("abogen.assets.flags", f"{v[0]}.png") if flag_path and os.path.exists(flag_path): diff --git a/abogen/pyqt/predownload_gui.py b/abogen/pyqt/predownload_gui.py index 47138f1..cc40933 100644 --- a/abogen/pyqt/predownload_gui.py +++ b/abogen/pyqt/predownload_gui.py @@ -21,7 +21,8 @@ from PyQt6.QtWidgets import ( ) from PyQt6.QtCore import QThread, pyqtSignal -from abogen.constants import COLORS, VOICES_INTERNAL +from abogen.constants import COLORS +from abogen.tts_backend_registry import get_metadata from abogen.spacy_utils import SPACY_MODELS import abogen.hf_tracker @@ -114,7 +115,7 @@ class PreDownloadWorker(QThread): self._voices_success = False return - voice_list = VOICES_INTERNAL + voice_list = get_metadata("kokoro").voices for idx, voice in enumerate(voice_list, start=1): if self._cancelled: self._voices_success = False @@ -462,14 +463,14 @@ class PreDownloadDialog(QDialog): try: from huggingface_hub import try_to_load_from_cache - for voice in VOICES_INTERNAL: + for voice in get_metadata("kokoro").voices: if not try_to_load_from_cache( repo_id="hexgrad/Kokoro-82M", filename=f"voices/{voice}.pt" ): missing.append(voice) except Exception: # If HF missing, report all as missing - return False, list(VOICES_INTERNAL) + return False, list(get_metadata("kokoro").voices) return (len(missing) == 0), missing def _check_kokoro_model(self) -> bool: diff --git a/abogen/pyqt/voice_formula_gui.py b/abogen/pyqt/voice_formula_gui.py index feefb3e..06980ec 100644 --- a/abogen/pyqt/voice_formula_gui.py +++ b/abogen/pyqt/voice_formula_gui.py @@ -28,11 +28,11 @@ from PyQt6.QtWidgets import ( from PyQt6.QtCore import Qt, QTimer, QPoint, QRect, QSize from PyQt6.QtGui import QPixmap, QIcon, QAction from abogen.constants import ( - VOICES_INTERNAL, SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION, LANGUAGE_DESCRIPTIONS, COLORS, ) +from abogen.tts_backend_registry import get_metadata import re import platform from abogen.utils import get_resource_path @@ -179,7 +179,7 @@ class VoiceMixer(QWidget): layout.addWidget(QLabel(name), alignment=Qt.AlignmentFlag.AlignCenter) # Voice name label with gender icon - is_female = self.voice_name in VOICES_INTERNAL and self.voice_name[1] == "f" + is_female = self.voice_name in get_metadata("kokoro").voices and self.voice_name[1] == "f" # Icons layout (flag and gender) icons_layout = QHBoxLayout() @@ -772,7 +772,7 @@ class VoiceFormulaDialog(QDialog): def add_voices(self, initial_state): first_enabled_voice = None - for voice in VOICES_INTERNAL: + for voice in get_metadata("kokoro").voices: language_code = voice[0] # First character is the language code matching_voice = next( (item for item in initial_state if item[0] == voice), None