Skip to content

the ultimate vocal synthesizer - sing, speak, beatbox, and more

Rust

compare tsp v2: MFA aligns renders over a noise floor, so a near-silent closure isn't read as silence

Jameson Hodge17cacae6eb14
diff --git a/crates/chimera-cli/src/compare/tsp.rs b/crates/chimera-cli/src/compare/tsp.rs
index 946c48a..a5ca6d5 100644
--- a/crates/chimera-cli/src/compare/tsp.rs
+++ b/crates/chimera-cli/src/compare/tsp.rs
@@ -197,6 +197,26 @@ fn said_words(g: &EnglishG2P, text: &str) -> Vec<String> {
.collect()
}
+/// A render over a noise floor like the recordings': white noise (a fixed sequence, so a render
+/// always aligns the same) `ALIGN_FLOOR_DB` below its loud level. A render's closures are near
+/// digital silence where a recording's sit on room and preamp noise, and without a floor MFA gives
+/// them to silence and reads the stop as its release alone.
+fn over_noise_floor(x: &[f64]) -> Vec<f32> {
+ let n20 = (0.02 * crate::FS) as usize;
+ let frames: Vec<f64> = x.chunks(n20).filter(|c| c.len() == n20).map(mean_square).collect();
+ let rms = (percentile(&frames, 0.95) * 10f64.powf(ALIGN_FLOOR_DB / 10.0) * 3.0).sqrt();
+ let mut state: u32 = 0x2545_f491;
+ x.iter()
+ .map(|&v| {
+ // xorshift32, uniform in ±1 (variance 1/3, hence the 3 above)
+ state ^= state << 13;
+ state ^= state >> 17;
+ state ^= state << 5;
+ (v + rms * (state as f64 / 2_147_483_648.0 - 1.0)) as f32
+ })
+ .collect()
+}
+
/// The Montreal Forced Aligner that `tools/tsp/setup.sh` installs, with its working files in
/// `root` (one per run: MFA keeps them under the corpus directory's name, and two runs at once
/// would share them) and the path of its english_us_arpa acoustic model.
@@ -254,8 +274,9 @@ fn align_synth(
let stem = name(sid, *female);
let d = format!("{corpus}/{stem}");
std::fs::create_dir_all(&d).map_err(|e| format!("{d}: {e}"))?;
- // 16-bit PCM, as the recordings are
- let x: Vec<f32> = s.x.iter().map(|&v| v as f32).collect();
+ // 16-bit PCM, as the recordings are, over a noise floor like theirs (the measures use
+ // the clean render)
+ let x = over_noise_floor(&s.x);
crate::wav::write(&format!("{d}/{stem}.wav"), &x, crate::FS as u32, false).map_err(|e| format!("{d}: {e}"))?;
std::fs::write(format!("{d}/{stem}.lab"), words.join(" ") + "\n").map_err(|e| format!("{d}: {e}"))?;
}
@@ -311,6 +332,9 @@ const MEL_HI: f64 = 10000.0;
const GATE_DB: f64 = 40.0;
/// YIN's aperiodicity threshold for a voiced frame (on the band below 1.2 kHz)
const YIN_THRESHOLD: f64 = 0.3;
+/// The noise floor renders are aligned over (dB re their loud level): the recordings' median,
+/// measured as `Sig::new` does (the 5th against the 95th percentile of 20 ms frames).
+const ALIGN_FLOOR_DB: f64 = -47.0;
/// Below this many tokens a speaker's category value is left out.
const MIN_TOKENS: usize = 3;
@@ -916,7 +940,7 @@ pub fn held_out(speaker: &str) -> bool {
}
/// Bump when a measure, a term or the score changes: the verdict refuses to compare across.
-const JUDGE_VERSION: u32 = 1;
+const JUDGE_VERSION: u32 = 2;
/// The scored groups, one share each. They hold the measures checked against the data and
/// against what the owner heard (docs/speech-comparison.md, "What is scored").
const GROUPS: [&str; 3] = ["level", "sibilants", "timing"];
@@ -1485,6 +1509,22 @@ mod tests {
Phone { ipa: ipa.into(), stress: 0, t0: 0.0, t1: 0.1 }
}
+ #[test]
+ fn a_render_is_aligned_over_a_noise_floor_like_the_recordings() {
+ // half a second of a loud tone, then half a second of digital silence
+ let fs = crate::FS;
+ let x: Vec<f64> = (0..fs as usize)
+ .map(|i| if (i as f64) < 0.5 * fs { 0.5 * (i as f64 * 0.05).sin() } else { 0.0 })
+ .collect();
+ let y = over_noise_floor(&x);
+ let ms = |v: &[f32]| v.iter().map(|a| (*a as f64) * (*a as f64)).sum::<f64>() / v.len() as f64;
+ let n = fs as usize / 2;
+ let floor_db = 10.0 * (ms(&y[n..]) / ms(&y[..n])).log10();
+ assert!((floor_db - ALIGN_FLOOR_DB).abs() < 0.5, "silence now sits {floor_db} dB below the tone");
+ // the same render always aligns the same
+ assert_eq!(y, over_noise_floor(&x));
+ }
+
#[test]
fn a_missing_measurement_has_no_cost() {
assert!(cost(f64::NAN, 1.0).is_nan());
diff --git a/docs/hill-climb/README.md b/docs/hill-climb/README.md
index ac34c8b..7841050 100644
--- a/docs/hill-climb/README.md
+++ b/docs/hill-climb/README.md
@@ -39,7 +39,7 @@ structural fixes, not a judge loosened until a change passes. So:
- **Targets**, from the baseline's report (details in log.md, "Batch 3 baseline"):
1. The female sibilants: /ʃ tʃ/ 16–17 dB too quiet, /s z/ centroids at 4.0–4.7 kHz where
women's are 7.1–7.4.
- 2. Closures and affricates too short (/k/, /dʒ/, /z/), nasals too long.
+ 2. /dʒ/ and /z/ too short, nasals too long.
3. /ð v/ 7–11 dB too loud in both voices.
4. Anything else with a large cost in `out/hill/best/tsp/report.md`.
- **Branch:** `t3/real-voice-hill-climb`.
diff --git a/docs/hill-climb/log.md b/docs/hill-climb/log.md
index b165bce..d389d62 100644
--- a/docs/hill-climb/log.md
+++ b/docs/hill-climb/log.md
@@ -1452,11 +1452,11 @@ Largest costs first. Costs are the speakers' report, female / male where both.
measured and logged in experiment 22, at −0.09 of score, and level /dʒ/ blocked it. Retry it first:
that term's limit moved with the kept run. The [h]'s broad noise (top at 10–14 kHz) is gone from /tʃ/;
nobody has found its source, and stops may still have it.
-6. **Short closures, long nasals.** Duration /k/ 3.4 / 3.6, /z/ 3.4 / 2.2, /ŋ/ 3.4 / 1.8, /n/ 1.1 / 1.9,
- and stressed vowels before sonorants (female 1.5). Note MFA's convention: read the planner and the
- report's numbers together (`phonetics/durations.rs`). Experiment 22: MFA gives 20–40 % of the synth's
- stop closures to silence, 2–3 % of the speakers', so measure that before lengthening a closure.
-7. **Weak female bursts.** /k/ 3.3, /t/ 2.9: 9 dB weak. They may move with lead 3.
+6. **Short /dʒ z/, long nasals.** Duration /z/ 4.0 / 3.0, /dʒ/ 3.4 / 3.9, /ŋ/ 3.1 / 1.7, /n/ 2.0 / 2.0.
+ (The judge's "short /k/" was the aligner on near-silent closures; see "A judge correction" below.
+ Read the planner's and the report's numbers together: `phonetics/durations.rs`.)
+7. **Bursts.** Female /t k/ are 8–9 dB weak (costs 2.8, 3.2), and may move with lead 3. The male /p/
+ is 7 dB loud (2.9).
8. **The male /ʃ/ centroid**, overshot by batch 2 (3.48 kHz, men 3.13). Cost 0.8. Its peak is low
(2–2.5 kHz, men 2.5–3.5): the excess is its tail, −2 to −8 dB at 5–10 kHz against the men's −3 to
−16. See lead 11.
@@ -1693,3 +1693,20 @@ Largest costs first. Costs are the speakers' report, female / male where both.
apart before acting on lead 6.
- **St** (experiment 21) can be reread: level /tʃ/ no longer trips, and male centroid /tʃ/ has room.
- **Female /tʃ/ and /ʃ/ are 15–16 dB quiet and peak low** (2.2–2.4 kHz, a real token 3.6–4.1): leads 3, 4.
+
+### A judge correction between experiments 22 and 23: the aligner gets a noise floor (judge version 2)
+
+Experiment 22 found MFA giving 20–40 % of the synth's stop closures to silence, against 2–3 % for the
+speakers. The renders' closures are near digital silence (−85 to −300 dB re their loud level; the
+recordings' sit at −50 to −54 dB). So MFA now sees each render over white noise at −47 dB re its loud
+level, the median floor of the recordings (250 recordings: p10 −53.5, p90 −37.9). The measures still
+use the clean render.
+
+- **It was hiding and inventing costs.** Median stop reads longer (/k/ 60 → 90 ms, /t/ 60 → 80 ms).
+ Duration /k/ 3.2 / 3.7 → 0.1 / 0. Lead 6's "short closures" was mostly this: lengthening them would
+ have made them too long. Male burst /p/ now shows (2.9), and female level /t/ (4.3).
+- **The level is not critical:** −52 dB and −47 dB give 1.352 and 1.359, with the same top terms.
+- **Re-scored with version 2:** before batch 1 2.001, after batch 1 1.853, this batch's baseline
+ 1.646 (held-out 1.710), after experiment 22 1.359 (held-out 1.533). `out/hill/baseline/tsp` and
+ `out/hill/best/tsp` hold those runs. Experiments 21 and 22 were kept on version 1 and stand. Their
+ score numbers aren't comparable with later ones.
diff --git a/docs/speech-comparison.md b/docs/speech-comparison.md
index d235454..9fd6b85 100644
--- a/docs/speech-comparison.md
+++ b/docs/speech-comparison.md
@@ -68,6 +68,13 @@ same settings for both (`tools/tsp/mfa.yaml`).
`tools/tsp/align.sh` regenerates it.
- **Renders.** Aligned on every run (about 25 s) with a dictionary of exactly what the G2P said,
including its reduced function words: "of" is AH0 V.
+- **A noise floor for the aligner.** MFA sees each render over white noise (a fixed sequence) 47 dB
+ below its loud level, the median floor of the recordings. The measures use the clean render. A
+ render's closures are near digital silence (−85 to −300 dB re its loud level; the recordings'
+ sit at −50 to −54 dB), and on them MFA gave part of a stop's closure to silence and read the stop
+ as little more than its release. The synth's /k/ read 0.7 of a mean phone against the speakers'
+ 1.1–1.2, a cost of 3.2 and 3.7. Over a floor it reads 1.1 and costs 0.1 and 0. −52 dB and −47 dB
+ give nearly the same result (score 1.352 and 1.359).
- **Why not the planner's own times.** The planner's segments are gestures, not sounds. Over
120 renders, MFA put the synth's vowels 29 ms shorter than the plan's segments (median; the
start 22 ms later and the end 12 ms earlier). It put voiceless fricatives 29 ms longer and
@@ -202,8 +209,7 @@ CHANGE, +0.000). Only scored terms count:
- **No clear change:** anything else.
These thresholds are policy, not measured audibility. A batch of many experiments will break a
-term even while the score falls a lot: batch 2 as a whole comes out WORSE (−0.214, with seven
-terms up by 0.5–1.0).
+term even while the score falls a lot, and batch 2 as a whole comes out WORSE for that reason.
## Caveats
@@ -224,20 +230,20 @@ terms up by 0.5–1.0).
## Baseline (2026-11-07, after batch 2)
-**Score 1.583 on the training speakers' sentences, 1.706 on the held-out speakers'.** A real
-speaker gets 0.277 (median over the training speakers; 0.242 for the held-out ones). Per sex:
-female 2.19, male 0.97.
+**Score 1.646 on the training speakers' sentences, 1.710 on the held-out speakers'.** A real
+speaker gets 0.277 (median over the training speakers; 0.243 for the held-out ones). Per sex:
+female 2.36, male 0.93.
| group | female | male |
|---|---|---|
-| level | 1.80 | 0.68 |
-| sibilants | 3.82 | 1.38 |
-| timing | 0.96 | 0.85 |
-| *spectrum* | *1.33* | *1.64* |
-| *formants* | *1.26* | *1.04* |
-| *voice* | *0.65* | *1.16* |
-| *voicing* | *0.35* | *0.46* |
-| *intonation* | *1.26* | *0.86* |
+| level | 2.20 | 0.77 |
+| sibilants | 4.00 | 1.35 |
+| timing | 0.89 | 0.66 |
+| *spectrum* | *1.39* | *1.68* |
+| *formants* | *1.25* | *1.05* |
+| *voice* | *0.66* | *1.16* |
+| *voicing* | *0.35* | *0.51* |
+| *intonation* | *1.25* | *0.86* |
(Diagnostics in italics.) What it points at, largest first:
@@ -245,26 +251,27 @@ female 2.19, male 0.97.
| | women | synth |
|---|---|---|
- | /tʃ/ level (frication) | −9 dB re her stressed vowels | −26 dB |
+ | /tʃ/ level (frication) | −9 dB re her stressed vowels | −28 dB |
| /ʃ/ level | −7 dB | −23 dB |
- | /s/ level | −11 dB | −21 dB |
+ | /s/ level | −11 dB | −22 dB |
| /s/ centroid | 7.4 kHz | 4.7 kHz |
| /z/ centroid | 7.1 kHz | 4.0 kHz |
| /ʃ/ centroid | 4.0 kHz | 3.3 kHz |
- The male /tʃ/ is 8 dB quiet and his /ʃ/ 6 dB. His /s z/ centroids are 1.2–1.5 kHz low.
- The female /h/ is 14 dB quiet.
-2. **Closures and affricates are short; nasals long.**
+ The male /tʃ/ is 8 dB quiet and his /ʃ/ 6 dB. His /s z/ centroids are 1.2–1.5 kHz low. The
+ female /h/ is 13 dB quiet.
+2. **Some sounds last too long or too short.**
| | speakers | synth |
|---|---|---|
- | /k/ | 1.1–1.2 of a mean phone | 0.7–0.8 |
- | /dʒ/ | 1.2–1.3 | 0.5 |
- | /z/ | 0.9–1.0 | 0.5–0.6 |
+ | /dʒ/ | 1.2–1.3 of a mean phone | 0.5 |
+ | /z/ | 0.9–1.0 | 0.45–0.53 |
+ | /tʃ/ | 1.5–1.6 | 1.1–1.2 |
| /ŋ/ | 0.9–1.0 | 1.3–1.4 |
+ | /n/ | 0.8 | 1.1 |
- Stressed vowels before sonorants are long (female 1.49 against 1.19).
-3. **Bursts.** Female /t k/ bursts are 9 dB weak. /ð/ and /v/ are 7–11 dB too loud in both voices.
+3. **Bursts and weak fricatives.** Female /t k/ bursts are 8–9 dB weak and the male /p/ burst 7 dB
+ loud. /ð/ and /v/ are 7–11 dB too loud in both voices.
4. **Diagnostics worth a look.**
- **The voice lacks presence at 1–4 kHz.** Over the stressed vowels, in dB re 0–8 kHz: at
1–2 kHz, women −10.8, female synth −16.1, men −10.6, male synth −19.7; at 2–4 kHz, −16.4,
@@ -278,10 +285,10 @@ female 2.19, male 0.97.
| commit | training | held-out | female | male |
|---|---|---|---|---|
-| before batch 1 (5186d64) | 1.994 | 2.063 | 2.86 | 1.13 |
-| after batch 1 (4980e3b) | 1.797 | 1.888 | 2.59 | 1.00 |
-| after batch 2 (now) | 1.583 | 1.706 | 2.19 | 0.97 |
+| before batch 1 (5186d64) | 2.001 | 2.143 | 2.92 | 1.08 |
+| after batch 1 (4980e3b) | 1.853 | 1.977 | 2.78 | 0.93 |
+| after batch 2 (e939cf7) | 1.646 | 1.710 | 2.36 | 0.93 |
-- **Batch 1** mostly helped timing (female 1.28 → 0.96, male 1.07 → 0.93).
+- **Batch 1** mostly helped timing (female 1.33 → 0.94, male 0.82 → 0.68).
- **Batch 2** moved the female /ʃ/ centroid from 2.8 to 3.3 kHz (women 4.0). It overshot the
male /ʃ/ (3.27 → 3.48 kHz, men 3.13). No batch moved the female sibilant levels.