From 116911c8ba233e95d2de0cb4d1ed259a0e659216 Mon Sep 17 00:00:00 2001 From: fondoger Date: Sat, 12 Apr 2025 22:31:53 +0800 Subject: [PATCH] Fix unit tests --- api/src/services/audio.py | 2 +- api/src/services/text_processing/text_processor.py | 4 ++-- api/src/services/tts_service.py | 2 +- api/tests/test_kokoro_v1.py | 2 +- api/tests/test_text_processor.py | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/src/services/audio.py b/api/src/services/audio.py index fd819b7..0218a8b 100644 --- a/api/src/services/audio.py +++ b/api/src/services/audio.py @@ -156,7 +156,7 @@ class AudioService: speed: The speaking speed of the voice chunk_text: The text sent to the model to generate the resulting speech is_last_chunk: Whether this is the last chunk - is_silent_chunk: Whether this chunk is a silent tag (e.g., [Silent](0.5s)) + is_silent_chunk: Whether this chunk is a silent tag. e.g. [Silent 0.5s] trim_audio: Whether audio should be trimmed normalizer: Optional AudioNormalizer instance for consistent normalization diff --git a/api/src/services/text_processing/text_processor.py b/api/src/services/text_processing/text_processor.py index 5ed47ee..93463ea 100644 --- a/api/src/services/text_processing/text_processor.py +++ b/api/src/services/text_processing/text_processor.py @@ -108,10 +108,10 @@ def get_sentence_info(text: str, custom_phenomes_list: Dict[str, str]) -> List[T del custom_phenomes_list[key] # Handle silence tags - # Eg: "This is a test sentence, [silent](/1s/) with silence for one second." + # Eg: "This is a test sentence, [silent 0.5s] with silence for one second." while match := SILENCE_TAG.search(sentence): match_prefix = sentence[:match.start()] # `This is a test sentence, ` - match_text = match.group(0) # `[silent](/1s/)` + match_text = match.group(0) # `[silent 0.5s]` match_suffix = sentence[match.end():] # ` with silence for one second.` if match_prefix.strip(): tokens = process_text_chunk(match_prefix.strip()) diff --git a/api/src/services/tts_service.py b/api/src/services/tts_service.py index 7a8aaa3..cb69b20 100644 --- a/api/src/services/tts_service.py +++ b/api/src/services/tts_service.py @@ -62,7 +62,7 @@ class TTSService: """Process tokens into audio.""" async with self._chunk_semaphore: try: - # Handle silence tags, eg: `[silent](0.5s)` + # Handle silence tags, eg: `[silent 0.5s]` if match := SILENCE_TAG.match(chunk_text): silence_duration = float(match.group(1)) silence_audio = np.zeros(int(silence_duration * 24000), dtype=np.int16) diff --git a/api/tests/test_kokoro_v1.py b/api/tests/test_kokoro_v1.py index 29d83c5..6891d8d 100644 --- a/api/tests/test_kokoro_v1.py +++ b/api/tests/test_kokoro_v1.py @@ -19,7 +19,7 @@ def test_initial_state(kokoro_backend): assert kokoro_backend._model is None assert kokoro_backend._pipelines == {} # Now using dict of pipelines # Device should be set based on settings - assert kokoro_backend.device in ["cuda", "cpu"] + assert kokoro_backend.device in ["cuda", "cpu", "mps"] @patch("torch.cuda.is_available", return_value=True) diff --git a/api/tests/test_text_processor.py b/api/tests/test_text_processor.py index 1838550..3c761b7 100644 --- a/api/tests/test_text_processor.py +++ b/api/tests/test_text_processor.py @@ -121,7 +121,7 @@ async def test_smart_split_with_punctuation(): @pytest.mark.asyncio async def test_smart_split_with_silence_tags(): """Test smart splitting handles silence tags correctly.""" - text = "This is a test sentence, [silent](/1s/) with silence for one second." + text = "This is a test sentence, [silent 1s] with silence for one second." chunks = [] async for chunk_text, chunk_tokens in smart_split(text): @@ -129,5 +129,5 @@ async def test_smart_split_with_silence_tags(): assert len(chunks) == 3 assert chunks[0] == "This is a test sentence, " - assert chunks[1] == "[silent](/1s/)" + assert chunks[1] == "[silent 1s]" assert chunks[2] == " with silence for one second."