diff options
| author | historia <historiavg@proton.me> | 2026-08-18 02:30:21 -0400 |
|---|---|---|
| committer | historia <historiavg@proton.me> | 2026-08-18 02:30:21 -0400 |
| commit | 6d0e740b4225859457109821a4c77feff72c24b5 (patch) | |
| tree | 3d27c8aa0c9f30140190e226fe2088fd53dc132b /converter/audio.py | |
| parent | cacc2064aa1e7c81436862db4be6cb8fc836a5cd (diff) | |
| download | tts-audiobook-generator-6d0e740b4225859457109821a4c77feff72c24b5.tar.gz | |
feat: show chapter in console when splitting m4b into chapters
Diffstat (limited to 'converter/audio.py')
| -rw-r--r-- | converter/audio.py | 17 |
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) |
