mirror of
https://github.com/remsky/Kokoro-FastAPI.git
synced 2025-08-05 16:48:53 +00:00
Fix unit tests
This commit is contained in:
parent
655c243f1d
commit
116911c8ba
5 changed files with 7 additions and 7 deletions
|
@ -156,7 +156,7 @@ class AudioService:
|
||||||
speed: The speaking speed of the voice
|
speed: The speaking speed of the voice
|
||||||
chunk_text: The text sent to the model to generate the resulting speech
|
chunk_text: The text sent to the model to generate the resulting speech
|
||||||
is_last_chunk: Whether this is the last chunk
|
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
|
trim_audio: Whether audio should be trimmed
|
||||||
normalizer: Optional AudioNormalizer instance for consistent normalization
|
normalizer: Optional AudioNormalizer instance for consistent normalization
|
||||||
|
|
||||||
|
|
|
@ -108,10 +108,10 @@ def get_sentence_info(text: str, custom_phenomes_list: Dict[str, str]) -> List[T
|
||||||
del custom_phenomes_list[key]
|
del custom_phenomes_list[key]
|
||||||
|
|
||||||
# Handle silence tags
|
# 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):
|
while match := SILENCE_TAG.search(sentence):
|
||||||
match_prefix = sentence[:match.start()] # `This is a test 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.`
|
match_suffix = sentence[match.end():] # ` with silence for one second.`
|
||||||
if match_prefix.strip():
|
if match_prefix.strip():
|
||||||
tokens = process_text_chunk(match_prefix.strip())
|
tokens = process_text_chunk(match_prefix.strip())
|
||||||
|
|
|
@ -62,7 +62,7 @@ class TTSService:
|
||||||
"""Process tokens into audio."""
|
"""Process tokens into audio."""
|
||||||
async with self._chunk_semaphore:
|
async with self._chunk_semaphore:
|
||||||
try:
|
try:
|
||||||
# Handle silence tags, eg: `[silent](0.5s)`
|
# Handle silence tags, eg: `[silent 0.5s]`
|
||||||
if match := SILENCE_TAG.match(chunk_text):
|
if match := SILENCE_TAG.match(chunk_text):
|
||||||
silence_duration = float(match.group(1))
|
silence_duration = float(match.group(1))
|
||||||
silence_audio = np.zeros(int(silence_duration * 24000), dtype=np.int16)
|
silence_audio = np.zeros(int(silence_duration * 24000), dtype=np.int16)
|
||||||
|
|
|
@ -19,7 +19,7 @@ def test_initial_state(kokoro_backend):
|
||||||
assert kokoro_backend._model is None
|
assert kokoro_backend._model is None
|
||||||
assert kokoro_backend._pipelines == {} # Now using dict of pipelines
|
assert kokoro_backend._pipelines == {} # Now using dict of pipelines
|
||||||
# Device should be set based on settings
|
# 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)
|
@patch("torch.cuda.is_available", return_value=True)
|
||||||
|
|
|
@ -121,7 +121,7 @@ async def test_smart_split_with_punctuation():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_smart_split_with_silence_tags():
|
async def test_smart_split_with_silence_tags():
|
||||||
"""Test smart splitting handles silence tags correctly."""
|
"""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 = []
|
chunks = []
|
||||||
async for chunk_text, chunk_tokens in smart_split(text):
|
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 len(chunks) == 3
|
||||||
assert chunks[0] == "This is a test sentence, "
|
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."
|
assert chunks[2] == " with silence for one second."
|
||||||
|
|
Loading…
Add table
Reference in a new issue