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 --- audiobook.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'audiobook.py') 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