feat(tts): change the speech speed without a restart and keep fast speech clear

MeloTTS's own speed shortens every sound and slurred fast speech (Whisper
large-v3 on five Korean sentences, three renders each: 5.5% character
errors at 1.5 and 20% at 2.0, against 1.4% at 1.0). The MeloTTS child now
speaks at most at its natural pace and makes faster speech with a WSOLA
time stretch that keeps the pitch (1.9% at 1.5, 2.2% at 2.0, about 15 ms
per 4 s of speech).

A voice.tts.speed saved while the services run goes to the worker at once
(new tts_speed message) and applies from the next sentence; the client
sends it again whenever the worker connects again. Version 0.1.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-15 23:39:04 +09:00
parent d17a3bbb61
commit dbe5c617bc
17 changed files with 268 additions and 16 deletions

View File

@@ -19,6 +19,8 @@ CHILD = os.path.join(os.path.dirname(os.path.abspath(__file__)), "melo_child.py"
class MeloEngine:
def __init__(self, python: str, device: str = "cuda", speed: float = 1.5, language: str = "KR"):
self.cmd = [python, CHILD, "--device", device, "--speed", str(speed), "--language", language]
# Read for each sentence, so a new speed (`tts_speed`) applies from the next one.
self.speed = speed
self._lock = threading.Lock()
self._proc: subprocess.Popen | None = None
self.native_rate: int | None = None
@@ -49,7 +51,7 @@ class MeloEngine:
if self._proc is None or self._proc.poll() is not None:
debug_log("melo child not running, restarting", "tts")
self._start()
self._proc.stdin.write((json.dumps({"text": text, "rate": rate}) + "\n").encode())
self._proc.stdin.write((json.dumps({"text": text, "rate": rate, "speed": self.speed}) + "\n").encode())
self._proc.stdin.flush()
header, payload = self._read()
if not header.get("ok"):