mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 21:50:28 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
412fb3bc7e | ||
|
|
d9b6081a06 | ||
|
|
674fc14813 | ||
|
|
fa144561fb | ||
|
|
1d27f6fd2e | ||
|
|
a03120d66f | ||
|
|
68b44a3516 | ||
|
|
3bbb88d446 | ||
|
|
a1ccd51ea0 | ||
|
|
13cf6f20a4 | ||
|
|
4311ed51d4 | ||
|
|
9170d9ae3e | ||
|
|
593d21675e | ||
|
|
9aebdecc60 | ||
|
|
290d246e80 | ||
|
|
5ac6e3bb2a | ||
|
|
6bf189312a | ||
|
|
22fdccd78d | ||
|
|
62aeaecf89 | ||
|
|
a7a41fa4f6 | ||
|
|
1ca4d0d5f9 | ||
|
|
e09535fa83 | ||
|
|
0863b25d82 | ||
|
|
b02416e068 | ||
|
|
8daa3cb3b5 | ||
|
|
20f31f82fd | ||
|
|
d5388c62be | ||
|
|
07a2fe2d5b | ||
|
|
58d9073ace | ||
|
|
2cbb2f8aa7 | ||
|
|
f7d8d5ccd8 | ||
|
|
e7d479d846 | ||
|
|
036eed3142 | ||
|
|
0d86d107e9 | ||
|
|
56b336a529 |
+3
-8
@@ -1,8 +1,3 @@
|
||||
- Added voice mixing, allowing multiple voices to be combined into a single “Mixed Voice”, a feature mentioned by @PulsarFTW in #1. Special thanks to @jborza for making this possible through his contributions in #5.
|
||||
- Added profile system to voice mixer, allowing users to create and manage multiple voice profiles.
|
||||
- Improvements in the voice mixer, mostly for organizing controls and enhancing user experience.
|
||||
- Added icons for flags and genders in the GUI, making it easier to identify different options.
|
||||
- Improved the content and chapter extraction process for EPUB files, ensuring better handling of various structures.
|
||||
- Switched to platformdirs for determining the correct desktop path, instead of using old methods.
|
||||
- Fixed preview voices was not using GPU acceleration, which was causing performance issues.
|
||||
- Improvements in code and documentation.
|
||||
- Added new output format: `m4b`, enabling chapter metadata in audiobooks. Special thanks to @jborza for implementing this feature in PR #10.
|
||||
- Better approach for determining the correct configuration folder for Linux and MacOS, using platformdirs. (Fixes Docker issue #12)
|
||||
- Improvements in documentation and code.
|
||||
@@ -85,12 +85,12 @@ Here’s Abogen in action: in this demo, it processes ∼3,000 characters of tex
|
||||
- **Voices**: First letter of the language code (e.g., `a` for American English, `b` for British English, etc.), second letter is for `m` for male and `f` for female.
|
||||
- **Voice mixer**: Create custom voices by mixing different voice models with a profile system.
|
||||
- **Generate subtitles**: `Disabled`, `Sentence`, `Sentence + Comma`, `1 word`, `2 words`, `3 words`, etc. (Represents the number of words in each subtitle entry)
|
||||
- **Output formats**: `.WAV`, `.FLAC`, or `.MP3`
|
||||
- **Output formats**: `.WAV`, `.FLAC`, `.MP3`, and `M4B (with chapters)` (Special thanks to [@jborza](https://github.com/jborza) for chapter support in PR [#10](https://github.com/denizsafak/abogen/pull/10))
|
||||
- **Save location**: `Save next to input file`, `Save to desktop`, or `Choose output folder`
|
||||
- **Chapter Control**: Select specific `chapters` from ePUBs or `chapters + pages` from PDFs.
|
||||
- **Options**:
|
||||
- **Replace single newlines with spaces**: Replaces single newlines with spaces in the text. This is useful for texts that have imaginary line breaks.
|
||||
- **Configure max words per subtitle**: Automatically configures the maximum number of words per subtitle entry.
|
||||
- **Configure max words per subtitle**: Configures the maximum number of words per subtitle entry.
|
||||
- **Create desktop shortcut**: Creates a shortcut on your desktop for easy access.
|
||||
- **Open config.json directory**: Opens the directory where the configuration file is stored.
|
||||
- **Open temp directory**: Opens the temporary directory where converted text files are stored.
|
||||
@@ -103,6 +103,30 @@ Here’s Abogen in action: in this demo, it processes ∼3,000 characters of tex
|
||||
|
||||
With voice mixer, you can create custom voices by mixing different voice models. You can adjust the weight of each voice and save your custom voice as a profile for future use. The voice mixer allows you to create unique and personalized voices. (Huge thanks to [@jborza](https://github.com/jborza) for making this possible through his contributions in [#5](https://github.com/denizsafak/abogen/pull/5))
|
||||
|
||||
## `About Chapter Markers`
|
||||
When you process ePUB or PDF files, abogen converts them into text files stored in your temporary directory. When you click "Edit," you're actually modifying these converted text files. In these text files, you'll notice tags that look like this:
|
||||
|
||||
```
|
||||
<<CHAPTER_MARKER:Chapter Title>>
|
||||
```
|
||||
These are chapter markers. They are automatically added when you process ePUB or PDF files, based on the chapters you select. They serve an important purpose:
|
||||
- Allow you to split the text into separate audio files for each chapter
|
||||
- Save time by letting you reprocess only specific chapters if errors occur, rather than the entire file
|
||||
|
||||
You can manually add these markers to plain text files for the same benefits. Simply include them in your text like this:
|
||||
|
||||
```
|
||||
<<CHAPTER_MARKER:Introduction>>
|
||||
This is the beginning of my text...
|
||||
|
||||
<<CHAPTER_MARKER:Main Content>>
|
||||
Here's another part...
|
||||
```
|
||||
When you process the text file, abogen will detect these markers automatically and ask if you want to save each chapter separately and create a merged version.
|
||||
|
||||

|
||||
|
||||
|
||||
## `Supported Languages`
|
||||
```
|
||||
# 🇺🇸 'a' => American English, 🇬🇧 'b' => British English
|
||||
@@ -131,6 +155,42 @@ audio-samplerate=48000
|
||||
volume-max=200
|
||||
```
|
||||
|
||||
## `Docker Guide`
|
||||
If you want to run Abogen in a Docker container:
|
||||
1) [Download the repository](https://github.com/denizsafak/abogen/archive/refs/heads/main.zip) and extract, or clone it using git.
|
||||
2) Go to `abogen` folder. You should see `Dockerfile` there.
|
||||
3) Open your termminal in that directory and run the following commands:
|
||||
|
||||
```bash
|
||||
# Build the Docker image:
|
||||
docker build --progress plain -t abogen .
|
||||
|
||||
# Note that building the image may take a while.
|
||||
# After building is complete, run the Docker container:
|
||||
|
||||
# Windows
|
||||
docker run --name abogen -v %cd%:/shared -p 5800:5800 -p 5900:5900 --gpus all abogen
|
||||
|
||||
# Linux
|
||||
docker run --name abogen -v $(pwd):/shared -p 5800:5800 -p 5900:5900 --gpus all abogen
|
||||
|
||||
# MacOS
|
||||
docker run --name abogen -v $(pwd):/shared -p 5800:5800 -p 5900:5900 abogen
|
||||
|
||||
# We expose port 5800 for use by a web browser, 5900 if you want to connect with a VNC client.
|
||||
```
|
||||
|
||||
Abogen launches automatically inside the container.
|
||||
- You can access it via a web browser at [http://localhost:5800](http://localhost:5800) or connect to it using a VNC client at `localhost:5900`.
|
||||
- You can use `/shared` directory to share files between your host and the container.
|
||||
- For later use, start it with `docker start abogen` and stop it with `docker stop abogen`.
|
||||
|
||||
Known issues:
|
||||
- Audio preview is not working inside container (ALSA error).
|
||||
- `Open temp directory` and `Open configuration directory` options in settings not working. (Tried pcmanfm, did not work with abogen).
|
||||
|
||||
(Special thanks to [@geo38](https://www.reddit.com/user/geo38/) from Reddit, who provided the Dockerfile and instructions in [this comment](https://www.reddit.com/r/selfhosted/comments/1k8x1yo/comment/mpe0bz8/).)
|
||||
|
||||
## `Similar Projects`
|
||||
Abogen is a standalone project, but it is inspired by and shares some similarities with other projects. Here are a few:
|
||||
- [audiblez](https://github.com/santinic/audiblez): Generate audiobooks from e-books. **(Has CLI and GUI support)**
|
||||
@@ -140,9 +200,9 @@ Abogen is a standalone project, but it is inspired by and shares some similariti
|
||||
|
||||
## `Roadmap`
|
||||
- [ ] Improve PDF support for better text extraction.
|
||||
- [ ] Add chapter metadata for .m4a files using ffmpeg-bin.
|
||||
- [x] Add chapter metadata for .m4a files. (Issue [#9](https://github.com/denizsafak/abogen/issues/9), PR [#10](https://github.com/denizsafak/abogen/pull/10))
|
||||
- [ ] Add support for different languages in GUI.
|
||||
- [x] Add voice formula feature that enables mixing different voice models. #1
|
||||
- [x] Add voice formula feature that enables mixing different voice models. (Issue [#1](https://github.com/denizsafak/abogen/issues/1), PR [#5](https://github.com/denizsafak/abogen/pull/5))
|
||||
- [ ] Add support for kokoro-onnx.
|
||||
- [ ] Add dark mode.
|
||||
|
||||
@@ -160,6 +220,7 @@ If you'd like to modify the code and contribute to development, you can [downloa
|
||||
```bash
|
||||
# Go to the directory where you extracted the repository and run:
|
||||
pip install -e . # Installs the package in editable mode
|
||||
pip install build # Install the build package
|
||||
python -m build # Builds the package in dist folder (optional)
|
||||
abogen # Opens the GUI
|
||||
```
|
||||
|
||||
+1
-1
@@ -221,7 +221,7 @@ if errorlevel 1 (
|
||||
|
||||
:: Install setup requirements
|
||||
echo Installing setup requirements...
|
||||
%PYTHON_CONSOLE_PATH% -m pip install --upgrade setuptools wheel sphinx hatchling --no-warn-script-location
|
||||
%PYTHON_CONSOLE_PATH% -m pip install --upgrade setuptools wheel sphinx hatchling progress --no-warn-script-location
|
||||
if errorlevel 1 (
|
||||
echo Failed to install setup requirements.
|
||||
pause
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
# Special thanks to @geo38 from Reddit, who provided this Dockerfile:
|
||||
# https://www.reddit.com/r/selfhosted/comments/1k8x1yo/comment/mpe0bz8/
|
||||
|
||||
# Use a docker base image that runs a window manager that can be viewed
|
||||
# outside the image with a web browser or VNC client.
|
||||
# https://github.com/jlesage/docker-baseimage-gui
|
||||
FROM jlesage/baseimage-gui:debian-12-v4
|
||||
|
||||
# Load stuff needed by abogen
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y \
|
||||
python3 \
|
||||
python3-venv \
|
||||
python3-pip \
|
||||
python3-pyqt5 \
|
||||
espeak-ng \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# The base image will run /startapp.sh on launch.
|
||||
#
|
||||
# The base image runs that script as user 'app' uid=1000. That user
|
||||
# does not exist in the base image but is created at run time.
|
||||
#
|
||||
# We need to install abogen in python venv (requirement of newer python3).
|
||||
#
|
||||
# The python venv has to be writable by the 'app' user as abogen dynamically
|
||||
# installs python packages, so create the venv as that user
|
||||
#
|
||||
# We intend to share the /shared directory with the host using a bind volume
|
||||
# in order to access any source files and the created files.
|
||||
|
||||
RUN echo '#!/bin/bash\nsource /app/venv/bin/activate\nexec abogen' > /startapp.sh \
|
||||
&& chmod 555 /startapp.sh \
|
||||
&& mkdir /app /shared \
|
||||
&& chown 1000:1000 /app /shared \
|
||||
&& chmod 755 /app /shared
|
||||
USER 1000:1000
|
||||
RUN python3 -m venv /app/venv
|
||||
RUN /bin/bash -c "source /app/venv/bin/activate && pip install abogen"
|
||||
# Change back to user ROOT as the startup scripts inside base image needs it
|
||||
USER root
|
||||
+1
-1
@@ -1 +1 @@
|
||||
1.0.3
|
||||
1.0.5
|
||||
+87
-11
@@ -11,7 +11,8 @@ import soundfile as sf
|
||||
from utils import clean_text
|
||||
from constants import PROGRAM_NAME, LANGUAGE_DESCRIPTIONS, SAMPLE_VOICE_TEXTS
|
||||
from voice_formulas import get_new_voice
|
||||
|
||||
import static_ffmpeg
|
||||
import threading # for efficient waiting
|
||||
|
||||
def get_sample_voice_text(lang_code):
|
||||
return SAMPLE_VOICE_TEXTS.get(lang_code, SAMPLE_VOICE_TEXTS["a"])
|
||||
@@ -128,6 +129,7 @@ class ConversionThread(QThread):
|
||||
use_gpu=True,
|
||||
): # Add use_gpu parameter
|
||||
super().__init__()
|
||||
self._chapter_options_event = threading.Event()
|
||||
self.np = np_module
|
||||
self.KPipeline = kpipeline_class
|
||||
self.file_name = file_name
|
||||
@@ -252,18 +254,12 @@ class ConversionThread(QThread):
|
||||
and not self.chapter_options_set
|
||||
):
|
||||
|
||||
self.waiting_for_user_input = True
|
||||
# Emit signal to main thread to show dialog
|
||||
# Emit signal to main thread and wait
|
||||
self.chapters_detected.emit(total_chapters)
|
||||
|
||||
# Wait for chapter options to be set
|
||||
while self.waiting_for_user_input and not self.cancel_requested:
|
||||
time.sleep(0.1)
|
||||
|
||||
self._chapter_options_event.wait()
|
||||
if self.cancel_requested:
|
||||
self.conversion_finished.emit("Cancelled", None)
|
||||
return
|
||||
|
||||
self.chapter_options_set = True
|
||||
|
||||
# Log all detected chapters at the beginning
|
||||
@@ -339,6 +335,12 @@ class ConversionThread(QThread):
|
||||
# Initialize current segment counter
|
||||
current_segment = 0
|
||||
|
||||
# Initialize chapter times
|
||||
chapters_time = [
|
||||
{"chapter": chapter[0], "start": 0.0, "end": 0.0}
|
||||
for chapter in chapters
|
||||
]
|
||||
|
||||
# Instead of processing the whole text, process by chapter
|
||||
for chapter_idx, (chapter_name, chapter_text) in enumerate(chapters, 1):
|
||||
if total_chapters > 1:
|
||||
@@ -354,6 +356,10 @@ class ConversionThread(QThread):
|
||||
chapter_subtitle_entries = []
|
||||
chapter_current_time = 0.0
|
||||
|
||||
# chapter start time
|
||||
chapter_time = chapters_time[chapter_idx - 1]
|
||||
chapter_time["start"] = current_time
|
||||
|
||||
# Set split_pattern to \n+ which will split on one or more newlines
|
||||
split_pattern = r"\n+"
|
||||
|
||||
@@ -467,6 +473,9 @@ class ConversionThread(QThread):
|
||||
# Update progress more frequently (after each result)
|
||||
self.progress_updated.emit(percent, etr_str)
|
||||
|
||||
# Update chapter end time
|
||||
chapter_time["end"] = current_time
|
||||
|
||||
# Save the individual chapter output if save_chapters_separately is enabled
|
||||
if (
|
||||
save_chapters_separately
|
||||
@@ -483,14 +492,20 @@ class ConversionThread(QThread):
|
||||
|
||||
# Concatenate chapter audio and save
|
||||
chapter_audio = self.np.concatenate(chapter_audio_segments)
|
||||
# If output format is m4b, save chapter as wav
|
||||
chapter_ext = self.output_format
|
||||
chapter_format = self.output_format
|
||||
if self.output_format == "m4b":
|
||||
chapter_ext = "wav"
|
||||
chapter_format = "wav"
|
||||
chapter_out_path = os.path.join(
|
||||
chapters_out_dir, f"{chapter_filename}.{self.output_format}"
|
||||
chapters_out_dir, f"{chapter_filename}.{chapter_ext}"
|
||||
)
|
||||
sf.write(
|
||||
chapter_out_path,
|
||||
chapter_audio,
|
||||
24000,
|
||||
format=self.output_format,
|
||||
format=chapter_format,
|
||||
)
|
||||
|
||||
# Generate .srt subtitle file for chapter if not Disabled
|
||||
@@ -531,6 +546,7 @@ class ConversionThread(QThread):
|
||||
or not self.save_chapters_separately
|
||||
or getattr(self, "merge_chapters_at_end", True)
|
||||
)
|
||||
m4b_picked = False # Ensure m4b_picked is always defined
|
||||
if audio_segments and merge_chapters:
|
||||
self.log_updated.emit("\nFinalizing audio file...\n")
|
||||
audio = self.np.concatenate(audio_segments)
|
||||
@@ -539,7 +555,16 @@ class ConversionThread(QThread):
|
||||
out_filename = f"{base_name}{suffix}.{self.output_format}"
|
||||
out_path = os.path.join(out_dir, out_filename)
|
||||
srt_path = os.path.splitext(out_path)[0] + ".srt"
|
||||
|
||||
# in case the user picked m4b format, we need to change the output format to wav
|
||||
if self.output_format == "m4b":
|
||||
out_path = os.path.splitext(out_path)[0] + ".wav"
|
||||
self.output_format = "wav"
|
||||
m4b_picked = True
|
||||
sf.write(out_path, audio, 24000, format=self.output_format)
|
||||
if m4b_picked:
|
||||
out_path = self._generate_m4b_with_chapters(out_path, chapters_time)
|
||||
|
||||
if self.subtitle_mode != "Disabled":
|
||||
with open(
|
||||
srt_path, "w", encoding="utf-8", errors="replace"
|
||||
@@ -579,6 +604,57 @@ class ConversionThread(QThread):
|
||||
self.save_chapters_separately = options["save_chapters_separately"]
|
||||
self.merge_chapters_at_end = options["merge_chapters_at_end"]
|
||||
self.waiting_for_user_input = False
|
||||
self._chapter_options_event.set()
|
||||
|
||||
def _generate_m4b_with_chapters(self, out_path, chapters_time):
|
||||
# If there is only one chapter, skip adding chapters and just return the wav file path
|
||||
if not chapters_time or len(chapters_time) <= 1:
|
||||
self.log_updated.emit(
|
||||
("File contains only one chapter or no chapters were detected. The audio will be saved as a standard .wav file instead.\n", "red")
|
||||
)
|
||||
return out_path
|
||||
# generate chapters.txt in the same folder as the output file
|
||||
chapters_info_path = os.path.splitext(out_path)[0] + "_chapters.txt"
|
||||
with open(chapters_info_path, "w", encoding="utf-8") as f:
|
||||
f.write(';FFMETADATA1\n') # required header for ffmpeg
|
||||
for chapter in chapters_time:
|
||||
f.write(f"[CHAPTER]\n")
|
||||
f.write(f"TIMEBASE=1/10\n")
|
||||
# use 10th of second for start/end time
|
||||
f.write(f"START={int(chapter["start"]*10)}\n")
|
||||
f.write(f"END={int(chapter["end"]*10)}\n")
|
||||
f.write(f"title={chapter["chapter"]}\n\n")
|
||||
# call ffmpeg to merge the chapters into the output file
|
||||
# ffmpeg installed on first call to add_paths()
|
||||
static_ffmpeg.add_paths()
|
||||
import subprocess
|
||||
out_path_m4b = os.path.splitext(out_path)[0] + ".m4b"
|
||||
# ffmpeg -i input.m4b -i ch.txt -map 0:a -map_chapters 1 output.m4b
|
||||
ffmpeg_cmd = [
|
||||
"ffmpeg",
|
||||
"-i", out_path,
|
||||
"-i", chapters_info_path,
|
||||
"-map", "0:a",
|
||||
"-map_chapters", "1",
|
||||
out_path_m4b
|
||||
]
|
||||
|
||||
self.log_updated.emit("Adding chapters to the audio file...\n")
|
||||
result = subprocess.run(ffmpeg_cmd, capture_output=True, text=True)
|
||||
# Check for errors in the ffmpeg command
|
||||
if result.returncode != 0:
|
||||
self.log_updated.emit((f"FFmpeg error: {result.stderr}", "red"))
|
||||
# Log error but continue with original file
|
||||
self.log_updated.emit(("Falling back to the original audio file without chapters\n", "orange"))
|
||||
return out_path
|
||||
else:
|
||||
self.log_updated.emit(("Successfully added chapters to the audio file.\n", "green"))
|
||||
|
||||
# delete the chapters path and original (wav) file
|
||||
os.remove(chapters_info_path)
|
||||
os.remove(out_path)
|
||||
# the new file is in m4b format - use that for messages
|
||||
return out_path_m4b
|
||||
|
||||
def _srt_time(self, t):
|
||||
"""Helper function to format time for SRT files"""
|
||||
|
||||
+49
-14
@@ -670,13 +670,18 @@ class abogen(QWidget):
|
||||
format_layout = QVBoxLayout()
|
||||
format_layout.addWidget(QLabel("Output Format:", self))
|
||||
self.format_combo = QComboBox(self)
|
||||
self.format_combo.setStyleSheet(
|
||||
"QComboBox { min-height: 20px; padding: 6px 12px; }"
|
||||
self.format_combo.setStyleSheet("QComboBox { min-height: 20px; padding: 6px 12px; }")
|
||||
# Add items with display labels and underlying keys
|
||||
for key, label in [("wav","wav"),("flac","flac"),("mp3","mp3"),("m4b","m4b (with chapters)")]:
|
||||
self.format_combo.addItem(label, key)
|
||||
# Initialize selection by matching saved key
|
||||
idx = self.format_combo.findData(self.selected_format)
|
||||
if idx >= 0:
|
||||
self.format_combo.setCurrentIndex(idx)
|
||||
# Map selection back to key on change
|
||||
self.format_combo.currentIndexChanged.connect(
|
||||
lambda i: self.on_format_changed(self.format_combo.itemData(i))
|
||||
)
|
||||
format_options = ["wav", "flac", "mp3"]
|
||||
self.format_combo.addItems(format_options)
|
||||
self.format_combo.setCurrentText(self.selected_format)
|
||||
self.format_combo.currentTextChanged.connect(self.on_format_changed)
|
||||
format_layout.addWidget(self.format_combo)
|
||||
controls_layout.addLayout(format_layout)
|
||||
# Save location
|
||||
@@ -1417,7 +1422,6 @@ class abogen(QWidget):
|
||||
if self.preview_playing:
|
||||
try:
|
||||
import pygame
|
||||
|
||||
pygame.mixer.music.stop()
|
||||
except Exception:
|
||||
pass
|
||||
@@ -1432,7 +1436,19 @@ class abogen(QWidget):
|
||||
self.voice_combo.setEnabled(False)
|
||||
self.btn_voice_formula_mixer.setEnabled(False) # Disable mixer button
|
||||
self.btn_start.setEnabled(False) # Disable start button during preview
|
||||
# start loading animation
|
||||
|
||||
# Start loading animation - ensure signal connection is always active
|
||||
if hasattr(self, 'loading_movie'):
|
||||
# Disconnect previous connections to avoid multiple connections
|
||||
try:
|
||||
self.loading_movie.frameChanged.disconnect()
|
||||
except TypeError:
|
||||
pass # Ignore error if not connected
|
||||
|
||||
# Reconnect the signal
|
||||
self.loading_movie.frameChanged.connect(
|
||||
lambda: self.btn_preview.setIcon(QIcon(self.loading_movie.currentPixmap()))
|
||||
)
|
||||
self.loading_movie.start()
|
||||
|
||||
def pipeline_loaded_callback(np_module, kpipeline_class, error):
|
||||
@@ -1480,8 +1496,11 @@ class abogen(QWidget):
|
||||
lang = self.selected_voice[0]
|
||||
voice = self.selected_voice
|
||||
|
||||
# use same gpu/cpu logic as in conversion
|
||||
gpu_msg, gpu_ok = get_gpu_acceleration(self.use_gpu)
|
||||
|
||||
self.preview_thread = VoicePreviewThread(
|
||||
np_module, kpipeline_class, lang, voice, speed, self.use_gpu
|
||||
np_module, kpipeline_class, lang, voice, speed, gpu_ok
|
||||
)
|
||||
self.preview_thread.finished.connect(self._play_preview_audio)
|
||||
self.preview_thread.error.connect(self._preview_error)
|
||||
@@ -1545,6 +1564,11 @@ class abogen(QWidget):
|
||||
|
||||
def _preview_cleanup(self):
|
||||
self.preview_playing = False
|
||||
self.loading_movie.stop()
|
||||
try:
|
||||
self.loading_movie.frameChanged.disconnect()
|
||||
except Exception:
|
||||
pass # Ignore error if not connected
|
||||
self.btn_preview.setIcon(self.play_icon)
|
||||
self.btn_preview.setToolTip("Preview selected voice")
|
||||
self.btn_preview.setEnabled(True)
|
||||
@@ -1820,25 +1844,36 @@ class abogen(QWidget):
|
||||
save_config(self.config)
|
||||
|
||||
def show_voice_formula_dialog(self):
|
||||
# If a profile is selected in combo, open mixer with that profile
|
||||
from voice_profiles import load_profiles
|
||||
profiles = load_profiles()
|
||||
initial_state = None
|
||||
selected_profile = self.selected_profile_name
|
||||
if selected_profile:
|
||||
entry = load_profiles().get(selected_profile, {})
|
||||
# support new dict format
|
||||
entry = profiles.get(selected_profile, {})
|
||||
if isinstance(entry, dict):
|
||||
initial_state = entry.get("voices", [])
|
||||
else:
|
||||
initial_state = entry
|
||||
elif self.mixed_voice_state is not None:
|
||||
initial_state = self.mixed_voice_state
|
||||
elif self.selected_voice:
|
||||
# If a single voice is selected, default to first profile if available
|
||||
if profiles:
|
||||
first_profile = next(iter(profiles))
|
||||
entry = profiles[first_profile]
|
||||
selected_profile = first_profile
|
||||
if isinstance(entry, dict):
|
||||
initial_state = entry.get("voices", [])
|
||||
else:
|
||||
initial_state = [(self.selected_voice, 1.0)] if self.selected_voice else []
|
||||
initial_state = entry
|
||||
else:
|
||||
initial_state = []
|
||||
else:
|
||||
initial_state = []
|
||||
dialog = VoiceFormulaDialog(
|
||||
self, initial_state=initial_state, selected_profile=selected_profile
|
||||
)
|
||||
if dialog.exec_() == QDialog.Accepted:
|
||||
# After OK, select the profile in combo and update config
|
||||
if dialog.current_profile:
|
||||
self.selected_profile_name = dialog.current_profile
|
||||
self.config["selected_profile_name"] = dialog.current_profile
|
||||
|
||||
+12
-3
@@ -66,10 +66,19 @@ def get_version():
|
||||
|
||||
# Define config path
|
||||
def get_user_config_path():
|
||||
if os.name == "nt":
|
||||
config_dir = os.path.join(os.environ["APPDATA"], "abogen")
|
||||
from platformdirs import user_config_dir
|
||||
# TODO Config directory is changed for Linux and MacOS. But if old config exists, it will be used.
|
||||
# On non‑Windows, prefer ~/.config/abogen if it already exists
|
||||
if platform.system() != "Windows":
|
||||
custom_dir = os.path.join(os.path.expanduser("~"), ".config", "abogen")
|
||||
if os.path.exists(custom_dir):
|
||||
config_dir = custom_dir
|
||||
else:
|
||||
config_dir = os.path.join(os.path.expanduser("~"), ".config", "abogen")
|
||||
config_dir = user_config_dir("abogen", appauthor=False, roaming=True)
|
||||
else:
|
||||
# Windows and fallback case
|
||||
config_dir = user_config_dir("abogen", appauthor=False, roaming=True)
|
||||
|
||||
os.makedirs(config_dir, exist_ok=True)
|
||||
return os.path.join(config_dir, "config.json")
|
||||
|
||||
|
||||
+66
-27
@@ -475,7 +475,6 @@ class VoiceFormulaDialog(QDialog):
|
||||
|
||||
self.add_voices(initial_state or [])
|
||||
self.update_weighted_sums()
|
||||
self.update_subtitle_combo_enabled()
|
||||
|
||||
# assemble splitter
|
||||
splitter.addWidget(profile_widget)
|
||||
@@ -496,8 +495,6 @@ class VoiceFormulaDialog(QDialog):
|
||||
for vm in self.voice_mixers:
|
||||
vm.spin_box.valueChanged.connect(self.mark_profile_modified)
|
||||
vm.checkbox.stateChanged.connect(lambda *_: self.mark_profile_modified())
|
||||
vm.spin_box.valueChanged.connect(self.update_subtitle_combo_enabled)
|
||||
vm.checkbox.stateChanged.connect(self.update_subtitle_combo_enabled)
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
# Bind Delete key to delete_profile when a profile is selected
|
||||
@@ -682,8 +679,6 @@ class VoiceFormulaDialog(QDialog):
|
||||
voice_mixer.checkbox.stateChanged.connect(
|
||||
lambda *_: self.mark_profile_modified()
|
||||
)
|
||||
voice_mixer.spin_box.valueChanged.connect(self.update_subtitle_combo_enabled)
|
||||
voice_mixer.checkbox.stateChanged.connect(self.update_subtitle_combo_enabled)
|
||||
return voice_mixer
|
||||
|
||||
def handle_voice_checkbox(self, voice_mixer, state):
|
||||
@@ -743,20 +738,6 @@ class VoiceFormulaDialog(QDialog):
|
||||
self.error_label.show()
|
||||
self.weighted_sums_container.hide()
|
||||
|
||||
def update_subtitle_combo_enabled(self):
|
||||
# Only enable subtitle_combo if at least one selected voice is from supported languages
|
||||
selected_langs = set()
|
||||
for vm in self.voice_mixers:
|
||||
if vm.checkbox.isChecked() and vm.spin_box.value() > 0:
|
||||
lang_code = vm.voice_name[0]
|
||||
selected_langs.add(lang_code)
|
||||
enable = any(
|
||||
lang in SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION
|
||||
for lang in selected_langs
|
||||
)
|
||||
if self.subtitle_combo:
|
||||
self.subtitle_combo.setEnabled(enable)
|
||||
|
||||
def disable_voice_by_name(self, voice_name):
|
||||
for mixer in self.voice_mixers:
|
||||
if mixer.voice_name == voice_name:
|
||||
@@ -819,7 +800,6 @@ class VoiceFormulaDialog(QDialog):
|
||||
# sync enabled state
|
||||
vm.toggle_inputs()
|
||||
self.update_weighted_sums()
|
||||
self.update_subtitle_combo_enabled()
|
||||
|
||||
def save_profile_by_name(self, name):
|
||||
profiles = load_profiles()
|
||||
@@ -846,10 +826,10 @@ class VoiceFormulaDialog(QDialog):
|
||||
self.update_weighted_sums()
|
||||
|
||||
def _handle_zero_weight_profiles(self):
|
||||
if self.profile_list.count() <= 1:
|
||||
profiles = load_profiles()
|
||||
if len(profiles) < 1:
|
||||
return False
|
||||
zero = []
|
||||
profiles = load_profiles()
|
||||
for i in range(self.profile_list.count()):
|
||||
item = self.profile_list.item(i)
|
||||
name = item.text().lstrip("*")
|
||||
@@ -868,7 +848,6 @@ class VoiceFormulaDialog(QDialog):
|
||||
if not zero:
|
||||
return False
|
||||
msg = f"{len(zero)} invalid profile(s) with no voices selected or their total weights are 0. They will be ignored and deleted. Do you want to delete?"
|
||||
# Use Delete instead of Ignore
|
||||
reply = QMessageBox.question(
|
||||
self,
|
||||
"Invalid Profiles",
|
||||
@@ -963,8 +942,17 @@ class VoiceFormulaDialog(QDialog):
|
||||
self.update_profile_list_colors()
|
||||
|
||||
def new_profile(self):
|
||||
import re
|
||||
while True:
|
||||
name, ok = QInputDialog.getText(self, "New Profile", "Enter profile name:")
|
||||
if ok and name:
|
||||
if not ok or not name:
|
||||
break
|
||||
name = name.strip() # Remove leading/trailing spaces
|
||||
if not name:
|
||||
continue
|
||||
if not re.match(r'^[\w\- ]+$', name):
|
||||
QMessageBox.warning(self, "Invalid Name", "Profile name can only contain letters, numbers, spaces, underscores, and hyphens.")
|
||||
continue
|
||||
profiles = load_profiles()
|
||||
# Remove 'New profile' placeholder if not persisted in JSON
|
||||
if (
|
||||
@@ -977,7 +965,7 @@ class VoiceFormulaDialog(QDialog):
|
||||
self._profile_dirty.pop("New profile", None)
|
||||
if name in profiles:
|
||||
QMessageBox.warning(self, "Duplicate Name", "Profile already exists.")
|
||||
return
|
||||
continue
|
||||
profiles[name] = {
|
||||
"voices": [],
|
||||
"language": self.language_combo.currentData(),
|
||||
@@ -996,6 +984,7 @@ class VoiceFormulaDialog(QDialog):
|
||||
parent = self.parent()
|
||||
if hasattr(parent, "populate_profiles_in_voice_combo"):
|
||||
parent.populate_profiles_in_voice_combo()
|
||||
break
|
||||
self.update_profile_save_buttons()
|
||||
self.update_profile_list_colors()
|
||||
self.update_weighted_sums()
|
||||
@@ -1182,21 +1171,64 @@ class VoiceFormulaDialog(QDialog):
|
||||
)
|
||||
|
||||
def rename_profile(self, item):
|
||||
name = item.text().lstrip("*")
|
||||
# block if profile has unsaved changes and it's not a virtual New profile
|
||||
if self._profile_dirty.get(name, False) and not (self._virtual_new_profile and name == "New profile"):
|
||||
QMessageBox.warning(
|
||||
self, "Unsaved Changes", "Please save the profile before renaming."
|
||||
)
|
||||
return
|
||||
old = item.text().lstrip("*")
|
||||
import re
|
||||
while True:
|
||||
new, ok = QInputDialog.getText(
|
||||
self, "Rename Profile", f"Profile name:", text=old
|
||||
)
|
||||
if ok and new and new != old:
|
||||
if not ok or not new or new == old:
|
||||
break
|
||||
new = new.strip() # Remove leading/trailing spaces
|
||||
if not new:
|
||||
continue
|
||||
if not re.match(r'^[\w\- ]+$', new):
|
||||
QMessageBox.warning(self, "Invalid Name", "Profile name can only contain letters, numbers, spaces, underscores, and hyphens.")
|
||||
continue
|
||||
|
||||
profiles = load_profiles()
|
||||
if new in profiles:
|
||||
QMessageBox.warning(self, "Duplicate Name", "Profile already exists.")
|
||||
return
|
||||
continue
|
||||
|
||||
# Special case for renaming the virtual "New profile"
|
||||
if self._virtual_new_profile and name == "New profile":
|
||||
# Create the profile with the new name
|
||||
profiles[new] = {
|
||||
"voices": self.get_selected_voices(),
|
||||
"language": self.language_combo.currentData(),
|
||||
}
|
||||
save_profiles(profiles)
|
||||
|
||||
# Update tracking properties
|
||||
self._virtual_new_profile = False
|
||||
self._profile_dirty.pop("New profile", None)
|
||||
self._profile_dirty[new] = False
|
||||
|
||||
# Update the current profile name
|
||||
self.current_profile = new
|
||||
item.setText(new)
|
||||
else:
|
||||
# Standard renaming for regular profiles
|
||||
profiles[new] = profiles.pop(old)
|
||||
save_profiles(profiles)
|
||||
item.setText(new)
|
||||
|
||||
# Update the current profile name if it was renamed
|
||||
if self.current_profile == old:
|
||||
self.current_profile = new
|
||||
|
||||
parent = self.parent()
|
||||
if hasattr(parent, "populate_profiles_in_voice_combo"):
|
||||
parent.populate_profiles_in_voice_combo()
|
||||
break
|
||||
self.update_profile_save_buttons()
|
||||
self.update_profile_list_colors()
|
||||
|
||||
@@ -1227,6 +1259,13 @@ class VoiceFormulaDialog(QDialog):
|
||||
self.update_profile_list_colors()
|
||||
|
||||
def duplicate_profile(self, item):
|
||||
name = item.text().lstrip("*")
|
||||
# block duplicating if profile has unsaved changes
|
||||
if self._profile_dirty.get(name, False):
|
||||
QMessageBox.warning(
|
||||
self, "Unsaved Changes", "Please save the profile before duplicating."
|
||||
)
|
||||
return
|
||||
src = item.text().lstrip("*")
|
||||
profiles = load_profiles()
|
||||
base = f"{src}_duplicate"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
import json
|
||||
from utils import get_user_config_path, get_resource_path
|
||||
from utils import get_user_config_path
|
||||
|
||||
|
||||
def _get_profiles_path():
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
+2
-1
@@ -22,7 +22,8 @@ dependencies = [
|
||||
"soundfile>=0.13.1",
|
||||
"pygame>=2.6.1",
|
||||
"charset_normalizer>=3.4.1",
|
||||
"chardet>=5.2.0"
|
||||
"chardet>=5.2.0",
|
||||
"static_ffmpeg>=2.13"
|
||||
]
|
||||
|
||||
classifiers = [
|
||||
|
||||
Reference in New Issue
Block a user