diff options
| author | historia <historiavg@proton.me> | 2026-08-17 19:39:31 -0400 |
|---|---|---|
| committer | historia <historiavg@proton.me> | 2026-08-17 19:39:31 -0400 |
| commit | 68ee76514a98169a5e7a075648b70ab40417fbdf (patch) | |
| tree | 906f9fb856eb1e66a26af0b57f5d65462b7977b1 /converter | |
| parent | b80fa9db6bab6cdb2856874b606a93149cfc1af2 (diff) | |
| download | tts-audiobook-generator-68ee76514a98169a5e7a075648b70ab40417fbdf.tar.gz | |
fix(converter): make m4b a single file with embedded chapters
Diffstat (limited to 'converter')
| -rw-r--r-- | converter/converter.py | 16 |
1 files changed, 10 insertions, 6 deletions
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") |
