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

@@ -30,6 +30,8 @@ pub trait Running: Send + Sync + 'static {
async fn stop(&self) -> Result<(), String>;
/// Worker, voice channel members and missed requests, for the snapshot.
fn status(&self, now: Instant) -> Value;
/// Speak at this speed (`voice.tts.speed`) from the next sentence on.
fn set_tts_speed(&self, _speed: f64) {}
}
/// What starts the services (the real ones, or a fake in tests).
@@ -167,6 +169,13 @@ impl Controller {
Err("cancelled".into())
}
/// Give the running services a new speech speed. False when nothing runs (the next start reads it
/// from the settings).
pub fn set_tts_speed(&self, speed: f64) -> bool {
let running = self.inner.lock().unwrap().running.clone();
running.map(|r| r.set_tts_speed(speed)).is_some()
}
/// Stop from running, or cancel a start; what was said is forgotten.
pub async fn stop(&self) -> Result<(), String> {
let running = {
@@ -367,6 +376,10 @@ impl Running for crate::services::Services {
"performance": self.llm.stage_view(),
})
}
fn set_tts_speed(&self, speed: f64) {
self.worker.set_tts_speed(speed);
}
}
#[cfg(test)]
@@ -381,6 +394,7 @@ mod tests {
stop_fails: std::sync::atomic::AtomicBool,
cleanups: AtomicU32,
cleanup_fails: std::sync::atomic::AtomicBool,
speeds: Mutex<Vec<f64>>,
}
struct FakeRunning(Arc<Counts>);
@@ -393,6 +407,9 @@ mod tests {
fn status(&self, _: Instant) -> Value {
json!({"worker": {"connected": true}, "voiceMembers": [{"id": "11", "name": "민수"}], "missed": []})
}
fn set_tts_speed(&self, speed: f64) {
self.0.speeds.lock().unwrap().push(speed);
}
}
struct FakeHost {
@@ -471,6 +488,17 @@ mod tests {
}
}
#[tokio::test]
async fn a_new_speech_speed_reaches_the_running_services_without_a_restart() {
let counts = Arc::new(Counts::default());
let c = Controller::new(FakeHost { counts: counts.clone(), fail_first: AtomicU32::new(0), events: Mutex::new(None) });
assert!(!c.set_tts_speed(1.7), "nothing runs: the next start reads the settings");
c.start().await.unwrap();
assert!(c.set_tts_speed(1.8));
assert_eq!(*counts.speeds.lock().unwrap(), [1.8]);
assert_eq!(counts.starts.load(Ordering::SeqCst), 1, "no restart");
}
#[tokio::test]
async fn a_stop_while_starting_cancels_the_start_or_stops_what_came_up() {
for honours_cancel in [true, false] {