diff options
| author | historia <historiavg@proton.me> | 2026-08-21 00:10:35 -0400 |
|---|---|---|
| committer | historia <historiavg@proton.me> | 2026-08-21 00:10:35 -0400 |
| commit | 0017f6b0421e549e9a2cdfadc104be64433724d3 (patch) | |
| tree | 735065e3f70b9c052eef3dc5741385bc74fd8e99 /tests/test_tts.py | |
| parent | 38c8fdcba7ce54ad0ad76be9ef0748df1c55ebc1 (diff) | |
| download | tts-audiobook-generator-0017f6b0421e549e9a2cdfadc104be64433724d3.tar.gz | |
fix: remove unnecessary truncation check
Diffstat (limited to 'tests/test_tts.py')
| -rw-r--r-- | tests/test_tts.py | 62 |
1 files changed, 3 insertions, 59 deletions
diff --git a/tests/test_tts.py b/tests/test_tts.py index 0b6da02..a0828de 100644 --- a/tests/test_tts.py +++ b/tests/test_tts.py @@ -385,31 +385,8 @@ class FasterTTSClientGenerateTests(unittest.TestCase): self.assertEqual(payload["response_format"], "pcm") -class TruncationDetectionTests(unittest.TestCase): - """check_for_truncation: servers cut audio silently past their caps, so - grossly short audio must fail the request (then retry / fail visibly).""" - - def test_duration_below_ratio_raises(self): - with self.assertRaises(RuntimeError) as ctx: - tts.check_for_truncation(" ".join(["w"] * 150), 25.0, "Chunk 1") - self.assertIn("truncated", str(ctx.exception)) - - def test_duration_at_ratio_passes(self): - tts.check_for_truncation(" ".join(["w"] * 150), 30.0, "Chunk 1") - - def test_unknown_duration_skips_check(self): - tts.check_for_truncation(" ".join(["w"] * 150), None, "Chunk 1") - - def test_short_requests_skip_check(self): - tts.check_for_truncation(" ".join(["w"] * 9), 0.0, "Chunk 1") - - def test_zero_duration_fails_checked_requests(self): - with self.assertRaises(RuntimeError): - tts.check_for_truncation(" ".join(["w"] * 150), 0.0, "Chunk 1") - - -class FasterTTSClientTruncationTests(unittest.TestCase): - """Audio far shorter than its text implies fails the faster request.""" +class FasterTTSClientGenerateTests(unittest.TestCase): + """Faster chunk generation: full-length audio produces a chunk file.""" def setUp(self): self._tmp = tempfile.TemporaryDirectory() @@ -426,15 +403,6 @@ class FasterTTSClientTruncationTests(unittest.TestCase): client.api_url = "http://127.0.0.1:8000" return client - def test_truncated_pcm_fails_the_chunk(self): - client = self._make_client() - text = " ".join(f"word{i}" for i in range(12)) - with patch.object(client, "_request_pcm", return_value=b"\x01\x00" * 24), \ - self.assertLogs("converter.tts", level="ERROR") as logs: - result = client.generate_chunk(text, 1) - self.assertIsNone(result) - self.assertTrue(any("truncated" in line for line in logs.output)) - def test_full_length_pcm_passes(self): client = self._make_client() text = " ".join(f"word{i}" for i in range(12)) @@ -504,20 +472,6 @@ class QwenTTSClientGenerateTests(unittest.TestCase): for call in mock_generate.call_args_list: self.assertLessEqual(len(call[0][0].split()), 5) - def test_truncated_sub_request_fails_the_chunk(self): - client = self._make_client() - # 0.1s of audio for 12 words (expected >= 2.4s). - source = self._write_wav(Path(self._tmp.name) / "short.wav", - b"\x01\x00" * int(0.1 * tts.SAMPLE_RATE)) - text = " ".join(f"word{i}" for i in range(12)) - with patch.object(client, "_generate_custom_voice", - return_value=(str(source),)) as mock_generate, \ - self.assertLogs("converter.tts", level="ERROR") as logs: - result = client.generate_chunk(text, 1) - self.assertIsNone(result) - self.assertEqual(mock_generate.call_count, 1) - self.assertTrue(any("truncated" in line for line in logs.output)) - def test_empty_text_fails_the_chunk(self): client = self._make_client() with patch.object(client, "_generate_custom_voice") as mock_generate: @@ -861,7 +815,7 @@ class AudioCppTTSClientRequestTests(unittest.TestCase): def test_whole_text_sent_as_one_request_without_client_chunking(self): client = self._make_client(chunk_text=False) # 9 words with CHUNK_SIZE=5 would split in two if client chunking - # were on; kept under the 10-word truncation-check threshold. + # were on. text = " ".join(f"word{i}" for i in range(9)) with patch.object(config, "CHUNK_SIZE", 5), \ patch.object(client, "_request_wav", @@ -1116,16 +1070,6 @@ class AudioCppTTSClientTruncationTests(unittest.TestCase): wav_file.writeframes(frames) return buffer.getvalue() - def test_truncated_wav_fails_the_chunk(self): - client = self._make_client() - text = " ".join(f"word{i}" for i in range(12)) - wav = self._wav_bytes(b"\x01\x00" * 24) # 0.001s for ~4.8s of speech - with patch.object(client, "_request_wav", return_value=wav), \ - self.assertLogs("converter.tts", level="ERROR") as logs: - result = client.generate_chunk(text, 1) - self.assertIsNone(result) - self.assertTrue(any("truncated" in line for line in logs.output)) - def test_full_length_wav_passes(self): client = self._make_client() text = " ".join(f"word{i}" for i in range(12)) |
