diff options
Diffstat (limited to 'app/tests/test_tts.py')
| -rw-r--r-- | app/tests/test_tts.py | 80 |
1 files changed, 14 insertions, 66 deletions
diff --git a/app/tests/test_tts.py b/app/tests/test_tts.py index a2df07f..87f98df 100644 --- a/app/tests/test_tts.py +++ b/app/tests/test_tts.py @@ -906,7 +906,7 @@ class AudioCppTTSClientRequestTests(unittest.TestCase): @staticmethod def _make_client(preset_mode=False, voice="Vivian", language="English", seed=-1, - chunk_text=True, family="qwen3_tts", task="tts", + family="qwen3_tts", task="tts", instructions=None, request_options=None): client = AudioCppTTSClient.__new__(AudioCppTTSClient) client.api_url = "http://127.0.0.1:8080" @@ -915,7 +915,6 @@ class AudioCppTTSClientRequestTests(unittest.TestCase): client.voice = voice client.language = language client._seed = seed - client.chunk_text = chunk_text client.family = family client.task = task client.profile = tts.AUDIOCPP_FAMILY_PROFILES.get( @@ -972,30 +971,8 @@ class AudioCppTTSClientRequestTests(unittest.TestCase): payload = json.loads(mock_urlopen.call_args[0][0].data.decode("utf-8")) self.assertNotIn("seed", payload) - 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. - text = " ".join(f"word{i}" for i in range(9)) - with patch.object(config, "CHUNK_SIZE", 5), \ - patch.object(client, "_request_wav", - return_value=self._wav_bytes()) as mock_request: - result = client.generate_chunk(text, 1) - self.assertIsNotNone(result) - self.assertEqual(mock_request.call_count, 1) - self.assertEqual(mock_request.call_args[0][0], text) - - def test_single_request_timeout_scales_with_text_length(self): - client = self._make_client(chunk_text=False) - long_text = " ".join(f"word{i}" for i in range(1500)) # ~10 min of audio - with patch("converter.tts.urllib.request.urlopen", - return_value=self._post_response(self._wav_bytes())) as mock_urlopen: - client._request_wav(long_text) - timeout = mock_urlopen.call_args[1]["timeout"] - self.assertGreater(timeout, config.API_TIMEOUT) - - def test_client_chunking_keeps_configured_timeout(self): - client = self._make_client(chunk_text=True) + def test_request_timeout_is_the_configured_api_timeout(self): + client = self._make_client() long_text = " ".join(f"word{i}" for i in range(1500)) with patch("converter.tts.urllib.request.urlopen", return_value=self._post_response(self._wav_bytes())) as mock_urlopen: @@ -1208,8 +1185,7 @@ class AudioCppTTSClientRequestTests(unittest.TestCase): class AudioCppHeartbeatTests(unittest.TestCase): - """The heartbeat label drops 'Chunk' when the server does its own - long-form chunking (chunk_text=False, the default).""" + """The heartbeat reports chunk progress while a request generates.""" def setUp(self): self._tmp = tempfile.TemporaryDirectory() @@ -1221,7 +1197,7 @@ class AudioCppHeartbeatTests(unittest.TestCase): self._tmp.cleanup() @staticmethod - def _client(chunk_text): + def _client(): client = AudioCppTTSClient.__new__(AudioCppTTSClient) client.api_url = "http://127.0.0.1:8080" client.model_id = config.AUDIOCPP_MODEL_ID @@ -1229,7 +1205,6 @@ class AudioCppHeartbeatTests(unittest.TestCase): client.voice = "Vivian" client.language = "English" client._seed = -1 - client.chunk_text = chunk_text client.family = "qwen3_tts" client.profile = tts.AUDIOCPP_DEFAULT_FAMILY_PROFILE return client @@ -1244,8 +1219,8 @@ class AudioCppHeartbeatTests(unittest.TestCase): wav_file.writeframes(b"\x01\x00" * 10) return buffer.getvalue() - def _run(self, chunk_text): - client = self._client(chunk_text) + def _run(self): + client = self._client() def slow_request(*_args, **_kwargs): time.sleep(0.12) @@ -1260,13 +1235,8 @@ class AudioCppHeartbeatTests(unittest.TestCase): self.assertTrue(result) return buf.getvalue() - def test_server_side_chunking_heartbeat_has_no_chunk_word(self): - out = self._run(chunk_text=False) - self.assertIn("Request still generating", out) - self.assertNotIn("Chunk", out) - - def test_client_side_chunking_heartbeat_keeps_chunk_word(self): - out = self._run(chunk_text=True) + def test_heartbeat_reports_chunk_progress(self): + out = self._run() self.assertIn("Chunk 1 still generating", out) @@ -1290,7 +1260,6 @@ class AudioCppTTSClientTruncationTests(unittest.TestCase): client.voice = "narrator" client.language = "English" client._seed = -1 - client.chunk_text = True client.family = "qwen3_tts" client.profile = tts.AUDIOCPP_FAMILY_PROFILES["qwen3_tts"] return client @@ -1336,7 +1305,7 @@ class BackendWiringTests(unittest.TestCase): backend=tts.BACKEND_AUDIOCPP, voice="narrator", language="ja") mock_audiocpp.assert_called_once_with(voice="narrator", language="Japanese", - chunk_text=False, model_id=None, + model_id=None, instructions=None, request_options={}) mock_faster.assert_not_called() @@ -1347,22 +1316,10 @@ class BackendWiringTests(unittest.TestCase): AudiobookConverter(voice_mode=tts.VOICE_MODE_CUSTOM, backend=tts.BACKEND_AUDIOCPP) mock_audiocpp.assert_called_once_with(voice=None, language=config.LANGUAGE, - chunk_text=False, model_id=None, + model_id=None, instructions=None, request_options={}) - def test_audiocpp_backend_chunk_flag_forces_client_chunking(self): - with patch("converter.converter.AudioCppTTSClient") as mock_audiocpp: - converter = AudiobookConverter(voice_mode=tts.VOICE_MODE_CLONE, - backend=tts.BACKEND_AUDIOCPP, - voice="narrator", chunk=True) - mock_audiocpp.assert_called_once_with(voice="narrator", - language=config.LANGUAGE, - chunk_text=True, model_id=None, - instructions=None, - request_options={}) - self.assertTrue(converter.client_chunks) - def test_audiocpp_backend_model_id_is_wired_through(self): with patch("converter.converter.AudioCppTTSClient") as mock_audiocpp: AudiobookConverter(voice_mode=tts.VOICE_MODE_CLONE, @@ -1370,7 +1327,7 @@ class BackendWiringTests(unittest.TestCase): model_id="higgs") mock_audiocpp.assert_called_once_with( voice="narrator", language=config.LANGUAGE, - chunk_text=False, model_id="higgs", instructions=None, + model_id="higgs", instructions=None, request_options={}) def test_audiocpp_backend_instructions_and_options_are_wired_through(self): @@ -1382,7 +1339,7 @@ class BackendWiringTests(unittest.TestCase): "speed": "1.1"}) mock_audiocpp.assert_called_once_with( voice=None, language=config.LANGUAGE, - chunk_text=False, model_id=None, + model_id=None, instructions="A warm adult narrator", request_options={"emotion": "neutral", "speed": "1.1"}) @@ -1411,19 +1368,10 @@ class BackendWiringTests(unittest.TestCase): voice="narrator") self.assertIsNone(converter.voice_clone_ref_audio) - def test_chapter_chunks_audiocpp_default_is_one_request(self): + def test_chapter_chunks_audiocpp_splits(self): converter = self._audiocpp_converter(voice="narrator") text = " ".join(f"word{i}" for i in range(50)) with patch.object(config, "CHUNK_SIZE", 10): - self.assertEqual(converter._chapter_chunks(text), [text]) - - def test_chapter_chunks_audiocpp_chunk_flag_splits(self): - with patch("converter.converter.AudioCppTTSClient"): - converter = AudiobookConverter(voice_mode=tts.VOICE_MODE_CLONE, - backend=tts.BACKEND_AUDIOCPP, - voice="narrator", chunk=True) - text = " ".join(f"word{i}" for i in range(50)) - with patch.object(config, "CHUNK_SIZE", 10): chunks = converter._chapter_chunks(text) self.assertGreater(len(chunks), 1) self.assertTrue(all(len(chunk.split()) <= 10 for chunk in chunks)) |
