mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Moved SupertonicPipeline from abogen/tts_supertonic.py to abogen/tts_backends/supertonic.py and load_numpy_kpipeline from abogen/utils.py to abogen/tts_backends/kokoro.py. Git correctly detects the Supertonic file as a rename (R), preserving full commit history. - New package: abogen/tts_backends/ - __init__.py (package marker) - supertonic.py (SupertonicPipeline, moved from tts_supertonic.py) - kokoro.py (load_numpy_kpipeline, moved from utils.py) - abogen/utils.py: re-exports load_numpy_kpipeline for backward compat - All imports updated to new canonical paths
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
import numpy as np
|
|
|
|
from abogen.tts_backends.supertonic import SupertonicPipeline
|
|
|
|
|
|
class _DummyTTS:
|
|
def get_voice_style(self, voice_name: str):
|
|
return {"voice": voice_name}
|
|
|
|
def synthesize(
|
|
self,
|
|
*,
|
|
text: str,
|
|
voice_style,
|
|
total_steps: int,
|
|
speed: float,
|
|
max_chunk_length: int,
|
|
silence_duration: float,
|
|
verbose: bool,
|
|
):
|
|
if "•" in text:
|
|
raise ValueError("Found 1 unsupported character(s): ['•']")
|
|
# Return 50ms of audio at 24kHz.
|
|
sr = 24000
|
|
audio = np.zeros(int(0.05 * sr), dtype="float32")
|
|
return audio, 0.05
|
|
|
|
|
|
def test_supertonic_pipeline_strips_unsupported_characters_and_retries():
|
|
# Avoid importing/initializing real supertonic by manually constructing the pipeline.
|
|
pipeline = SupertonicPipeline.__new__(SupertonicPipeline)
|
|
pipeline.sample_rate = 24000
|
|
pipeline.total_steps = 5
|
|
pipeline.max_chunk_length = 1000
|
|
pipeline._tts = _DummyTTS()
|
|
|
|
segs = list(pipeline("Hello • world", voice="M1", speed=1.0))
|
|
assert len(segs) == 1
|
|
assert segs[0].graphemes == "Hello world" or segs[0].graphemes == "Hello world"
|
|
assert isinstance(segs[0].audio, np.ndarray)
|
|
assert segs[0].audio.dtype == np.float32
|
|
assert segs[0].audio.size > 0
|
|
|
|
|
|
def test_supertonic_pipeline_drops_chunk_if_only_unsupported_characters():
|
|
pipeline = SupertonicPipeline.__new__(SupertonicPipeline)
|
|
pipeline.sample_rate = 24000
|
|
pipeline.total_steps = 5
|
|
pipeline.max_chunk_length = 1000
|
|
pipeline._tts = _DummyTTS()
|
|
|
|
segs = list(pipeline("•", voice="M1", speed=1.0))
|
|
assert segs == []
|