mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 21:50:28 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b3125b624 | ||
|
|
bb5c4204de | ||
|
|
43f5589a9d | ||
|
|
10d3f470e7 | ||
|
|
c72c8e777c | ||
|
|
b51e094af1 | ||
|
|
04844997d5 | ||
|
|
7835211a25 | ||
|
|
6bb6fcb406 | ||
|
|
ad8a6e520e | ||
|
|
fe22fe83b0 | ||
|
|
afbd5203fe | ||
|
|
4b175c7cf2 | ||
|
|
334c0654ca | ||
|
|
42b7979585 |
@@ -1,3 +1,14 @@
|
||||
# 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
|
||||
- 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.
|
||||
|
||||
@@ -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>
|
||||
|
||||
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">
|
||||
|
||||
@@ -42,7 +42,8 @@ python -m venv venv
|
||||
venv\Scripts\activate
|
||||
|
||||
# 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:
|
||||
# Not supported yet, because ROCm is not available on Windows. Use Linux if you have AMD GPU.
|
||||
@@ -114,7 +115,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.
|
||||
|
||||
## `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:
|
||||
- Set speech speed
|
||||
- Select a voice (or create a custom voice using voice mixer)
|
||||
@@ -132,7 +133,7 @@ Here’s Abogen in action: in this demo, it processes ∼3,000 characters of tex
|
||||
|
||||
| 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. |
|
||||
| **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. |
|
||||
@@ -168,6 +169,8 @@ 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 cache directory** | Opens the cache directory where converted text files are stored. |
|
||||
| **Clear cache files** | Deletes cache files created during the conversion or preview. |
|
||||
| **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). |
|
||||
| **Check for updates at startup** | Automatically checks for updates when the program starts. |
|
||||
| **Disable Kokoro's internet access** | Prevents Kokoro from downloading models or voices from HuggingFace Hub, useful for offline use. |
|
||||
| **Reset to default settings** | Resets all settings to their default values. |
|
||||
@@ -227,7 +230,30 @@ Similar to chapter markers, it is possible to add metadata tags for `M4B` files.
|
||||
<<METADATA_ALBUM_ARTIST:Album Artist>>
|
||||
<<METADATA_COMPOSER:Narrator>>
|
||||
<<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` 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` 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`
|
||||
```
|
||||
@@ -250,6 +276,7 @@ I highly recommend using [MPV](https://mpv.io/installation/) to play your audio
|
||||
# --- MPV Settings ---
|
||||
save-position-on-quit
|
||||
keep-open=yes
|
||||
audio-display=no
|
||||
# --- Subtitle ---
|
||||
sub-ass-override=no
|
||||
sub-margin-y=50
|
||||
@@ -345,14 +372,20 @@ 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>
|
||||
</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:
|
||||
> Open your terminal in the Abogen folder (the folder that contains `python_embedded`) and type:
|
||||
> ```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 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.
|
||||
>
|
||||
> 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.
|
||||
|
||||
</details>
|
||||
|
||||
@@ -382,7 +415,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:
|
||||
> 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
|
||||
> 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:
|
||||
> ```bash
|
||||
@@ -458,4 +491,4 @@ This project is available under the MIT License - see the [LICENSE](https://gith
|
||||
> [!IMPORTANT]
|
||||
> 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.
|
||||
|
||||
> 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"
|
||||
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
|
||||
|
||||
if "%cuda_available%"=="False" (
|
||||
echo Installing PyTorch with CUDA %CUDA_VERSION% 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
|
||||
echo Installing PyTorch with CUDA (12.8) support...
|
||||
:: 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.
|
||||
if errorlevel 1 (
|
||||
echo Failed to install PyTorch.
|
||||
@@ -305,8 +304,10 @@ if /I "%IS_NVIDIA%"=="true" (
|
||||
if errorlevel 2 (
|
||||
echo Skipping PyTorch installation.
|
||||
) else (
|
||||
echo Installing PyTorch with CUDA %CUDA_VERSION% 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
|
||||
echo Installing PyTorch with CUDA (12.8) support...
|
||||
:: 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 (
|
||||
echo Failed to install PyTorch.
|
||||
pause
|
||||
|
||||
@@ -14,6 +14,8 @@ RUN apt-get update \
|
||||
python3-pip \
|
||||
python3-pyqt6 \
|
||||
espeak-ng \
|
||||
libxcb-cursor0 \
|
||||
libgl1 \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
1.2.1
|
||||
1.2.2
|
||||
@@ -89,6 +89,9 @@ class HandlerDialog(QDialog):
|
||||
def __init__(self, book_path, file_type=None, checked_chapters=None, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
# Normalize path
|
||||
book_path = os.path.normpath(os.path.abspath(book_path))
|
||||
|
||||
# Determine file type if not explicitly provided
|
||||
if file_type:
|
||||
self.file_type = file_type
|
||||
@@ -374,6 +377,7 @@ class HandlerDialog(QDialog):
|
||||
|
||||
# Include replace_single_newlines in cache key since it affects text cleaning
|
||||
from abogen.utils import load_config
|
||||
|
||||
cfg = load_config()
|
||||
replace_single_newlines = cfg.get("replace_single_newlines", False)
|
||||
|
||||
@@ -2211,6 +2215,7 @@ class HandlerDialog(QDialog):
|
||||
def _format_metadata_tags(self):
|
||||
"""Format metadata tags for insertion at the beginning of the text"""
|
||||
import datetime
|
||||
from abogen.utils import get_user_cache_path
|
||||
|
||||
metadata = self.book_metadata
|
||||
filename = os.path.splitext(os.path.basename(self.book_path))[0]
|
||||
@@ -2231,6 +2236,21 @@ class HandlerDialog(QDialog):
|
||||
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
|
||||
metadata_tags = [
|
||||
f"<<METADATA_TITLE:{title}>>",
|
||||
@@ -2242,6 +2262,9 @@ class HandlerDialog(QDialog):
|
||||
f"<<METADATA_GENRE:Audiobook>>",
|
||||
]
|
||||
|
||||
if cover_tag:
|
||||
metadata_tags.append(cover_tag)
|
||||
|
||||
return "\n".join(metadata_tags)
|
||||
|
||||
def _get_markdown_selected_text(self):
|
||||
|
||||
+5
-3
@@ -2,9 +2,7 @@ from abogen.utils import get_version
|
||||
|
||||
# Program Information
|
||||
PROGRAM_NAME = "abogen"
|
||||
PROGRAM_DESCRIPTION = (
|
||||
"Generate audiobooks from EPUBs, PDFs and text with synchronized captions."
|
||||
)
|
||||
PROGRAM_DESCRIPTION = "Generate audiobooks from EPUBs, PDFs, text and subtitles with synchronized captions."
|
||||
GITHUB_URL = "https://github.com/denizsafak/abogen"
|
||||
VERSION = get_version()
|
||||
|
||||
@@ -44,6 +42,7 @@ SUPPORTED_SOUND_FORMATS = [
|
||||
SUPPORTED_SUBTITLE_FORMATS = [
|
||||
"srt",
|
||||
"ass",
|
||||
"vtt",
|
||||
]
|
||||
|
||||
# Supported input formats
|
||||
@@ -51,6 +50,9 @@ SUPPORTED_INPUT_FORMATS = [
|
||||
"epub",
|
||||
"pdf",
|
||||
"txt",
|
||||
"srt",
|
||||
"ass",
|
||||
"vtt",
|
||||
]
|
||||
|
||||
# Supported languages for subtitle generation
|
||||
|
||||
+1073
-84
File diff suppressed because it is too large
Load Diff
+145
-16
@@ -161,7 +161,7 @@ class InputBox(QLabel):
|
||||
self.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
self.setAcceptDrops(True)
|
||||
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(
|
||||
f"QLabel {{ {self.STYLE_DEFAULT} }} QLabel:hover {{ {self.STYLE_DEFAULT_HOVER} }}"
|
||||
@@ -255,7 +255,7 @@ class InputBox(QLabel):
|
||||
except Exception:
|
||||
return str(n)
|
||||
|
||||
doc_extensions = (".epub", ".pdf", ".md", ".markdown")
|
||||
doc_extensions = (".epub", ".pdf", ".md", ".markdown", ".srt", ".ass", ".vtt")
|
||||
char_source_path = file_path
|
||||
cached_char_count = None
|
||||
|
||||
@@ -321,11 +321,11 @@ class InputBox(QLabel):
|
||||
else: # PDF - always use Pages
|
||||
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()
|
||||
# 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
|
||||
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)
|
||||
if (
|
||||
@@ -337,6 +337,12 @@ class InputBox(QLabel):
|
||||
|
||||
self.edit_btn.setVisible(should_show_edit)
|
||||
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)
|
||||
self.resizeEvent(None)
|
||||
if hasattr(window, "btn_add_to_queue"):
|
||||
@@ -367,7 +373,7 @@ class InputBox(QLabel):
|
||||
self.window().save_chapters_separately = None
|
||||
self.window().merge_chapters_at_end = None
|
||||
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(
|
||||
f"QLabel {{ {self.STYLE_DEFAULT} }} QLabel:hover {{ {self.STYLE_DEFAULT_HOVER} }}"
|
||||
@@ -379,9 +385,21 @@ class InputBox(QLabel):
|
||||
self.textbox_btn.show()
|
||||
self.edit_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, "lang_code", "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
|
||||
if hasattr(self.window(), "btn_add_to_queue"):
|
||||
self.window().btn_add_to_queue.setEnabled(False)
|
||||
if hasattr(window, "btn_add_to_queue"):
|
||||
window.btn_add_to_queue.setEnabled(False)
|
||||
# Reset the input_box_cleared_by_queue flag after setting file info
|
||||
if hasattr(self.window(), "input_box_cleared_by_queue"):
|
||||
self.window().input_box_cleared_by_queue = True
|
||||
@@ -407,6 +425,7 @@ class InputBox(QLabel):
|
||||
or ext.endswith(".epub")
|
||||
or ext.endswith(".pdf")
|
||||
or ext.endswith((".md", ".markdown"))
|
||||
or ext.endswith((".srt", ".ass", ".vtt"))
|
||||
):
|
||||
event.acceptProposedAction()
|
||||
# Set hover style based on current state
|
||||
@@ -460,12 +479,20 @@ class InputBox(QLabel):
|
||||
file_path.lower().endswith(".epub")
|
||||
or file_path.lower().endswith(".pdf")
|
||||
or file_path.lower().endswith((".md", ".markdown"))
|
||||
or file_path.lower().endswith((".srt", ".ass", ".vtt"))
|
||||
):
|
||||
# Determine file type
|
||||
if file_path.lower().endswith(".epub"):
|
||||
file_type = "epub"
|
||||
elif file_path.lower().endswith(".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:
|
||||
file_type = "markdown"
|
||||
|
||||
@@ -477,7 +504,9 @@ class InputBox(QLabel):
|
||||
)
|
||||
event.acceptProposedAction()
|
||||
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()
|
||||
else:
|
||||
event.ignore()
|
||||
@@ -796,6 +825,8 @@ class abogen(QWidget):
|
||||
"use_gpu", True # Load GPU setting with default True
|
||||
)
|
||||
self.replace_single_newlines = self.config.get("replace_single_newlines", False)
|
||||
self.use_silent_gaps = self.config.get("use_silent_gaps", False)
|
||||
self.subtitle_speed_method = self.config.get("subtitle_speed_method", "tts")
|
||||
self._pending_close_event = None
|
||||
self.gpu_ok = False # Initialize GPU availability status
|
||||
|
||||
@@ -1291,7 +1322,10 @@ class abogen(QWidget):
|
||||
return
|
||||
try:
|
||||
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:
|
||||
return
|
||||
@@ -1312,6 +1346,11 @@ class abogen(QWidget):
|
||||
# Don't set file info immediately, open_book_file will handle it after dialog is accepted
|
||||
if not self.open_book_file(file_path):
|
||||
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:
|
||||
self.selected_file, self.selected_file_type = file_path, "txt"
|
||||
self.displayed_file_path = (
|
||||
@@ -1817,6 +1856,8 @@ class abogen(QWidget):
|
||||
output_format=self.selected_format,
|
||||
total_char_count=self.char_count,
|
||||
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_chapters_separately=getattr(self, "save_chapters_separately", None),
|
||||
merge_chapters_at_end=getattr(self, "merge_chapters_at_end", None),
|
||||
@@ -1900,6 +1941,7 @@ class abogen(QWidget):
|
||||
self.replace_single_newlines = getattr(
|
||||
queued_item, "replace_single_newlines", False
|
||||
)
|
||||
self.use_silent_gaps = getattr(queued_item, "use_silent_gaps", False)
|
||||
# Restore the original file path for save location
|
||||
self.displayed_file_path = (
|
||||
queued_item.save_base_path or queued_item.file_name
|
||||
@@ -2045,6 +2087,10 @@ class abogen(QWidget):
|
||||
self.conversion_thread.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 separate_chapters_format setting
|
||||
self.conversion_thread.separate_chapters_format = (
|
||||
self.separate_chapters_format
|
||||
@@ -2767,12 +2813,29 @@ class abogen(QWidget):
|
||||
|
||||
def show_chapter_options_dialog(self, chapter_count):
|
||||
"""Show dialog to ask user about chapter processing options when chapters are detected in a .txt file"""
|
||||
# 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
|
||||
|
||||
dialog = ChapterOptionsDialog(chapter_count, parent=self)
|
||||
dialog.setWindowModality(Qt.WindowModality.ApplicationModal)
|
||||
|
||||
# If dialog is accepted, pass the options to the conversion thread
|
||||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
options = dialog.get_options()
|
||||
if (
|
||||
@@ -2781,7 +2844,6 @@ class abogen(QWidget):
|
||||
):
|
||||
self.conversion_thread.set_chapter_options(options)
|
||||
else:
|
||||
# If dialog is rejected, cancel the conversion
|
||||
self.cancel_conversion()
|
||||
|
||||
def apply_theme(self, theme):
|
||||
@@ -3040,6 +3102,44 @@ class abogen(QWidget):
|
||||
# Add separator
|
||||
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 "Disable Kokoro's internet access" option
|
||||
disable_kokoro_action = QAction("Disable Kokoro's internet access", self)
|
||||
disable_kokoro_action.setCheckable(True)
|
||||
@@ -3075,6 +3175,35 @@ class abogen(QWidget):
|
||||
self.config["replace_single_newlines"] = enabled
|
||||
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 restart_app(self):
|
||||
|
||||
import sys
|
||||
@@ -3521,9 +3650,9 @@ Categories=AudioVideo;Audio;Utility;
|
||||
# Get the abogen cache directory
|
||||
cache_dir = get_user_cache_path()
|
||||
|
||||
# Find all .txt files in the abogen cache directory
|
||||
pattern = os.path.join(cache_dir, "*.txt")
|
||||
cache_files = glob.glob(pattern)
|
||||
# Find all .txt files and cover images in the abogen cache directory
|
||||
cache_files = glob.glob(os.path.join(cache_dir, "*.txt"))
|
||||
cache_files.extend(glob.glob(os.path.join(cache_dir, "cover_*.jpg")))
|
||||
|
||||
# Count the files
|
||||
file_count = len(cache_files)
|
||||
@@ -3555,7 +3684,7 @@ Categories=AudioVideo;Audio;Utility;
|
||||
msg_box.setText(msg_text + "\nDo you want to delete them?")
|
||||
|
||||
# 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)
|
||||
# Only enable checkbox if preview files exist
|
||||
preview_cache_checkbox.setEnabled(preview_count > 0)
|
||||
|
||||
+18
-1
@@ -4,6 +4,23 @@ import platform
|
||||
import atexit
|
||||
import signal
|
||||
|
||||
# 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)
|
||||
try:
|
||||
from PyQt6.QtCore import QLibraryInfo
|
||||
@@ -134,7 +151,7 @@ def main():
|
||||
# Set the .desktop name on Linux
|
||||
if platform.system() == "Linux":
|
||||
try:
|
||||
app.setDesktopFileName("abogen.desktop")
|
||||
app.setDesktopFileName("abogen")
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
|
||||
@@ -87,7 +87,11 @@ class DroppableQueueListWidget(QListWidget):
|
||||
def dragEnterEvent(self, event):
|
||||
if event.mimeData().hasUrls():
|
||||
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.setVisible(True)
|
||||
event.acceptProposedAction()
|
||||
@@ -98,7 +102,11 @@ class DroppableQueueListWidget(QListWidget):
|
||||
def dragMoveEvent(self, event):
|
||||
if event.mimeData().hasUrls():
|
||||
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()
|
||||
return
|
||||
event.ignore()
|
||||
@@ -113,7 +121,11 @@ class DroppableQueueListWidget(QListWidget):
|
||||
file_paths = [
|
||||
url.toLocalFile()
|
||||
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:
|
||||
self.parent_dialog.add_files_from_paths(file_paths)
|
||||
@@ -151,7 +163,7 @@ class QueueManager(QDialog):
|
||||
# Add informative instructions at the top
|
||||
instructions = QLabel(
|
||||
"<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. "
|
||||
"Each file in the queue keeps the configuration settings active when it was added. "
|
||||
"Changing the main window configuration afterward <b>does not</b> affect files already in the queue. "
|
||||
@@ -163,7 +175,7 @@ class QueueManager(QDialog):
|
||||
layout.addWidget(instructions)
|
||||
# Overlay label for empty queue
|
||||
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.empty_overlay.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
@@ -290,7 +302,9 @@ class QueueManager(QDialog):
|
||||
f"<b>Subtitle Mode:</b> {getattr(item, 'subtitle_mode', '')}<br>"
|
||||
f"<b>Output Format:</b> {getattr(item, 'output_format', '')}<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> {getattr(item, 'replace_single_newlines', False)}<br>"
|
||||
f"<b>Use Silent Gaps:</b> {getattr(item, 'use_silent_gaps', False)}<br>"
|
||||
f"<b>Speed Method:</b> {getattr(item, 'subtitle_speed_method', 'tts')}"
|
||||
)
|
||||
# Add book handler options if present
|
||||
save_chapters_separately = getattr(item, "save_chapters_separately", None)
|
||||
@@ -403,6 +417,12 @@ class QueueManager(QDialog):
|
||||
attrs["replace_single_newlines"] = getattr(
|
||||
parent, "replace_single_newlines", False
|
||||
)
|
||||
# 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
|
||||
attrs["save_chapters_separately"] = getattr(
|
||||
parent, "save_chapters_separately", None
|
||||
@@ -449,6 +469,9 @@ class QueueManager(QDialog):
|
||||
)
|
||||
for attr, value in current_attrs.items():
|
||||
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
|
||||
try:
|
||||
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
||||
@@ -480,6 +503,10 @@ class QueueManager(QDialog):
|
||||
== getattr(item, "total_char_count", None)
|
||||
and getattr(queued_item, "replace_single_newlines", False)
|
||||
== getattr(item, "replace_single_newlines", False)
|
||||
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)
|
||||
== getattr(item, "save_base_path", None)
|
||||
and getattr(queued_item, "save_chapters_separately", None)
|
||||
@@ -506,9 +533,12 @@ class QueueManager(QDialog):
|
||||
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(
|
||||
self, "Select .txt files", "", "Text Files (*.txt)"
|
||||
self,
|
||||
"Select text or subtitle files",
|
||||
"",
|
||||
"Supported Files (*.txt *.srt *.ass *.vtt)",
|
||||
)
|
||||
if not files:
|
||||
return
|
||||
|
||||
@@ -14,6 +14,8 @@ class QueuedItem:
|
||||
output_format: str
|
||||
total_char_count: int
|
||||
replace_single_newlines: bool = False
|
||||
use_silent_gaps: bool = False
|
||||
subtitle_speed_method: str = "tts"
|
||||
save_base_path: str = None
|
||||
save_chapters_separately: bool = None
|
||||
merge_chapters_at_end: bool = None
|
||||
|
||||
@@ -257,6 +257,12 @@ def calculate_text_length(text):
|
||||
|
||||
|
||||
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:
|
||||
import torch
|
||||
from torch.cuda import is_available as cuda_available
|
||||
|
||||
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 |
Reference in New Issue
Block a user