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:
@@ -226,6 +226,9 @@ struct Inner {
|
||||
/// The LLM state the brain should have: sent again on every connection, so a worker that
|
||||
/// missed it (a dropped connection, a restarted worker) catches up.
|
||||
llm: Mutex<Option<Value>>,
|
||||
/// The latest speech speed set while running, sent again on every connection: a restarted worker
|
||||
/// starts with the speed of its arguments.
|
||||
tts_speed: Mutex<Option<f64>>,
|
||||
/// The number of the latest switch.
|
||||
llm_switches: std::sync::atomic::AtomicU64,
|
||||
}
|
||||
@@ -248,6 +251,7 @@ impl WorkerClient {
|
||||
wake: Notify::new(),
|
||||
llm_idle: watch::channel(0).0,
|
||||
llm: Mutex::new(None),
|
||||
tts_speed: Mutex::new(None),
|
||||
llm_switches: std::sync::atomic::AtomicU64::new(0),
|
||||
});
|
||||
(Self { inner }, rx)
|
||||
@@ -497,6 +501,14 @@ impl WorkerClient {
|
||||
self.set_llm(json!({"type": "llm", "state": "ready", "game": game}))
|
||||
}
|
||||
|
||||
/// Speak at `speed` from the next sentence on (`tts_speed`). False when not connected; it still
|
||||
/// goes out on the next connection.
|
||||
pub fn set_tts_speed(&self, speed: f64) -> bool {
|
||||
let mut s = self.inner.tts_speed.lock().unwrap();
|
||||
*s = Some(speed);
|
||||
self.send_json(json!({"type": "tts_speed", "speed": speed}))
|
||||
}
|
||||
|
||||
fn set_llm(&self, m: Value) -> bool {
|
||||
let mut llm = self.inner.llm.lock().unwrap();
|
||||
*llm = Some(m.clone());
|
||||
@@ -637,9 +649,11 @@ async fn connect_once(inner: &Arc<Inner>) -> bool {
|
||||
|
||||
let (tx, mut rx) = mpsc::unbounded_channel::<Message>();
|
||||
{
|
||||
// Locks in the order llm, then state (as `llm_state` takes them): the latest LLM state goes
|
||||
// first, and the connection is ready for sending before an LLM state set meanwhile is sent.
|
||||
// Locks in the order llm, tts_speed, then state (as `llm_state` and `set_tts_speed` take
|
||||
// them): the latest LLM state and speed go first, and the connection is ready for sending
|
||||
// before one set meanwhile is sent.
|
||||
let llm = inner.llm.lock().unwrap();
|
||||
let speed = inner.tts_speed.lock().unwrap();
|
||||
let mut st = inner.state.lock().unwrap();
|
||||
if st.closed {
|
||||
return true;
|
||||
@@ -647,6 +661,9 @@ async fn connect_once(inner: &Arc<Inner>) -> bool {
|
||||
if let Some(m) = llm.clone() {
|
||||
let _ = tx.send(Message::text(m.to_string()));
|
||||
}
|
||||
if let Some(s) = *speed {
|
||||
let _ = tx.send(Message::text(json!({"type": "tts_speed", "speed": s}).to_string()));
|
||||
}
|
||||
st.conn = Some(tx);
|
||||
inner.ready.send_replace(Some(hello_ok.clone()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user