the ultimate vocal synthesizer - sing, speak, beatbox, and more
Rust
Hill climb 22: /tʃ/'s span holds its closure and frication, and its constriction lasts until the folds close, with no [h] after it
Jameson Hodge34f49c6220b8
diff --git a/crates/chimera/src/phonetics/durations.rs b/crates/chimera/src/phonetics/durations.rsindex df993b8..88baa15 100644--- a/crates/chimera/src/phonetics/durations.rs+++ b/crates/chimera/src/phonetics/durations.rs@@ -44,7 +44,9 @@ fn table(ipa: &str) -> Option<(f64, f64)> {"d" => (75.0, 50.0),"g" => (80.0, 60.0),"ʔ" => (40.0, 30.0),- "tʃ" => (70.0, 50.0),+ // not Klatt's 70/50, which can't hold a closure and its frication (his /t/ alone is 75):+ // the TSP speakers' /tʃ/ phone, 125-140 ms, with Klatt's ratio of minimum to inherent+ "tʃ" => (125.0, 88.0),"dʒ" => (50.0, 30.0),"f" => (100.0, 80.0),"v" => (60.0, 40.0),diff --git a/crates/chimera/src/phonetics/planner.rs b/crates/chimera/src/phonetics/planner.rsindex 0a2f971..d149800 100644--- a/crates/chimera/src/phonetics/planner.rs+++ b/crates/chimera/src/phonetics/planner.rs@@ -283,11 +283,13 @@ pub fn plan_utterance(input: &[Segment], o: &PlanOptions) -> Plan {}}Manner::Affricate => {- let split = t0 + dur * 0.55;+ let split = t0 + dur * AFFRICATE_CLOSURE;add_oral(&def.targets, t0, split, 2.0, def.ipa);- let rel = def.release.and_then(|r| phoneme(r, body));- if let Some(rel) = rel {- add_oral(&rel.targets, split + 0.008, t1, 1.4, def.ipa);+ // the release is the fricative's own gesture, not a contact release's: it takes+ // the fricative's articulators (the jaw too) and holds to the span's end, where+ // the folds have closed (below). Its 8 ms lead hands over from the closure.+ if let Some(rel) = def.release.and_then(|r| phoneme(r, body)) {+ oral_gestures_into(&rel, &rel.targets, split - 0.015, t1, 1.4, def.ipa, &mut gestures);}}Manner::Fricative | Manner::Approximant | Manner::Lateral => add_oral(&def.targets, t0, t1, 1.3, def.ipa),@@ -307,7 +309,13 @@ pub fn plan_utterance(input: &[Segment], o: &PlanOptions) -> Plan {} else if def.glottal == Some(Glottal::Stop) {gestures.push(Gesture::new(t0, t1, 0.012, 0.015, 8.0, one(ControlKey::CLOSURE, 1.0)).label("ʔ"));} else if def.voicing == Voicing::Voiceless {- if def.manner == Manner::Stop || def.manner == Manner::Affricate {+ if def.manner == Manner::Affricate {+ // apart from the closure on, and together again as the frication ends: in an+ // affricate the frication is the voice onset time, with no [h] after it, and the+ // vowel keeps its planned length+ let open = t0 + 0.15 * dur;+ gestures.push(Gesture::new(open, js_max(open, t1 - 0.03), 0.035, 0.03, 6.0, one(ControlKey::ABDUCTION, 0.36)).label("aspiration"));+ } else if def.manner == Manner::Stop {// aspirated when syllable-initial before a vowel and not after /s/ (English-like)let aspirated = next_vowel && !prev_seg.is_some_and(|p| p.ipa == "s");let vot = if aspirated { 0.05 / rate } else { 0.012 };@@ -398,6 +406,10 @@ pub fn plan_utterance(input: &[Segment], o: &PlanOptions) -> Plan {Plan { gestures, segments: planned, end }}+/// The share of an affricate's span that is closure, the rest being frication (the TSP speakers'+/// /tʃ/: about 55 ms of closure, 60-65 ms of frication and a fading tail).+const AFFRICATE_CLOSURE: f64 = 0.45;+/// Front-to-back order of the oral places of articulation.fn place_rank(place: &str) -> Option<u8> {Some(match place {diff --git a/crates/chimera/tests/affricates.rs b/crates/chimera/tests/affricates.rsnew file mode 100644index 0000000..2fbafab--- /dev/null+++ b/crates/chimera/tests/affricates.rs@@ -0,0 +1,56 @@+//! A voiceless affricate is a closure, then a release straight into frication that lasts until the+//! voicing starts (experiment 22). Its constriction used to let go 40 ms before the folds closed: a+//! short /ʃ/ and then an [h], heard as a stop and an [h] ("chain" as "king").+use chimera::anatomy::human::{BODY_FEMALE, BODY_MALE};+use chimera::phonetics::ipa::tokenize_ipa;+use chimera::phonetics::planner::{PlanOptions, plan_utterance};+use chimera::voice::human_voice::{HumanVoice, SourcePatch};++const FS: f64 = 48000.0;+const FRAME: usize = 480;++/// Per 10 ms frame: the level (dB), and the share (dB) left by two one-pole low-passes at 1 kHz.+/// /ʃ/, with its peak above 2 kHz, loses most of its energy to them; an [h] and a vowel don't.+fn frames(x: &[f32]) -> Vec<(f64, f64)> {+ let a = 1.0 - (-2.0 * std::f64::consts::PI * 1000.0 / FS).exp();+ let (mut y1, mut y2) = (0.0f64, 0.0f64);+ x.chunks_exact(FRAME)+ .map(|f| {+ let (mut all, mut low) = (1e-20f64, 1e-20f64);+ for s in f {+ let s = f64::from(*s);+ y1 += a * (s - y1);+ y2 += a * (y1 - y2);+ all += s * s;+ low += y2 * y2;+ }+ (10.0 * (all / FRAME as f64).log10(), 10.0 * (low / all).log10())+ })+ .collect()+}++#[test]+fn a_voiceless_affricates_frication_runs_into_the_vowel_with_no_h_after_it() {+ for (body, name, f0) in [(BODY_MALE, "male", 112.0), (BODY_FEMALE, "female", 205.0)] {+ let plan = plan_utterance(&tokenize_ipa("ˈɑtʃɑ"), &PlanOptions { body: name.into(), t0: 0.05, f0: Some(f0), ..Default::default() });+ let span = plan.segments.iter().find(|s| s.ipa == "tʃ").unwrap();+ let (t0, t1) = (span.t0, span.t1);+ let mut v = HumanVoice::new(FS, body, 2);+ v.set_source(&SourcePatch::f0(f0));+ v.schedule(&plan.gestures);+ let mut out = vec![0.0f32; (FS * (plan.end + 0.3)).round() as usize];+ for chunk in out.chunks_mut(128) {+ v.render(chunk);+ }+ let fr = frames(&out);+ let at = |t: f64| (t * FS / FRAME as f64) as usize;+ let vowel = fr[at(t1 + 0.1)..at(t1 + 0.14)].iter().map(|f| f.0).fold(f64::MIN, f64::max);+ let fric: Vec<usize> = (at(t0)..at(t1 + 0.1)).filter(|&i| fr[i].1 < -10.0 && fr[i].0 > vowel - 30.0).collect();+ let (first, last) = (*fric.first().unwrap(), *fric.last().unwrap());+ let voiced = (last..fr.len()).find(|&i| fr[i].0 > vowel - 8.0).unwrap();+ let (length, gap) = ((last - first + 1) * 10, (voiced - last - 1) * 10);+ println!("{name}: frication {length} ms, then {gap} ms to the voice");+ assert!(length >= 50, "{name}: frication lasts {length} ms (real /tʃ/: 50-80)");+ assert!(gap <= 20, "{name}: {gap} ms between the frication and the voice");+ }+}