the ultimate vocal synthesizer - sing, speak, beatbox, and more
Rust
Korean: correct 밟- before consonants and ㅎ (#109)
GeonRyoung3ea22d70aa8c
diff --git a/crates/chimera/src/phonetics/korean.rs b/crates/chimera/src/phonetics/korean.rsindex 6cb4cb1..bb6fc62 100644--- a/crates/chimera/src/phonetics/korean.rs+++ b/crates/chimera/src/phonetics/korean.rs@@ -136,6 +136,16 @@ fn join(a: &mut Block, b: &mut Block) {return;}}+ // Standard Pronunciation 10: 밟- keeps ㅂ before consonants. Before ㅎ,+ // preserve ㄹ and aspirate ㅂ instead (밟히다 -> 발피다, rule 12).+ if a.text == '밟' && a.coda == ['ㄹ', 'ㅂ'] {+ if b.onset == Some('ㅎ') {+ a.coda = vec!['ㄹ'];+ b.onset = Some('ㅍ');+ return;+ }+ a.coda = vec!['ㅂ'];+ }let Some(c) = simplify(&a.coda).map(neutral) else { return };a.coda = vec![c];let o = b.onset.unwrap();diff --git a/crates/chimera/tests/syllables.rs b/crates/chimera/tests/syllables.rsindex 36bb268..e70f341 100644--- a/crates/chimera/tests/syllables.rs+++ b/crates/chimera/tests/syllables.rs@@ -76,6 +76,24 @@ fn sung(text: &str) -> String {lyrics_to_syllables(text, &word).iter().map(|s| format!("{}{}{}", marked(&s.onset), s.nucleus.ipa, marked(&s.coda))).collect::<Vec<_>>().join(".")}+#[test]+fn korean_step_stem_keeps_p_before_consonants_and_l_before_h() {+ for (text, expected) in [("밟다", "pʰ45ap.t˭a"), ("밟고", "pʰ45ap.k˭o"), ("밟는", "pʰ45am.nɯn"), ("밟히다", "pʰ45al.pʰ90i.da")] {+ assert_eq!(sung(text), expected, "{text}");+ }+}++#[test]+fn korean_stem_exceptions_preserve_liaison_and_unrelated_clusters() {+ for (text, expected) in [("읽다", "ik.t˭a"), ("읽어", "il.gʌ"), ("닭고기", "tʰ45ak.k˭o.gi"), ("밟아", "pʰ45al.ba"), ("넓어", "nʌl.bʌ"), ("여덟", "jʌ.dʌl")] {+ assert_eq!(sung(text), expected, "{text}");+ }+ let syllables = lyrics_to_syllables("읽고 밟히다", &word);+ assert_eq!(syllables.iter().map(|s| s.text.as_str()).collect::<Vec<_>>(), ["읽", "고", "밟", "히", "다"]);+ assert_eq!(syllables.iter().filter(|s| s.word_end).count(), 2);+ assert!(syllables.iter().all(|s| s.nucleus.dur.is_none()));+}+#[test]fn hangul_sings_one_syllable_per_block_with_korean_sound_rules() {assert_eq!(sung("빵야"), "p˭aŋ.ja"); // ㅇ coda stays; tense ㅃ is voiceless and unaspirated