mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Corrections to code logic
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
from abogen.utils import get_version
|
||||
|
||||
# Program Information
|
||||
PROGRAM_NAME = "abogen"
|
||||
PROGRAM_DESCRIPTION = (
|
||||
"Generate audiobooks from EPUBs, PDFs and text with synchronized captions."
|
||||
)
|
||||
GITHUB_URL = "https://github.com/denizsafak/abogen"
|
||||
VERSION = get_version()
|
||||
@@ -21,7 +21,7 @@ from PyQt5.QtWidgets import (
|
||||
QMenu,
|
||||
)
|
||||
from PyQt5.QtCore import Qt
|
||||
from abogen.utils import clean_text, calculate_text_length
|
||||
from utils import clean_text, calculate_text_length
|
||||
import os
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
from utils import get_version, get_user_config_path
|
||||
|
||||
# Program Information
|
||||
PROGRAM_NAME = "abogen"
|
||||
PROGRAM_DESCRIPTION = (
|
||||
"Generate audiobooks from EPUBs, PDFs and text with synchronized captions."
|
||||
)
|
||||
GITHUB_URL = "https://github.com/denizsafak/abogen"
|
||||
VERSION = get_version()
|
||||
|
||||
# Language description mapping
|
||||
LANGUAGE_DESCRIPTIONS = {
|
||||
"a": "American English",
|
||||
"b": "British English",
|
||||
"e": "Spanish",
|
||||
"f": "French",
|
||||
"h": "Hindi",
|
||||
"i": "Italian",
|
||||
"j": "Japanese",
|
||||
"p": "Brazilian Portuguese",
|
||||
"z": "Mandarin Chinese",
|
||||
}
|
||||
|
||||
# Supported languages for subtitle generation
|
||||
# Currently, only 'a (American English)' and 'b (British English)' are supported for subtitle generation.
|
||||
# This is because tokens that contain timestamps are not generated for other languages in the Kokoro pipeline.
|
||||
# Please refer to: https://github.com/hexgrad/kokoro/blob/6d87f4ae7abc2d14dbc4b3ef2e5f19852e861ac2/kokoro/pipeline.py
|
||||
# 383 English processing (unchanged)
|
||||
# 384 if self.lang_code in 'ab':
|
||||
SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION = [
|
||||
"a",
|
||||
"b",
|
||||
]
|
||||
|
||||
# Voice and sample text constants
|
||||
VOICES_INTERNAL = [
|
||||
"af_alloy",
|
||||
"af_aoede",
|
||||
"af_bella",
|
||||
"af_heart",
|
||||
"af_jessica",
|
||||
"af_kore",
|
||||
"af_nicole",
|
||||
"af_nova",
|
||||
"af_river",
|
||||
"af_sarah",
|
||||
"af_sky",
|
||||
"am_adam",
|
||||
"am_echo",
|
||||
"am_eric",
|
||||
"am_fenrir",
|
||||
"am_liam",
|
||||
"am_michael",
|
||||
"am_onyx",
|
||||
"am_puck",
|
||||
"am_santa",
|
||||
"bf_alice",
|
||||
"bf_emma",
|
||||
"bf_isabella",
|
||||
"bf_lily",
|
||||
"bm_daniel",
|
||||
"bm_fable",
|
||||
"bm_george",
|
||||
"bm_lewis",
|
||||
"ef_dora",
|
||||
"em_alex",
|
||||
"em_santa",
|
||||
"ff_siwis",
|
||||
"hf_alpha",
|
||||
"hf_beta",
|
||||
"hm_omega",
|
||||
"hm_psi",
|
||||
"if_sara",
|
||||
"im_nicola",
|
||||
"jf_alpha",
|
||||
"jf_gongitsune",
|
||||
"jf_nezumi",
|
||||
"jf_tebukuro",
|
||||
"jm_kumo",
|
||||
"pf_dora",
|
||||
"pm_alex",
|
||||
"pm_santa",
|
||||
"zf_xiaobei",
|
||||
"zf_xiaoni",
|
||||
"zf_xiaoxiao",
|
||||
"zf_xiaoyi",
|
||||
"zm_yunjian",
|
||||
"zm_yunxi",
|
||||
"zm_yunxia",
|
||||
"zm_yunyang",
|
||||
]
|
||||
|
||||
# Voice and sample text mapping
|
||||
SAMPLE_VOICE_TEXTS = {
|
||||
"a": "This is a sample of the selected voice.",
|
||||
"b": "This is a sample of the selected voice.",
|
||||
"e": "Este es una muestra de la voz seleccionada.",
|
||||
"f": "Ceci est un exemple de la voix sélectionnée.",
|
||||
"h": "यह चयनित आवाज़ का एक नमूना है।",
|
||||
"i": "Questo è un esempio della voce selezionata.",
|
||||
"j": "これは選択した声のサンプルです。",
|
||||
"p": "Este é um exemplo da voz selecionada.",
|
||||
"z": "这是所选语音的示例。",
|
||||
}
|
||||
|
||||
# flags mapping for voice display
|
||||
FLAGS = {
|
||||
"a": "🇺🇸",
|
||||
"b": "🇬🇧",
|
||||
"e": "🇪🇸",
|
||||
"f": "🇫🇷",
|
||||
"h": "🇮🇳",
|
||||
"i": "🇮🇹",
|
||||
"j": "🇯🇵",
|
||||
"p": "🇧🇷",
|
||||
"z": "🇨🇳",
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import time
|
||||
from PyQt5.QtCore import QThread, pyqtSignal, Qt
|
||||
from PyQt5.QtWidgets import QCheckBox, QVBoxLayout, QDialog, QLabel, QDialogButtonBox
|
||||
import soundfile as sf
|
||||
from abogen.utils import clean_text, SAMPLE_VOICE_TEXTS, LANGUAGE_DESCRIPTIONS
|
||||
from abogen import PROGRAM_NAME
|
||||
from utils import clean_text
|
||||
from constants import PROGRAM_NAME, LANGUAGE_DESCRIPTIONS, SAMPLE_VOICE_TEXTS
|
||||
|
||||
|
||||
def get_sample_voice_text(lang_code):
|
||||
@@ -688,6 +688,7 @@ class PlayAudioThread(QThread):
|
||||
try:
|
||||
import pygame
|
||||
import time as _time
|
||||
|
||||
pygame.mixer.init()
|
||||
pygame.mixer.music.load(self.wav_path)
|
||||
pygame.mixer.music.play()
|
||||
|
||||
+13
-7
@@ -46,7 +46,7 @@ from PyQt5.QtGui import (
|
||||
QColor,
|
||||
QMovie,
|
||||
)
|
||||
from abogen.utils import (
|
||||
from utils import (
|
||||
load_config,
|
||||
save_config,
|
||||
get_gpu_acceleration,
|
||||
@@ -56,14 +56,19 @@ from abogen.utils import (
|
||||
calculate_text_length,
|
||||
get_resource_path,
|
||||
LoadPipelineThread,
|
||||
)
|
||||
from conversion import ConversionThread, VoicePreviewThread, PlayAudioThread
|
||||
from book_handler import HandlerDialog
|
||||
from constants import (
|
||||
PROGRAM_NAME,
|
||||
VERSION,
|
||||
GITHUB_URL,
|
||||
PROGRAM_DESCRIPTION,
|
||||
LANGUAGE_DESCRIPTIONS,
|
||||
FLAGS,
|
||||
VOICES_INTERNAL,
|
||||
SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION,
|
||||
LANGUAGE_DESCRIPTIONS,
|
||||
)
|
||||
from abogen.conversion import ConversionThread, VoicePreviewThread, PlayAudioThread
|
||||
from abogen.book_handler import HandlerDialog
|
||||
from abogen import PROGRAM_NAME, VERSION, GITHUB_URL, PROGRAM_DESCRIPTION
|
||||
from threading import Thread
|
||||
|
||||
# Import ctypes for Windows-specific taskbar icon
|
||||
@@ -1271,6 +1276,7 @@ class abogen(QWidget):
|
||||
if self.preview_playing:
|
||||
try:
|
||||
import pygame
|
||||
|
||||
pygame.mixer.music.stop()
|
||||
except Exception:
|
||||
pass
|
||||
@@ -1470,7 +1476,7 @@ class abogen(QWidget):
|
||||
|
||||
def show_chapter_options_dialog(self, chapter_count):
|
||||
"""Show dialog to ask user about chapter processing options when chapters are detected in a .txt file"""
|
||||
from abogen.conversion import ChapterOptionsDialog
|
||||
from conversion import ChapterOptionsDialog
|
||||
|
||||
dialog = ChapterOptionsDialog(chapter_count, parent=self)
|
||||
dialog.setWindowModality(Qt.ApplicationModal)
|
||||
@@ -1539,7 +1545,7 @@ class abogen(QWidget):
|
||||
|
||||
def reveal_config_in_explorer(self):
|
||||
"""Open the configuration file location in file explorer."""
|
||||
from abogen.utils import get_user_config_path
|
||||
from utils import get_user_config_path
|
||||
|
||||
try:
|
||||
config_path = get_user_config_path()
|
||||
|
||||
+11
-4
@@ -3,9 +3,12 @@ import sys
|
||||
import platform
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from PyQt5.QtGui import QIcon
|
||||
from abogen.gui import abogen
|
||||
from abogen.utils import get_resource_path
|
||||
from abogen import PROGRAM_NAME, VERSION
|
||||
|
||||
# Add the directory to Python path
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__)))
|
||||
from gui import abogen
|
||||
from utils import get_resource_path
|
||||
from constants import PROGRAM_NAME, VERSION
|
||||
|
||||
# Ensure sys.stdout and sys.stderr are valid in GUI mode
|
||||
if sys.stdout is None:
|
||||
@@ -28,7 +31,11 @@ if platform.system() == "Windows":
|
||||
if platform.system() == "Linux":
|
||||
xdg_session = os.environ.get("XDG_SESSION_TYPE", "").lower()
|
||||
desktop = os.environ.get("XDG_CURRENT_DESKTOP", "").lower()
|
||||
if "gnome" in desktop and xdg_session == "wayland" and "QT_QPA_PLATFORM" not in os.environ:
|
||||
if (
|
||||
"gnome" in desktop
|
||||
and xdg_session == "wayland"
|
||||
and "QT_QPA_PLATFORM" not in os.environ
|
||||
):
|
||||
os.environ["QT_QPA_PLATFORM"] = "wayland"
|
||||
|
||||
|
||||
|
||||
+2
-112
@@ -10,114 +10,6 @@ from threading import Thread
|
||||
os.environ["HF_HUB_DISABLE_SYMLINKS_WARNING"] = "1"
|
||||
warnings.filterwarnings("ignore")
|
||||
|
||||
# Language description mapping
|
||||
LANGUAGE_DESCRIPTIONS = {
|
||||
"a": "American English",
|
||||
"b": "British English",
|
||||
"e": "Spanish",
|
||||
"f": "French",
|
||||
"h": "Hindi",
|
||||
"i": "Italian",
|
||||
"j": "Japanese",
|
||||
"p": "Brazilian Portuguese",
|
||||
"z": "Mandarin Chinese",
|
||||
}
|
||||
|
||||
# Supported languages for subtitle generation
|
||||
# Currently, only 'a (American English)' and 'b (British English)' are supported for subtitle generation.
|
||||
# This is because tokens that contain timestamps are not generated for other languages in the Kokoro pipeline.
|
||||
# Please refer to: https://github.com/hexgrad/kokoro/blob/6d87f4ae7abc2d14dbc4b3ef2e5f19852e861ac2/kokoro/pipeline.py
|
||||
# 383 English processing (unchanged)
|
||||
# 384 if self.lang_code in 'ab':
|
||||
SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION = [
|
||||
"a",
|
||||
"b",
|
||||
]
|
||||
|
||||
# Voice and sample text constants
|
||||
VOICES_INTERNAL = [
|
||||
"af_alloy",
|
||||
"af_aoede",
|
||||
"af_bella",
|
||||
"af_heart",
|
||||
"af_jessica",
|
||||
"af_kore",
|
||||
"af_nicole",
|
||||
"af_nova",
|
||||
"af_river",
|
||||
"af_sarah",
|
||||
"af_sky",
|
||||
"am_adam",
|
||||
"am_echo",
|
||||
"am_eric",
|
||||
"am_fenrir",
|
||||
"am_liam",
|
||||
"am_michael",
|
||||
"am_onyx",
|
||||
"am_puck",
|
||||
"am_santa",
|
||||
"bf_alice",
|
||||
"bf_emma",
|
||||
"bf_isabella",
|
||||
"bf_lily",
|
||||
"bm_daniel",
|
||||
"bm_fable",
|
||||
"bm_george",
|
||||
"bm_lewis",
|
||||
"ef_dora",
|
||||
"em_alex",
|
||||
"em_santa",
|
||||
"ff_siwis",
|
||||
"hf_alpha",
|
||||
"hf_beta",
|
||||
"hm_omega",
|
||||
"hm_psi",
|
||||
"if_sara",
|
||||
"im_nicola",
|
||||
"jf_alpha",
|
||||
"jf_gongitsune",
|
||||
"jf_nezumi",
|
||||
"jf_tebukuro",
|
||||
"jm_kumo",
|
||||
"pf_dora",
|
||||
"pm_alex",
|
||||
"pm_santa",
|
||||
"zf_xiaobei",
|
||||
"zf_xiaoni",
|
||||
"zf_xiaoxiao",
|
||||
"zf_xiaoyi",
|
||||
"zm_yunjian",
|
||||
"zm_yunxi",
|
||||
"zm_yunxia",
|
||||
"zm_yunyang",
|
||||
]
|
||||
|
||||
# Voice and sample text mapping
|
||||
SAMPLE_VOICE_TEXTS = {
|
||||
"a": "This is a sample of the selected voice.",
|
||||
"b": "This is a sample of the selected voice.",
|
||||
"e": "Este es una muestra de la voz seleccionada.",
|
||||
"f": "Ceci est un exemple de la voix sélectionnée.",
|
||||
"h": "यह चयनित आवाज़ का एक नमूना है।",
|
||||
"i": "Questo è un esempio della voce selezionata.",
|
||||
"j": "これは選択した声のサンプルです。",
|
||||
"p": "Este é um exemplo da voz selecionada.",
|
||||
"z": "这是所选语音的示例。",
|
||||
}
|
||||
|
||||
# flags mapping for voice display
|
||||
FLAGS = {
|
||||
"a": "🇺🇸",
|
||||
"b": "🇬🇧",
|
||||
"e": "🇪🇸",
|
||||
"f": "🇫🇷",
|
||||
"h": "🇮🇳",
|
||||
"i": "🇮🇹",
|
||||
"j": "🇯🇵",
|
||||
"p": "🇧🇷",
|
||||
"z": "🇨🇳",
|
||||
}
|
||||
|
||||
|
||||
def get_resource_path(package, resource):
|
||||
"""
|
||||
@@ -174,8 +66,6 @@ def get_user_config_path():
|
||||
return os.path.join(config_dir, "config.json")
|
||||
|
||||
|
||||
CONFIG_PATH = get_user_config_path()
|
||||
|
||||
_sleep_procs = {"Darwin": None, "Linux": None} # Store sleep prevention processes
|
||||
|
||||
|
||||
@@ -193,7 +83,7 @@ def clean_text(text):
|
||||
|
||||
def load_config():
|
||||
try:
|
||||
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
|
||||
with open(get_user_config_path(), "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
return {}
|
||||
@@ -201,7 +91,7 @@ def load_config():
|
||||
|
||||
def save_config(config):
|
||||
try:
|
||||
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
|
||||
with open(get_user_config_path(), "w", encoding="utf-8") as f:
|
||||
json.dump(config, f, indent=2)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user