From 68ee76514a98169a5e7a075648b70ab40417fbdf Mon Sep 17 00:00:00 2001 From: historia Date: Mon, 17 Aug 2026 19:39:31 -0400 Subject: fix(converter): make m4b a single file with embedded chapters --- converter/converter.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'converter') diff --git a/converter/converter.py b/converter/converter.py index ce2c351..f63a412 100644 --- a/converter/converter.py +++ b/converter/converter.py @@ -99,10 +99,14 @@ class AudiobookConverter: return False stem = output_name or file_path.stem - embed_chapters = (self.output_format == "m4b" and self.single_file - and len(sections) > 1) - if embed_chapters: - return self._convert_single_m4b_with_chapters(sections, stem, start_time) + + # m4b is always a single file; multi-chapter books get embedded + # chapter markers so listeners can skip between chapters. + if self.output_format == "m4b": + if len(sections) > 1: + return self._convert_m4b_with_chapters(sections, stem, start_time) + output_path = config.AUDIOBOOKS_FOLDER / f"{stem}.{self.output_format}" + return self._convert_text(sections[0].text, output_path, start_time) if self.single_file or len(sections) == 1: text = "\n\n".join(section.text for section in sections) @@ -124,7 +128,7 @@ class AudiobookConverter: # Always cleanup, even on failure or interrupt audio.cleanup_chunks() - def _convert_single_m4b_with_chapters(self, sections, stem: str, start_time: float) -> bool: + def _convert_m4b_with_chapters(self, sections, stem: str, start_time: float) -> bool: """Convert each chapter to audio, then assemble a single m4b with embedded chapter markers.""" chapter_files = [] @@ -250,7 +254,7 @@ class AudiobookConverter: print(f"Reference audio: {Path(self.voice_clone_ref_audio).name}") print(f"Language: {config.VOICE_CLONE_LANGUAGE}") print(f"Output format: {self.output_format}") - if self.single_file: + if self.single_file and self.output_format == "mp3": print("Chapter mode: single file (--single-file)") if abs(self.speed - 1.0) >= 1e-6: print(f"Playback speed: {self.speed:g}x") -- cgit v1.2.3