Fix unit tests

This commit is contained in:
fondoger 2025-04-12 22:31:53 +08:00
parent 655c243f1d
commit 116911c8ba
5 changed files with 7 additions and 7 deletions

View file

@ -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

View file

@ -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())

View file

@ -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)

View file

@ -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)

View file

@ -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."