aboutsummaryrefslogtreecommitdiff
path: root/tests/test_converter.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-18 19:32:48 -0400
committerhistoria <historiavg@proton.me>2026-08-18 19:32:48 -0400
commit7e8bf663a65111fb648b01d9f45ad08eddbf2515 (patch)
tree83a979f15d8c7d532c3cf2ffaabac927753e27b4 /tests/test_converter.py
parentabc610097fe3a6ff1c1282f728fb0d75440f6ba8 (diff)
downloadtts-audiobook-generator-7e8bf663a65111fb648b01d9f45ad08eddbf2515.tar.gz
feat: include narrator in output filenames
Diffstat (limited to 'tests/test_converter.py')
-rw-r--r--tests/test_converter.py54
1 files changed, 49 insertions, 5 deletions
diff --git a/tests/test_converter.py b/tests/test_converter.py
index 351849a..ae307a2 100644
--- a/tests/test_converter.py
+++ b/tests/test_converter.py
@@ -97,6 +97,50 @@ class FindExistingOutputsTests(unittest.TestCase):
found = [p.name for p in find_existing_outputs("book [1]", "mp3")]
self.assertEqual(sorted(found), ["book [1].mp3", "book [1]_1.5x.mp3"])
+ def test_narrator_named_outputs_detected(self):
+ for name in ("dune_Vivian.mp3", "dune_Vivian_1.5.mp3", "dune_Vivian_01_Dune.mp3"):
+ self._touch(name)
+ found = [p.name for p in find_existing_outputs("dune_Vivian", "mp3")]
+ self.assertEqual(len(found), 3)
+
+ def test_legacy_outputs_without_narrator_ignored(self):
+ self._touch("dune.mp3")
+ self._touch("dune_1.5.mp3")
+ self.assertEqual(find_existing_outputs("dune_Vivian", "mp3"), [])
+
+
+class NarratorTagTests(unittest.TestCase):
+ def _converter(self, voice_mode, ref_audio=None):
+ converter = AudiobookConverter.__new__(AudiobookConverter)
+ converter.voice_mode = voice_mode
+ converter.voice_clone_ref_audio = ref_audio
+ return converter
+
+ def test_custom_voice_uses_speaker_display_name(self):
+ self.assertEqual(self._converter(config.VOICE_MODE_CUSTOM)._narrator_tag(),
+ "Vivian")
+
+ def test_multi_word_display_name_gets_underscores(self):
+ with patch.object(config, "CUSTOM_VOICE_SPEAKER", "uncle_fu"):
+ self.assertEqual(self._converter(config.VOICE_MODE_CUSTOM)._narrator_tag(),
+ "Uncle_Fu")
+
+ def test_clone_uses_reference_audio_stem(self):
+ self.assertEqual(self._converter(config.VOICE_MODE_CLONE, "/x/ref.wav")._narrator_tag(),
+ "ref")
+
+ def test_clone_stem_spaces_become_underscores(self):
+ self.assertEqual(self._converter(config.VOICE_MODE_CLONE, "/x/my voice.wav")._narrator_tag(),
+ "my_voice")
+
+ def test_invalid_characters_sanitized(self):
+ self.assertEqual(self._converter(config.VOICE_MODE_CLONE, "/x/bad:name?.wav")._narrator_tag(),
+ "bad_name")
+
+ def test_empty_after_sanitize_falls_back(self):
+ self.assertEqual(self._converter(config.VOICE_MODE_CLONE, "/x/???.wav")._narrator_tag(),
+ "narrator")
+
class PromptOverwriteTests(unittest.TestCase):
def test_single_file_yes(self):
@@ -160,22 +204,22 @@ class RunOverwritePromptTests(unittest.TestCase):
self._output_tmp.cleanup()
def test_declined_book_is_skipped(self):
- (config.AUDIOBOOKS_FOLDER / "book.mp3").write_bytes(b"existing")
+ (config.AUDIOBOOKS_FOLDER / "book_Vivian.mp3").write_bytes(b"existing")
with patch("builtins.input", return_value="n"):
self.assertTrue(self.converter.run())
self.assertEqual(self.converted, [])
- self.assertTrue((config.AUDIOBOOKS_FOLDER / "book.mp3").exists())
+ self.assertTrue((config.AUDIOBOOKS_FOLDER / "book_Vivian.mp3").exists())
def test_accepted_book_is_converted(self):
- (config.AUDIOBOOKS_FOLDER / "book.mp3").write_bytes(b"existing")
+ (config.AUDIOBOOKS_FOLDER / "book_Vivian.mp3").write_bytes(b"existing")
with patch("builtins.input", return_value="y"):
self.assertTrue(self.converter.run())
- self.assertEqual(self.converted, [("book.txt", "book")])
+ self.assertEqual(self.converted, [("book.txt", "book_Vivian")])
def test_new_book_converted_without_prompt(self):
with patch("builtins.input", side_effect=AssertionError("should not prompt")):
self.assertTrue(self.converter.run())
- self.assertEqual(self.converted, [("book.txt", "book")])
+ self.assertEqual(self.converted, [("book.txt", "book_Vivian")])
if __name__ == "__main__":