Skip to content

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

Rust

Hill climb 25: a nasal's span starts where it sounds closed, not at contact; a vowel and its coda /ɹ/ share Klatt's one nucleus span (long nasals, vowels before /ɹ/ double)

Jameson Hodgea5b617637922
diff --git a/crates/chimera/src/phonetics/durations.rs b/crates/chimera/src/phonetics/durations.rs
index 88baa15..8590383 100644
--- a/crates/chimera/src/phonetics/durations.rs
+++ b/crates/chimera/src/phonetics/durations.rs
@@ -2,7 +2,8 @@
//! DUR = MIN + (INH − MIN) · PRCNT
//! with PRCNT the product of context factors: phrase-final lengthening, non-final shortening,
//! non-word-final and polysyllabic shortening, unstressed shortening (MIN halved), the vowel
-//! length cue of the following consonant (bat/bad), cluster shortening, and aspiration.
+//! length cue of the following consonant (bat/bad), cluster shortening, and aspiration. A vowel and
+//! the /ɹ/ after it in its syllable share the span Klatt gives the nucleus.
//! Inherent / minimum durations (ms) per phoneme follow Klatt's table.
use super::Segment;
@@ -70,6 +71,9 @@ fn table(ipa: &str) -> Option<(f64, f64)> {
})
}
+/// The least left of a vowel in a vowel + /ɹ/ nucleus (s): Klatt's shortest vowel minimum, /ɪ/'s.
+const NUCLEUS_VOWEL_MIN: f64 = 0.04;
+
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SegInfo {
@@ -109,7 +113,8 @@ pub fn klatt_durations(segs: &[Segment], info: impl Fn(&Segment) -> SegInfo) ->
}
}
- segs.iter()
+ let mut durs: Vec<f64> = segs
+ .iter()
.enumerate()
.map(|(i, s)| {
if let Some(d) = s.dur {
@@ -190,5 +195,14 @@ pub fn klatt_durations(segs: &[Segment], info: impl Fn(&Segment) -> SegInfo) ->
}
(min + (inh - min) * p) / 1000.0
})
- .collect()
+ .collect();
+ // Klatt transcribes a vowel and its /ɹ/ as one nucleus (/AR/ "bar", /OR/ "boar"...), where the
+ // G2P gives two segments: without this the pair gets the vowel's whole span and the /ɹ/'s on top
+ for i in 0..n.saturating_sub(1) {
+ let coda = i + 2 >= n || !inf[i + 2].vowel;
+ if inf[i].vowel && segs[i + 1].ipa == "ɹ" && word[i + 1] == word[i] && coda && segs[i].dur.is_none() && segs[i + 1].dur.is_none() {
+ durs[i] = (durs[i] - durs[i + 1]).max(NUCLEUS_VOWEL_MIN);
+ }
+ }
+ durs
}
diff --git a/crates/chimera/src/phonetics/planner.rs b/crates/chimera/src/phonetics/planner.rs
index d7cd4c2..23cf0ff 100644
--- a/crates/chimera/src/phonetics/planner.rs
+++ b/crates/chimera/src/phonetics/planner.rs
@@ -281,7 +281,8 @@ pub fn plan_utterance(input: &[Segment], o: &PlanOptions) -> Plan {
// The delay leaves the closure 30 ms before its release (its 10 ms minimum hold and
// its ~20 ms early release), so a short sung stop isn't pushed past its own end.
Manner::Stop if pre_placed_behind_closure(&segs, i) => add_oral(&def.targets, t0 + js_min(PLACED_CLOSURE_DELAY, js_max(0.0, dur - 0.03)), t1, 1.55, def.ipa),
- Manner::Stop | Manner::Nasal => add_oral(&def.targets, t0, t1, 1.55, def.ipa),
+ Manner::Stop => add_oral(&def.targets, t0, t1, 1.55, def.ipa),
+ Manner::Nasal => add_oral(&def.targets, t0 + js_min(nasal_closure_delay(def.place), js_max(0.0, dur - 0.03)), t1, 1.55, def.ipa),
Manner::Tap => add_oral(&def.targets, t0, t1, 2.8, def.ipa),
Manner::Trill => {
// driven trill: rapid alternation of near-closure and release at ~26 Hz
@@ -306,8 +307,10 @@ pub fn plan_utterance(input: &[Segment], o: &PlanOptions) -> Plan {
Manner::Fricative | Manner::Approximant | Manner::Lateral => add_oral(&def.targets, t0, t1, 1.3, def.ipa),
Manner::Glottal | Manner::Vowel => {}
}
- // nasality: the velum lowers in anticipation (into the preceding vowel, as in English) and
- // seals again by the end of the nasal; 0.45 cm² is ample for the murmur
+ // nasality: the velum lowers in anticipation (into the preceding vowel, as in English). The
+ // port opens about 37 ms before the span and seals about 29 ms after it, as its lag isn't
+ // compensated. The speakers' /nd/ holds its murmur at least that late, and sealing at the
+ // span's end breaks level /d/ (hill-climb log, experiment 25). 0.45 cm² is ample for the murmur
if def.nasal == Some(true) {
gestures.push(Gesture::new(t0 - 0.02, t1 - 0.02, 0.05, 0.03, 4.0, one(ArticKey::Velum, 0.45)).label("velum"));
}
@@ -424,6 +427,20 @@ pub fn plan_utterance(input: &[Segment], o: &PlanOptions) -> Plan {
/// /tʃ/: about 55 ms of closure, 60-65 ms of frication and a fading tail).
const AFFRICATE_CLOSURE: f64 = 0.45;
+/// How much later a nasal's closure is aimed than its span's start (s). `oral_gestures_into` brings
+/// contact to about its `a` (a median 0-9 ms early in running speech), but a nasal is heard from when
+/// the oral area falls under about 0.05 cm², when the sound has already left for the nose, and that
+/// is where MFA starts it on a render: a median 7-13 ms before the span at the lips, 14-18 at the
+/// tip, 19-20 at the dorsum. Klatt's durations are acoustic, so a span starts where it sounds closed
+/// (hill-climb log, experiment 25). A short sung nasal keeps the 30 ms a stop's delay leaves.
+fn nasal_closure_delay(place: &str) -> f64 {
+ match place {
+ "bilabial" | "labiodental" => 0.01,
+ "velar" | "uvular" | "palatal" => 0.02,
+ _ => 0.015,
+ }
+}
+
/// Front-to-back order of the oral places of articulation.
fn place_rank(place: &str) -> Option<u8> {
Some(match place {
@@ -473,7 +490,8 @@ fn pitch_ramp(dur: f64) -> f64 {
/// Oral gestures for one consonant constriction held acoustically from `a` to `b` (closure to
/// release): a dominant gesture on the consonant's own articulators and a weak one on the rest.
-/// Movement latencies are compensated so the acoustic closure and release land on a and b.
+/// Movement latencies are compensated so that contact and the acoustic release land about on a and
+/// b. The closure is heard earlier than contact: see `nasal_closure_delay`.
pub fn oral_gestures(def: &PhonemeDef, tg: &ArticPatch, a: f64, b: f64, speed: f64, label: &str) -> Vec<Gesture> {
let mut out = Vec::with_capacity(4);
oral_gestures_into(def, tg, a, b, speed, label, &mut out);
diff --git a/crates/chimera/tests/nasal_spans.rs b/crates/chimera/tests/nasal_spans.rs
new file mode 100644
index 0000000..d04c6c3
--- /dev/null
+++ b/crates/chimera/tests/nasal_spans.rs
@@ -0,0 +1,77 @@
+//! A nasal's span is where it sounds closed, and a vowel and the /ɹ/ after it share one span
+//! (experiment 25). Klatt's durations are acoustic. With the closing gesture aimed at contact, the
+//! oral area fell under 0.05 cm² 7-20 ms before the span, the nasal read 90 ms where its plan said 56
+//! and the speakers' read 70, and each sentence's vowels before nasals lost that time.
+use chimera::anatomy::human::{BODY_FEMALE, BODY_MALE};
+use chimera::phonetics::durations::{SegInfo, klatt_durations};
+use chimera::phonetics::inventory::Manner;
+use chimera::phonetics::ipa::tokenize_ipa;
+use chimera::phonetics::planner::{PlanOptions, plan_utterance};
+use chimera::phonetics::Segment;
+use chimera::voice::human_voice::{HumanVoice, SourcePatch, VoiceTelemetry};
+
+const FS: f64 = 48000.0;
+
+/// For each nasal after a vowel in a phrase, the time from its span's start to where the oral area
+/// first falls under 0.05 cm², in ms.
+fn closures_vs_spans(ipa: &str, name: &str) -> Vec<f64> {
+ let (body, f0) = if name == "female" { (BODY_FEMALE, 205.0) } else { (BODY_MALE, 112.0) };
+ let plan = plan_utterance(&tokenize_ipa(ipa), &PlanOptions { body: name.into(), t0: 0.05, f0: Some(f0), ..Default::default() });
+ let mut v = HumanVoice::new(FS, body, 2);
+ v.set_source(&SourcePatch::f0(f0));
+ v.schedule(&plan.gestures);
+ let mut block = vec![0.0f32; 128];
+ let mut tel = VoiceTelemetry::default();
+ let mut closed = Vec::new();
+ let mut n = 0usize;
+ while (n as f64) < FS * plan.end {
+ v.render(&mut block);
+ v.telemetry(&mut tel);
+ n += 128;
+ closed.push((n as f64 / FS, tel.or_areas.iter().any(|a| *a < 0.05)));
+ }
+ let mut out = Vec::new();
+ for (i, s) in plan.segments.iter().enumerate() {
+ if matches!(s.ipa.as_str(), "m" | "n" | "ŋ") && i > 0 && plan.segments[i - 1].kind == "vowel" {
+ let at = closed.iter().find(|(t, c)| *t > s.t0 - 0.06 && *c).unwrap_or_else(|| panic!("/{}/ never closes", s.ipa)).0;
+ out.push((at - s.t0) * 1000.0);
+ }
+ }
+ out
+}
+
+/// The median nasal: a fixed delay can't land every one on its span. Its travel moves it, as a stop's
+/// (experiment 17): from a stressed /ɑ/ it lands about 20 ms late, from /i/ about 10 early.
+#[test]
+fn a_nasal_sounds_closed_about_when_its_span_starts() {
+ for name in ["male", "female"] {
+ let mut d = closures_vs_spans("ðəˈmɛnɪˈsʌməˈlaɪnzɑnəˈfɔɹmɪŋˈlɔŋəˈsɪŋɪŋˈsʌmənˈɡɹinˈfɪŋɡɚ", name);
+ d.sort_by(f64::total_cmp);
+ let median = d[d.len() / 2];
+ assert!(d.len() >= 10 && median.abs() < 7.0, "{name}: {d:?}");
+ }
+}
+
+fn seg(ipa: &str) -> Segment {
+ Segment { ipa: ipa.to_string(), ..Default::default() }
+}
+
+fn info(s: &Segment) -> SegInfo {
+ match s.ipa.as_str() {
+ "ɑ" => SegInfo { vowel: true, ..Default::default() },
+ "ɹ" | "l" => SegInfo { vowel: false, manner: Some(Manner::Approximant), voiced: Some(true), dur: None },
+ _ => SegInfo { vowel: false, manner: Some(Manner::Stop), voiced: Some(false), dur: None },
+ }
+}
+
+#[test]
+fn a_vowel_and_its_coda_r_share_the_vowels_span() {
+ // /l/ takes the same inherent duration and the same context rules as /ɹ/, and no nucleus
+ let with_l = klatt_durations(&[seg("p"), seg("ɑ"), seg("l"), seg("k")], info);
+ let with_r = klatt_durations(&[seg("p"), seg("ɑ"), seg("ɹ"), seg("k")], info);
+ assert!((with_r[1] + with_r[2] - with_l[1]).abs() < 1e-9, "ɑ {} + ɹ {} against ɑ {}", with_r[1], with_r[2], with_l[1]);
+ // an /ɹ/ that opens the next syllable is not a coda
+ let open = klatt_durations(&[seg("p"), seg("ɑ"), seg("ɹ"), seg("ɑ")], info);
+ let open_l = klatt_durations(&[seg("p"), seg("ɑ"), seg("l"), seg("ɑ")], info);
+ assert!((open[1] - open_l[1]).abs() < 1e-9);
+}