aboutsummaryrefslogtreecommitdiff
path: root/audiobook.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-24 12:57:54 -0400
committerhistoria <historiavg@proton.me>2026-08-24 12:57:54 -0400
commitaac8febbdb45b7994e209bc74a44f8fc98fc745d (patch)
tree1b74a62aa672e19d53dc0a3597d5020db8c2c8d0 /audiobook.py
parent4db8ea7a63107297450819d227497ebbb121ff38 (diff)
downloadtts-audiobook-generator-aac8febbdb45b7994e209bc74a44f8fc98fc745d.tar.gz
feat: --input and --output flags
Diffstat (limited to 'audiobook.py')
-rwxr-xr-xaudiobook.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/audiobook.py b/audiobook.py
index 6c075ea..2eeabfe 100755
--- a/audiobook.py
+++ b/audiobook.py
@@ -35,6 +35,7 @@ sys.path.insert(0, str(APP_DIR))
from backends import envs as _envs # noqa: I001
from converter import config
+from converter import converter as _converter_mod
from converter.converter import (
AUDIO_FORMATS,
AudiobookConverter,
@@ -56,16 +57,23 @@ def convert(backend: str = None, voice: str = None, clone: str = None,
language: str = None, speed: float = 1.0, single_file: bool = False,
output_format: str = None, debug: bool = False, chunk: bool = False,
model_id: str = None, instructions: str = None,
- request_options: dict = None) -> int:
+ request_options: dict = None, input_dir: Path = None,
+ output_dir: Path = None) -> int:
"""Run one conversion pass with explicit options (used by the CLI and hub).
Returns the process exit code (0 on success, 1 on failure, 130 on
Ctrl-C). BACKEND defaults to config.BACKEND, OUTPUT_FORMAT to
config.AUDIO_FORMAT. LANGUAGE is already-normalized where required.
+ INPUT_DIR/OUTPUT_DIR override the default input/ and output/ folders
+ when given.
"""
backend = backend or config.BACKEND
output_format = output_format or config.AUDIO_FORMAT
request_options = request_options or {}
+ if input_dir is not None:
+ _converter_mod.BOOKS_FOLDER = Path(input_dir)
+ if output_dir is not None:
+ _converter_mod.AUDIOBOOKS_FOLDER = Path(output_dir)
setup_logging(debug=debug)
setup_directories()
@@ -192,6 +200,15 @@ Examples:
help=f"Output container format (default: {config.AUDIO_FORMAT}). m4b uses AAC audio."
)
parser.add_argument(
+ "--input", type=Path, metavar="DIR", default=None,
+ help=("Directory containing the source books (.txt/.pdf/.epub). "
+ "Defaults to ./input.")
+ )
+ parser.add_argument(
+ "--output", type=Path, metavar="DIR", default=None,
+ help="Directory to write finished audiobooks to. Defaults to ./output."
+ )
+ parser.add_argument(
"--single-file", action="store_true",
help=("Combine all chapters into a single audio file. By default books with "
"chapters (e.g. EPUB) are converted to one file per chapter. "
@@ -267,6 +284,9 @@ Examples:
if args.speed <= 0:
parser.error(f"--speed must be a positive number (got {args.speed:g})")
+ if args.input is not None and not args.input.is_dir():
+ parser.error(f"--input: no such directory: {args.input}")
+
if args.chunk:
if args.backend == BACKEND_AUDIOCPP:
print("[WARNING] --chunk: the audio.cpp server already splits long text "
@@ -350,6 +370,7 @@ Examples:
output_format=args.format, debug=args.debug, chunk=args.chunk,
model_id=args.model, instructions=args.instructions,
request_options=request_options,
+ input_dir=args.input, output_dir=args.output,
))