Skip to content

Commit 1243307

Browse files
tlongwell-blocknpub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d
andauthored
fix(huddle): Pocket TTS quality overhaul — reference parity + cross-message pipelining (#997)
Signed-off-by: Tyler Longwell <[email protected]> Co-authored-by: npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@sprout-oss.stage.blox.sqprod.co>
1 parent 00dc491 commit 1243307

8 files changed

Lines changed: 1367 additions & 1419 deletions

File tree

‎desktop/scripts/check-file-sizes.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const overrides = new Map([
3535
["src-tauri/src/managed_agents/runtime.rs", 1940],
3636
["src-tauri/src/managed_agents/personas.rs", 1080],
3737
["src-tauri/src/managed_agents/persona_card.rs", 1050],
38-
["src-tauri/src/huddle/tts.rs", 1364],
3938
["src/shared/api/tauri.ts", 1196],
4039
["src-tauri/src/nostr_convert.rs", 1126],
4140
["src/shared/api/relayClientSession.ts", 1022],

‎desktop/src-tauri/examples/pocket_bench.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn main() {
6363
let gen = || GenerationConfig {
6464
speed: 1.05,
6565
num_steps: 1,
66-
silence_scale: 0.0,
66+
silence_scale: 1.0, // production setting (huddle::pocket::SYNTH_SILENCE_SCALE)
6767
reference_audio: Some(samples.clone()),
6868
reference_sample_rate: sr,
6969
..Default::default()
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
//! Clipping probe for any fixed playback gain applied after Pocket TTS synth.
2+
//!
3+
//! Synthesises a spread of sentences (short/long, calm/energetic) and reports
4+
//! the raw peak of each, the post-gain peak, and the fraction of samples that
5+
//! would hit a ±1.0 clamp — i.e. how much a fixed gain would flat-top the
6+
//! waveform ("blown out" distortion).
7+
//!
8+
//! History: the production pipeline briefly shipped a fixed 9.3× gain
9+
//! calibrated on a single bench utterance that peaked at 0.076. This probe
10+
//! showed real output peaks at 0.4–0.97, so that gain clipped 13–34% of all
11+
//! samples (the 2026-06-12 "blown out" report). Production now applies no
12+
//! gain — run this probe before reintroducing one.
13+
//!
14+
//! Run with model files in ~/.buzz/models/pocket-tts (override with arg 1):
15+
//! cargo run --release --example pocket_clip_probe
16+
17+
use std::path::PathBuf;
18+
19+
use sherpa_onnx::{
20+
self, GenerationConfig, OfflineTts, OfflineTtsConfig, OfflineTtsModelConfig,
21+
OfflineTtsPocketModelConfig, Wave,
22+
};
23+
24+
/// Candidate gain under test (the regressed production value).
25+
const GAIN: f32 = 9.3;
26+
27+
const PROMPTS: &[&str] = &[
28+
"Hello, this is a test of the new Pocket TTS engine running on sherpa-onnx.",
29+
"Yep, I can hear you.",
30+
"Absolutely! That sounds fantastic, let's do it right now!",
31+
"The quick brown fox jumps over the lazy dog near the riverbank.",
32+
"I found three problems in the code: a race condition, a memory leak, and an off-by-one error in the loop bounds.",
33+
"No.",
34+
"Warning! The build failed because seventeen tests crashed unexpectedly!",
35+
"Sure, I can walk you through the whole pipeline step by step whenever you're ready.",
36+
];
37+
38+
fn main() {
39+
let model_dir = std::env::args().nth(1).unwrap_or_else(|| {
40+
dirs::home_dir()
41+
.expect("home dir")
42+
.join(".buzz/models/pocket-tts")
43+
.to_string_lossy()
44+
.into_owned()
45+
});
46+
eprintln!("Model dir: {model_dir}");
47+
48+
let dir = PathBuf::from(&model_dir);
49+
let p = |name: &str| dir.join(name).to_string_lossy().into_owned();
50+
51+
let cfg = OfflineTtsConfig {
52+
model: OfflineTtsModelConfig {
53+
pocket: OfflineTtsPocketModelConfig {
54+
lm_main: Some(p("lm_main.int8.onnx")),
55+
lm_flow: Some(p("lm_flow.int8.onnx")),
56+
encoder: Some(p("encoder.onnx")),
57+
decoder: Some(p("decoder.int8.onnx")),
58+
text_conditioner: Some(p("text_conditioner.onnx")),
59+
vocab_json: Some(p("vocab.json")),
60+
token_scores_json: Some(p("token_scores.json")),
61+
voice_embedding_cache_capacity: 16,
62+
},
63+
num_threads: 1,
64+
debug: false,
65+
..Default::default()
66+
},
67+
..Default::default()
68+
};
69+
let engine = OfflineTts::create(&cfg).expect("engine create");
70+
71+
let voice_path = dir.join("reference_sample.wav");
72+
let wave = Wave::read(voice_path.to_str().unwrap()).expect("voice WAV");
73+
let voice_samples = wave.samples().to_vec();
74+
let voice_sr = wave.sample_rate();
75+
76+
let gen = || GenerationConfig {
77+
speed: 1.05,
78+
num_steps: 1,
79+
silence_scale: 1.0,
80+
reference_audio: Some(voice_samples.clone()),
81+
reference_sample_rate: voice_sr,
82+
..Default::default()
83+
};
84+
85+
// Warmup.
86+
let _ = engine.generate_with_config("warmup.", &gen(), None::<fn(&[f32], f32) -> bool>);
87+
88+
println!(
89+
"{:<46} | {:>8} | {:>9} | {:>9} | {:>10}",
90+
"prompt", "raw peak", "raw RMS", "post-gain", "% clipped"
91+
);
92+
println!("{}", "-".repeat(95));
93+
94+
let mut worst_clip = 0.0f32;
95+
for prompt in PROMPTS {
96+
let out = engine
97+
.generate_with_config(prompt, &gen(), None::<fn(&[f32], f32) -> bool>)
98+
.expect("synth");
99+
let samples = out.samples();
100+
101+
let peak = samples.iter().fold(0.0f32, |m, s| m.max(s.abs()));
102+
let rms = (samples.iter().map(|s| s * s).sum::<f32>() / samples.len() as f32).sqrt();
103+
let post = peak * GAIN;
104+
let clipped = samples.iter().filter(|s| s.abs() * GAIN > 1.0).count();
105+
let clip_pct = 100.0 * clipped as f32 / samples.len() as f32;
106+
worst_clip = worst_clip.max(clip_pct);
107+
108+
let label: String = prompt.chars().take(44).collect();
109+
println!("{label:<46} | {peak:>8.4} | {rms:>9.4} | {post:>9.3} | {clip_pct:>9.3}%");
110+
}
111+
112+
println!();
113+
println!(
114+
"Verdict: worst-case clipped fraction {worst_clip:.3}% — {}",
115+
if worst_clip > 0.1 {
116+
"AUDIBLE DISTORTION LIKELY (gain too hot)"
117+
} else if worst_clip > 0.0 {
118+
"marginal — occasional transient clipping"
119+
} else {
120+
"no clipping at this gain"
121+
}
122+
);
123+
}

‎desktop/src-tauri/examples/pocket_onset_probe.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn main() {
7272
let cfg = GenerationConfig {
7373
speed: 1.05,
7474
num_steps: 1,
75-
silence_scale: 0.0,
75+
silence_scale: 1.0, // production setting (huddle::pocket::SYNTH_SILENCE_SCALE)
7676
reference_audio: Some(voice_samples.clone()),
7777
reference_sample_rate: voice_sr,
7878
..Default::default()
@@ -100,7 +100,7 @@ fn main() {
100100
let cfg = GenerationConfig {
101101
speed: 1.05,
102102
num_steps: 1,
103-
silence_scale: 0.0,
103+
silence_scale: 1.0, // production setting (huddle::pocket::SYNTH_SILENCE_SCALE)
104104
reference_audio: Some(voice_samples.clone()),
105105
reference_sample_rate: voice_sr,
106106
..Default::default()

‎desktop/src-tauri/examples/prod_probe.rs‎

Lines changed: 0 additions & 220 deletions
This file was deleted.

0 commit comments

Comments
 (0)