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

@@ -43,6 +43,8 @@ class FakeTts:
def __init__(self, delay: float = 0.0):
self.delay = delay
self.texts = []
self.speed = 1.5
self.speeds = []
def synthesize(self, text, rate):
if self.delay:
@@ -50,6 +52,7 @@ class FakeTts:
if "FAIL" in text:
raise RuntimeError("engine broke")
self.texts.append(text)
self.speeds.append(self.speed)
return np.full(len(text) * 10, 1000, dtype=np.int16)
@@ -272,6 +275,29 @@ def test_a_failing_sentence_ends_the_request_as_failed():
assert tts.texts == ["첫 문장입니다."]
@pytest.mark.unit
def test_a_new_speech_speed_applies_to_the_sentences_made_after_it():
tts = FakeTts()
async def body(url):
async with connect(url) as ws:
await hello(ws)
await ws.send(json.dumps({"type": "tts", "id": "a", "text": "보통 속도 문장이에요."}))
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "tts_done")
await ws.send(json.dumps({"type": "tts_speed", "speed": 1.8}))
out = []
for bad in (2.5, 0.2, "fast", True):
await ws.send(json.dumps({"type": "tts_speed", "speed": bad}))
out.append(json.loads(await ws.recv()))
await ws.send(json.dumps({"type": "tts", "id": "b", "text": "빨라진 문장이에요."}))
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "tts_done")
return out
errors = asyncio.run(with_worker(body, tts=tts))
assert [e["code"] for e in errors] == ["bad_message"] * 4
assert tts.speeds == [1.5, 1.8], "a refused speed leaves the last good one"
@pytest.mark.unit
def test_tts_without_an_engine_reports_unavailable():
async def body(url):