From aac8febbdb45b7994e209bc74a44f8fc98fc745d Mon Sep 17 00:00:00 2001 From: historia Date: Mon, 24 Aug 2026 12:57:54 -0400 Subject: feat: --input and --output flags --- README.md | 2 ++ audiobook.py | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c12f073..f3f718d 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ You need one of the following backends (the TUI sets them up for you; manual ste | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `--backend {audiocpp,qwen,faster}` | TTS server to use (default `audiocpp`). | | `--format {mp3,m4b,ogg,flac}` | Output format (default `m4b`). | +| `--input ` | Directory containing the books to convert (default `./input`). | +| `--output ` | Directory to write finished audiobooks to (default `./output`). | | `--speed ` | Playback speed, pitch-preserving (`1.0` = normal). A normal-speed copy is also output. | | `--single-file` | Merge all chapters into a single file. `m4b` is always one file. | | `--language ` | Output language for the synthesized speech. Can add an accent even if the text is English. | 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() @@ -191,6 +199,15 @@ Examples: "--format", choices=list(AUDIO_FORMATS), default=config.AUDIO_FORMAT, 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 " @@ -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, )) -- cgit v1.2.3