mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56f81ef892 | ||
|
|
968c673e58 | ||
|
|
174ff4232f | ||
|
|
c43659005e | ||
|
|
e3cdd1a9ca | ||
|
|
ed31aaf632 | ||
|
|
0820c40b14 | ||
|
|
0ac2810515 | ||
|
|
1c3fd9e4cf | ||
|
|
e96c19ace6 | ||
|
|
4e678c7e13 | ||
|
|
7ee40d6aca | ||
|
|
55a4f958ee | ||
|
|
6c633e9167 | ||
|
|
566158c132 | ||
|
|
bf43d1799d | ||
|
|
7293b4b826 | ||
|
|
34f2d712b3 | ||
|
|
5ef2612df6 | ||
|
|
290c265d5e | ||
|
|
ed418ac11d | ||
|
|
e6abf2e541 | ||
|
|
f5d95547c5 | ||
|
|
795bd8f1aa | ||
|
|
c4e2a5ef0d | ||
|
|
f57d1994cf | ||
|
|
6482a56479 | ||
|
|
8ddfd01dff | ||
|
|
ac551abd55 | ||
|
|
711858ce2c | ||
|
|
5cca6235e1 | ||
|
|
115ab2a0f2 | ||
|
|
bf5dfddee6 | ||
|
|
23a89a618b | ||
|
|
4ad384dc9f | ||
|
|
5ec06e7d49 | ||
|
|
7f75aa8209 | ||
|
|
cd2e5c9150 | ||
|
|
f477703b1a | ||
|
|
6b3125b624 | ||
|
|
bb5c4204de | ||
|
|
43f5589a9d | ||
|
|
10d3f470e7 | ||
|
|
c72c8e777c | ||
|
|
b51e094af1 | ||
|
|
04844997d5 | ||
|
|
7835211a25 | ||
|
|
6bb6fcb406 | ||
|
|
ad8a6e520e | ||
|
|
fe22fe83b0 | ||
|
|
afbd5203fe | ||
|
|
4b175c7cf2 | ||
|
|
334c0654ca | ||
|
|
42b7979585 |
@@ -0,0 +1 @@
|
|||||||
|
3.12
|
||||||
@@ -1,3 +1,41 @@
|
|||||||
|
# 1.2.5
|
||||||
|
- Added new option: `Override item settings with current selection` in the queue manager. When enabled, all items in the queue will be processed using the current global settings selected in the main GUI, overriding their individual settings. When disabled, each item will retain its own specific settings.
|
||||||
|
- Fixed `Error "Could not load the Qt platform plugin "xcb"` error that occurred in some Linux distributions due to missing `libxcb-cursor0` library by conditionally loading the bundled library when the system version is unavailable, issue mentioned by @bmcgonag in #101.
|
||||||
|
- Fixed the `No module named pip` error that occurred for users who installed Abogen via the [**uv**](https://github.com/astral-sh/uv) installer.
|
||||||
|
- Fixed defaults for `replace_single_newlines` not being applied correctly in some cases.
|
||||||
|
- Fixed `Save chapters separately for queued epubs is ignored`, issue mentioned by @dymas-cz in #109.
|
||||||
|
- Fixed incorrect sentence segmentation when using spaCy, where text would erroneously split after opening parentheses.
|
||||||
|
- Improvements in code and documentation.
|
||||||
|
|
||||||
|
# 1.2.4
|
||||||
|
- **Subtitle generation is now available for all languages!** Abogen now supports subtitle generation for non-English languages using audio duration-based timing. Available modes include `Line`, `Sentence`, and `Sentence + Comma`. (Note: Word-level subtitle modes remain English-only due to Kokoro's timestamp token limitations.)
|
||||||
|
- New option: **"Use spaCy for sentence segmentation"** You can now use [spaCy](https://spacy.io/) to automatically detect sentence boundaries and produce cleaner, more readable subtitles. Quick summary:
|
||||||
|
- **What it does:** Splits text into natural sentences so subtitle entries read better and align more naturally with speech.
|
||||||
|
- **Why this helps:** The previous punctuation-based splitting could break sentences incorrectly at common abbreviations (e.g. "Mr.", "Dr.", "Prof.") or initials, producing wrong subtitle breaks. spaCy avoids those false splits by using linguistic rules to detect real sentence boundaries.
|
||||||
|
- **For Non-English:** spaCy runs **before** audio generation to create better sentence chunks for TTS.
|
||||||
|
- **For English:** spaCy runs **during** subtitle generation to find accurate sentence breaks after TTS.
|
||||||
|
- **Note:** spaCy segmentation is only applied when subtitle mode is `Sentence` or `Sentence + Comma`. When turned off, it falls back to simple punctuation-based splitting.
|
||||||
|
- New option: **Pre-download models and voices for offline use** You can now pre-download all required Kokoro models, voices, and spaCy language models using this option in the settings menu. Allowing you to use Abogen completely offline without any internet connection.
|
||||||
|
- Added support for `.` separator in timestamps (e.g. `HH:MM:SS.ms`) for timestamp-based text files.
|
||||||
|
- Optimized regex compilation and eliminated busy-wait loops.
|
||||||
|
- Possibly fixed `Silent truncation of long paragraphs` issue mentioned in [#91](https://github.com/denizsafak/abogen/issues/91) by [@xklzlxr](https://github.com/xklzlxr)
|
||||||
|
- Fixed unused regex patterns and variable naming conventions.
|
||||||
|
- Improvements in code and documentation.
|
||||||
|
|
||||||
|
# 1.2.3
|
||||||
|
- Same as 1.2.2, re-released to fix an issue with subtitle timing when using timestamp-based text files.
|
||||||
|
|
||||||
|
# 1.2.2
|
||||||
|
- **You can now voice your subtitle files!** Simply add `.srt`, `.ass` or `.vtt` files to generate timed audio. Alternatively, add a text file with timestamps in `HH:MM:SS` or `HH:MM:SS,ms` format to generate audio that matches the timestamps. See [here](https://github.com/denizsafak/abogen?tab=readme-ov-file#about-timestamp-based-text-files) for detailed instructions.
|
||||||
|
- New option: **"Use silent gaps between subtitles"**: Prevents unnecessary audio speed-up by letting speech continue into the silent gaps between subtitles.
|
||||||
|
- New option: **"Subtitle speed adjustment method"**: Choose how to speed up audio when needed:
|
||||||
|
- **TTS Regeneration (better quality):** Re-generates the audio at a faster speed for more natural sound.
|
||||||
|
- **FFmpeg Time-stretch (better speed):** Quickly speeds up the generated audio.
|
||||||
|
- Added support for embedding cover images in M4B files. Abogen now automatically extracts cover images from EPUB and PDF files. You can also manually specify a cover image using the `<<METADATA_COVER_PATH:path>>` tag in your text file. (To prevent MPV from showing the cover image, you can add `audio-display=no` to your MPV config file.)
|
||||||
|
- Fixed `[WinError 1114] A dynamic link library (DLL) initialization routine failed` error on Windows, pre-loading PyTorch DLLs before initializing PyQt6 to avoid DLL initialization errors, mentioned in #98 by @ephr0n.
|
||||||
|
- Potential fix for `CUDA GPU is not available` issue, by ensuring PyTorch is installed correctly with CUDA support on Windows using the installer script.
|
||||||
|
- Improvements in code and documentation.
|
||||||
|
|
||||||
# 1.2.1
|
# 1.2.1
|
||||||
- Upgraded Abogen's interface from PyQt5 to PyQt6 for better compatibility and long-term support.
|
- Upgraded Abogen's interface from PyQt5 to PyQt6 for better compatibility and long-term support.
|
||||||
- Added tooltip indicators in queue manager to display book handler options (`Save chapters separately` and `Merge chapters at the end`) for queued items.
|
- Added tooltip indicators in queue manager to display book handler options (`Save chapters separately` and `Merge chapters at the end`) for queued items.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<a href="https://trendshift.io/repositories/14433" target="_blank"><img src="https://trendshift.io/api/badge/repositories/14433" alt="denizsafak%2Fabogen | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
<a href="https://trendshift.io/repositories/14433" target="_blank"><img src="https://trendshift.io/api/badge/repositories/14433" alt="denizsafak%2Fabogen | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
||||||
|
|
||||||
Abogen is a powerful text-to-speech conversion tool that makes it easy to turn ePub, PDF, text or markdown files into high-quality audio with matching subtitles in seconds. Use it for audiobooks, voiceovers for Instagram, YouTube, TikTok, or any project that needs natural-sounding text-to-speech, using [Kokoro-82M](https://huggingface.co/hexgrad/Kokoro-82M).
|
Abogen is a powerful text-to-speech conversion tool that makes it easy to turn ePub, PDF, text, markdown, or subtitle files into high-quality audio with matching subtitles in seconds. Use it for audiobooks, voiceovers for Instagram, YouTube, TikTok, or any project that needs natural-sounding text-to-speech, using [Kokoro-82M](https://huggingface.co/hexgrad/Kokoro-82M).
|
||||||
|
|
||||||
<img title="Abogen Main" src='https://raw.githubusercontent.com/denizsafak/abogen/refs/heads/main/demo/abogen.png' width="380"> <img title="Abogen Processing" src='https://raw.githubusercontent.com/denizsafak/abogen/refs/heads/main/demo/abogen2.png' width="380">
|
<img title="Abogen Main" src='https://raw.githubusercontent.com/denizsafak/abogen/refs/heads/main/demo/abogen.png' width="380"> <img title="Abogen Processing" src='https://raw.githubusercontent.com/denizsafak/abogen/refs/heads/main/demo/abogen2.png' width="380">
|
||||||
|
|
||||||
@@ -21,10 +21,10 @@ https://github.com/user-attachments/assets/094ba3df-7d66-494a-bc31-0e4b41d0b865
|
|||||||
|
|
||||||
## `How to install?` <a href="https://pypi.org/project/abogen/" target="_blank"><img src="https://img.shields.io/pypi/pyversions/abogen" alt="Abogen Compatible PyPi Python Versions" align="right" style="margin-top:6px;"></a>
|
## `How to install?` <a href="https://pypi.org/project/abogen/" target="_blank"><img src="https://img.shields.io/pypi/pyversions/abogen" alt="Abogen Compatible PyPi Python Versions" align="right" style="margin-top:6px;"></a>
|
||||||
|
|
||||||
### Windows
|
### `Windows`
|
||||||
Go to [espeak-ng latest release](https://github.com/espeak-ng/espeak-ng/releases/latest) download and run the *.msi file.
|
Go to [espeak-ng latest release](https://github.com/espeak-ng/espeak-ng/releases/latest) download and run the *.msi file.
|
||||||
|
|
||||||
#### OPTION 1: Install using script
|
#### <b>OPTION 1: Install using script</b>
|
||||||
1. [Download](https://github.com/denizsafak/abogen/archive/refs/heads/main.zip) the repository
|
1. [Download](https://github.com/denizsafak/abogen/archive/refs/heads/main.zip) the repository
|
||||||
2. Extract the ZIP file
|
2. Extract the ZIP file
|
||||||
3. Run `WINDOWS_INSTALL.bat` by double-clicking it
|
3. Run `WINDOWS_INSTALL.bat` by double-clicking it
|
||||||
@@ -34,7 +34,26 @@ This method handles everything automatically - installing all dependencies inclu
|
|||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> You don't need to install Python separately. The script will install Python automatically.
|
> You don't need to install Python separately. The script will install Python automatically.
|
||||||
|
|
||||||
#### OPTION 2: Install using pip
|
#### <b>OPTION 2: Install using uv</b>
|
||||||
|
First, [install uv](https://docs.astral.sh/uv/getting-started/installation/) if you haven't already.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# For NVIDIA GPUs (CUDA 12.8) - Recommended
|
||||||
|
uv tool install --python 3.12 abogen[cuda]
|
||||||
|
|
||||||
|
# For NVIDIA GPUs (CUDA 12.6) - Older drivers
|
||||||
|
uv tool install --python 3.12 abogen[cuda126]
|
||||||
|
|
||||||
|
# For NVIDIA GPUs (CUDA 13.0) - Newer drivers
|
||||||
|
uv tool install --python 3.12 abogen[cuda130]
|
||||||
|
|
||||||
|
# For AMD GPUs or without GPU (CPU) - ROCm is not available on Windows. Use Linux if you have AMD GPU
|
||||||
|
uv tool install --python 3.12 abogen
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>Alternative: Install using pip (click to expand)</b></summary>
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Create a virtual environment (optional)
|
# Create a virtual environment (optional)
|
||||||
mkdir abogen && cd abogen
|
mkdir abogen && cd abogen
|
||||||
@@ -42,7 +61,8 @@ python -m venv venv
|
|||||||
venv\Scripts\activate
|
venv\Scripts\activate
|
||||||
|
|
||||||
# For NVIDIA GPUs:
|
# For NVIDIA GPUs:
|
||||||
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
|
# We need to use an older version of PyTorch (2.8.0) until this issue is fixed: https://github.com/pytorch/pytorch/issues/166628
|
||||||
|
pip install torch==2.8.0+cu128 torchvision==0.23.0+cu128 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cu128
|
||||||
|
|
||||||
# For AMD GPUs:
|
# For AMD GPUs:
|
||||||
# Not supported yet, because ROCm is not available on Windows. Use Linux if you have AMD GPU.
|
# Not supported yet, because ROCm is not available on Windows. Use Linux if you have AMD GPU.
|
||||||
@@ -51,7 +71,23 @@ pip install torch torchvision torchaudio --index-url https://download.pytorch.or
|
|||||||
pip install abogen
|
pip install abogen
|
||||||
```
|
```
|
||||||
|
|
||||||
### Mac
|
</details>
|
||||||
|
|
||||||
|
### `Mac`
|
||||||
|
|
||||||
|
First, [install uv](https://docs.astral.sh/uv/getting-started/installation/) if you haven't already.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install espeak-ng
|
||||||
|
brew install espeak-ng
|
||||||
|
|
||||||
|
# Install abogen (Automatically handles Silicon Mac/MPS support)
|
||||||
|
uv tool install --python 3.12 abogen
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>Alternative: Install using pip (click to expand)</b></summary>
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Install espeak-ng
|
# Install espeak-ng
|
||||||
brew install espeak-ng
|
brew install espeak-ng
|
||||||
@@ -68,7 +104,29 @@ pip3 install abogen
|
|||||||
# After installing abogen, we need to install Kokoro's development version which includes MPS support.
|
# After installing abogen, we need to install Kokoro's development version which includes MPS support.
|
||||||
pip3 install git+https://github.com/hexgrad/kokoro.git
|
pip3 install git+https://github.com/hexgrad/kokoro.git
|
||||||
```
|
```
|
||||||
### Linux
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
### `Linux`
|
||||||
|
|
||||||
|
First, [install uv](https://docs.astral.sh/uv/getting-started/installation/) if you haven't already.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install espeak-ng
|
||||||
|
sudo apt install espeak-ng # Ubuntu/Debian
|
||||||
|
sudo pacman -S espeak-ng # Arch Linux
|
||||||
|
sudo dnf install espeak-ng # Fedora
|
||||||
|
|
||||||
|
# For NVIDIA GPUs or without GPU (CPU) - No need to include [CUDA] in here.
|
||||||
|
uv tool install --python 3.12 abogen
|
||||||
|
|
||||||
|
# For AMD GPUs (ROCm 6.4)
|
||||||
|
uv tool install --python 3.12 abogen[rocm]
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>Alternative: Install using pip (click to expand)</b></summary>
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Install espeak-ng
|
# Install espeak-ng
|
||||||
sudo apt install espeak-ng # Ubuntu/Debian
|
sudo apt install espeak-ng # Ubuntu/Debian
|
||||||
@@ -91,6 +149,8 @@ pip3 install abogen
|
|||||||
pip3 uninstall torch
|
pip3 uninstall torch
|
||||||
pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.4
|
pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.4
|
||||||
```
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
|
|
||||||
> See [How to fix "CUDA GPU is not available. Using CPU" warning?](#cuda-warning)
|
> See [How to fix "CUDA GPU is not available. Using CPU" warning?](#cuda-warning)
|
||||||
|
|
||||||
@@ -100,12 +160,11 @@ pip3 install --pre torch torchvision torchaudio --index-url https://download.pyt
|
|||||||
|
|
||||||
> See [How to fix "[WinError 1114] A dynamic link library (DLL) initialization routine failed" error?](#WinError-1114)
|
> See [How to fix "[WinError 1114] A dynamic link library (DLL) initialization routine failed" error?](#WinError-1114)
|
||||||
|
|
||||||
> See [How to use "uv" instead of "pip"?](#use-uv-instead-of-pip)
|
|
||||||
|
|
||||||
> Special thanks to [@hg000125](https://github.com/hg000125) for his contribution in [#23](https://github.com/denizsafak/abogen/issues/23). AMD GPU support is possible thanks to his work.
|
> Special thanks to [@hg000125](https://github.com/hg000125) for his contribution in [#23](https://github.com/denizsafak/abogen/issues/23). AMD GPU support is possible thanks to his work.
|
||||||
|
|
||||||
## `How to run?`
|
## `How to run?`
|
||||||
If you installed using pip, you can simply run the following command to start Abogen:
|
|
||||||
|
You can simply run this command to start Abogen:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
abogen
|
abogen
|
||||||
@@ -114,7 +173,7 @@ abogen
|
|||||||
> If you installed Abogen using the Windows installer `(WINDOWS_INSTALL.bat)`, It should have created a shortcut in the same folder, or your desktop. You can run it from there. If you lost the shortcut, Abogen is located in `python_embedded/Scripts/abogen.exe`. You can run it from there directly.
|
> If you installed Abogen using the Windows installer `(WINDOWS_INSTALL.bat)`, It should have created a shortcut in the same folder, or your desktop. You can run it from there. If you lost the shortcut, Abogen is located in `python_embedded/Scripts/abogen.exe`. You can run it from there directly.
|
||||||
|
|
||||||
## `How to use?`
|
## `How to use?`
|
||||||
1) Drag and drop any ePub, PDF, text or markdown file (or use the built-in text editor)
|
1) Drag and drop any ePub, PDF, text, markdown, or subtitle file (or use the built-in text editor)
|
||||||
2) Configure the settings:
|
2) Configure the settings:
|
||||||
- Set speech speed
|
- Set speech speed
|
||||||
- Select a voice (or create a custom voice using voice mixer)
|
- Select a voice (or create a custom voice using voice mixer)
|
||||||
@@ -132,7 +191,7 @@ Here’s Abogen in action: in this demo, it processes ∼3,000 characters of tex
|
|||||||
|
|
||||||
| Options | Description |
|
| Options | Description |
|
||||||
|---------|-------------|
|
|---------|-------------|
|
||||||
| **Input Box** | Drag and drop `ePub`, `PDF`, `.TXT` or `.MD` files (or use built-in text editor) |
|
| **Input Box** | Drag and drop `ePub`, `PDF`, `.TXT`, `.MD`, `.SRT`, `.ASS` or `.VTT` files (or use built-in text editor) |
|
||||||
| **Queue options** | Add multiple files to a queue and process them in batch, with individual settings for each file. See [Queue mode](#queue-mode) for more details. |
|
| **Queue options** | Add multiple files to a queue and process them in batch, with individual settings for each file. See [Queue mode](#queue-mode) for more details. |
|
||||||
| **Speed** | Adjust speech rate from `0.1x` to `2.0x` |
|
| **Speed** | Adjust speech rate from `0.1x` to `2.0x` |
|
||||||
| **Select Voice** | 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. |
|
| **Select Voice** | 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. |
|
||||||
@@ -168,8 +227,12 @@ Here’s Abogen in action: in this demo, it processes ∼3,000 characters of tex
|
|||||||
| **Open config directory** | Opens the directory where the configuration file is stored. |
|
| **Open config directory** | Opens the directory where the configuration file is stored. |
|
||||||
| **Open cache directory** | Opens the cache directory where converted text files are stored. |
|
| **Open cache directory** | Opens the cache directory where converted text files are stored. |
|
||||||
| **Clear cache files** | Deletes cache files created during the conversion or preview. |
|
| **Clear cache files** | Deletes cache files created during the conversion or preview. |
|
||||||
| **Check for updates at startup** | Automatically checks for updates when the program starts. |
|
| **Use silent gaps between subtitles** | Prevents unnecessary audio speed-up by letting speech continue into the silent gaps between subtitle etries. In short, it ignores the end times in subtitle entries and uses the silent space until the beginning of the next subtitle entry. When disabled, it speeds up the audio to fit the exact time interval specified in the subtitle. (for subtitle files). |
|
||||||
|
| **Subtitle speed adjustment method** | Choose how to speed up audio when needed: `TTS Regeneration (better quality)` re-generates the audio at a faster speed, while `FFmpeg Time-stretch (better speed)` quickly speeds up the generated audio. (for subtitle files). |
|
||||||
|
| **Use spaCy for sentence segmentation** | When this option is enabled, Abogen uses [spaCy](https://spacy.io/) to detect sentence boundaries more accurately, instead of using punctuation marks (like periods, question marks, etc.) to split sentences, which could incorrectly cut off phrases like "Mr." or "Dr.". With spaCy, sentences are divided more accurately. For non-English text, spaCy runs **before** audio generation to create sentence chunks. For English text, spaCy runs **during** subtitle generation to improve timing and readability. spaCy is only used when subtitle mode is `Sentence` or `Sentence + Comma`. If you prefer the old punctuation splitting method, you can turn this option off. |
|
||||||
|
| **Pre-download models and voices for offline use** | Opens a window that displays the available models and voices. Click `Download all` button to download all required models and voices, allowing you to use Abogen completely offline without any internet connection. |
|
||||||
| **Disable Kokoro's internet access** | Prevents Kokoro from downloading models or voices from HuggingFace Hub, useful for offline use. |
|
| **Disable Kokoro's internet access** | Prevents Kokoro from downloading models or voices from HuggingFace Hub, useful for offline use. |
|
||||||
|
| **Check for updates at startup** | Automatically checks for updates when the program starts. |
|
||||||
| **Reset to default settings** | Resets all settings to their default values. |
|
| **Reset to default settings** | Resets all settings to their default values. |
|
||||||
|
|
||||||
> Special thanks to [@robmckinnon](https://github.com/robmckinnon) for adding Sentence + Highlighting feature in PR [#65](https://github.com/denizsafak/abogen/pull/65)
|
> Special thanks to [@robmckinnon](https://github.com/robmckinnon) for adding Sentence + Highlighting feature in PR [#65](https://github.com/denizsafak/abogen/pull/65)
|
||||||
@@ -186,8 +249,9 @@ With voice mixer, you can create custom voices by mixing different voice models.
|
|||||||
|
|
||||||
Abogen supports **queue mode**, allowing you to add multiple files to a processing queue. This is useful if you want to convert several files in one batch.
|
Abogen supports **queue mode**, allowing you to add multiple files to a processing queue. This is useful if you want to convert several files in one batch.
|
||||||
|
|
||||||
- You can add text files (`.txt`) directly using the **Add files** button in the Queue Manager. To add PDF, EPUB, or markdown files, use the input box in the main window and click the **Add to Queue** button.
|
- You can add text files (`.txt`) and subtitle files (`.srt`, `.ass`, `.vtt`) directly using the **Add files** button in the Queue Manager or by dragging and dropping them into the queue list. To add PDF, EPUB, or markdown files, use the input box in the main window and click the **Add to Queue** button.
|
||||||
- Each file in the queue keeps the configuration settings that were active when it was added. Changing the main window configuration afterward does **not** affect files already in the queue.
|
- Each file in the queue keeps the configuration settings that were active when it was added. Changing the main window configuration afterward does **not** affect files already in the queue.
|
||||||
|
- You can enable the **Override item settings with current selection** option to force all items in the queue to use the configuration currently selected in the main window, overriding their saved settings.
|
||||||
- You can view each file's configuration by hovering over them.
|
- You can view each file's configuration by hovering over them.
|
||||||
|
|
||||||
Abogen will process each item in the queue automatically, saving outputs as configured.
|
Abogen will process each item in the queue automatically, saving outputs as configured.
|
||||||
@@ -227,7 +291,30 @@ Similar to chapter markers, it is possible to add metadata tags for `M4B` files.
|
|||||||
<<METADATA_ALBUM_ARTIST:Album Artist>>
|
<<METADATA_ALBUM_ARTIST:Album Artist>>
|
||||||
<<METADATA_COMPOSER:Narrator>>
|
<<METADATA_COMPOSER:Narrator>>
|
||||||
<<METADATA_GENRE:Audiobook>>
|
<<METADATA_GENRE:Audiobook>>
|
||||||
|
<<METADATA_COVER_PATH:path/to/cover.jpg>>
|
||||||
```
|
```
|
||||||
|
> Note: `METADATA_COVER_PATH` is used to embed a cover image into the generated M4B file. Abogen automatically extracts the cover from EPUB and PDF files and adds this tag for you.
|
||||||
|
|
||||||
|
## `About Timestamp-based Text Files`
|
||||||
|
Similar to converting subtitle files to audio, Abogen can automatically detect text files that contain timestamps in `HH:MM:SS`, `HH:MM:SS,ms` or `HH:MM:SS.ms` format. When timestamps are found inside your text file, Abogen will ask if you want to use them for audio timing. This is useful for creating timed narrations, scripts, or transcripts where you need exact control over when each segment is spoken.
|
||||||
|
|
||||||
|
Format your text file like this:
|
||||||
|
```
|
||||||
|
00:00:00
|
||||||
|
This is the first segment of text.
|
||||||
|
|
||||||
|
00:00:15
|
||||||
|
This is the second segment, starting at 15 seconds.
|
||||||
|
|
||||||
|
00:00:45
|
||||||
|
And this is the third segment, starting at 45 seconds.
|
||||||
|
```
|
||||||
|
|
||||||
|
**Important notes:**
|
||||||
|
- Timestamps must be in `HH:MM:SS`, `HH:MM:SS,ms` or `HH:MM:SS.ms` format (e.g., `00:05:30` for 5 minutes 30 seconds, or `00:05:30.500` for 5 minutes 30.5 seconds)
|
||||||
|
- Milliseconds are optional and provide precision up to 1/1000th of a second
|
||||||
|
- Text before the first timestamp (if any) will automatically start at `00:00:00`
|
||||||
|
- When using timestamps, the subtitle generation mode setting is ignored
|
||||||
|
|
||||||
## `Supported Languages`
|
## `Supported Languages`
|
||||||
```
|
```
|
||||||
@@ -250,6 +337,7 @@ I highly recommend using [MPV](https://mpv.io/installation/) to play your audio
|
|||||||
# --- MPV Settings ---
|
# --- MPV Settings ---
|
||||||
save-position-on-quit
|
save-position-on-quit
|
||||||
keep-open=yes
|
keep-open=yes
|
||||||
|
audio-display=no
|
||||||
# --- Subtitle ---
|
# --- Subtitle ---
|
||||||
sub-ass-override=no
|
sub-ass-override=no
|
||||||
sub-margin-y=50
|
sub-margin-y=50
|
||||||
@@ -298,6 +386,17 @@ Known issues:
|
|||||||
|
|
||||||
> 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/).
|
> 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/).
|
||||||
|
|
||||||
|
## `🌐 Web Application`
|
||||||
|
|
||||||
|
A web-based version of Abogen has been developed by [@jeremiahsb](https://github.com/jeremiahsb).
|
||||||
|
|
||||||
|
**Access the repository here:** [jeremiahsb/abogen](https://github.com/jeremiahsb/abogen)
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> I intend to merge this implementation into the main repository in the future once existing conflicts are resolved. Until then, please be aware that the web version is maintained independently and may not always be in sync with the latest updates in this repository.
|
||||||
|
|
||||||
|
> Special thanks to [@jeremiahsb](https://github.com/jeremiahsb) for implementing the web app!
|
||||||
|
|
||||||
## `Similar Projects`
|
## `Similar Projects`
|
||||||
Abogen is a standalone project, but it is inspired by and shares some similarities with other projects. Here are a few:
|
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)**
|
- [audiblez](https://github.com/santinic/audiblez): Generate audiobooks from e-books. **(Has CLI and GUI support)**
|
||||||
@@ -345,14 +444,29 @@ This will start Abogen in command-line mode and display detailed error messages.
|
|||||||
<a name="cuda-warning">How to fix "CUDA GPU is not available. Using CPU" warning?</a>
|
<a name="cuda-warning">How to fix "CUDA GPU is not available. Using CPU" warning?</a>
|
||||||
</b></summary>
|
</b></summary>
|
||||||
|
|
||||||
> This message means PyTorch couldn't use your GPU. On Windows, Abogen supports NVIDIA GPUs with CUDA. AMD GPUs are supported only on Linux. Abogen will still run on the CPU, but it will be slower.
|
> This message means PyTorch could not use your GPU and has fallen back to the CPU. On Windows, Abogen only supports NVIDIA GPUs with CUDA. AMD GPUs are not supported on Windows (they are only supported on Linux with ROCm). Abogen will still work on the CPU, but processing will be slower compared to a supported GPU.
|
||||||
>
|
>
|
||||||
> If you have a compatible NVIDIA GPU on Windows and still see this warning:
|
> If you have a compatible NVIDIA GPU on Windows and still see this warning:
|
||||||
> Open your terminal in the Abogen folder (the folder that contains `python_embedded`) and type:
|
> Open your terminal in the Abogen folder (the folder that contains `python_embedded`) and type:
|
||||||
> ```bash
|
> ```bash
|
||||||
> python_embedded\python.exe -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
|
> python_embedded\python.exe -m pip install --force-reinstall torch==2.8.0+cu128 torchvision==0.23.0+cu128 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cu128
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> If this does not resolve the issue and you are using an older NVIDIA GPU that does not support CUDA 12.8, you can try installing an older version of PyTorch that supports your GPU. For example, for CUDA 12.6, run:
|
||||||
|
> ```bash
|
||||||
|
> python_embedded\python.exe -m pip install --force-reinstall torch==2.8.0+cu126 torchvision==0.23.0+cu126 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cu126
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> If you have an AMD GPU, you need to use Linux and follow the Linux/ROCm [instructions](#linux). If you want to keep running on CPU, no action is required, but performance will just be reduced. See [#32](https://github.com/denizsafak/abogen/issues/32) for more details.
|
||||||
|
>
|
||||||
|
> If you used `uv` to install Abogen, you can uninstall and try reinstalling with another CUDA version:
|
||||||
|
> ```bash
|
||||||
|
> uv tool uninstall abogen
|
||||||
|
> # First, try CUDA 13.0 for newer drivers
|
||||||
|
> uv tool install --python 3.12 abogen[cuda130]
|
||||||
|
> # If that doesn't work, try CUDA 12.6 for older drivers
|
||||||
|
> uv tool install --python 3.12 abogen[cuda126]
|
||||||
> ```
|
> ```
|
||||||
> If you have an AMD GPU, use Linux and follow the Linux/ROCm [instructions](#how-to-install-). If you want to keep running on CPU, no action is required, but performance will just be reduced. See [#32](https://github.com/denizsafak/abogen/issues/32) for more details.
|
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
@@ -371,7 +485,7 @@ This will start Abogen in command-line mode and display detailed error messages.
|
|||||||
<a name="no-matching-distribution-found">How to fix "No matching distribution found" error?<a>
|
<a name="no-matching-distribution-found">How to fix "No matching distribution found" error?<a>
|
||||||
</b></summary>
|
</b></summary>
|
||||||
|
|
||||||
> Try installing Abogen on supported Python (3.10 to 3.12) versions. You can use [pyenv](https://github.com/pyenv/pyenv) to manage multiple Python versions easily in Linux. Watch this [video](https://www.youtube.com/watch?v=MVyb-nI4KyI) by NetworkChuck for a quick guide.
|
> Try installing Abogen on supported Python (3.10 to 3.12) versions. I recommend installing with [uv](https://docs.astral.sh/uv/getting-started/installation/). You can also use [pyenv](https://github.com/pyenv/pyenv) to manage multiple Python versions easily on Linux. Watch this [video](https://www.youtube.com/watch?v=MVyb-nI4KyI) by NetworkChuck for a quick guide.
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
@@ -382,7 +496,7 @@ This will start Abogen in command-line mode and display detailed error messages.
|
|||||||
> I faced this error when trying to run Abogen in a virtual Windows machine without GPU support. Here's how I fixed it:
|
> I faced this error when trying to run Abogen in a virtual Windows machine without GPU support. Here's how I fixed it:
|
||||||
> If you installed Abogen using the Windows installer `(WINDOWS_INSTALL.bat)`, go to Abogen's folder (that contains `python_embedded`), open your terminal there and run:
|
> If you installed Abogen using the Windows installer `(WINDOWS_INSTALL.bat)`, go to Abogen's folder (that contains `python_embedded`), open your terminal there and run:
|
||||||
> ```bash
|
> ```bash
|
||||||
> python_embedded\python.exe -m pip install torch==2.8.0 torchaudio==2.8.0 torchvision==0.23.0
|
> python_embedded\python.exe -m pip install --force-reinstall torch==2.8.0+cu128 torchvision==0.23.0+cu128 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cu128
|
||||||
> ```
|
> ```
|
||||||
> If you installed Abogen using pip, open your terminal in the virtual environment and run:
|
> If you installed Abogen using pip, open your terminal in the virtual environment and run:
|
||||||
> ```bash
|
> ```bash
|
||||||
@@ -400,18 +514,6 @@ This will start Abogen in command-line mode and display detailed error messages.
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details><summary><b>
|
|
||||||
<a name="use-uv-instead-of-pip">How to use "uv" instead of "pip"?</a>
|
|
||||||
</b></summary>
|
|
||||||
|
|
||||||
> Abogen needs "pip", because Kokoro uses pip to download voice models from HuggingFace Hub. If you want to use "uv" instead of "pip", you can use the following command to run Abogen:
|
|
||||||
>
|
|
||||||
> ```bash
|
|
||||||
> uvx --with pip abogen
|
|
||||||
> ```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details><summary><b>
|
<details><summary><b>
|
||||||
<a name="use-uv-instead-of-pip">How to uninstall Abogen?</a>
|
<a name="use-uv-instead-of-pip">How to uninstall Abogen?</a>
|
||||||
</b></summary>
|
</b></summary>
|
||||||
@@ -423,6 +525,11 @@ This will start Abogen in command-line mode and display detailed error messages.
|
|||||||
>pip uninstall abogen # uninstalls abogen
|
>pip uninstall abogen # uninstalls abogen
|
||||||
>pip cache purge # removes pip cache
|
>pip cache purge # removes pip cache
|
||||||
>```
|
>```
|
||||||
|
>- If you installed Abogen using uv, type:
|
||||||
|
>```bash
|
||||||
|
>uv tool uninstall abogen # uninstalls abogen
|
||||||
|
>uv cache clear # removes uv cache
|
||||||
|
>```
|
||||||
> - If you installed Abogen using the Windows installer (WINDOWS_INSTALL.bat), just remove the folder that contains Abogen. It installs everything inside `python_embedded` folder, no other directories are created.
|
> - If you installed Abogen using the Windows installer (WINDOWS_INSTALL.bat), just remove the folder that contains Abogen. It installs everything inside `python_embedded` folder, no other directories are created.
|
||||||
> - If you installed espeak-ng, you need to remove it separately.
|
> - If you installed espeak-ng, you need to remove it separately.
|
||||||
|
|
||||||
@@ -430,6 +537,7 @@ This will start Abogen in command-line mode and display detailed error messages.
|
|||||||
|
|
||||||
## `Contributing`
|
## `Contributing`
|
||||||
I welcome contributions! If you have ideas for new features, improvements, or bug fixes, please fork the repository and submit a pull request.
|
I welcome contributions! If you have ideas for new features, improvements, or bug fixes, please fork the repository and submit a pull request.
|
||||||
|
|
||||||
### For developers and contributors
|
### For developers and contributors
|
||||||
If you'd like to modify the code and contribute to development, you can [download the repository](https://github.com/denizsafak/abogen/archive/refs/heads/main.zip), extract it and run the following commands to build **or** install the package:
|
If you'd like to modify the code and contribute to development, you can [download the repository](https://github.com/denizsafak/abogen/archive/refs/heads/main.zip), extract it and run the following commands to build **or** install the package:
|
||||||
```bash
|
```bash
|
||||||
@@ -443,6 +551,7 @@ Feel free to explore the code and make any changes you like.
|
|||||||
|
|
||||||
## `Credits`
|
## `Credits`
|
||||||
- Abogen uses [Kokoro](https://github.com/hexgrad/kokoro) for its high-quality, natural-sounding text-to-speech synthesis. Huge thanks to the Kokoro team for making this possible.
|
- Abogen uses [Kokoro](https://github.com/hexgrad/kokoro) for its high-quality, natural-sounding text-to-speech synthesis. Huge thanks to the Kokoro team for making this possible.
|
||||||
|
- Thanks to the [spaCy](https://spacy.io/) project for its sentence-segmentation tools, which help Abogen produce cleaner, more natural sentence segmentation.
|
||||||
- Thanks to [@wojiushixiaobai](https://github.com/wojiushixiaobai) for [Embedded Python](https://github.com/wojiushixiaobai/Python-Embed-Win64) packages. These modified packages include pip pre-installed, enabling Abogen to function as a standalone application without requiring users to separately install Python in Windows.
|
- Thanks to [@wojiushixiaobai](https://github.com/wojiushixiaobai) for [Embedded Python](https://github.com/wojiushixiaobai/Python-Embed-Win64) packages. These modified packages include pip pre-installed, enabling Abogen to function as a standalone application without requiring users to separately install Python in Windows.
|
||||||
- Thanks to creators of [EbookLib](https://github.com/aerkalov/ebooklib), a Python library for reading and writing ePub files, which is used for extracting text from ePub files.
|
- Thanks to creators of [EbookLib](https://github.com/aerkalov/ebooklib), a Python library for reading and writing ePub files, which is used for extracting text from ePub files.
|
||||||
- Special thanks to the [PyQt](https://www.riverbankcomputing.com/software/pyqt/) team for providing the cross-platform GUI toolkit that powers Abogen's interface.
|
- Special thanks to the [PyQt](https://www.riverbankcomputing.com/software/pyqt/) team for providing the cross-platform GUI toolkit that powers Abogen's interface.
|
||||||
@@ -455,7 +564,7 @@ This project is available under the MIT License - see the [LICENSE](https://gith
|
|||||||
## `Star History`
|
## `Star History`
|
||||||
[](https://www.star-history.com/#denizsafak/abogen&Date)
|
[](https://www.star-history.com/#denizsafak/abogen&Date)
|
||||||
|
|
||||||
> [!IMPORTANT]
|
> [!NOTE]
|
||||||
> Subtitle generation currently works only for English. This is because Kokoro provides timestamp tokens only for English text. If you want subtitles in other languages, please request this feature in the [Kokoro project](https://github.com/hexgrad/kokoro). For more technical details, see [this line](https://github.com/hexgrad/kokoro/blob/6d87f4ae7abc2d14dbc4b3ef2e5f19852e861ac2/kokoro/pipeline.py#L383) in the Kokoro's code.
|
> Abogen supports subtitle generation for all languages. However, word-level subtitle modes (e.g., "1 word", "2 words", "3 words", etc.) are only available for English because [Kokoro provides timestamp tokens only for English text](https://github.com/hexgrad/kokoro/blob/6d87f4ae7abc2d14dbc4b3ef2e5f19852e861ac2/kokoro/pipeline.py#L383). For non-English languages, Abogen uses a duration-based fallback that supports sentence-level and comma-based subtitle modes ("Line", "Sentence", "Sentence + Comma"). If you need word-level subtitles for other languages, please request that feature in the [Kokoro project](https://github.com/hexgrad/kokoro).
|
||||||
|
|
||||||
> Tags: audiobook, kokoro, text-to-speech, TTS, audiobook generator, audiobooks, text to speech, audiobook maker, audiobook creator, audiobook generator, voice-synthesis, text to audio, text to audio converter, text to speech converter, text to speech generator, text to speech software, text to speech app, epub to audio, pdf to audio, markdown to audio, content-creation, media-generation
|
> Tags: audiobook, kokoro, text-to-speech, TTS, audiobook generator, audiobooks, text to speech, audiobook maker, audiobook creator, audiobook generator, voice-synthesis, text to audio, text to audio converter, text to speech converter, text to speech generator, text to speech software, text to speech app, epub to audio, pdf to audio, markdown to audio, subtitle to audio, srt to audio, ass to audio, vtt to audio, webvtt to audio, content-creation, media-generation
|
||||||
|
|||||||
+8
-7
@@ -8,9 +8,6 @@ cd /d "%~dp0"
|
|||||||
:: Japanese: "ja"
|
:: Japanese: "ja"
|
||||||
set MISAKI_LANG=en
|
set MISAKI_LANG=en
|
||||||
|
|
||||||
:: Set PyTorch CUDA version
|
|
||||||
set CUDA_VERSION=128
|
|
||||||
|
|
||||||
:::
|
:::
|
||||||
::: _ ____ ___ ____ _____ _ _
|
::: _ ____ ___ ____ _____ _ _
|
||||||
::: / \ | __ ) / _ \ / ___|| ____| \ | |
|
::: / \ | __ ) / _ \ / ___|| ____| \ | |
|
||||||
@@ -281,8 +278,10 @@ if /I "%IS_NVIDIA%"=="true" (
|
|||||||
for /f %%i in ('%PYTHON_CONSOLE_PATH% -c "from torch.cuda import is_available; print(is_available())"') do set cuda_available=%%i
|
for /f %%i in ('%PYTHON_CONSOLE_PATH% -c "from torch.cuda import is_available; print(is_available())"') do set cuda_available=%%i
|
||||||
|
|
||||||
if "%cuda_available%"=="False" (
|
if "%cuda_available%"=="False" (
|
||||||
echo Installing PyTorch with CUDA %CUDA_VERSION% support...
|
echo "Installing PyTorch with CUDA (12.8) support..."
|
||||||
%PYTHON_CONSOLE_PATH% -m pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu%CUDA_VERSION% --no-warn-script-location
|
:: We need to use an older version of PyTorch (2.8.0) until this issue is fixed: https://github.com/pytorch/pytorch/issues/166628
|
||||||
|
:: Solution mentioned by @mazenemam19 in #99:
|
||||||
|
%PYTHON_CONSOLE_PATH% -m pip install torch==2.8.0+cu128 torchvision==0.23.0+cu128 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cu128 --no-warn-script-location
|
||||||
echo.
|
echo.
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo Failed to install PyTorch.
|
echo Failed to install PyTorch.
|
||||||
@@ -305,8 +304,10 @@ if /I "%IS_NVIDIA%"=="true" (
|
|||||||
if errorlevel 2 (
|
if errorlevel 2 (
|
||||||
echo Skipping PyTorch installation.
|
echo Skipping PyTorch installation.
|
||||||
) else (
|
) else (
|
||||||
echo Installing PyTorch with CUDA %CUDA_VERSION% support...
|
echo "Installing PyTorch with CUDA (12.8) support..."
|
||||||
%PYTHON_CONSOLE_PATH% -m pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu%CUDA_VERSION% --no-warn-script-location
|
:: We need to use an older version of PyTorch (2.8.0) until this issue is fixed: https://github.com/pytorch/pytorch/issues/166628
|
||||||
|
:: Solution mentioned by @mazenemam19 in #99:
|
||||||
|
%PYTHON_CONSOLE_PATH% -m pip install torch==2.8.0+cu128 torchvision==0.23.0+cu128 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cu128 --no-warn-script-location
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo Failed to install PyTorch.
|
echo Failed to install PyTorch.
|
||||||
pause
|
pause
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ RUN apt-get update \
|
|||||||
python3-pip \
|
python3-pip \
|
||||||
python3-pyqt6 \
|
python3-pyqt6 \
|
||||||
espeak-ng \
|
espeak-ng \
|
||||||
|
libxcb-cursor0 \
|
||||||
|
libgl1 \
|
||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
1.2.1
|
1.2.5
|
||||||
+57
-23
@@ -44,6 +44,17 @@ logging.basicConfig(
|
|||||||
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
|
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Pre-compile frequently used regex patterns for better performance
|
||||||
|
_BRACKETED_NUMBERS_PATTERN = re.compile(r"\[\s*\d+\s*\]")
|
||||||
|
_STANDALONE_PAGE_NUMBERS_PATTERN = re.compile(r"^\s*\d+\s*$", re.MULTILINE)
|
||||||
|
_PAGE_NUMBERS_AT_END_PATTERN = re.compile(r"\s+\d+\s*$", re.MULTILINE)
|
||||||
|
_PAGE_NUMBERS_WITH_DASH_PATTERN = re.compile(
|
||||||
|
r"\s+[-–—]\s*\d+\s*[-–—]?\s*$", re.MULTILINE
|
||||||
|
)
|
||||||
|
_HTML_TAG_PATTERN = re.compile(r"<[^>]+>")
|
||||||
|
_LEADING_DASH_PATTERN = re.compile(r"^\s*[-–—]\s*")
|
||||||
|
_LEADING_SIMPLE_DASH_PATTERN = re.compile(r"^\s*-\s*")
|
||||||
|
|
||||||
|
|
||||||
class HandlerDialog(QDialog):
|
class HandlerDialog(QDialog):
|
||||||
# Class variables to remember checkbox states between dialog instances
|
# Class variables to remember checkbox states between dialog instances
|
||||||
@@ -89,6 +100,9 @@ class HandlerDialog(QDialog):
|
|||||||
def __init__(self, book_path, file_type=None, checked_chapters=None, parent=None):
|
def __init__(self, book_path, file_type=None, checked_chapters=None, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
|
# Normalize path
|
||||||
|
book_path = os.path.normpath(os.path.abspath(book_path))
|
||||||
|
|
||||||
# Determine file type if not explicitly provided
|
# Determine file type if not explicitly provided
|
||||||
if file_type:
|
if file_type:
|
||||||
self.file_type = file_type
|
self.file_type = file_type
|
||||||
@@ -374,8 +388,9 @@ class HandlerDialog(QDialog):
|
|||||||
|
|
||||||
# Include replace_single_newlines in cache key since it affects text cleaning
|
# Include replace_single_newlines in cache key since it affects text cleaning
|
||||||
from abogen.utils import load_config
|
from abogen.utils import load_config
|
||||||
|
|
||||||
cfg = load_config()
|
cfg = load_config()
|
||||||
replace_single_newlines = cfg.get("replace_single_newlines", False)
|
replace_single_newlines = cfg.get("replace_single_newlines", True)
|
||||||
|
|
||||||
cache_key = (self.book_path, mod_time, self.file_type, replace_single_newlines)
|
cache_key = (self.book_path, mod_time, self.file_type, replace_single_newlines)
|
||||||
|
|
||||||
@@ -424,19 +439,12 @@ class HandlerDialog(QDialog):
|
|||||||
"""Pre-process all page contents from PDF document"""
|
"""Pre-process all page contents from PDF document"""
|
||||||
for page_num in range(len(self.pdf_doc)):
|
for page_num in range(len(self.pdf_doc)):
|
||||||
text = clean_text(self.pdf_doc[page_num].get_text())
|
text = clean_text(self.pdf_doc[page_num].get_text())
|
||||||
# Remove bracketed numbers (citations, footnotes)
|
# Remove bracketed numbers, page numbers, etc. using pre-compiled patterns
|
||||||
text = re.sub(r"\[\s*\d+\s*\]", "", text)
|
# Combine all regex operations for better performance
|
||||||
|
text = _BRACKETED_NUMBERS_PATTERN.sub("", text)
|
||||||
# Remove standalone page numbers (numbers alone on a line)
|
text = _STANDALONE_PAGE_NUMBERS_PATTERN.sub("", text)
|
||||||
text = re.sub(r"^\s*\d+\s*$", "", text, flags=re.MULTILINE)
|
text = _PAGE_NUMBERS_AT_END_PATTERN.sub("", text)
|
||||||
|
text = _PAGE_NUMBERS_WITH_DASH_PATTERN.sub("", text)
|
||||||
# Remove page numbers at the end of paragraphs
|
|
||||||
# This pattern looks for digits surrounded by whitespace at the end of paragraphs
|
|
||||||
text = re.sub(r"\s+\d+\s*$", "", text, flags=re.MULTILINE)
|
|
||||||
|
|
||||||
# Also remove page numbers followed by a hyphen or dash at paragraph end
|
|
||||||
# (common in headers/footers like "- 42 -")
|
|
||||||
text = re.sub(r"\s+[-–—]\s*\d+\s*[-–—]?\s*$", "", text, flags=re.MULTILINE)
|
|
||||||
|
|
||||||
page_id = f"page_{page_num + 1}"
|
page_id = f"page_{page_num + 1}"
|
||||||
self.content_texts[page_id] = text
|
self.content_texts[page_id] = text
|
||||||
@@ -565,7 +573,7 @@ class HandlerDialog(QDialog):
|
|||||||
text = clean_text(soup.get_text()).strip()
|
text = clean_text(soup.get_text()).strip()
|
||||||
if text:
|
if text:
|
||||||
self.content_texts[doc_href] = text
|
self.content_texts[doc_href] = text
|
||||||
self.content_lengths[doc_href] = len(text)
|
self.content_lengths[doc_href] = calculate_text_length(text)
|
||||||
|
|
||||||
title = None
|
title = None
|
||||||
if soup.title and soup.title.string:
|
if soup.title and soup.title.string:
|
||||||
@@ -888,7 +896,7 @@ class HandlerDialog(QDialog):
|
|||||||
text = clean_text(slice_soup.get_text()).strip()
|
text = clean_text(slice_soup.get_text()).strip()
|
||||||
if text:
|
if text:
|
||||||
self.content_texts[current_src] = text
|
self.content_texts[current_src] = text
|
||||||
self.content_lengths[current_src] = len(text)
|
self.content_lengths[current_src] = calculate_text_length(text)
|
||||||
else:
|
else:
|
||||||
self.content_texts[current_src] = ""
|
self.content_texts[current_src] = ""
|
||||||
self.content_lengths[current_src] = 0
|
self.content_lengths[current_src] = 0
|
||||||
@@ -2011,7 +2019,8 @@ class HandlerDialog(QDialog):
|
|||||||
html_content += "<hr/>"
|
html_content += "<hr/>"
|
||||||
|
|
||||||
if self.book_metadata["description"]:
|
if self.book_metadata["description"]:
|
||||||
desc = re.sub(r"<[^>]+>", "", self.book_metadata["description"])
|
# Use pre-compiled pattern for better performance
|
||||||
|
desc = _HTML_TAG_PATTERN.sub("", self.book_metadata["description"])
|
||||||
html_content += f"<h3>Description:</h3><p>{desc}</p>"
|
html_content += f"<h3>Description:</h3><p>{desc}</p>"
|
||||||
|
|
||||||
if self.file_type == "pdf":
|
if self.file_type == "pdf":
|
||||||
@@ -2211,6 +2220,7 @@ class HandlerDialog(QDialog):
|
|||||||
def _format_metadata_tags(self):
|
def _format_metadata_tags(self):
|
||||||
"""Format metadata tags for insertion at the beginning of the text"""
|
"""Format metadata tags for insertion at the beginning of the text"""
|
||||||
import datetime
|
import datetime
|
||||||
|
from abogen.utils import get_user_cache_path
|
||||||
|
|
||||||
metadata = self.book_metadata
|
metadata = self.book_metadata
|
||||||
filename = os.path.splitext(os.path.basename(self.book_path))[0]
|
filename = os.path.splitext(os.path.basename(self.book_path))[0]
|
||||||
@@ -2231,6 +2241,21 @@ class HandlerDialog(QDialog):
|
|||||||
f"{total_chapters} {'Chapters' if self.file_type == 'epub' else 'Pages'}"
|
f"{total_chapters} {'Chapters' if self.file_type == 'epub' else 'Pages'}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Handle cover image
|
||||||
|
cover_tag = ""
|
||||||
|
if metadata.get("cover_image"):
|
||||||
|
try:
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
cache_dir = get_user_cache_path()
|
||||||
|
cover_path = os.path.join(cache_dir, f"cover_{uuid.uuid4()}.jpg")
|
||||||
|
cover_path = os.path.normpath(cover_path)
|
||||||
|
with open(cover_path, "wb") as f:
|
||||||
|
f.write(metadata["cover_image"])
|
||||||
|
cover_tag = f"<<METADATA_COVER_PATH:{cover_path}>>"
|
||||||
|
except Exception as e:
|
||||||
|
logging.warning(f"Failed to save cover image: {e}")
|
||||||
|
|
||||||
# Format metadata tags
|
# Format metadata tags
|
||||||
metadata_tags = [
|
metadata_tags = [
|
||||||
f"<<METADATA_TITLE:{title}>>",
|
f"<<METADATA_TITLE:{title}>>",
|
||||||
@@ -2242,6 +2267,9 @@ class HandlerDialog(QDialog):
|
|||||||
f"<<METADATA_GENRE:Audiobook>>",
|
f"<<METADATA_GENRE:Audiobook>>",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if cover_tag:
|
||||||
|
metadata_tags.append(cover_tag)
|
||||||
|
|
||||||
return "\n".join(metadata_tags)
|
return "\n".join(metadata_tags)
|
||||||
|
|
||||||
def _get_markdown_selected_text(self):
|
def _get_markdown_selected_text(self):
|
||||||
@@ -2273,8 +2301,8 @@ class HandlerDialog(QDialog):
|
|||||||
text = self.content_texts.get(identifier)
|
text = self.content_texts.get(identifier)
|
||||||
if text and text.strip():
|
if text and text.strip():
|
||||||
title = item.text(0)
|
title = item.text(0)
|
||||||
# Remove leading dashes from title
|
# Remove leading dashes from title using pre-compiled pattern
|
||||||
title = re.sub(r"^\s*[-–—]\s*", "", title).strip()
|
title = _LEADING_DASH_PATTERN.sub("", title).strip()
|
||||||
marker = f"<<CHAPTER_MARKER:{title}>>"
|
marker = f"<<CHAPTER_MARKER:{title}>>"
|
||||||
chapter_texts.append(marker + "\n" + text)
|
chapter_texts.append(marker + "\n" + text)
|
||||||
|
|
||||||
@@ -2308,7 +2336,8 @@ class HandlerDialog(QDialog):
|
|||||||
text = self.content_texts.get(identifier)
|
text = self.content_texts.get(identifier)
|
||||||
if text and text.strip():
|
if text and text.strip():
|
||||||
title = item.text(0)
|
title = item.text(0)
|
||||||
title = re.sub(r"^\s*[-–—]\s*", "", title).strip()
|
# Use pre-compiled pattern for better performance
|
||||||
|
title = _LEADING_DASH_PATTERN.sub("", title).strip()
|
||||||
marker = f"<<CHAPTER_MARKER:{title}>>"
|
marker = f"<<CHAPTER_MARKER:{title}>>"
|
||||||
chapter_texts.append(marker + "\n" + text)
|
chapter_texts.append(marker + "\n" + text)
|
||||||
|
|
||||||
@@ -2378,12 +2407,16 @@ class HandlerDialog(QDialog):
|
|||||||
combined_text += "\n\n" + child_text
|
combined_text += "\n\n" + child_text
|
||||||
included_text_ids.add(child_id)
|
included_text_ids.add(child_id)
|
||||||
if combined_text.strip():
|
if combined_text.strip():
|
||||||
title = re.sub(r"^\s*-\s*", "", parent_title).strip()
|
# Use pre-compiled pattern for better performance
|
||||||
|
title = _LEADING_SIMPLE_DASH_PATTERN.sub(
|
||||||
|
"", parent_title
|
||||||
|
).strip()
|
||||||
marker = f"<<CHAPTER_MARKER:{title}>>"
|
marker = f"<<CHAPTER_MARKER:{title}>>"
|
||||||
section_titles.append((title, marker + "\n" + combined_text))
|
section_titles.append((title, marker + "\n" + combined_text))
|
||||||
included_text_ids.add(parent_id)
|
included_text_ids.add(parent_id)
|
||||||
elif not parent_checked and checked_children:
|
elif not parent_checked and checked_children:
|
||||||
title = re.sub(r"^\s*-\s*", "", parent_title).strip()
|
# Use pre-compiled pattern for better performance
|
||||||
|
title = _LEADING_SIMPLE_DASH_PATTERN.sub("", parent_title).strip()
|
||||||
marker = f"<<CHAPTER_MARKER:{title}>>"
|
marker = f"<<CHAPTER_MARKER:{title}>>"
|
||||||
for idx, (child, child_id) in enumerate(checked_children):
|
for idx, (child, child_id) in enumerate(checked_children):
|
||||||
text = self.content_texts.get(child_id, "")
|
text = self.content_texts.get(child_id, "")
|
||||||
@@ -2403,7 +2436,8 @@ class HandlerDialog(QDialog):
|
|||||||
text = self.content_texts.get(identifier, "")
|
text = self.content_texts.get(identifier, "")
|
||||||
if text:
|
if text:
|
||||||
title = item.text(0)
|
title = item.text(0)
|
||||||
title = re.sub(r"^\s*-\s*", "", title).strip()
|
# Use pre-compiled pattern for better performance
|
||||||
|
title = _LEADING_SIMPLE_DASH_PATTERN.sub("", title).strip()
|
||||||
marker = f"<<CHAPTER_MARKER:{title}>>"
|
marker = f"<<CHAPTER_MARKER:{title}>>"
|
||||||
section_titles.append((title, marker + "\n" + text))
|
section_titles.append((title, marker + "\n" + text))
|
||||||
included_text_ids.add(identifier)
|
included_text_ids.add(identifier)
|
||||||
|
|||||||
+6
-7
@@ -2,9 +2,7 @@ from abogen.utils import get_version
|
|||||||
|
|
||||||
# Program Information
|
# Program Information
|
||||||
PROGRAM_NAME = "abogen"
|
PROGRAM_NAME = "abogen"
|
||||||
PROGRAM_DESCRIPTION = (
|
PROGRAM_DESCRIPTION = "Generate audiobooks from EPUBs, PDFs, text and subtitles with synchronized captions."
|
||||||
"Generate audiobooks from EPUBs, PDFs and text with synchronized captions."
|
|
||||||
)
|
|
||||||
GITHUB_URL = "https://github.com/denizsafak/abogen"
|
GITHUB_URL = "https://github.com/denizsafak/abogen"
|
||||||
VERSION = get_version()
|
VERSION = get_version()
|
||||||
|
|
||||||
@@ -44,6 +42,7 @@ SUPPORTED_SOUND_FORMATS = [
|
|||||||
SUPPORTED_SUBTITLE_FORMATS = [
|
SUPPORTED_SUBTITLE_FORMATS = [
|
||||||
"srt",
|
"srt",
|
||||||
"ass",
|
"ass",
|
||||||
|
"vtt",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Supported input formats
|
# Supported input formats
|
||||||
@@ -51,6 +50,9 @@ SUPPORTED_INPUT_FORMATS = [
|
|||||||
"epub",
|
"epub",
|
||||||
"pdf",
|
"pdf",
|
||||||
"txt",
|
"txt",
|
||||||
|
"srt",
|
||||||
|
"ass",
|
||||||
|
"vtt",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Supported languages for subtitle generation
|
# Supported languages for subtitle generation
|
||||||
@@ -59,10 +61,7 @@ SUPPORTED_INPUT_FORMATS = [
|
|||||||
# Please refer to: https://github.com/hexgrad/kokoro/blob/6d87f4ae7abc2d14dbc4b3ef2e5f19852e861ac2/kokoro/pipeline.py
|
# Please refer to: https://github.com/hexgrad/kokoro/blob/6d87f4ae7abc2d14dbc4b3ef2e5f19852e861ac2/kokoro/pipeline.py
|
||||||
# 383 English processing (unchanged)
|
# 383 English processing (unchanged)
|
||||||
# 384 if self.lang_code in 'ab':
|
# 384 if self.lang_code in 'ab':
|
||||||
SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION = [
|
SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION = list(LANGUAGE_DESCRIPTIONS.keys())
|
||||||
"a",
|
|
||||||
"b",
|
|
||||||
]
|
|
||||||
|
|
||||||
# Voice and sample text constants
|
# Voice and sample text constants
|
||||||
VOICES_INTERNAL = [
|
VOICES_INTERNAL = [
|
||||||
|
|||||||
+1348
-94
File diff suppressed because it is too large
Load Diff
+400
-68
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import platform
|
import platform
|
||||||
import base64
|
import base64
|
||||||
@@ -161,7 +162,7 @@ class InputBox(QLabel):
|
|||||||
self.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
self.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||||
self.setAcceptDrops(True)
|
self.setAcceptDrops(True)
|
||||||
self.setText(
|
self.setText(
|
||||||
"Drag and drop your file here or click to browse.\n(.txt, .epub, .pdf, .md)"
|
"Drag and drop your file here or click to browse.\n(.txt, .epub, .pdf, .md, .srt, .ass, .vtt)"
|
||||||
)
|
)
|
||||||
self.setStyleSheet(
|
self.setStyleSheet(
|
||||||
f"QLabel {{ {self.STYLE_DEFAULT} }} QLabel:hover {{ {self.STYLE_DEFAULT_HOVER} }}"
|
f"QLabel {{ {self.STYLE_DEFAULT} }} QLabel:hover {{ {self.STYLE_DEFAULT_HOVER} }}"
|
||||||
@@ -255,7 +256,7 @@ class InputBox(QLabel):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return str(n)
|
return str(n)
|
||||||
|
|
||||||
doc_extensions = (".epub", ".pdf", ".md", ".markdown")
|
doc_extensions = (".epub", ".pdf", ".md", ".markdown", ".srt", ".ass", ".vtt")
|
||||||
char_source_path = file_path
|
char_source_path = file_path
|
||||||
cached_char_count = None
|
cached_char_count = None
|
||||||
|
|
||||||
@@ -321,11 +322,11 @@ class InputBox(QLabel):
|
|||||||
else: # PDF - always use Pages
|
else: # PDF - always use Pages
|
||||||
self.chapters_btn.setText(f"Pages ({chapter_count})")
|
self.chapters_btn.setText(f"Pages ({chapter_count})")
|
||||||
|
|
||||||
# Hide textbox and show edit only for .txt files
|
# Hide textbox and show edit only for .txt, .srt, .ass, .vtt files
|
||||||
self.textbox_btn.hide()
|
self.textbox_btn.hide()
|
||||||
# Show edit button for txt files directly
|
# Show edit button for txt/subtitle files directly
|
||||||
# Or for epub/pdf files that have generated a temp txt file
|
# Or for epub/pdf files that have generated a temp txt file
|
||||||
should_show_edit = file_path.lower().endswith(".txt")
|
should_show_edit = file_path.lower().endswith((".txt", ".srt", ".ass", ".vtt"))
|
||||||
|
|
||||||
# For epub/pdf files, show edit if we have a selected_file (temp txt)
|
# For epub/pdf files, show edit if we have a selected_file (temp txt)
|
||||||
if (
|
if (
|
||||||
@@ -337,6 +338,12 @@ class InputBox(QLabel):
|
|||||||
|
|
||||||
self.edit_btn.setVisible(should_show_edit)
|
self.edit_btn.setVisible(should_show_edit)
|
||||||
self.go_to_folder_btn.show()
|
self.go_to_folder_btn.show()
|
||||||
|
|
||||||
|
# Disable subtitle generation for subtitle input files
|
||||||
|
is_subtitle_input = file_path.lower().endswith((".srt", ".ass", ".vtt"))
|
||||||
|
if hasattr(window, "subtitle_combo"):
|
||||||
|
window.subtitle_combo.setEnabled(not is_subtitle_input)
|
||||||
|
|
||||||
# Enable add to queue button only when file is accepted (input box is green)
|
# Enable add to queue button only when file is accepted (input box is green)
|
||||||
self.resizeEvent(None)
|
self.resizeEvent(None)
|
||||||
if hasattr(window, "btn_add_to_queue"):
|
if hasattr(window, "btn_add_to_queue"):
|
||||||
@@ -367,7 +374,7 @@ class InputBox(QLabel):
|
|||||||
self.window().save_chapters_separately = None
|
self.window().save_chapters_separately = None
|
||||||
self.window().merge_chapters_at_end = None
|
self.window().merge_chapters_at_end = None
|
||||||
self.setText(
|
self.setText(
|
||||||
"Drag and drop your file here or click to browse.\n(.txt, .epub, .pdf, .md)"
|
"Drag and drop your file here or click to browse.\n(.txt, .epub, .pdf, .md, .srt, .ass, .vtt)"
|
||||||
)
|
)
|
||||||
self.setStyleSheet(
|
self.setStyleSheet(
|
||||||
f"QLabel {{ {self.STYLE_DEFAULT} }} QLabel:hover {{ {self.STYLE_DEFAULT_HOVER} }}"
|
f"QLabel {{ {self.STYLE_DEFAULT} }} QLabel:hover {{ {self.STYLE_DEFAULT_HOVER} }}"
|
||||||
@@ -379,9 +386,21 @@ class InputBox(QLabel):
|
|||||||
self.textbox_btn.show()
|
self.textbox_btn.show()
|
||||||
self.edit_btn.hide()
|
self.edit_btn.hide()
|
||||||
self.go_to_folder_btn.hide()
|
self.go_to_folder_btn.hide()
|
||||||
|
|
||||||
|
# Re-enable subtitle and replace newlines controls when cleared
|
||||||
|
window = self.window()
|
||||||
|
if hasattr(window, "subtitle_combo"):
|
||||||
|
# Only enable if language supports it
|
||||||
|
current_lang = getattr(window, "selected_lang", "a")
|
||||||
|
window.subtitle_combo.setEnabled(
|
||||||
|
current_lang in SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION
|
||||||
|
)
|
||||||
|
if hasattr(window, "replace_newlines_combo"):
|
||||||
|
window.replace_newlines_combo.setEnabled(True)
|
||||||
|
|
||||||
# Disable add to queue button when input is cleared
|
# Disable add to queue button when input is cleared
|
||||||
if hasattr(self.window(), "btn_add_to_queue"):
|
if hasattr(window, "btn_add_to_queue"):
|
||||||
self.window().btn_add_to_queue.setEnabled(False)
|
window.btn_add_to_queue.setEnabled(False)
|
||||||
# Reset the input_box_cleared_by_queue flag after setting file info
|
# Reset the input_box_cleared_by_queue flag after setting file info
|
||||||
if hasattr(self.window(), "input_box_cleared_by_queue"):
|
if hasattr(self.window(), "input_box_cleared_by_queue"):
|
||||||
self.window().input_box_cleared_by_queue = True
|
self.window().input_box_cleared_by_queue = True
|
||||||
@@ -407,6 +426,7 @@ class InputBox(QLabel):
|
|||||||
or ext.endswith(".epub")
|
or ext.endswith(".epub")
|
||||||
or ext.endswith(".pdf")
|
or ext.endswith(".pdf")
|
||||||
or ext.endswith((".md", ".markdown"))
|
or ext.endswith((".md", ".markdown"))
|
||||||
|
or ext.endswith((".srt", ".ass", ".vtt"))
|
||||||
):
|
):
|
||||||
event.acceptProposedAction()
|
event.acceptProposedAction()
|
||||||
# Set hover style based on current state
|
# Set hover style based on current state
|
||||||
@@ -460,12 +480,20 @@ class InputBox(QLabel):
|
|||||||
file_path.lower().endswith(".epub")
|
file_path.lower().endswith(".epub")
|
||||||
or file_path.lower().endswith(".pdf")
|
or file_path.lower().endswith(".pdf")
|
||||||
or file_path.lower().endswith((".md", ".markdown"))
|
or file_path.lower().endswith((".md", ".markdown"))
|
||||||
|
or file_path.lower().endswith((".srt", ".ass", ".vtt"))
|
||||||
):
|
):
|
||||||
# Determine file type
|
# Determine file type
|
||||||
if file_path.lower().endswith(".epub"):
|
if file_path.lower().endswith(".epub"):
|
||||||
file_type = "epub"
|
file_type = "epub"
|
||||||
elif file_path.lower().endswith(".pdf"):
|
elif file_path.lower().endswith(".pdf"):
|
||||||
file_type = "pdf"
|
file_type = "pdf"
|
||||||
|
elif file_path.lower().endswith((".srt", ".ass", ".vtt")):
|
||||||
|
# For subtitle files, treat them like txt files (direct processing)
|
||||||
|
win.selected_file, win.selected_file_type = file_path, "txt"
|
||||||
|
win.displayed_file_path = file_path
|
||||||
|
self.set_file_info(file_path)
|
||||||
|
event.acceptProposedAction()
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
file_type = "markdown"
|
file_type = "markdown"
|
||||||
|
|
||||||
@@ -477,7 +505,9 @@ class InputBox(QLabel):
|
|||||||
)
|
)
|
||||||
event.acceptProposedAction()
|
event.acceptProposedAction()
|
||||||
else:
|
else:
|
||||||
self.set_error("Please drop a .txt, .epub, .pdf, or .md file.")
|
self.set_error(
|
||||||
|
"Please drop a .txt, .epub, .pdf, .md, .srt, .ass, or .vtt file."
|
||||||
|
)
|
||||||
event.ignore()
|
event.ignore()
|
||||||
else:
|
else:
|
||||||
event.ignore()
|
event.ignore()
|
||||||
@@ -795,7 +825,10 @@ class abogen(QWidget):
|
|||||||
self.use_gpu = self.config.get(
|
self.use_gpu = self.config.get(
|
||||||
"use_gpu", True # Load GPU setting with default True
|
"use_gpu", True # Load GPU setting with default True
|
||||||
)
|
)
|
||||||
self.replace_single_newlines = self.config.get("replace_single_newlines", False)
|
self.replace_single_newlines = self.config.get("replace_single_newlines", True)
|
||||||
|
self.use_silent_gaps = self.config.get("use_silent_gaps", True)
|
||||||
|
self.subtitle_speed_method = self.config.get("subtitle_speed_method", "tts")
|
||||||
|
self.use_spacy_segmentation = self.config.get("use_spacy_segmentation", True)
|
||||||
self._pending_close_event = None
|
self._pending_close_event = None
|
||||||
self.gpu_ok = False # Initialize GPU availability status
|
self.gpu_ok = False # Initialize GPU availability status
|
||||||
|
|
||||||
@@ -1031,9 +1064,6 @@ class abogen(QWidget):
|
|||||||
)
|
)
|
||||||
self.subtitle_combo.setCurrentText(self.subtitle_mode)
|
self.subtitle_combo.setCurrentText(self.subtitle_mode)
|
||||||
self.subtitle_combo.currentTextChanged.connect(self.on_subtitle_mode_changed)
|
self.subtitle_combo.currentTextChanged.connect(self.on_subtitle_mode_changed)
|
||||||
# Enable/disable subtitle options based on selected language (profile or voice)
|
|
||||||
enable = self.selected_lang in SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION
|
|
||||||
self.subtitle_combo.setEnabled(enable)
|
|
||||||
subtitle_layout.addWidget(self.subtitle_combo)
|
subtitle_layout.addWidget(self.subtitle_combo)
|
||||||
controls_layout.addLayout(subtitle_layout)
|
controls_layout.addLayout(subtitle_layout)
|
||||||
|
|
||||||
@@ -1115,10 +1145,10 @@ class abogen(QWidget):
|
|||||||
except Exception:
|
except Exception:
|
||||||
# Fail-safe: don't crash UI if model manipulation isn't supported on some platforms
|
# Fail-safe: don't crash UI if model manipulation isn't supported on some platforms
|
||||||
pass
|
pass
|
||||||
# Enable/disable subtitle format based on selected language
|
|
||||||
self.subtitle_format_combo.setEnabled(
|
# Enable/disable subtitle options based on selected language (profile or voice)
|
||||||
self.selected_lang in SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION
|
self.update_subtitle_options_availability()
|
||||||
)
|
|
||||||
controls_layout.addLayout(subtitle_format_layout)
|
controls_layout.addLayout(subtitle_format_layout)
|
||||||
|
|
||||||
# Replace single newlines dropdown (acts like checkbox)
|
# Replace single newlines dropdown (acts like checkbox)
|
||||||
@@ -1291,7 +1321,10 @@ class abogen(QWidget):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
file_path, _ = QFileDialog.getOpenFileName(
|
file_path, _ = QFileDialog.getOpenFileName(
|
||||||
self, "Select File", "", "Supported Files (*.txt *.epub *.pdf *.md)"
|
self,
|
||||||
|
"Select File",
|
||||||
|
"",
|
||||||
|
"Supported Files (*.txt *.epub *.pdf *.md *.srt *.ass *.vtt)",
|
||||||
)
|
)
|
||||||
if not file_path:
|
if not file_path:
|
||||||
return
|
return
|
||||||
@@ -1312,6 +1345,11 @@ class abogen(QWidget):
|
|||||||
# Don't set file info immediately, open_book_file will handle it after dialog is accepted
|
# Don't set file info immediately, open_book_file will handle it after dialog is accepted
|
||||||
if not self.open_book_file(file_path):
|
if not self.open_book_file(file_path):
|
||||||
return
|
return
|
||||||
|
elif file_path.lower().endswith((".srt", ".ass", ".vtt")):
|
||||||
|
# Handle subtitle files like text files
|
||||||
|
self.selected_file, self.selected_file_type = file_path, "txt"
|
||||||
|
self.displayed_file_path = file_path
|
||||||
|
self.input_box.set_file_info(file_path)
|
||||||
else:
|
else:
|
||||||
self.selected_file, self.selected_file_type = file_path, "txt"
|
self.selected_file, self.selected_file_type = file_path, "txt"
|
||||||
self.displayed_file_path = (
|
self.displayed_file_path = (
|
||||||
@@ -1551,19 +1589,69 @@ class abogen(QWidget):
|
|||||||
self.config["speed"] = s
|
self.config["speed"] = s
|
||||||
save_config(self.config)
|
save_config(self.config)
|
||||||
|
|
||||||
|
def update_subtitle_options_availability(self):
|
||||||
|
"""
|
||||||
|
Update the enabled state of subtitle options based on the selected language.
|
||||||
|
For non-English languages, only sentence-based and line-based modes are supported.
|
||||||
|
"""
|
||||||
|
# Check if current file is a subtitle file
|
||||||
|
is_subtitle_input = False
|
||||||
|
if self.selected_file and self.selected_file.lower().endswith(
|
||||||
|
(".srt", ".ass", ".vtt")
|
||||||
|
):
|
||||||
|
is_subtitle_input = True
|
||||||
|
|
||||||
|
if self.selected_lang not in SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION:
|
||||||
|
self.subtitle_combo.setEnabled(False)
|
||||||
|
self.subtitle_format_combo.setEnabled(False)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Only enable subtitle_combo if it's NOT a subtitle input
|
||||||
|
self.subtitle_combo.setEnabled(not is_subtitle_input)
|
||||||
|
self.subtitle_format_combo.setEnabled(True)
|
||||||
|
|
||||||
|
is_english = self.selected_lang in ["a", "b"]
|
||||||
|
|
||||||
|
# Items to keep enabled for non-English
|
||||||
|
allowed_modes = ["Disabled", "Line", "Sentence", "Sentence + Comma"]
|
||||||
|
|
||||||
|
model = self.subtitle_combo.model()
|
||||||
|
for i in range(self.subtitle_combo.count()):
|
||||||
|
text = self.subtitle_combo.itemText(i)
|
||||||
|
item = model.item(i)
|
||||||
|
if not item:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if is_english:
|
||||||
|
item.setEnabled(True)
|
||||||
|
else:
|
||||||
|
if text in allowed_modes:
|
||||||
|
item.setEnabled(True)
|
||||||
|
else:
|
||||||
|
item.setEnabled(False)
|
||||||
|
|
||||||
|
# If current selection is disabled, switch to a valid one
|
||||||
|
current_text = self.subtitle_combo.currentText()
|
||||||
|
current_idx = self.subtitle_combo.currentIndex()
|
||||||
|
current_item = model.item(current_idx)
|
||||||
|
|
||||||
|
if current_item and not current_item.isEnabled():
|
||||||
|
# Switch to "Sentence" if available, else "Disabled"
|
||||||
|
sentence_idx = self.subtitle_combo.findText("Sentence")
|
||||||
|
if sentence_idx >= 0:
|
||||||
|
self.subtitle_combo.setCurrentIndex(sentence_idx)
|
||||||
|
else:
|
||||||
|
self.subtitle_combo.setCurrentIndex(0) # Disabled
|
||||||
|
|
||||||
|
self.subtitle_mode = self.subtitle_combo.currentText()
|
||||||
|
|
||||||
def on_voice_changed(self, index):
|
def on_voice_changed(self, index):
|
||||||
voice = self.voice_combo.itemData(index)
|
voice = self.voice_combo.itemData(index)
|
||||||
self.selected_voice, self.selected_lang = voice, voice[0]
|
self.selected_voice, self.selected_lang = voice, voice[0]
|
||||||
self.config["selected_voice"] = voice
|
self.config["selected_voice"] = voice
|
||||||
save_config(self.config)
|
save_config(self.config)
|
||||||
# Enable/disable subtitle options based on language
|
# Enable/disable subtitle options based on language
|
||||||
if self.selected_lang in SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION:
|
self.update_subtitle_options_availability()
|
||||||
self.subtitle_combo.setEnabled(True)
|
|
||||||
self.subtitle_format_combo.setEnabled(True)
|
|
||||||
self.subtitle_mode = self.subtitle_combo.currentText()
|
|
||||||
else:
|
|
||||||
self.subtitle_combo.setEnabled(False)
|
|
||||||
self.subtitle_format_combo.setEnabled(False)
|
|
||||||
|
|
||||||
def on_voice_combo_changed(self, index):
|
def on_voice_combo_changed(self, index):
|
||||||
data = self.voice_combo.itemData(index)
|
data = self.voice_combo.itemData(index)
|
||||||
@@ -1585,12 +1673,7 @@ class abogen(QWidget):
|
|||||||
self.config.pop("selected_voice", None)
|
self.config.pop("selected_voice", None)
|
||||||
save_config(self.config)
|
save_config(self.config)
|
||||||
# enable subtitles based on profile language
|
# enable subtitles based on profile language
|
||||||
self.subtitle_combo.setEnabled(
|
self.update_subtitle_options_availability()
|
||||||
self.selected_lang in SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION
|
|
||||||
)
|
|
||||||
self.subtitle_format_combo.setEnabled(
|
|
||||||
self.selected_lang in SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
self.mixed_voice_state = None
|
self.mixed_voice_state = None
|
||||||
self.selected_profile_name = None
|
self.selected_profile_name = None
|
||||||
@@ -1599,13 +1682,7 @@ class abogen(QWidget):
|
|||||||
if "selected_profile_name" in self.config:
|
if "selected_profile_name" in self.config:
|
||||||
del self.config["selected_profile_name"]
|
del self.config["selected_profile_name"]
|
||||||
save_config(self.config)
|
save_config(self.config)
|
||||||
if self.selected_lang in SUPPORTED_LANGUAGES_FOR_SUBTITLE_GENERATION:
|
self.update_subtitle_options_availability()
|
||||||
self.subtitle_combo.setEnabled(True)
|
|
||||||
self.subtitle_format_combo.setEnabled(True)
|
|
||||||
self.subtitle_mode = self.subtitle_combo.currentText()
|
|
||||||
else:
|
|
||||||
self.subtitle_combo.setEnabled(False)
|
|
||||||
self.subtitle_format_combo.setEnabled(False)
|
|
||||||
|
|
||||||
def update_subtitle_combo_for_profile(self, profile_name):
|
def update_subtitle_combo_for_profile(self, profile_name):
|
||||||
from abogen.voice_profiles import load_profiles
|
from abogen.voice_profiles import load_profiles
|
||||||
@@ -1817,6 +1894,8 @@ class abogen(QWidget):
|
|||||||
output_format=self.selected_format,
|
output_format=self.selected_format,
|
||||||
total_char_count=self.char_count,
|
total_char_count=self.char_count,
|
||||||
replace_single_newlines=self.replace_single_newlines,
|
replace_single_newlines=self.replace_single_newlines,
|
||||||
|
use_silent_gaps=self.use_silent_gaps,
|
||||||
|
subtitle_speed_method=self.subtitle_speed_method,
|
||||||
save_base_path=save_base_path,
|
save_base_path=save_base_path,
|
||||||
save_chapters_separately=getattr(self, "save_chapters_separately", None),
|
save_chapters_separately=getattr(self, "save_chapters_separately", None),
|
||||||
merge_chapters_at_end=getattr(self, "merge_chapters_at_end", None),
|
merge_chapters_at_end=getattr(self, "merge_chapters_at_end", None),
|
||||||
@@ -1833,7 +1912,7 @@ class abogen(QWidget):
|
|||||||
and queued_item.output_folder == item_queue.output_folder
|
and queued_item.output_folder == item_queue.output_folder
|
||||||
and queued_item.subtitle_mode == item_queue.subtitle_mode
|
and queued_item.subtitle_mode == item_queue.subtitle_mode
|
||||||
and queued_item.output_format == item_queue.output_format
|
and queued_item.output_format == item_queue.output_format
|
||||||
and getattr(queued_item, "replace_single_newlines", False)
|
and getattr(queued_item, "replace_single_newlines", True)
|
||||||
== item_queue.replace_single_newlines
|
== item_queue.replace_single_newlines
|
||||||
and getattr(queued_item, "save_base_path", None)
|
and getattr(queued_item, "save_base_path", None)
|
||||||
== item_queue.save_base_path
|
== item_queue.save_base_path
|
||||||
@@ -1873,6 +1952,11 @@ class abogen(QWidget):
|
|||||||
dialog = QueueManager(self, self.queued_items)
|
dialog = QueueManager(self, self.queued_items)
|
||||||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||||
self.queued_items = dialog.get_queue()
|
self.queued_items = dialog.get_queue()
|
||||||
|
|
||||||
|
# Reload config to capture the new "Override" setting
|
||||||
|
# The QueueManager writes to disk, so we must refresh our local copy
|
||||||
|
self.config = load_config()
|
||||||
|
|
||||||
# re-enable/disable buttons based on queue state
|
# re-enable/disable buttons based on queue state
|
||||||
self.enable_disable_queue_buttons()
|
self.enable_disable_queue_buttons()
|
||||||
|
|
||||||
@@ -1888,22 +1972,62 @@ class abogen(QWidget):
|
|||||||
def start_next_queued_item(self):
|
def start_next_queued_item(self):
|
||||||
if self.current_queue_index < len(self.queued_items):
|
if self.current_queue_index < len(self.queued_items):
|
||||||
queued_item = self.queued_items[self.current_queue_index]
|
queued_item = self.queued_items[self.current_queue_index]
|
||||||
|
|
||||||
self.selected_file = queued_item.file_name
|
self.selected_file = queued_item.file_name
|
||||||
|
self.char_count = queued_item.total_char_count
|
||||||
|
|
||||||
|
# Restore the original file path for save location (Important for EPUB/PDF)
|
||||||
|
self.displayed_file_path = (
|
||||||
|
queued_item.save_base_path or queued_item.file_name
|
||||||
|
)
|
||||||
|
|
||||||
|
# Restore chapter options (Structure specific, must be preserved)
|
||||||
|
self.save_chapters_separately = getattr(
|
||||||
|
queued_item, "save_chapters_separately", None
|
||||||
|
)
|
||||||
|
self.merge_chapters_at_end = getattr(
|
||||||
|
queued_item, "merge_chapters_at_end", None
|
||||||
|
)
|
||||||
|
|
||||||
|
# CHECK GLOBAL OVERRIDE SETTING
|
||||||
|
if not self.config.get("queue_override_settings", False):
|
||||||
self.selected_lang = queued_item.lang_code
|
self.selected_lang = queued_item.lang_code
|
||||||
self.speed_slider.setValue(int(queued_item.speed * 100))
|
self.speed_slider.setValue(int(queued_item.speed * 100))
|
||||||
|
|
||||||
|
# Load the specific voice string
|
||||||
self.selected_voice = queued_item.voice
|
self.selected_voice = queued_item.voice
|
||||||
|
# Clear complex GUI states so the specific voice string is used
|
||||||
|
self.mixed_voice_state = None
|
||||||
|
self.selected_profile_name = None
|
||||||
|
|
||||||
self.save_option = queued_item.save_option
|
self.save_option = queued_item.save_option
|
||||||
self.selected_output_folder = queued_item.output_folder
|
self.selected_output_folder = queued_item.output_folder
|
||||||
self.subtitle_mode = queued_item.subtitle_mode
|
self.subtitle_mode = queued_item.subtitle_mode
|
||||||
self.selected_format = queued_item.output_format
|
self.selected_format = queued_item.output_format
|
||||||
self.char_count = queued_item.total_char_count
|
|
||||||
self.replace_single_newlines = getattr(
|
self.replace_single_newlines = getattr(
|
||||||
queued_item, "replace_single_newlines", False
|
queued_item, "replace_single_newlines", True
|
||||||
)
|
)
|
||||||
# Restore the original file path for save location
|
self.use_silent_gaps = getattr(queued_item, "use_silent_gaps", False)
|
||||||
self.displayed_file_path = (
|
self.subtitle_speed_method = getattr(
|
||||||
queued_item.save_base_path or queued_item.file_name
|
queued_item, "subtitle_speed_method", "tts"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# This ensures that if conversion.py (or utils) reads from config/disk
|
||||||
|
# instead of using passed arguments, it sees the correct queue values.
|
||||||
|
self.config["replace_single_newlines"] = self.replace_single_newlines
|
||||||
|
self.config["subtitle_mode"] = self.subtitle_mode
|
||||||
|
self.config["selected_format"] = self.selected_format
|
||||||
|
self.config["use_silent_gaps"] = self.use_silent_gaps
|
||||||
|
self.config["subtitle_speed_method"] = self.subtitle_speed_method
|
||||||
|
|
||||||
|
# Sync Voice/Profile in config
|
||||||
|
self.config["selected_voice"] = self.selected_voice
|
||||||
|
if "selected_profile_name" in self.config:
|
||||||
|
del self.config["selected_profile_name"]
|
||||||
|
|
||||||
|
# Note: Speed is already synced via self.speed_slider.setValue() -> update_speed_label()
|
||||||
|
save_config(self.config)
|
||||||
|
|
||||||
self.start_conversion(from_queue=True)
|
self.start_conversion(from_queue=True)
|
||||||
else:
|
else:
|
||||||
# Queue finished, reset index
|
# Queue finished, reset index
|
||||||
@@ -2002,7 +2126,7 @@ class abogen(QWidget):
|
|||||||
# pipeline_loaded_callback remains unchanged
|
# pipeline_loaded_callback remains unchanged
|
||||||
def pipeline_loaded_callback(np_module, kpipeline_class, error):
|
def pipeline_loaded_callback(np_module, kpipeline_class, error):
|
||||||
if error:
|
if error:
|
||||||
self.update_log((f"Error loading numpy or KPipeline: {error}", False))
|
self.update_log((f"Error loading numpy or KPipeline: {error}", "red"))
|
||||||
prevent_sleep_end()
|
prevent_sleep_end()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -2045,6 +2169,12 @@ class abogen(QWidget):
|
|||||||
self.conversion_thread.replace_single_newlines = (
|
self.conversion_thread.replace_single_newlines = (
|
||||||
self.replace_single_newlines
|
self.replace_single_newlines
|
||||||
)
|
)
|
||||||
|
# Pass use_silent_gaps setting
|
||||||
|
self.conversion_thread.use_silent_gaps = self.use_silent_gaps
|
||||||
|
# Pass subtitle_speed_method setting
|
||||||
|
self.conversion_thread.subtitle_speed_method = self.subtitle_speed_method
|
||||||
|
# Pass use_spacy_segmentation setting
|
||||||
|
self.conversion_thread.use_spacy_segmentation = self.use_spacy_segmentation
|
||||||
# Pass separate_chapters_format setting
|
# Pass separate_chapters_format setting
|
||||||
self.conversion_thread.separate_chapters_format = (
|
self.conversion_thread.separate_chapters_format = (
|
||||||
self.separate_chapters_format
|
self.separate_chapters_format
|
||||||
@@ -2095,36 +2225,95 @@ class abogen(QWidget):
|
|||||||
threading.Thread(target=gpu_and_load, daemon=True).start()
|
threading.Thread(target=gpu_and_load, daemon=True).start()
|
||||||
|
|
||||||
def show_queue_summary(self):
|
def show_queue_summary(self):
|
||||||
"""Show a styled, resizable summary dialog after queue finishes."""
|
"""Show a summary dialog after queue finishes."""
|
||||||
if not self.queued_items:
|
if not self.queued_items:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Build HTML summary for better styling
|
# Check if override was active (this determines which settings were ACTUALLY used)
|
||||||
|
override_active = self.config.get("queue_override_settings", False)
|
||||||
|
|
||||||
|
# If override is ON, capture the global settings that were used for processing
|
||||||
|
if override_active:
|
||||||
|
g_voice = self.get_voice_formula()
|
||||||
|
g_lang = self.get_selected_lang(g_voice)
|
||||||
|
g_speed = self.speed_slider.value() / 100.0
|
||||||
|
g_sub_mode = self.get_actual_subtitle_mode()
|
||||||
|
g_format = self.selected_format
|
||||||
|
g_newlines = self.replace_single_newlines
|
||||||
|
g_silent_gaps = self.use_silent_gaps
|
||||||
|
g_speed_method = self.subtitle_speed_method
|
||||||
|
|
||||||
|
# Build HTML summary (Default Styling)
|
||||||
summary_html = "<html><body>"
|
summary_html = "<html><body>"
|
||||||
|
|
||||||
|
header_text = "Queue finished"
|
||||||
|
if override_active:
|
||||||
|
header_text += " (Global Settings Applied)"
|
||||||
|
|
||||||
summary_html += (
|
summary_html += (
|
||||||
f"<h2 style='color:{COLORS['LIGHT_BG']};'>Queue finished</h2>"
|
f"<h2>{header_text}</h2>"
|
||||||
f"Processed {len(self.queued_items)} items:<br><br>"
|
f"Processed {len(self.queued_items)} items:<br><br>"
|
||||||
)
|
)
|
||||||
|
|
||||||
for idx, item in enumerate(self.queued_items, 1):
|
for idx, item in enumerate(self.queued_items, 1):
|
||||||
output = getattr(item, "output_path", None)
|
# Resolve Effective Settings
|
||||||
if not output:
|
if override_active:
|
||||||
output = "Unknown"
|
eff_lang = g_lang
|
||||||
|
eff_voice = g_voice
|
||||||
|
eff_speed = g_speed
|
||||||
|
eff_sub_mode = g_sub_mode
|
||||||
|
eff_format = g_format
|
||||||
|
eff_newlines = g_newlines
|
||||||
|
eff_silent = g_silent_gaps
|
||||||
|
eff_method = g_speed_method
|
||||||
|
else:
|
||||||
|
eff_lang = item.lang_code
|
||||||
|
eff_voice = item.voice
|
||||||
|
eff_speed = item.speed
|
||||||
|
eff_sub_mode = item.subtitle_mode
|
||||||
|
eff_format = item.output_format
|
||||||
|
eff_newlines = getattr(item, "replace_single_newlines", True)
|
||||||
|
eff_silent = getattr(item, "use_silent_gaps", False)
|
||||||
|
eff_method = getattr(item, "subtitle_speed_method", "tts")
|
||||||
|
|
||||||
|
# Retrieve File-Specific Data (Never Overridden)
|
||||||
|
eff_chars = item.total_char_count
|
||||||
|
eff_input = item.file_name
|
||||||
|
eff_output = getattr(item, "output_path", "Unknown")
|
||||||
|
eff_save_sep = getattr(item, "save_chapters_separately", None)
|
||||||
|
eff_merge = getattr(item, "merge_chapters_at_end", None)
|
||||||
|
|
||||||
|
# --- Construct Display Block ---
|
||||||
summary_html += (
|
summary_html += (
|
||||||
f"<span style='color:{COLORS['GREEN']}; font-weight:bold;'>{idx}) {os.path.basename(item.file_name)}</span><br>"
|
f"<span style='color:{COLORS['GREEN']}; font-weight:bold;'>{idx}) {os.path.basename(eff_input)}</span><br>"
|
||||||
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Language:</span> {item.lang_code}<br>"
|
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Language:</span> {eff_lang}<br>"
|
||||||
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Voice:</span> {item.voice}<br>"
|
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Voice:</span> {eff_voice}<br>"
|
||||||
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Speed:</span> {item.speed}<br>"
|
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Speed:</span> {eff_speed}<br>"
|
||||||
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Characters:</span> {item.total_char_count}<br>"
|
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Characters:</span> {eff_chars}<br>"
|
||||||
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Input:</span> {item.file_name}<br>"
|
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Format:</span> {eff_format}<br>"
|
||||||
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Output:</span> {output}</span>"
|
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Subtitle Mode:</span> {eff_sub_mode}<br>"
|
||||||
f"<br><br>"
|
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Method:</span> {eff_method}<br>"
|
||||||
|
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Silent Gaps:</span> {eff_silent}<br>"
|
||||||
|
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Repl. Newlines:</span> {eff_newlines}<br>"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Book/Chapter specific options
|
||||||
|
if eff_save_sep is not None:
|
||||||
|
summary_html += f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Split Chapters:</span> {eff_save_sep}<br>"
|
||||||
|
if eff_save_sep and eff_merge is not None:
|
||||||
|
summary_html += f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Merge End:</span> {eff_merge}<br>"
|
||||||
|
|
||||||
|
summary_html += (
|
||||||
|
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Input:</span> {eff_input}<br>"
|
||||||
|
f"<span style='color:{COLORS['LIGHT_DISABLED']};'>Output:</span> {eff_output}<br><br>"
|
||||||
|
)
|
||||||
|
|
||||||
summary_html += "</body></html>"
|
summary_html += "</body></html>"
|
||||||
|
|
||||||
dialog = QDialog(self)
|
dialog = QDialog(self)
|
||||||
dialog.setWindowTitle("Queue Summary")
|
dialog.setWindowTitle("Queue Summary")
|
||||||
dialog.resize(550, 650) # Make window resizable and larger
|
# Allow resizing
|
||||||
|
dialog.resize(550, 650)
|
||||||
|
|
||||||
layout = QVBoxLayout(dialog)
|
layout = QVBoxLayout(dialog)
|
||||||
text_edit = QTextEdit(dialog)
|
text_edit = QTextEdit(dialog)
|
||||||
@@ -2139,7 +2328,7 @@ class abogen(QWidget):
|
|||||||
|
|
||||||
dialog.setLayout(layout)
|
dialog.setLayout(layout)
|
||||||
dialog.setMinimumSize(400, 300)
|
dialog.setMinimumSize(400, 300)
|
||||||
dialog.setSizeGripEnabled(True) # Allow resizing
|
dialog.setSizeGripEnabled(True)
|
||||||
dialog.exec()
|
dialog.exec()
|
||||||
|
|
||||||
def on_conversion_finished(self, message, output_path):
|
def on_conversion_finished(self, message, output_path):
|
||||||
@@ -2181,7 +2370,7 @@ class abogen(QWidget):
|
|||||||
self.is_converting = False
|
self.is_converting = False
|
||||||
elapsed = int(time.time() - self.start_time)
|
elapsed = int(time.time() - self.start_time)
|
||||||
h, m, s = elapsed // 3600, (elapsed % 3600) // 60, elapsed % 60
|
h, m, s = elapsed // 3600, (elapsed % 3600) // 60, elapsed % 60
|
||||||
self.update_log(f"\nTime elapsed: {h:02d}:{m:02d}:{s:02d}")
|
self.update_log((f"\nTime elapsed: {h:02d}:{m:02d}:{s:02d}", "grey"))
|
||||||
|
|
||||||
# Default to showing the button
|
# Default to showing the button
|
||||||
show_open_file_button = True
|
show_open_file_button = True
|
||||||
@@ -2744,6 +2933,33 @@ class abogen(QWidget):
|
|||||||
self.conversion_thread.cancel()
|
self.conversion_thread.cancel()
|
||||||
self.conversion_thread.wait()
|
self.conversion_thread.wait()
|
||||||
|
|
||||||
|
def cleanup_preview_threads(self):
|
||||||
|
# Stop preview generation thread
|
||||||
|
if (
|
||||||
|
hasattr(self, "preview_thread")
|
||||||
|
and self.preview_thread is not None
|
||||||
|
and self.preview_thread.isRunning()
|
||||||
|
):
|
||||||
|
self.preview_thread.terminate()
|
||||||
|
self.preview_thread.wait()
|
||||||
|
|
||||||
|
# Stop audio playback thread
|
||||||
|
if (
|
||||||
|
hasattr(self, "play_audio_thread")
|
||||||
|
and self.play_audio_thread is not None
|
||||||
|
and self.play_audio_thread.isRunning()
|
||||||
|
):
|
||||||
|
self.play_audio_thread.stop()
|
||||||
|
self.play_audio_thread.wait()
|
||||||
|
|
||||||
|
# Cleanup pygame mixer if initialized
|
||||||
|
try:
|
||||||
|
pygame = sys.modules.get("pygame")
|
||||||
|
if pygame and pygame.mixer.get_init():
|
||||||
|
pygame.mixer.quit()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
if self.is_converting:
|
if self.is_converting:
|
||||||
box = QMessageBox(self)
|
box = QMessageBox(self)
|
||||||
@@ -2758,21 +2974,40 @@ class abogen(QWidget):
|
|||||||
box.setDefaultButton(QMessageBox.StandardButton.No)
|
box.setDefaultButton(QMessageBox.StandardButton.No)
|
||||||
if box.exec() == QMessageBox.StandardButton.Yes:
|
if box.exec() == QMessageBox.StandardButton.Yes:
|
||||||
self.cleanup_conversion_thread()
|
self.cleanup_conversion_thread()
|
||||||
|
self.cleanup_preview_threads()
|
||||||
event.accept()
|
event.accept()
|
||||||
else:
|
else:
|
||||||
event.ignore()
|
event.ignore()
|
||||||
else:
|
else:
|
||||||
self.cleanup_conversion_thread()
|
self.cleanup_conversion_thread()
|
||||||
|
self.cleanup_preview_threads()
|
||||||
event.accept()
|
event.accept()
|
||||||
|
|
||||||
def show_chapter_options_dialog(self, chapter_count):
|
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"""
|
"""Show dialog to ask user about chapter processing options when chapters are detected in a .txt file"""
|
||||||
|
# Check if this is a timestamp detection (-1) or chapter detection
|
||||||
|
if chapter_count == -1:
|
||||||
|
from abogen.conversion import TimestampDetectionDialog
|
||||||
|
|
||||||
|
dialog = TimestampDetectionDialog(parent=self)
|
||||||
|
dialog.setWindowModality(Qt.WindowModality.ApplicationModal)
|
||||||
|
|
||||||
|
# Dialog always accepts (Yes or No), never cancels the conversion
|
||||||
|
dialog.exec()
|
||||||
|
treat_as_subtitle = dialog.use_timestamps()
|
||||||
|
if (
|
||||||
|
hasattr(self, "conversion_thread")
|
||||||
|
and self.conversion_thread.isRunning()
|
||||||
|
):
|
||||||
|
self.conversion_thread.set_timestamp_response(treat_as_subtitle)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Normal chapter detection
|
||||||
from abogen.conversion import ChapterOptionsDialog
|
from abogen.conversion import ChapterOptionsDialog
|
||||||
|
|
||||||
dialog = ChapterOptionsDialog(chapter_count, parent=self)
|
dialog = ChapterOptionsDialog(chapter_count, parent=self)
|
||||||
dialog.setWindowModality(Qt.WindowModality.ApplicationModal)
|
dialog.setWindowModality(Qt.WindowModality.ApplicationModal)
|
||||||
|
|
||||||
# If dialog is accepted, pass the options to the conversion thread
|
|
||||||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||||
options = dialog.get_options()
|
options = dialog.get_options()
|
||||||
if (
|
if (
|
||||||
@@ -2781,7 +3016,6 @@ class abogen(QWidget):
|
|||||||
):
|
):
|
||||||
self.conversion_thread.set_chapter_options(options)
|
self.conversion_thread.set_chapter_options(options)
|
||||||
else:
|
else:
|
||||||
# If dialog is rejected, cancel the conversion
|
|
||||||
self.cancel_conversion()
|
self.cancel_conversion()
|
||||||
|
|
||||||
def apply_theme(self, theme):
|
def apply_theme(self, theme):
|
||||||
@@ -3040,6 +3274,63 @@ class abogen(QWidget):
|
|||||||
# Add separator
|
# Add separator
|
||||||
menu.addSeparator()
|
menu.addSeparator()
|
||||||
|
|
||||||
|
# Add use silent gaps option (for subtitle files)
|
||||||
|
self.silent_gaps_action = QAction("Use silent gaps between subtitles", self)
|
||||||
|
self.silent_gaps_action.setCheckable(True)
|
||||||
|
self.silent_gaps_action.setChecked(self.use_silent_gaps)
|
||||||
|
self.silent_gaps_action.triggered.connect(
|
||||||
|
lambda checked: self.toggle_use_silent_gaps(checked)
|
||||||
|
)
|
||||||
|
menu.addAction(self.silent_gaps_action)
|
||||||
|
|
||||||
|
# Subtitle speed adjustment method
|
||||||
|
speed_method_menu = menu.addMenu("Subtitle speed adjustment method")
|
||||||
|
speed_method_menu.setToolTip(
|
||||||
|
"Choose speed adjustment method:\n"
|
||||||
|
"TTS Regeneration: Better quality\n"
|
||||||
|
"FFmpeg Time-stretch: Faster processing"
|
||||||
|
)
|
||||||
|
|
||||||
|
speed_method_group = QActionGroup(self)
|
||||||
|
speed_method_group.setExclusive(True)
|
||||||
|
|
||||||
|
for method, label in [
|
||||||
|
("tts", "TTS Regeneration (better quality)"),
|
||||||
|
("ffmpeg", "FFmpeg Time-stretch (better speed)"),
|
||||||
|
]:
|
||||||
|
action = QAction(label, speed_method_menu)
|
||||||
|
action.setCheckable(True)
|
||||||
|
action.setChecked(self.subtitle_speed_method == method)
|
||||||
|
action.triggered.connect(
|
||||||
|
lambda checked, m=method: self.toggle_subtitle_speed_method(m)
|
||||||
|
)
|
||||||
|
speed_method_group.addAction(action)
|
||||||
|
speed_method_menu.addAction(action)
|
||||||
|
|
||||||
|
self.speed_method_group = speed_method_group
|
||||||
|
|
||||||
|
# Add separator
|
||||||
|
menu.addSeparator()
|
||||||
|
|
||||||
|
# Add spaCy sentence segmentation option
|
||||||
|
spacy_action = QAction("Use spaCy for sentence segmentation", self)
|
||||||
|
spacy_action.setCheckable(True)
|
||||||
|
spacy_action.setChecked(self.use_spacy_segmentation)
|
||||||
|
spacy_action.triggered.connect(
|
||||||
|
lambda checked: self.toggle_spacy_segmentation(checked)
|
||||||
|
)
|
||||||
|
menu.addAction(spacy_action)
|
||||||
|
|
||||||
|
# Add separator
|
||||||
|
menu.addSeparator()
|
||||||
|
|
||||||
|
# Add "Pre-download models and voices for offline use" option
|
||||||
|
predownload_action = QAction(
|
||||||
|
"Pre-download models and voices for offline use", self
|
||||||
|
)
|
||||||
|
predownload_action.triggered.connect(self.show_predownload_dialog)
|
||||||
|
menu.addAction(predownload_action)
|
||||||
|
|
||||||
# Add "Disable Kokoro's internet access" option
|
# Add "Disable Kokoro's internet access" option
|
||||||
disable_kokoro_action = QAction("Disable Kokoro's internet access", self)
|
disable_kokoro_action = QAction("Disable Kokoro's internet access", self)
|
||||||
disable_kokoro_action.setCheckable(True)
|
disable_kokoro_action.setCheckable(True)
|
||||||
@@ -3075,6 +3366,40 @@ class abogen(QWidget):
|
|||||||
self.config["replace_single_newlines"] = enabled
|
self.config["replace_single_newlines"] = enabled
|
||||||
save_config(self.config)
|
save_config(self.config)
|
||||||
|
|
||||||
|
def toggle_use_silent_gaps(self, enabled):
|
||||||
|
# Show confirmation dialog with explanation
|
||||||
|
action = "enable" if enabled else "disable"
|
||||||
|
message = (
|
||||||
|
"When enabled, allows speech to continue naturally into the silent periods between subtitles, "
|
||||||
|
"preventing unnecessary audio speed-up based on subtitle end timestamps.\n\nWhen disabled, ensures strict subtitle timing where "
|
||||||
|
f"audio ends exactly when the subtitle ends.\n\nDo you want to {action} this option?"
|
||||||
|
)
|
||||||
|
|
||||||
|
reply = QMessageBox.question(
|
||||||
|
self,
|
||||||
|
"Use Silent Gaps Between Subtitles",
|
||||||
|
message,
|
||||||
|
QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Cancel,
|
||||||
|
)
|
||||||
|
|
||||||
|
if reply == QMessageBox.StandardButton.Ok:
|
||||||
|
self.use_silent_gaps = enabled
|
||||||
|
self.config["use_silent_gaps"] = enabled
|
||||||
|
save_config(self.config)
|
||||||
|
else:
|
||||||
|
# Revert the checkbox state if cancelled
|
||||||
|
self.silent_gaps_action.setChecked(not enabled)
|
||||||
|
|
||||||
|
def toggle_subtitle_speed_method(self, method):
|
||||||
|
self.subtitle_speed_method = method
|
||||||
|
self.config["subtitle_speed_method"] = method
|
||||||
|
save_config(self.config)
|
||||||
|
|
||||||
|
def toggle_spacy_segmentation(self, enabled):
|
||||||
|
self.use_spacy_segmentation = enabled
|
||||||
|
self.config["use_spacy_segmentation"] = enabled
|
||||||
|
save_config(self.config)
|
||||||
|
|
||||||
def restart_app(self):
|
def restart_app(self):
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@@ -3370,6 +3695,13 @@ Categories=AudioVideo;Audio;Utility;
|
|||||||
self.voice_combo.setCurrentIndex(idx)
|
self.voice_combo.setCurrentIndex(idx)
|
||||||
self.mixed_voice_state = dialog.get_selected_voices()
|
self.mixed_voice_state = dialog.get_selected_voices()
|
||||||
|
|
||||||
|
def show_predownload_dialog(self):
|
||||||
|
"""Show the pre-download models and voices dialog."""
|
||||||
|
from abogen.predownload_gui import PreDownloadDialog
|
||||||
|
|
||||||
|
dialog = PreDownloadDialog(self)
|
||||||
|
dialog.exec()
|
||||||
|
|
||||||
def show_about_dialog(self):
|
def show_about_dialog(self):
|
||||||
"""Show an About dialog with program information including GitHub link."""
|
"""Show an About dialog with program information including GitHub link."""
|
||||||
# Get application icon for dialog
|
# Get application icon for dialog
|
||||||
@@ -3521,9 +3853,9 @@ Categories=AudioVideo;Audio;Utility;
|
|||||||
# Get the abogen cache directory
|
# Get the abogen cache directory
|
||||||
cache_dir = get_user_cache_path()
|
cache_dir = get_user_cache_path()
|
||||||
|
|
||||||
# Find all .txt files in the abogen cache directory
|
# Find all .txt files and cover images in the abogen cache directory
|
||||||
pattern = os.path.join(cache_dir, "*.txt")
|
cache_files = glob.glob(os.path.join(cache_dir, "*.txt"))
|
||||||
cache_files = glob.glob(pattern)
|
cache_files.extend(glob.glob(os.path.join(cache_dir, "cover_*.jpg")))
|
||||||
|
|
||||||
# Count the files
|
# Count the files
|
||||||
file_count = len(cache_files)
|
file_count = len(cache_files)
|
||||||
@@ -3555,7 +3887,7 @@ Categories=AudioVideo;Audio;Utility;
|
|||||||
msg_box.setText(msg_text + "\nDo you want to delete them?")
|
msg_box.setText(msg_text + "\nDo you want to delete them?")
|
||||||
|
|
||||||
# Add checkbox for preview cache
|
# Add checkbox for preview cache
|
||||||
preview_cache_checkbox = QCheckBox("Clean preview cache", msg_box)
|
preview_cache_checkbox = QCheckBox("Also clean preview cache", msg_box)
|
||||||
preview_cache_checkbox.setChecked(False)
|
preview_cache_checkbox.setChecked(False)
|
||||||
# Only enable checkbox if preview files exist
|
# Only enable checkbox if preview files exist
|
||||||
preview_cache_checkbox.setEnabled(preview_count > 0)
|
preview_cache_checkbox.setEnabled(preview_count > 0)
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
+43
-3
@@ -3,6 +3,26 @@ import sys
|
|||||||
import platform
|
import platform
|
||||||
import atexit
|
import atexit
|
||||||
import signal
|
import signal
|
||||||
|
from abogen.utils import get_resource_path, load_config, prevent_sleep_end
|
||||||
|
|
||||||
|
|
||||||
|
# Fix PyTorch DLL loading issue ([WinError 1114]) on Windows before importing PyQt6
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
import ctypes
|
||||||
|
from importlib.util import find_spec
|
||||||
|
|
||||||
|
try:
|
||||||
|
if (
|
||||||
|
(spec := find_spec("torch"))
|
||||||
|
and spec.origin
|
||||||
|
and os.path.exists(
|
||||||
|
dll_path := os.path.join(os.path.dirname(spec.origin), "lib", "c10.dll")
|
||||||
|
)
|
||||||
|
):
|
||||||
|
ctypes.CDLL(os.path.normpath(dll_path))
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Qt platform plugin detection (fixes #59)
|
# Qt platform plugin detection (fixes #59)
|
||||||
try:
|
try:
|
||||||
@@ -25,6 +45,28 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
print("PyQt6 not installed.")
|
print("PyQt6 not installed.")
|
||||||
|
|
||||||
|
|
||||||
|
# Pre-load "libxcb-cursor" on Linux (fixes #101)
|
||||||
|
if platform.system() == "Linux":
|
||||||
|
arch = platform.machine().lower()
|
||||||
|
lib_filename = {"x86_64": "libxcb-cursor-amd64.so.0", "amd64": "libxcb-cursor-amd64.so.0", "aarch64": "libxcb-cursor-arm64.so.0", "arm64": "libxcb-cursor-arm64.so.0"}.get(arch)
|
||||||
|
if lib_filename:
|
||||||
|
import ctypes
|
||||||
|
try:
|
||||||
|
# Try to load the system libxcb-cursor.so.0 first
|
||||||
|
ctypes.CDLL('libxcb-cursor.so.0', mode=ctypes.RTLD_GLOBAL)
|
||||||
|
except OSError:
|
||||||
|
# System lib not available, load the bundled version
|
||||||
|
lib_path = get_resource_path('abogen.libs', lib_filename)
|
||||||
|
if lib_path:
|
||||||
|
try:
|
||||||
|
ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
|
||||||
|
except OSError:
|
||||||
|
# If it fails (e.g. wrong glibc version on very old systems),
|
||||||
|
# we simply ignore it and hope the system has the library.
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Set application ID for Windows taskbar icon
|
# Set application ID for Windows taskbar icon
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
try:
|
try:
|
||||||
@@ -47,8 +89,6 @@ from PyQt6.QtCore import (
|
|||||||
# Add the directory to Python path
|
# Add the directory to Python path
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__)))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__)))
|
||||||
|
|
||||||
from abogen.utils import get_resource_path, load_config, prevent_sleep_end
|
|
||||||
|
|
||||||
# Set Hugging Face Hub environment variables
|
# Set Hugging Face Hub environment variables
|
||||||
os.environ["HF_HUB_DISABLE_TELEMETRY"] = "1" # Disable Hugging Face telemetry
|
os.environ["HF_HUB_DISABLE_TELEMETRY"] = "1" # Disable Hugging Face telemetry
|
||||||
os.environ["HF_HUB_ETAG_TIMEOUT"] = "10" # Metadata request timeout (seconds)
|
os.environ["HF_HUB_ETAG_TIMEOUT"] = "10" # Metadata request timeout (seconds)
|
||||||
@@ -134,7 +174,7 @@ def main():
|
|||||||
# Set the .desktop name on Linux
|
# Set the .desktop name on Linux
|
||||||
if platform.system() == "Linux":
|
if platform.system() == "Linux":
|
||||||
try:
|
try:
|
||||||
app.setDesktopFileName("abogen.desktop")
|
app.setDesktopFileName("abogen")
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,590 @@
|
|||||||
|
"""
|
||||||
|
Pre-download dialog and worker for Abogen
|
||||||
|
|
||||||
|
This module consolidates pre-download logic for Kokoro voices and model
|
||||||
|
and spaCy language models. The code favors clarity, avoids duplication,
|
||||||
|
and handles optional dependencies gracefully.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import List, Optional, Tuple
|
||||||
|
import importlib
|
||||||
|
import importlib.util
|
||||||
|
|
||||||
|
from PyQt6.QtWidgets import (
|
||||||
|
QDialog,
|
||||||
|
QVBoxLayout,
|
||||||
|
QHBoxLayout,
|
||||||
|
QLabel,
|
||||||
|
QPushButton,
|
||||||
|
QSpacerItem,
|
||||||
|
QSizePolicy,
|
||||||
|
)
|
||||||
|
from PyQt6.QtCore import QThread, pyqtSignal
|
||||||
|
|
||||||
|
from abogen.constants import COLORS, VOICES_INTERNAL
|
||||||
|
from abogen.spacy_utils import SPACY_MODELS
|
||||||
|
import abogen.hf_tracker
|
||||||
|
|
||||||
|
|
||||||
|
# Helpers
|
||||||
|
def _unique_sorted_models() -> List[str]:
|
||||||
|
"""Return a sorted list of unique spaCy model package names."""
|
||||||
|
return sorted(set(SPACY_MODELS.values()))
|
||||||
|
|
||||||
|
|
||||||
|
def _is_package_installed(pkg_name: str) -> bool:
|
||||||
|
"""Return True if a package with the given name can be imported (site-packages)."""
|
||||||
|
try:
|
||||||
|
return importlib.util.find_spec(pkg_name) is not None
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# NOTE: explicit HF cache helper removed; we use try_to_load_from_cache in-scope where needed
|
||||||
|
|
||||||
|
|
||||||
|
class PreDownloadWorker(QThread):
|
||||||
|
"""Worker thread to download required models/voices.
|
||||||
|
|
||||||
|
Emits human-readable messages via `progress`. Uses `category_done` to indicate
|
||||||
|
a category (voices/model/spacy) finished successfully. Emits `error` on exception
|
||||||
|
and `finished` after all work completes.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Emit (category, status, message)
|
||||||
|
progress = pyqtSignal(str, str, str)
|
||||||
|
category_done = pyqtSignal(str)
|
||||||
|
finished = pyqtSignal()
|
||||||
|
error = pyqtSignal(str)
|
||||||
|
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self._cancelled = False
|
||||||
|
# repo and filenames used for Kokoro model
|
||||||
|
self._repo_id = "hexgrad/Kokoro-82M"
|
||||||
|
self._model_files = ["kokoro-v1_0.pth", "config.json"]
|
||||||
|
# Track download success per category
|
||||||
|
self._voices_success = False
|
||||||
|
self._model_success = False
|
||||||
|
self._spacy_success = False
|
||||||
|
# Suppress HF tracker warnings during downloads
|
||||||
|
self._original_emitter = abogen.hf_tracker.show_warning_signal_emitter
|
||||||
|
|
||||||
|
def cancel(self) -> None:
|
||||||
|
self._cancelled = True
|
||||||
|
|
||||||
|
def run(self) -> None:
|
||||||
|
# Suppress HF tracker warnings during downloads
|
||||||
|
abogen.hf_tracker.show_warning_signal_emitter = None
|
||||||
|
try:
|
||||||
|
self._download_kokoro_voices()
|
||||||
|
if self._cancelled:
|
||||||
|
return
|
||||||
|
if self._voices_success:
|
||||||
|
self.category_done.emit("voices")
|
||||||
|
|
||||||
|
self._download_kokoro_model()
|
||||||
|
if self._cancelled:
|
||||||
|
return
|
||||||
|
if self._model_success:
|
||||||
|
self.category_done.emit("model")
|
||||||
|
|
||||||
|
self._download_spacy_models()
|
||||||
|
if self._cancelled:
|
||||||
|
return
|
||||||
|
if self._spacy_success:
|
||||||
|
self.category_done.emit("spacy")
|
||||||
|
|
||||||
|
self.finished.emit()
|
||||||
|
except Exception as exc: # pragma: no cover - best-effort reporting
|
||||||
|
self.error.emit(str(exc))
|
||||||
|
finally:
|
||||||
|
# Restore original emitter
|
||||||
|
abogen.hf_tracker.show_warning_signal_emitter = self._original_emitter
|
||||||
|
|
||||||
|
# Kokoro voices
|
||||||
|
def _download_kokoro_voices(self) -> None:
|
||||||
|
self._voices_success = True
|
||||||
|
try:
|
||||||
|
from huggingface_hub import hf_hub_download, try_to_load_from_cache
|
||||||
|
except Exception:
|
||||||
|
self.progress.emit(
|
||||||
|
"voice", "warning", "huggingface_hub not installed, skipping voices..."
|
||||||
|
)
|
||||||
|
self._voices_success = False
|
||||||
|
return
|
||||||
|
|
||||||
|
voice_list = VOICES_INTERNAL
|
||||||
|
for idx, voice in enumerate(voice_list, start=1):
|
||||||
|
if self._cancelled:
|
||||||
|
self._voices_success = False
|
||||||
|
return
|
||||||
|
filename = f"voices/{voice}.pt"
|
||||||
|
if try_to_load_from_cache(repo_id=self._repo_id, filename=filename):
|
||||||
|
self.progress.emit(
|
||||||
|
"voice",
|
||||||
|
"installed",
|
||||||
|
f"{idx}/{len(voice_list)}: {voice} already present",
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
self.progress.emit(
|
||||||
|
"voice", "downloading", f"{idx}/{len(voice_list)}: {voice}..."
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
hf_hub_download(repo_id=self._repo_id, filename=filename)
|
||||||
|
self.progress.emit("voice", "downloaded", f"{voice} downloaded")
|
||||||
|
except Exception as exc:
|
||||||
|
self.progress.emit(
|
||||||
|
"voice", "warning", f"could not download {voice}: {exc}"
|
||||||
|
)
|
||||||
|
self._voices_success = False
|
||||||
|
|
||||||
|
# Kokoro model
|
||||||
|
def _download_kokoro_model(self) -> None:
|
||||||
|
self._model_success = True
|
||||||
|
try:
|
||||||
|
from huggingface_hub import hf_hub_download, try_to_load_from_cache
|
||||||
|
except Exception:
|
||||||
|
self.progress.emit(
|
||||||
|
"model", "warning", "huggingface_hub not installed, skipping model..."
|
||||||
|
)
|
||||||
|
self._model_success = False
|
||||||
|
return
|
||||||
|
for fname in self._model_files:
|
||||||
|
if self._cancelled:
|
||||||
|
self._model_success = False
|
||||||
|
return
|
||||||
|
category = "config" if fname == "config.json" else "model"
|
||||||
|
if try_to_load_from_cache(repo_id=self._repo_id, filename=fname):
|
||||||
|
self.progress.emit(
|
||||||
|
category, "installed", f"file {fname} already present"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
self.progress.emit(category, "downloading", f"file {fname}...")
|
||||||
|
try:
|
||||||
|
hf_hub_download(repo_id=self._repo_id, filename=fname)
|
||||||
|
self.progress.emit(category, "downloaded", f"file {fname} downloaded")
|
||||||
|
except Exception as exc:
|
||||||
|
self.progress.emit(
|
||||||
|
category, "warning", f"could not download file {fname}: {exc}"
|
||||||
|
)
|
||||||
|
self._model_success = False
|
||||||
|
|
||||||
|
# spaCy models
|
||||||
|
def _download_spacy_models(self) -> None:
|
||||||
|
"""Download spaCy models. Prefer missing models provided by parent.
|
||||||
|
|
||||||
|
Parent dialog will populate _spacy_models_missing during checking.
|
||||||
|
"""
|
||||||
|
self._spacy_success = True
|
||||||
|
# Determine which models to process: prefer parent-provided missing list to avoid
|
||||||
|
# re-checking everything; otherwise use the full unique list.
|
||||||
|
parent = self.parent()
|
||||||
|
models_to_process: List[str] = _unique_sorted_models()
|
||||||
|
try:
|
||||||
|
if (
|
||||||
|
parent is not None
|
||||||
|
and hasattr(parent, "_spacy_models_missing")
|
||||||
|
and parent._spacy_models_missing
|
||||||
|
):
|
||||||
|
models_to_process = list(dict.fromkeys(parent._spacy_models_missing))
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# If spaCy is not available to run the CLI, skip gracefully
|
||||||
|
try:
|
||||||
|
import spacy.cli as _spacy_cli
|
||||||
|
except Exception:
|
||||||
|
self.progress.emit(
|
||||||
|
"spacy", "warning", "spaCy not available, skipping spaCy models..."
|
||||||
|
)
|
||||||
|
self._spacy_success = False
|
||||||
|
return
|
||||||
|
|
||||||
|
for idx, model_name in enumerate(models_to_process, start=1):
|
||||||
|
if self._cancelled:
|
||||||
|
self._spacy_success = False
|
||||||
|
return
|
||||||
|
if _is_package_installed(model_name):
|
||||||
|
self.progress.emit(
|
||||||
|
"spacy",
|
||||||
|
"installed",
|
||||||
|
f"{idx}/{len(models_to_process)}: {model_name} already installed",
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
self.progress.emit(
|
||||||
|
"spacy",
|
||||||
|
"downloading",
|
||||||
|
f"{idx}/{len(models_to_process)}: {model_name}...",
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
_spacy_cli.download(model_name)
|
||||||
|
self.progress.emit("spacy", "downloaded", f"{model_name} downloaded")
|
||||||
|
except Exception as exc:
|
||||||
|
self.progress.emit(
|
||||||
|
"spacy", "warning", f"could not download {model_name}: {exc}"
|
||||||
|
)
|
||||||
|
self._spacy_success = False
|
||||||
|
|
||||||
|
|
||||||
|
class PreDownloadDialog(QDialog):
|
||||||
|
"""Dialog to show and control pre-download process."""
|
||||||
|
|
||||||
|
VOICE_PREFIX = "Kokoro voices: "
|
||||||
|
MODEL_PREFIX = "Kokoro model: "
|
||||||
|
CONFIG_PREFIX = "Kokoro config: "
|
||||||
|
SPACY_PREFIX = "spaCy models: "
|
||||||
|
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.setWindowTitle("Pre-download Models and Voices")
|
||||||
|
self.setMinimumWidth(500)
|
||||||
|
self.worker: Optional[PreDownloadWorker] = None
|
||||||
|
self.has_missing = False
|
||||||
|
self._spacy_models_checked: List[tuple] = []
|
||||||
|
self._spacy_models_missing: List[str] = []
|
||||||
|
self._status_worker = None
|
||||||
|
|
||||||
|
# Map keywords to (label, prefix) - labels filled after UI creation
|
||||||
|
self.status_map = {
|
||||||
|
"voice": (None, self.VOICE_PREFIX),
|
||||||
|
"spacy": (None, self.SPACY_PREFIX),
|
||||||
|
"model": (None, self.MODEL_PREFIX),
|
||||||
|
"config": (None, self.CONFIG_PREFIX),
|
||||||
|
}
|
||||||
|
|
||||||
|
self.category_map = {
|
||||||
|
"voices": ["voice"],
|
||||||
|
"model": ["model", "config"],
|
||||||
|
"spacy": ["spacy"],
|
||||||
|
}
|
||||||
|
|
||||||
|
self._setup_ui()
|
||||||
|
self._start_status_check()
|
||||||
|
|
||||||
|
def _setup_ui(self) -> None:
|
||||||
|
layout = QVBoxLayout(self)
|
||||||
|
layout.setSpacing(0)
|
||||||
|
layout.setContentsMargins(15, 0, 15, 15)
|
||||||
|
|
||||||
|
desc = QLabel(
|
||||||
|
"You can pre-download all required models and voices for offline use.\n"
|
||||||
|
"This includes Kokoro voices, Kokoro model (and config), and spaCy models."
|
||||||
|
)
|
||||||
|
desc.setWordWrap(True)
|
||||||
|
layout.addWidget(desc)
|
||||||
|
|
||||||
|
# Status rows
|
||||||
|
status_layout = QVBoxLayout()
|
||||||
|
status_title = QLabel("<b>Current Status:</b>")
|
||||||
|
status_layout.addWidget(status_title)
|
||||||
|
|
||||||
|
self.voices_status = QLabel(self.VOICE_PREFIX + "⏳ Checking...")
|
||||||
|
row = QHBoxLayout()
|
||||||
|
row.addWidget(self.voices_status)
|
||||||
|
row.addStretch()
|
||||||
|
status_layout.addLayout(row)
|
||||||
|
|
||||||
|
self.model_status = QLabel(self.MODEL_PREFIX + "⏳ Checking...")
|
||||||
|
row = QHBoxLayout()
|
||||||
|
row.addWidget(self.model_status)
|
||||||
|
row.addStretch()
|
||||||
|
status_layout.addLayout(row)
|
||||||
|
|
||||||
|
self.config_status = QLabel(self.CONFIG_PREFIX + "⏳ Checking...")
|
||||||
|
row = QHBoxLayout()
|
||||||
|
row.addWidget(self.config_status)
|
||||||
|
row.addStretch()
|
||||||
|
status_layout.addLayout(row)
|
||||||
|
|
||||||
|
self.spacy_status = QLabel(self.SPACY_PREFIX + "⏳ Checking...")
|
||||||
|
row = QHBoxLayout()
|
||||||
|
row.addWidget(self.spacy_status)
|
||||||
|
row.addStretch()
|
||||||
|
status_layout.addLayout(row)
|
||||||
|
|
||||||
|
# register labels
|
||||||
|
self.status_map["voice"] = (self.voices_status, self.VOICE_PREFIX)
|
||||||
|
self.status_map["model"] = (self.model_status, self.MODEL_PREFIX)
|
||||||
|
self.status_map["config"] = (self.config_status, self.CONFIG_PREFIX)
|
||||||
|
self.status_map["spacy"] = (self.spacy_status, self.SPACY_PREFIX)
|
||||||
|
|
||||||
|
layout.addLayout(status_layout)
|
||||||
|
|
||||||
|
layout.addItem(
|
||||||
|
QSpacerItem(0, 20, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Fixed)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Buttons
|
||||||
|
button_row = QHBoxLayout()
|
||||||
|
button_row.setSpacing(10)
|
||||||
|
self.download_btn = QPushButton("Download all")
|
||||||
|
self.download_btn.setMinimumWidth(100)
|
||||||
|
self.download_btn.setMinimumHeight(35)
|
||||||
|
self.download_btn.setEnabled(False)
|
||||||
|
self.download_btn.clicked.connect(self._start_download)
|
||||||
|
button_row.addWidget(self.download_btn)
|
||||||
|
|
||||||
|
self.close_btn = QPushButton("Close")
|
||||||
|
self.close_btn.setMinimumWidth(100)
|
||||||
|
self.close_btn.setMinimumHeight(35)
|
||||||
|
self.close_btn.clicked.connect(self._handle_close)
|
||||||
|
button_row.addWidget(self.close_btn)
|
||||||
|
|
||||||
|
layout.addLayout(button_row)
|
||||||
|
self.adjustSize()
|
||||||
|
|
||||||
|
# Status checking worker
|
||||||
|
class StatusCheckWorker(QThread):
|
||||||
|
voices_checked = pyqtSignal(bool, list)
|
||||||
|
model_checked = pyqtSignal(bool)
|
||||||
|
config_checked = pyqtSignal(bool)
|
||||||
|
spacy_model_checking = pyqtSignal(str)
|
||||||
|
spacy_model_result = pyqtSignal(str, bool)
|
||||||
|
spacy_checked = pyqtSignal(bool, list)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
parent = self.parent()
|
||||||
|
if parent is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
voices_ok, missing_voices = parent._check_kokoro_voices()
|
||||||
|
self.voices_checked.emit(voices_ok, missing_voices)
|
||||||
|
|
||||||
|
model_ok = parent._check_kokoro_model()
|
||||||
|
self.model_checked.emit(model_ok)
|
||||||
|
|
||||||
|
config_ok = parent._check_kokoro_config()
|
||||||
|
self.config_checked.emit(config_ok)
|
||||||
|
|
||||||
|
# Check spaCy models by package name to detect site-package installs
|
||||||
|
unique = _unique_sorted_models()
|
||||||
|
missing: List[str] = []
|
||||||
|
for name in unique:
|
||||||
|
self.spacy_model_checking.emit(name)
|
||||||
|
ok = _is_package_installed(name)
|
||||||
|
self.spacy_model_result.emit(name, ok)
|
||||||
|
if not ok:
|
||||||
|
missing.append(name)
|
||||||
|
parent._spacy_models_missing = missing
|
||||||
|
self.spacy_checked.emit(len(missing) == 0, missing)
|
||||||
|
|
||||||
|
def _start_status_check(self) -> None:
|
||||||
|
self._status_worker = self.StatusCheckWorker(self)
|
||||||
|
self._status_worker.voices_checked.connect(self._update_voices_status)
|
||||||
|
self._status_worker.model_checked.connect(self._update_model_status)
|
||||||
|
self._status_worker.config_checked.connect(self._update_config_status)
|
||||||
|
self._status_worker.spacy_model_checking.connect(self._spacy_model_checking)
|
||||||
|
self._status_worker.spacy_model_result.connect(self._spacy_model_result)
|
||||||
|
self._status_worker.spacy_checked.connect(self._update_spacy_status)
|
||||||
|
|
||||||
|
# These are initialized in __init__ to keep consistent object state
|
||||||
|
|
||||||
|
# Set checking visual state
|
||||||
|
for lbl in (
|
||||||
|
self.voices_status,
|
||||||
|
self.model_status,
|
||||||
|
self.config_status,
|
||||||
|
self.spacy_status,
|
||||||
|
):
|
||||||
|
lbl.setStyleSheet(f"color: {COLORS['ORANGE']};")
|
||||||
|
|
||||||
|
self.spacy_status.setText(self.SPACY_PREFIX + "⏳ Checking...")
|
||||||
|
self._status_worker.start()
|
||||||
|
|
||||||
|
# UI update callbacks
|
||||||
|
def _spacy_model_checking(self, name: str) -> None:
|
||||||
|
self.spacy_status.setText(f"{self.SPACY_PREFIX}Checking {name}...")
|
||||||
|
|
||||||
|
def _spacy_model_result(self, name: str, ok: bool) -> None:
|
||||||
|
self._spacy_models_checked.append((name, ok))
|
||||||
|
if not ok and name not in self._spacy_models_missing:
|
||||||
|
self._spacy_models_missing.append(name)
|
||||||
|
checked = len(self._spacy_models_checked)
|
||||||
|
missing_count = len(self._spacy_models_missing)
|
||||||
|
if missing_count:
|
||||||
|
self.spacy_status.setText(
|
||||||
|
f"{self.SPACY_PREFIX}{checked} checked, {missing_count} missing..."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.spacy_status.setText(f"{self.SPACY_PREFIX}{checked} checked...")
|
||||||
|
|
||||||
|
def _update_voices_status(self, ok: bool, missing: List[str]) -> None:
|
||||||
|
if ok:
|
||||||
|
self._set_status("voice", "✓ Downloaded", COLORS["GREEN"])
|
||||||
|
else:
|
||||||
|
self.has_missing = True
|
||||||
|
if missing:
|
||||||
|
self._set_status(
|
||||||
|
"voice", f"✗ Missing {len(missing)} voices", COLORS["RED"]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self._set_status("voice", "✗ Not downloaded", COLORS["RED"])
|
||||||
|
|
||||||
|
def _update_model_status(self, ok: bool) -> None:
|
||||||
|
if ok:
|
||||||
|
self._set_status("model", "✓ Downloaded", COLORS["GREEN"])
|
||||||
|
else:
|
||||||
|
self.has_missing = True
|
||||||
|
self._set_status("model", "✗ Not downloaded", COLORS["RED"])
|
||||||
|
|
||||||
|
def _update_config_status(self, ok: bool) -> None:
|
||||||
|
if ok:
|
||||||
|
self._set_status("config", "✓ Downloaded", COLORS["GREEN"])
|
||||||
|
else:
|
||||||
|
self.has_missing = True
|
||||||
|
self._set_status("config", "✗ Not downloaded", COLORS["RED"])
|
||||||
|
|
||||||
|
def _update_spacy_status(self, ok: bool, missing: List[str]) -> None:
|
||||||
|
if ok:
|
||||||
|
self._set_status("spacy", "✓ Downloaded", COLORS["GREEN"])
|
||||||
|
else:
|
||||||
|
self.has_missing = True
|
||||||
|
if missing:
|
||||||
|
self._set_status(
|
||||||
|
"spacy", f"✗ Missing {len(missing)} model(s)", COLORS["RED"]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self._set_status("spacy", "✗ Not downloaded", COLORS["RED"])
|
||||||
|
self.download_btn.setEnabled(self.has_missing)
|
||||||
|
|
||||||
|
def _set_status(self, key: str, text: str, color: str) -> None:
|
||||||
|
lbl, prefix = self.status_map.get(key, (None, ""))
|
||||||
|
if not lbl:
|
||||||
|
return
|
||||||
|
lbl.setText(prefix + text)
|
||||||
|
lbl.setStyleSheet(f"color: {color};")
|
||||||
|
|
||||||
|
# Helper checks
|
||||||
|
def _check_kokoro_voices(self) -> Tuple[bool, List[str]]:
|
||||||
|
"""Return (ok, missing_list) for Kokoro voices check."""
|
||||||
|
missing = []
|
||||||
|
try:
|
||||||
|
from huggingface_hub import try_to_load_from_cache
|
||||||
|
|
||||||
|
for voice in VOICES_INTERNAL:
|
||||||
|
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 (len(missing) == 0), missing
|
||||||
|
|
||||||
|
def _check_kokoro_model(self) -> bool:
|
||||||
|
try:
|
||||||
|
from huggingface_hub import try_to_load_from_cache
|
||||||
|
|
||||||
|
return (
|
||||||
|
try_to_load_from_cache(
|
||||||
|
repo_id="hexgrad/Kokoro-82M", filename="kokoro-v1_0.pth"
|
||||||
|
)
|
||||||
|
is not None
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _check_kokoro_config(self) -> bool:
|
||||||
|
try:
|
||||||
|
from huggingface_hub import try_to_load_from_cache
|
||||||
|
|
||||||
|
return (
|
||||||
|
try_to_load_from_cache(
|
||||||
|
repo_id="hexgrad/Kokoro-82M", filename="config.json"
|
||||||
|
)
|
||||||
|
is not None
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _check_spacy_models(self) -> bool:
|
||||||
|
unique = _unique_sorted_models()
|
||||||
|
missing = [m for m in unique if not _is_package_installed(m)]
|
||||||
|
self._spacy_models_missing = missing
|
||||||
|
return len(missing) == 0
|
||||||
|
|
||||||
|
# Download control
|
||||||
|
def _start_download(self) -> None:
|
||||||
|
self.download_btn.setEnabled(False)
|
||||||
|
self.download_btn.setText("Downloading...")
|
||||||
|
# mark the start of downloads; this triggers the labels
|
||||||
|
self._on_progress("system", "starting", "Processing, please wait...")
|
||||||
|
self.worker = PreDownloadWorker(self)
|
||||||
|
self.worker.progress.connect(self._on_progress)
|
||||||
|
self.worker.category_done.connect(self._on_category_done)
|
||||||
|
self.worker.finished.connect(self._on_download_finished)
|
||||||
|
self.worker.error.connect(self._on_download_error)
|
||||||
|
self.worker.start()
|
||||||
|
|
||||||
|
def _on_progress(self, category: str, status: str, message: str) -> None:
|
||||||
|
"""Map worker (category, status, message) to UI label updates.
|
||||||
|
|
||||||
|
Status is one of: 'downloading', 'installed', 'downloaded', 'warning', 'starting'.
|
||||||
|
Category is one of: 'voice', 'model', 'spacy', 'config', or 'system'.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# If the category targets a specific label, update directly
|
||||||
|
if category in self.status_map:
|
||||||
|
lbl, prefix = self.status_map[category]
|
||||||
|
if not lbl:
|
||||||
|
return
|
||||||
|
# Compose message and set color based on status token
|
||||||
|
full_text = prefix + message
|
||||||
|
if len(full_text) > 60:
|
||||||
|
display_text = full_text[:57] + "..."
|
||||||
|
lbl.setText(display_text)
|
||||||
|
lbl.setToolTip(full_text)
|
||||||
|
else:
|
||||||
|
lbl.setText(full_text)
|
||||||
|
lbl.setToolTip("") # Clear tooltip if not needed
|
||||||
|
if status == "downloading":
|
||||||
|
lbl.setStyleSheet(f"color: {COLORS['ORANGE']};")
|
||||||
|
elif status in ("installed", "downloaded"):
|
||||||
|
lbl.setStyleSheet(f"color: {COLORS['GREEN']};")
|
||||||
|
elif status == "warning":
|
||||||
|
lbl.setStyleSheet(f"color: {COLORS['RED']};")
|
||||||
|
elif status == "error":
|
||||||
|
lbl.setStyleSheet(f"color: {COLORS['RED']};")
|
||||||
|
return
|
||||||
|
|
||||||
|
# System-level messages
|
||||||
|
if category == "system":
|
||||||
|
if status == "starting":
|
||||||
|
for k in self.status_map:
|
||||||
|
lbl, prefix = self.status_map[k]
|
||||||
|
if lbl:
|
||||||
|
lbl.setText(prefix + "Processing, please wait...")
|
||||||
|
lbl.setStyleSheet(f"color: {COLORS['ORANGE']};")
|
||||||
|
# other system statuses don't require action
|
||||||
|
return
|
||||||
|
except Exception:
|
||||||
|
# Do not let UI thread crash on unexpected worker message
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _on_category_done(self, category: str) -> None:
|
||||||
|
for key in self.category_map.get(category, []):
|
||||||
|
self._set_status(key, "✓ Downloaded", COLORS["GREEN"])
|
||||||
|
|
||||||
|
def _on_download_finished(self) -> None:
|
||||||
|
self.has_missing = False
|
||||||
|
self.download_btn.setText("Download all")
|
||||||
|
self.download_btn.setEnabled(False)
|
||||||
|
|
||||||
|
def _on_download_error(self, error_msg: str) -> None:
|
||||||
|
self.download_btn.setText("Download all")
|
||||||
|
self.download_btn.setEnabled(True)
|
||||||
|
for key in self.status_map:
|
||||||
|
self._set_status(key, f"✗ Error - {error_msg}", COLORS["RED"])
|
||||||
|
|
||||||
|
def _handle_close(self) -> None:
|
||||||
|
if self.worker and self.worker.isRunning():
|
||||||
|
self.worker.cancel()
|
||||||
|
self.worker.wait(2000)
|
||||||
|
self.accept()
|
||||||
|
|
||||||
|
def closeEvent(self, event) -> None:
|
||||||
|
if self.worker and self.worker.isRunning():
|
||||||
|
self.worker.cancel()
|
||||||
|
self.worker.wait(2000)
|
||||||
|
super().closeEvent(event)
|
||||||
+109
-26
@@ -15,11 +15,27 @@ from PyQt6.QtWidgets import (
|
|||||||
QWidget,
|
QWidget,
|
||||||
QSizePolicy,
|
QSizePolicy,
|
||||||
QAbstractItemView,
|
QAbstractItemView,
|
||||||
|
QCheckBox,
|
||||||
)
|
)
|
||||||
from PyQt6.QtCore import QFileInfo, Qt
|
from PyQt6.QtCore import QFileInfo, Qt
|
||||||
from abogen.constants import COLORS
|
from abogen.constants import COLORS
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from PyQt6.QtGui import QFontMetrics
|
from PyQt6.QtGui import QFontMetrics
|
||||||
|
from abogen.utils import load_config, save_config
|
||||||
|
|
||||||
|
# Define attributes that are safe to override with global settings
|
||||||
|
OVERRIDE_FIELDS = [
|
||||||
|
"lang_code",
|
||||||
|
"speed",
|
||||||
|
"voice",
|
||||||
|
"save_option",
|
||||||
|
"output_folder",
|
||||||
|
"subtitle_mode",
|
||||||
|
"output_format",
|
||||||
|
"replace_single_newlines",
|
||||||
|
"use_silent_gaps",
|
||||||
|
"subtitle_speed_method",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class ElidedLabel(QLabel):
|
class ElidedLabel(QLabel):
|
||||||
@@ -87,7 +103,11 @@ class DroppableQueueListWidget(QListWidget):
|
|||||||
def dragEnterEvent(self, event):
|
def dragEnterEvent(self, event):
|
||||||
if event.mimeData().hasUrls():
|
if event.mimeData().hasUrls():
|
||||||
for url in event.mimeData().urls():
|
for url in event.mimeData().urls():
|
||||||
if url.isLocalFile() and url.toLocalFile().lower().endswith(".txt"):
|
file_path = url.toLocalFile().lower()
|
||||||
|
if url.isLocalFile() and (
|
||||||
|
file_path.endswith(".txt")
|
||||||
|
or file_path.endswith((".srt", ".ass", ".vtt"))
|
||||||
|
):
|
||||||
self.drag_overlay.resize(self.size())
|
self.drag_overlay.resize(self.size())
|
||||||
self.drag_overlay.setVisible(True)
|
self.drag_overlay.setVisible(True)
|
||||||
event.acceptProposedAction()
|
event.acceptProposedAction()
|
||||||
@@ -98,7 +118,11 @@ class DroppableQueueListWidget(QListWidget):
|
|||||||
def dragMoveEvent(self, event):
|
def dragMoveEvent(self, event):
|
||||||
if event.mimeData().hasUrls():
|
if event.mimeData().hasUrls():
|
||||||
for url in event.mimeData().urls():
|
for url in event.mimeData().urls():
|
||||||
if url.isLocalFile() and url.toLocalFile().lower().endswith(".txt"):
|
file_path = url.toLocalFile().lower()
|
||||||
|
if url.isLocalFile() and (
|
||||||
|
file_path.endswith(".txt")
|
||||||
|
or file_path.endswith((".srt", ".ass", ".vtt"))
|
||||||
|
):
|
||||||
event.acceptProposedAction()
|
event.acceptProposedAction()
|
||||||
return
|
return
|
||||||
event.ignore()
|
event.ignore()
|
||||||
@@ -113,7 +137,11 @@ class DroppableQueueListWidget(QListWidget):
|
|||||||
file_paths = [
|
file_paths = [
|
||||||
url.toLocalFile()
|
url.toLocalFile()
|
||||||
for url in event.mimeData().urls()
|
for url in event.mimeData().urls()
|
||||||
if url.isLocalFile() and url.toLocalFile().lower().endswith(".txt")
|
if url.isLocalFile()
|
||||||
|
and (
|
||||||
|
url.toLocalFile().lower().endswith(".txt")
|
||||||
|
or url.toLocalFile().lower().endswith((".srt", ".ass", ".vtt"))
|
||||||
|
)
|
||||||
]
|
]
|
||||||
if file_paths:
|
if file_paths:
|
||||||
self.parent_dialog.add_files_from_paths(file_paths)
|
self.parent_dialog.add_files_from_paths(file_paths)
|
||||||
@@ -137,6 +165,8 @@ class QueueManager(QDialog):
|
|||||||
queue
|
queue
|
||||||
) # Store a deep copy of the original queue
|
) # Store a deep copy of the original queue
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
self.config = load_config() # Load config for persistence
|
||||||
|
|
||||||
layout = QVBoxLayout()
|
layout = QVBoxLayout()
|
||||||
layout.setContentsMargins(15, 15, 15, 15) # set main layout margins
|
layout.setContentsMargins(15, 15, 15, 15) # set main layout margins
|
||||||
layout.setSpacing(12) # set spacing between widgets in main layout
|
layout.setSpacing(12) # set spacing between widgets in main layout
|
||||||
@@ -151,19 +181,32 @@ class QueueManager(QDialog):
|
|||||||
# Add informative instructions at the top
|
# Add informative instructions at the top
|
||||||
instructions = QLabel(
|
instructions = QLabel(
|
||||||
"<h2>How Queue Works?</h2>"
|
"<h2>How Queue Works?</h2>"
|
||||||
"You can add text files (.txt) directly using the '<b>Add files</b>' button below. "
|
"You can add text and subtitle files (.txt, .srt, .ass, .vtt) directly using the '<b>Add files</b>' button below. "
|
||||||
"To add PDF, EPUB or markdown files, use the input box in the main window and click the <b>'Add to Queue'</b> button. "
|
"To add PDF, EPUB or markdown files, use the input box in the main window and click the <b>'Add to Queue'</b> button. "
|
||||||
"Each file in the queue keeps the configuration settings active when it was added. "
|
"By default, each file in the queue keeps the configuration settings active when they were added. "
|
||||||
"Changing the main window configuration afterward <b>does not</b> affect files already in the queue. "
|
"Enabling the <b>'Override item settings with current selection'</b> option below will force all items to use the configuration currently selected in the main window. "
|
||||||
"You can view each file's configuration by hovering over them."
|
"You can view each file's configuration by hovering over them."
|
||||||
)
|
)
|
||||||
instructions.setAlignment(Qt.AlignmentFlag.AlignLeft)
|
instructions.setAlignment(Qt.AlignmentFlag.AlignLeft)
|
||||||
instructions.setWordWrap(True)
|
instructions.setWordWrap(True)
|
||||||
instructions.setStyleSheet("margin-bottom: 8px;")
|
|
||||||
layout.addWidget(instructions)
|
layout.addWidget(instructions)
|
||||||
|
|
||||||
|
# Override Checkbox
|
||||||
|
self.override_chk = QCheckBox("Override item settings with current selection")
|
||||||
|
self.override_chk.setToolTip(
|
||||||
|
"If checked, all items in the queue will be processed using the \n"
|
||||||
|
"settings currently selected in the main window, ignoring their saved state."
|
||||||
|
)
|
||||||
|
# Load saved state (default to False)
|
||||||
|
self.override_chk.setChecked(self.config.get("queue_override_settings", False))
|
||||||
|
# Trigger process_queue to update tooltips immediately when toggled
|
||||||
|
self.override_chk.stateChanged.connect(self.process_queue)
|
||||||
|
self.override_chk.setStyleSheet("margin-bottom: 8px;")
|
||||||
|
layout.addWidget(self.override_chk)
|
||||||
|
|
||||||
# Overlay label for empty queue
|
# Overlay label for empty queue
|
||||||
self.empty_overlay = QLabel(
|
self.empty_overlay = QLabel(
|
||||||
"Drag and drop your text files here or use the 'Add files' button.",
|
"Drag and drop your text or subtitle files here or use the 'Add files' button.",
|
||||||
self.listwidget,
|
self.listwidget,
|
||||||
)
|
)
|
||||||
self.empty_overlay.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
self.empty_overlay.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||||
@@ -233,8 +276,21 @@ class QueueManager(QDialog):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.empty_overlay.hide()
|
self.empty_overlay.hide()
|
||||||
|
|
||||||
|
# Get current global settings and checkbox state for overrides
|
||||||
|
current_global_settings = self.get_current_attributes()
|
||||||
|
is_override_active = self.override_chk.isChecked()
|
||||||
|
|
||||||
icon_provider = QFileIconProvider()
|
icon_provider = QFileIconProvider()
|
||||||
for item in self.queue:
|
for item in self.queue:
|
||||||
|
# Dynamic Attribute Retrieval Helper
|
||||||
|
def get_val(attr, default=""):
|
||||||
|
# If override is ON and attr is overrideable, use global setting
|
||||||
|
if is_override_active and attr in OVERRIDE_FIELDS:
|
||||||
|
return current_global_settings.get(attr, default)
|
||||||
|
# Otherwise return the item's saved attribute
|
||||||
|
return getattr(item, attr, default)
|
||||||
|
|
||||||
# Determine display file path (prefer save_base_path for original file)
|
# Determine display file path (prefer save_base_path for original file)
|
||||||
display_file_path = getattr(item, "save_base_path", None) or item.file_name
|
display_file_path = getattr(item, "save_base_path", None) or item.file_name
|
||||||
processing_file_path = item.file_name
|
processing_file_path = item.file_name
|
||||||
@@ -259,8 +315,14 @@ class QueueManager(QDialog):
|
|||||||
# Get icon for the display file
|
# Get icon for the display file
|
||||||
icon = icon_provider.icon(QFileInfo(display_file_path))
|
icon = icon_provider.icon(QFileInfo(display_file_path))
|
||||||
list_item = QListWidgetItem()
|
list_item = QListWidgetItem()
|
||||||
# Set tooltip with detailed info
|
|
||||||
output_folder = getattr(item, "output_folder", "")
|
# Tooltip Generation
|
||||||
|
tooltip = ""
|
||||||
|
# If override is active, add the warning header on its own line
|
||||||
|
if is_override_active:
|
||||||
|
tooltip += "<b style='color: #ff9900;'>(Global Override Active)</b><br>"
|
||||||
|
|
||||||
|
output_folder = get_val("output_folder")
|
||||||
# For plain .txt inputs we don't need to show a separate processing file
|
# For plain .txt inputs we don't need to show a separate processing file
|
||||||
show_processing = True
|
show_processing = True
|
||||||
try:
|
try:
|
||||||
@@ -271,28 +333,31 @@ class QueueManager(QDialog):
|
|||||||
except Exception:
|
except Exception:
|
||||||
show_processing = True
|
show_processing = True
|
||||||
|
|
||||||
tooltip = f"<b>Input File:</b> {display_file_path}<br>"
|
tooltip += f"<b>Input File:</b> {display_file_path}<br>"
|
||||||
if (
|
if (
|
||||||
show_processing
|
show_processing
|
||||||
and processing_file_path
|
and processing_file_path
|
||||||
and processing_file_path != display_file_path
|
and processing_file_path != display_file_path
|
||||||
):
|
):
|
||||||
tooltip += f"<b>Processing File:</b> {processing_file_path}<br>"
|
tooltip += f"<b>Processing File:</b> {processing_file_path}<br>"
|
||||||
|
|
||||||
tooltip += (
|
tooltip += (
|
||||||
f"<b>Language:</b> {getattr(item, 'lang_code', '')}<br>"
|
f"<b>Language:</b> {get_val('lang_code')}<br>"
|
||||||
f"<b>Speed:</b> {getattr(item, 'speed', '')}<br>"
|
f"<b>Speed:</b> {get_val('speed')}<br>"
|
||||||
f"<b>Voice:</b> {getattr(item, 'voice', '')}<br>"
|
f"<b>Voice:</b> {get_val('voice')}<br>"
|
||||||
f"<b>Save Option:</b> {getattr(item, 'save_option', '')}<br>"
|
f"<b>Save Option:</b> {get_val('save_option')}<br>"
|
||||||
)
|
)
|
||||||
if output_folder not in (None, "", "None"):
|
if output_folder not in (None, "", "None"):
|
||||||
tooltip += f"<b>Output Folder:</b> {output_folder}<br>"
|
tooltip += f"<b>Output Folder:</b> {output_folder}<br>"
|
||||||
tooltip += (
|
tooltip += (
|
||||||
f"<b>Subtitle Mode:</b> {getattr(item, 'subtitle_mode', '')}<br>"
|
f"<b>Subtitle Mode:</b> {get_val('subtitle_mode')}<br>"
|
||||||
f"<b>Output Format:</b> {getattr(item, 'output_format', '')}<br>"
|
f"<b>Output Format:</b> {get_val('output_format')}<br>"
|
||||||
f"<b>Characters:</b> {getattr(item, 'total_char_count', '')}<br>"
|
f"<b>Characters:</b> {getattr(item, 'total_char_count', '')}<br>"
|
||||||
f"<b>Replace Single Newlines:</b> {getattr(item, 'replace_single_newlines', False)}"
|
f"<b>Replace Single Newlines:</b> {get_val('replace_single_newlines', True)}<br>"
|
||||||
|
f"<b>Use Silent Gaps:</b> {get_val('use_silent_gaps', False)}<br>"
|
||||||
|
f"<b>Speed Method:</b> {get_val('subtitle_speed_method', 'tts')}"
|
||||||
)
|
)
|
||||||
# Add book handler options if present
|
# Add book handler options if present (Preserve logic: specific to file structure)
|
||||||
save_chapters_separately = getattr(item, "save_chapters_separately", None)
|
save_chapters_separately = getattr(item, "save_chapters_separately", None)
|
||||||
merge_chapters_at_end = getattr(item, "merge_chapters_at_end", None)
|
merge_chapters_at_end = getattr(item, "merge_chapters_at_end", None)
|
||||||
if save_chapters_separately is not None:
|
if save_chapters_separately is not None:
|
||||||
@@ -401,7 +466,13 @@ class QueueManager(QDialog):
|
|||||||
attrs["total_char_count"] = getattr(parent, "char_count", "")
|
attrs["total_char_count"] = getattr(parent, "char_count", "")
|
||||||
# replace_single_newlines
|
# replace_single_newlines
|
||||||
attrs["replace_single_newlines"] = getattr(
|
attrs["replace_single_newlines"] = getattr(
|
||||||
parent, "replace_single_newlines", False
|
parent, "replace_single_newlines", True
|
||||||
|
)
|
||||||
|
# use_silent_gaps
|
||||||
|
attrs["use_silent_gaps"] = getattr(parent, "use_silent_gaps", False)
|
||||||
|
# subtitle_speed_method
|
||||||
|
attrs["subtitle_speed_method"] = getattr(
|
||||||
|
parent, "subtitle_speed_method", "tts"
|
||||||
)
|
)
|
||||||
# book handler options
|
# book handler options
|
||||||
attrs["save_chapters_separately"] = getattr(
|
attrs["save_chapters_separately"] = getattr(
|
||||||
@@ -449,6 +520,9 @@ class QueueManager(QDialog):
|
|||||||
)
|
)
|
||||||
for attr, value in current_attrs.items():
|
for attr, value in current_attrs.items():
|
||||||
setattr(item, attr, value)
|
setattr(item, attr, value)
|
||||||
|
# Override subtitle_mode to "Disabled" for subtitle files
|
||||||
|
if file_path.lower().endswith((".srt", ".ass", ".vtt")):
|
||||||
|
item.subtitle_mode = "Disabled"
|
||||||
# Read file content and calculate total_char_count using calculate_text_length
|
# Read file content and calculate total_char_count using calculate_text_length
|
||||||
try:
|
try:
|
||||||
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
||||||
@@ -478,8 +552,12 @@ class QueueManager(QDialog):
|
|||||||
== getattr(item, "output_format", None)
|
== getattr(item, "output_format", None)
|
||||||
and getattr(queued_item, "total_char_count", None)
|
and getattr(queued_item, "total_char_count", None)
|
||||||
== getattr(item, "total_char_count", None)
|
== getattr(item, "total_char_count", None)
|
||||||
and getattr(queued_item, "replace_single_newlines", False)
|
and getattr(queued_item, "replace_single_newlines", True)
|
||||||
== getattr(item, "replace_single_newlines", False)
|
== getattr(item, "replace_single_newlines", True)
|
||||||
|
and getattr(queued_item, "use_silent_gaps", False)
|
||||||
|
== getattr(item, "use_silent_gaps", False)
|
||||||
|
and getattr(queued_item, "subtitle_speed_method", "tts")
|
||||||
|
== getattr(item, "subtitle_speed_method", "tts")
|
||||||
and getattr(queued_item, "save_base_path", None)
|
and getattr(queued_item, "save_base_path", None)
|
||||||
== getattr(item, "save_base_path", None)
|
== getattr(item, "save_base_path", None)
|
||||||
and getattr(queued_item, "save_chapters_separately", None)
|
and getattr(queued_item, "save_chapters_separately", None)
|
||||||
@@ -504,11 +582,13 @@ class QueueManager(QDialog):
|
|||||||
|
|
||||||
def add_more_files(self):
|
def add_more_files(self):
|
||||||
from PyQt6.QtWidgets import QFileDialog
|
from PyQt6.QtWidgets import QFileDialog
|
||||||
from abogen.utils import calculate_text_length # import the function
|
|
||||||
|
|
||||||
# Only allow .txt files
|
# Allow .txt, .srt, .ass, and .vtt files
|
||||||
files, _ = QFileDialog.getOpenFileNames(
|
files, _ = QFileDialog.getOpenFileNames(
|
||||||
self, "Select .txt files", "", "Text Files (*.txt)"
|
self,
|
||||||
|
"Select text or subtitle files",
|
||||||
|
"",
|
||||||
|
"Supported Files (*.txt *.srt *.ass *.vtt)",
|
||||||
)
|
)
|
||||||
if not files:
|
if not files:
|
||||||
return
|
return
|
||||||
@@ -744,7 +824,10 @@ class QueueManager(QDialog):
|
|||||||
menu.exec(global_pos)
|
menu.exec(global_pos)
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
# Accept: keep changes
|
# Save the override state to config so it persists globally
|
||||||
|
self.config["queue_override_settings"] = self.override_chk.isChecked()
|
||||||
|
save_config(self.config)
|
||||||
|
|
||||||
super().accept()
|
super().accept()
|
||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ class QueuedItem:
|
|||||||
subtitle_mode: str
|
subtitle_mode: str
|
||||||
output_format: str
|
output_format: str
|
||||||
total_char_count: int
|
total_char_count: int
|
||||||
replace_single_newlines: bool = False
|
replace_single_newlines: bool = True
|
||||||
|
use_silent_gaps: bool = False
|
||||||
|
subtitle_speed_method: str = "tts"
|
||||||
save_base_path: str = None
|
save_base_path: str = None
|
||||||
save_chapters_separately: bool = None
|
save_chapters_separately: bool = None
|
||||||
merge_chapters_at_end: bool = None
|
merge_chapters_at_end: bool = None
|
||||||
|
|||||||
@@ -0,0 +1,161 @@
|
|||||||
|
"""
|
||||||
|
Lazy-loaded spaCy utilities for sentence segmentation.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Cached spaCy module and models (lazy loaded)
|
||||||
|
_spacy = None
|
||||||
|
_nlp_cache = {}
|
||||||
|
|
||||||
|
# Language code to spaCy model mapping
|
||||||
|
SPACY_MODELS = {
|
||||||
|
"a": "en_core_web_sm", # American English
|
||||||
|
"b": "en_core_web_sm", # British English
|
||||||
|
"e": "es_core_news_sm", # Spanish
|
||||||
|
"f": "fr_core_news_sm", # French
|
||||||
|
"i": "it_core_news_sm", # Italian
|
||||||
|
"p": "pt_core_news_sm", # Brazilian Portuguese
|
||||||
|
"z": "zh_core_web_sm", # Mandarin Chinese
|
||||||
|
"j": "ja_core_news_sm", # Japanese
|
||||||
|
"h": "xx_sent_ud_sm", # Hindi (multi-language model)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _load_spacy():
|
||||||
|
"""Lazy load spaCy module."""
|
||||||
|
global _spacy
|
||||||
|
if _spacy is None:
|
||||||
|
try:
|
||||||
|
import spacy
|
||||||
|
|
||||||
|
_spacy = spacy
|
||||||
|
except ImportError:
|
||||||
|
return None
|
||||||
|
return _spacy
|
||||||
|
|
||||||
|
|
||||||
|
def get_spacy_model(lang_code, log_callback=None):
|
||||||
|
"""
|
||||||
|
Get or load a spaCy model for the given language code.
|
||||||
|
Downloads the model automatically if not available.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
lang_code: Language code (a, b, e, f, etc.)
|
||||||
|
log_callback: Optional function to log messages
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Loaded spaCy model or None if unavailable
|
||||||
|
"""
|
||||||
|
|
||||||
|
def log(msg, is_error=False):
|
||||||
|
# Prefer GUI log callback when provided to avoid spamming stdout.
|
||||||
|
if log_callback:
|
||||||
|
color = "red" if is_error else "grey"
|
||||||
|
try:
|
||||||
|
log_callback((msg, color))
|
||||||
|
except Exception:
|
||||||
|
# Fallback to printing if callback misbehaves
|
||||||
|
print(msg)
|
||||||
|
else:
|
||||||
|
print(msg)
|
||||||
|
|
||||||
|
# Check if model is cached
|
||||||
|
if lang_code in _nlp_cache:
|
||||||
|
return _nlp_cache[lang_code]
|
||||||
|
|
||||||
|
# Check if language is supported
|
||||||
|
model_name = SPACY_MODELS.get(lang_code)
|
||||||
|
if not model_name:
|
||||||
|
log(f"\nspaCy: No model mapping for language '{lang_code}'...")
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Lazy load spaCy
|
||||||
|
spacy = _load_spacy()
|
||||||
|
if spacy is None:
|
||||||
|
log("\nspaCy: Module not installed, falling back to default segmentation...")
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Try to load the model
|
||||||
|
try:
|
||||||
|
log(f"\nLoading spaCy model '{model_name}'...")
|
||||||
|
# sentence segmentation involving parentheses, quotes, and complex structure.
|
||||||
|
# We only disable heavier components we don't need like NER.
|
||||||
|
nlp = spacy.load(
|
||||||
|
model_name,
|
||||||
|
disable=["ner", "tagger", "lemmatizer", "attribute_ruler"],
|
||||||
|
)
|
||||||
|
|
||||||
|
# Ensure a sentence segmentation strategy is in place
|
||||||
|
# The parser provides sents, but if it's missing (unlikely for core models), fallback to sentencizer
|
||||||
|
if "parser" not in nlp.pipe_names and "sentencizer" not in nlp.pipe_names:
|
||||||
|
nlp.add_pipe("sentencizer")
|
||||||
|
|
||||||
|
_nlp_cache[lang_code] = nlp
|
||||||
|
return nlp
|
||||||
|
except OSError:
|
||||||
|
# Model not found, attempt download
|
||||||
|
log(f"\nspaCy: Downloading model '{model_name}'...")
|
||||||
|
try:
|
||||||
|
from spacy.cli import download
|
||||||
|
|
||||||
|
download(model_name)
|
||||||
|
# Retry loading with the same fix
|
||||||
|
nlp = spacy.load(
|
||||||
|
model_name,
|
||||||
|
disable=["ner", "tagger", "lemmatizer", "attribute_ruler"],
|
||||||
|
)
|
||||||
|
if "parser" not in nlp.pipe_names and "sentencizer" not in nlp.pipe_names:
|
||||||
|
nlp.add_pipe("sentencizer")
|
||||||
|
|
||||||
|
_nlp_cache[lang_code] = nlp
|
||||||
|
log(f"spaCy model '{model_name}' downloaded and loaded")
|
||||||
|
return nlp
|
||||||
|
except Exception as e:
|
||||||
|
log(
|
||||||
|
f"\nspaCy: Failed to download model '{model_name}': {e}...",
|
||||||
|
is_error=True,
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
except Exception as e:
|
||||||
|
log(f"\nspaCy: Error loading model '{model_name}': {e}...", is_error=True)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def segment_sentences(text, lang_code, log_callback=None):
|
||||||
|
"""
|
||||||
|
Segment text into sentences using spaCy.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
text: Text to segment
|
||||||
|
lang_code: Language code
|
||||||
|
log_callback: Optional function to log messages
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List of sentence strings, or None if spaCy unavailable
|
||||||
|
"""
|
||||||
|
nlp = get_spacy_model(lang_code, log_callback)
|
||||||
|
if nlp is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Ensure spaCy can handle large texts by adjusting max_length if necessary
|
||||||
|
try:
|
||||||
|
text_len = len(text or "")
|
||||||
|
if text_len and hasattr(nlp, "max_length") and text_len > nlp.max_length:
|
||||||
|
# increase a bit beyond the text length to be safe
|
||||||
|
nlp.max_length = text_len + 1000
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Process text and extract sentences
|
||||||
|
doc = nlp(text)
|
||||||
|
return [sent.text.strip() for sent in doc.sents if sent.text.strip()]
|
||||||
|
|
||||||
|
|
||||||
|
def is_spacy_available():
|
||||||
|
"""Check if spaCy can be imported."""
|
||||||
|
return _load_spacy() is not None
|
||||||
|
|
||||||
|
|
||||||
|
def clear_cache():
|
||||||
|
"""Clear the model cache to free memory."""
|
||||||
|
global _nlp_cache
|
||||||
|
_nlp_cache.clear()
|
||||||
+26
-12
@@ -10,6 +10,13 @@ from threading import Thread
|
|||||||
|
|
||||||
warnings.filterwarnings("ignore")
|
warnings.filterwarnings("ignore")
|
||||||
|
|
||||||
|
# Pre-compile frequently used regex patterns for better performance
|
||||||
|
_WHITESPACE_PATTERN = re.compile(r"[^\S\n]+")
|
||||||
|
_MULTIPLE_NEWLINES_PATTERN = re.compile(r"\n{3,}")
|
||||||
|
_SINGLE_NEWLINE_PATTERN = re.compile(r"(?<!\n)\n(?!\n)")
|
||||||
|
_CHAPTER_MARKER_PATTERN = re.compile(r"<<CHAPTER_MARKER:.*?>>")
|
||||||
|
_METADATA_PATTERN = re.compile(r"<<METADATA_[^:]+:[^>]*>>")
|
||||||
|
|
||||||
|
|
||||||
def detect_encoding(file_path):
|
def detect_encoding(file_path):
|
||||||
import chardet
|
import chardet
|
||||||
@@ -126,15 +133,18 @@ _sleep_procs = {"Darwin": None, "Linux": None} # Store sleep prevention process
|
|||||||
def clean_text(text, *args, **kwargs):
|
def clean_text(text, *args, **kwargs):
|
||||||
# Load replace_single_newlines from config
|
# Load replace_single_newlines from config
|
||||||
cfg = load_config()
|
cfg = load_config()
|
||||||
replace_single_newlines = cfg.get("replace_single_newlines", False)
|
replace_single_newlines = cfg.get("replace_single_newlines", True)
|
||||||
# Collapse all whitespace (excluding newlines) into single spaces per line and trim edges
|
# Collapse all whitespace (excluding newlines) into single spaces per line and trim edges
|
||||||
lines = [re.sub(r"[^\S\n]+", " ", line).strip() for line in text.splitlines()]
|
# Use pre-compiled pattern for better performance
|
||||||
|
lines = [_WHITESPACE_PATTERN.sub(" ", line).strip() for line in text.splitlines()]
|
||||||
text = "\n".join(lines)
|
text = "\n".join(lines)
|
||||||
# Standardize paragraph breaks (multiple newlines become exactly two) and trim overall whitespace
|
# Standardize paragraph breaks (multiple newlines become exactly two) and trim overall whitespace
|
||||||
text = re.sub(r"\n{3,}", "\n\n", text).strip()
|
# Use pre-compiled pattern for better performance
|
||||||
|
text = _MULTIPLE_NEWLINES_PATTERN.sub("\n\n", text).strip()
|
||||||
# Optionally replace single newlines with spaces, but preserve double newlines
|
# Optionally replace single newlines with spaces, but preserve double newlines
|
||||||
if replace_single_newlines:
|
if replace_single_newlines:
|
||||||
text = re.sub(r"(?<!\n)\n(?!\n)", " ", text)
|
# Use pre-compiled pattern for better performance
|
||||||
|
text = _SINGLE_NEWLINE_PATTERN.sub(" ", text)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
@@ -243,20 +253,24 @@ def save_config(config):
|
|||||||
|
|
||||||
|
|
||||||
def calculate_text_length(text):
|
def calculate_text_length(text):
|
||||||
# Ignore chapter markers
|
# Use pre-compiled patterns for better performance
|
||||||
text = re.sub(r"<<CHAPTER_MARKER:.*?>>", "", text)
|
# Ignore chapter markers and metadata patterns in a single pass
|
||||||
# Ignore metadata patterns
|
text = _CHAPTER_MARKER_PATTERN.sub("", text)
|
||||||
text = re.sub(r"<<METADATA_[^:]+:[^>]*>>", "", text)
|
text = _METADATA_PATTERN.sub("", text)
|
||||||
# Ignore newlines
|
# Ignore newlines and leading/trailing spaces
|
||||||
text = text.replace("\n", "")
|
text = text.replace("\n", "").strip()
|
||||||
# Ignore leading/trailing spaces
|
|
||||||
text = text.strip()
|
|
||||||
# Calculate character count
|
# Calculate character count
|
||||||
char_count = len(text)
|
char_count = len(text)
|
||||||
return char_count
|
return char_count
|
||||||
|
|
||||||
|
|
||||||
def get_gpu_acceleration(enabled):
|
def get_gpu_acceleration(enabled):
|
||||||
|
"""
|
||||||
|
Check GPU acceleration availability.
|
||||||
|
|
||||||
|
Note: On Windows, torch DLLs must be pre-loaded in main.py before PyQt6
|
||||||
|
to avoid DLL initialization errors.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
import torch
|
import torch
|
||||||
from torch.cuda import is_available as cuda_available
|
from torch.cuda import is_available as cuda_available
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Build PyPI package (wheel and sdist) to `dist` folder for abogen."""
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
output_dir = os.path.join(script_dir, "dist")
|
||||||
|
|
||||||
|
print("🔧 abogen PyPI Package Builder")
|
||||||
|
print("=" * 40)
|
||||||
|
print(f"📁 Script directory: {script_dir}")
|
||||||
|
print(f"📦 Output directory: {output_dir}")
|
||||||
|
|
||||||
|
# Try to print package version if present
|
||||||
|
version = None
|
||||||
|
version_file = os.path.join(script_dir, "abogen", "VERSION")
|
||||||
|
if os.path.isfile(version_file):
|
||||||
|
try:
|
||||||
|
with open(version_file, "r", encoding="utf-8") as vf:
|
||||||
|
version = vf.read().strip()
|
||||||
|
except Exception:
|
||||||
|
version = None
|
||||||
|
if version:
|
||||||
|
print(f"🔖 Package version: {version}")
|
||||||
|
|
||||||
|
# Check if build module is installed, install if not
|
||||||
|
# Temporarily remove script_dir from sys.path to avoid importing local build.py
|
||||||
|
import sys
|
||||||
|
original_path = sys.path[:]
|
||||||
|
try:
|
||||||
|
sys.path = [p for p in sys.path if os.path.abspath(p) != script_dir]
|
||||||
|
import build
|
||||||
|
except ImportError:
|
||||||
|
print("📦 Installing build module...")
|
||||||
|
subprocess.run([sys.executable, "-m", "pip", "install", "build"], check=True)
|
||||||
|
finally:
|
||||||
|
sys.path = original_path
|
||||||
|
|
||||||
|
# Create output directory
|
||||||
|
print(f"📂 Preparing output directory: {output_dir}")
|
||||||
|
if os.path.exists(output_dir):
|
||||||
|
shutil.rmtree(output_dir)
|
||||||
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|
||||||
|
print("🏗️ Building PyPI package...")
|
||||||
|
print(" Using temporary directory to avoid module conflicts...")
|
||||||
|
|
||||||
|
# Run from temp directory to avoid local build.py shadowing the build module
|
||||||
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
|
print(f" Temp directory: {tmpdir}")
|
||||||
|
print(" Running: python -m build -o <output_dir> <source_dir>")
|
||||||
|
|
||||||
|
result = subprocess.run(
|
||||||
|
[sys.executable, "-m", "build", "-o", output_dir, script_dir],
|
||||||
|
check=False,
|
||||||
|
cwd=tmpdir,
|
||||||
|
)
|
||||||
|
|
||||||
|
print("\n" + "=" * 40)
|
||||||
|
if result.returncode == 0:
|
||||||
|
print("✅ Build successful!")
|
||||||
|
print(f"📦 Files created in {output_dir}:")
|
||||||
|
|
||||||
|
files = os.listdir(output_dir)
|
||||||
|
if files:
|
||||||
|
for f in files:
|
||||||
|
file_path = os.path.join(output_dir, f)
|
||||||
|
size = os.path.getsize(file_path)
|
||||||
|
print(f" 📄 {f} ({size:,} bytes)")
|
||||||
|
else:
|
||||||
|
print(" (No files found)")
|
||||||
|
|
||||||
|
print("\n🚀 Ready for upload with:\n")
|
||||||
|
print(" - To test on Test PyPI:")
|
||||||
|
print(f" python -m twine upload --repository testpypi {output_dir}/*")
|
||||||
|
print("\n - To upload to PyPI (when ready):")
|
||||||
|
print(f" python -m twine upload {output_dir}/*")
|
||||||
|
else:
|
||||||
|
print("❌ Build failed!")
|
||||||
|
print(f" Exit code: {result.returncode}")
|
||||||
|
sys.exit(result.returncode)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 63 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 150 KiB After Width: | Height: | Size: 148 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 125 KiB After Width: | Height: | Size: 103 KiB |
+77
-1
@@ -13,6 +13,7 @@ license = "MIT"
|
|||||||
requires-python = ">=3.10, <3.13"
|
requires-python = ">=3.10, <3.13"
|
||||||
keywords = ["audiobook", "epub", "pdf", "text-to-speech", "subtitle", "tts", "kokoro", "accessibility", "book-converter", "voice-synthesis", "multilingual", "chapter-management", "subtitles", "content-creation", "media-generation"]
|
keywords = ["audiobook", "epub", "pdf", "text-to-speech", "subtitle", "tts", "kokoro", "accessibility", "book-converter", "voice-synthesis", "multilingual", "chapter-management", "subtitles", "content-creation", "media-generation"]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"pip",
|
||||||
"PyQt6>=6.10.0",
|
"PyQt6>=6.10.0",
|
||||||
"kokoro>=0.9.4",
|
"kokoro>=0.9.4",
|
||||||
"misaki[zh]>=0.9.4",
|
"misaki[zh]>=0.9.4",
|
||||||
@@ -25,7 +26,8 @@ dependencies = [
|
|||||||
"charset_normalizer>=3.4.1",
|
"charset_normalizer>=3.4.1",
|
||||||
"chardet>=5.2.0",
|
"chardet>=5.2.0",
|
||||||
"static_ffmpeg>=2.13",
|
"static_ffmpeg>=2.13",
|
||||||
"Markdown>=3.9"
|
"Markdown>=3.9",
|
||||||
|
"spacy>=3.8.7"
|
||||||
]
|
]
|
||||||
|
|
||||||
classifiers = [
|
classifiers = [
|
||||||
@@ -69,3 +71,77 @@ packages = ["abogen"]
|
|||||||
[tool.hatch.version]
|
[tool.hatch.version]
|
||||||
path = "abogen/VERSION"
|
path = "abogen/VERSION"
|
||||||
pattern = "^(?P<version>.+)$"
|
pattern = "^(?P<version>.+)$"
|
||||||
|
|
||||||
|
# --- OPTIONAL DEPENDENCIES ---
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
# NVIDIA GPU (Windows) (CUDA 12.6) # uv tool install abogen[cuda126]
|
||||||
|
cuda126 = ["torch"]
|
||||||
|
# NVIDIA GPU (Windows) (CUDA 12.8) # uv tool install abogen[cuda]
|
||||||
|
cuda = ["torch"]
|
||||||
|
# NVIDIA GPU (Windows) (CUDA 13.0) # uv tool install abogen[cuda130]
|
||||||
|
cuda130 = ["torch"]
|
||||||
|
# AMD GPU (Linux) (ROCm 6.4) # uv tool install abogen[rocm]
|
||||||
|
rocm = ["torch", "pytorch-triton-rocm"]
|
||||||
|
|
||||||
|
# --- KOKORO CONFIGURATION (for macOS) ---
|
||||||
|
|
||||||
|
[tool.uv.sources]
|
||||||
|
kokoro = [
|
||||||
|
{ git = "https://github.com/hexgrad/kokoro.git", marker = "sys_platform == 'darwin'" },
|
||||||
|
{ index = "pypi", marker = "sys_platform != 'darwin'" }
|
||||||
|
]
|
||||||
|
|
||||||
|
# --- TORCH CONFIGURATION ---
|
||||||
|
|
||||||
|
torch = [
|
||||||
|
# ROCm 6.4 Nightly (AMD)
|
||||||
|
{ index = "pytorch-rocm-64-nightly", marker = "extra == 'rocm'" },
|
||||||
|
|
||||||
|
# CUDA 13.0 (NVIDIA)
|
||||||
|
{ index = "pytorch-cuda-130", marker = "extra == 'cuda130' and extra != 'rocm'" },
|
||||||
|
|
||||||
|
# CUDA 12.6 (NVIDIA)
|
||||||
|
{ index = "pytorch-cuda-126", marker = "extra == 'cuda126' and extra != 'rocm' and extra != 'cuda130'" },
|
||||||
|
|
||||||
|
# CUDA 12.8 (NVIDIA)
|
||||||
|
{ index = "pytorch-cuda-128", marker = "extra == 'cuda' and extra != 'rocm' and extra != 'cuda130' and extra != 'cuda126'" }
|
||||||
|
]
|
||||||
|
|
||||||
|
# --- TRITON CONFIGURATION ---
|
||||||
|
|
||||||
|
pytorch-triton-rocm = [
|
||||||
|
{ index = "pytorch-rocm-64-nightly", marker = "extra == 'rocm'" }
|
||||||
|
]
|
||||||
|
|
||||||
|
# --- INDEX DEFINITIONS ---
|
||||||
|
|
||||||
|
# PyPI Index
|
||||||
|
[[tool.uv.index]]
|
||||||
|
name = "pypi"
|
||||||
|
url = "https://pypi.org/simple"
|
||||||
|
default = true
|
||||||
|
|
||||||
|
# CUDA 12.6 Index
|
||||||
|
[[tool.uv.index]]
|
||||||
|
name = "pytorch-cuda-126"
|
||||||
|
url = "https://download.pytorch.org/whl/cu126"
|
||||||
|
explicit = true
|
||||||
|
|
||||||
|
# CUDA 12.8 Index
|
||||||
|
[[tool.uv.index]]
|
||||||
|
name = "pytorch-cuda-128"
|
||||||
|
url = "https://download.pytorch.org/whl/cu128"
|
||||||
|
explicit = true
|
||||||
|
|
||||||
|
# CUDA 13.0 Index
|
||||||
|
[[tool.uv.index]]
|
||||||
|
name = "pytorch-cuda-130"
|
||||||
|
url = "https://download.pytorch.org/whl/cu130"
|
||||||
|
explicit = true
|
||||||
|
|
||||||
|
# ROCm 6.4 Nightly Index
|
||||||
|
[[tool.uv.index]]
|
||||||
|
name = "pytorch-rocm-64-nightly"
|
||||||
|
url = "https://download.pytorch.org/whl/nightly/rocm6.4"
|
||||||
|
explicit = true
|
||||||
|
|||||||
Reference in New Issue
Block a user