aboutsummaryrefslogtreecommitdiff
path: root/converter/audio.py
diff options
context:
space:
mode:
Diffstat (limited to 'converter/audio.py')
-rw-r--r--converter/audio.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/converter/audio.py b/converter/audio.py
index f1c508c..5a7ec35 100644
--- a/converter/audio.py
+++ b/converter/audio.py
@@ -210,14 +210,17 @@ def _collect_chunk_files(total_chunks: int,
def combine_chunks(total_chunks: int, output_path: Path,
chunk_results: Optional[Dict[int, Optional[Path]]] = None,
- speed: float = 1.0, output_format: str = "mp3") -> bool:
+ speed: float = 1.0, output_format: str = "mp3",
+ intermediate: bool = False) -> bool:
"""Combine audio chunks into the final audiobook using ffmpeg's concat demuxer.
``chunk_results`` maps chunk numbers to the audio file each chunk produced
(None for failed chunks); failed and missing chunks are skipped. When
``speed`` differs from 1.0, an additional speed-adjusted copy is written
next to the normal-speed file. Chunks are streamed by ffmpeg, so the whole
- book is never held in memory.
+ book is never held in memory. Set ``intermediate`` for scratch chapter
+ audio on the way to a larger output (e.g. a chaptered m4b) so save
+ messages don't present it as the final audiobook.
"""
if shutil.which("ffmpeg") is None or shutil.which("ffprobe") is None:
logger.error("ffmpeg and ffprobe are required to combine audio chunks (install ffmpeg)")
@@ -265,8 +268,14 @@ def combine_chunks(total_chunks: int, output_path: Path,
if not duration_ok:
return False
- logger.info("Audiobook saved: %s (%d/%d chunks)", output_path, len(chunk_files), total_chunks)
- print(f"[INFO] Saved audiobook: {output_path.name} ({len(chunk_files)}/{total_chunks} chunks)")
+ if intermediate:
+ logger.info("Chapter audio saved (intermediate): %s (%d/%d chunks)",
+ output_path, len(chunk_files), total_chunks)
+ print(f"[INFO] Saved chapter audio (intermediate): {output_path.name} "
+ f"({len(chunk_files)}/{total_chunks} chunks)")
+ else:
+ logger.info("Audiobook saved: %s (%d/%d chunks)", output_path, len(chunk_files), total_chunks)
+ print(f"[INFO] Saved audiobook: {output_path.name} ({len(chunk_files)}/{total_chunks} chunks)")
if speed_path is not None:
logger.info("Saved speed-adjusted audiobook (%gx): %s", speed, speed_path)