Skip to content

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

Rust

Korean front end: tense stops voiceless and unaspirated, aspirated stops said, ㅈ ㅊ ㅉ and ㅅ before i alveolo-palatal

Joshua Phama17a1e92e204
diff --git a/crates/chimera/src/phonetics/korean.rs b/crates/chimera/src/phonetics/korean.rs
index 0ea9f4e..b92977a 100644
--- a/crates/chimera/src/phonetics/korean.rs
+++ b/crates/chimera/src/phonetics/korean.rs
@@ -4,8 +4,10 @@
//! neutralise to seven sounds, obstruents nasalise before nasals (국물 → 궁물), ㄴ/ㄹ meet as [ll],
//! ㅎ aspirates its neighbour (좋다 → 조타), and obstruents tense after an obstruent coda.
//!
-//! The engine has no tense (fortis) stops, so tense ㄲ ㄸ ㅃ ㅉ sing as unaspirated (voiced) stops,
-//! and lax and aspirated stops both take the planner's aspiration. ㅅ before [i] or [j] is [ʃ].
+//! Stops say their own aspiration (Segment::aspirated): aspirated ㅋ ㅌ ㅍ ㅊ are aspirated, and
+//! tense ㄲ ㄸ ㅃ ㅉ are voiceless and unaspirated (the engine has no stiff "fortis" phonation yet).
+//! Lax stops keep the planner's default: aspirated word-initially, voiced between voiced sounds.
+//! ㅈ ㅊ ㅉ are alveolo-palatal [tɕ], and ㅅ ㅆ before [i] or [j] are [ɕ].
use super::syllables::FrontEnd;
use super::{Segment, Syllable};
@@ -154,28 +156,33 @@ fn join(a: &mut Block, b: &mut Block) {
}
}
-fn onset_ipa(o: char, voiced_before: bool, front: bool, after_l: bool) -> &'static str {
+/// An initial's sound, and its aspiration when the letter decides it (None: the planner's default).
+fn onset_ipa(o: char, voiced_before: bool, front: bool, after_l: bool) -> (&'static str, Option<bool>) {
match o {
- 'ㄱ' if voiced_before => "g",
- 'ㄱ' | 'ㅋ' => "k",
- 'ㄲ' => "g",
- 'ㄷ' if voiced_before => "d",
- 'ㄷ' | 'ㅌ' => "t",
- 'ㄸ' => "d",
- 'ㅂ' if voiced_before => "b",
- 'ㅂ' | 'ㅍ' => "p",
- 'ㅃ' => "b",
- 'ㅈ' if voiced_before => "dʒ",
- 'ㅈ' | 'ㅊ' => "tʃ",
- 'ㅉ' => "dʒ",
- 'ㅅ' | 'ㅆ' if front => "ʃ",
- 'ㅅ' | 'ㅆ' => "s",
- 'ㅎ' if voiced_before => "ɦ",
- 'ㅎ' => "h",
- 'ㄴ' => "n",
- 'ㅁ' => "m",
- 'ㄹ' if after_l => "l",
- 'ㄹ' => "ɾ",
+ 'ㄱ' if voiced_before => ("g", None),
+ 'ㄱ' => ("k", None),
+ 'ㅋ' => ("k", Some(true)),
+ 'ㄲ' => ("k", Some(false)),
+ 'ㄷ' if voiced_before => ("d", None),
+ 'ㄷ' => ("t", None),
+ 'ㅌ' => ("t", Some(true)),
+ 'ㄸ' => ("t", Some(false)),
+ 'ㅂ' if voiced_before => ("b", None),
+ 'ㅂ' => ("p", None),
+ 'ㅍ' => ("p", Some(true)),
+ 'ㅃ' => ("p", Some(false)),
+ 'ㅈ' if voiced_before => ("dʑ", None),
+ 'ㅈ' => ("tɕ", None),
+ 'ㅊ' => ("tɕ", Some(true)),
+ 'ㅉ' => ("tɕ", Some(false)),
+ 'ㅅ' | 'ㅆ' if front => ("ɕ", None),
+ 'ㅅ' | 'ㅆ' => ("s", None),
+ 'ㅎ' if voiced_before => ("ɦ", None),
+ 'ㅎ' => ("h", None),
+ 'ㄴ' => ("n", None),
+ 'ㅁ' => ("m", None),
+ 'ㄹ' if after_l => ("l", None),
+ 'ㄹ' => ("ɾ", None),
_ => unreachable!("not an initial: {o}"),
}
}
@@ -208,7 +215,14 @@ pub fn word_syllables(word: &str) -> Vec<Syllable> {
let prev_coda = if i > 0 { blocks[i - 1].coda.last().copied() } else { None };
let voiced_before = i > 0 && prev_coda.is_none_or(|c| matches!(c, 'ㄴ' | 'ㄹ' | 'ㅁ' | 'ㅇ'));
let front = b.vowel == "i" && b.glide != "w" || b.glide == "j";
- let mut onset: Vec<Segment> = b.onset.map(|o| Segment::new(onset_ipa(o, voiced_before, front, prev_coda == Some('ㄹ')))).into_iter().collect();
+ let mut onset: Vec<Segment> = b
+ .onset
+ .map(|o| {
+ let (ipa, aspirated) = onset_ipa(o, voiced_before, front, prev_coda == Some('ㄹ'));
+ Segment { aspirated, ..Segment::new(ipa) }
+ })
+ .into_iter()
+ .collect();
// ㅢ after a consonant is plain [i] (희 → 히)
if !b.glide.is_empty() && !(b.glide == "ɰ" && b.onset.is_some()) {
onset.push(Segment::new(b.glide));
diff --git a/crates/chimera/tests/syllables.rs b/crates/chimera/tests/syllables.rs
index b6b253a..d6e9184 100644
--- a/crates/chimera/tests/syllables.rs
+++ b/crates/chimera/tests/syllables.rs
@@ -56,21 +56,23 @@ fn lyrics_words_melisma_phrase_ends_unreduced_function_words() {
assert!(syl[1].word_end && !syl[0].word_end);
}
-/// Each syllable as onset+nucleus+coda IPA, joined with "."
+/// Each syllable as onset+nucleus+coda IPA, joined with "."; a stop's aspiration, when its front end
+/// decides it, as ʰ (aspirated) or ˭ (unaspirated)
fn sung(text: &str) -> String {
- lyrics_to_syllables(text, &word).iter().map(|s| format!("{}{}{}", ipa(&s.onset), s.nucleus.ipa, ipa(&s.coda))).collect::<Vec<_>>().join(".")
+ let marked = |segs: &[Segment]| segs.iter().map(|s| format!("{}{}", s.ipa, match s.aspirated { Some(true) => "ʰ", Some(false) => "˭", None => "" })).collect::<String>();
+ lyrics_to_syllables(text, &word).iter().map(|s| format!("{}{}{}", marked(&s.onset), s.nucleus.ipa, marked(&s.coda))).collect::<Vec<_>>().join(".")
}
#[test]
fn hangul_sings_one_syllable_per_block_with_korean_sound_rules() {
- assert_eq!(sung("빵야"), "baŋ.ja"); // ㅇ coda stays; tense ㅃ sings unaspirated
+ assert_eq!(sung("빵야"), "p˭aŋ.ja"); // ㅇ coda stays; tense ㅃ is voiceless and unaspirated
assert_eq!(sung("먹어"), "mʌ.gʌ"); // a coda moves onto a silent ㅇ, voiced between vowels
- assert_eq!(sung("좋아"), "tʃo.a"); // ㅎ drops before a vowel
- assert_eq!(sung("좋다"), "tʃo.ta"); // ㅎ + ㄷ aspirates
+ assert_eq!(sung("좋아"), "tɕo.a"); // ㅎ drops before a vowel; ㅈ is alveolo-palatal
+ assert_eq!(sung("좋다"), "tɕo.tʰa"); // ㅎ + ㄷ aspirates
assert_eq!(sung("국물"), "kuŋ.mul"); // nasalisation
- assert_eq!(sung("신라"), "ʃil.la"); // ㄴ + ㄹ is [ll]; ㅅ before i is [ʃ]
+ assert_eq!(sung("신라"), "ɕil.la"); // ㄴ + ㄹ is [ll]; ㅅ before i is [ɕ]
assert_eq!(sung("없는"), "ʌm.nɯn"); // a two-letter coda simplifies, then nasalises
- assert_eq!(sung("학교"), "hak.gjo"); // tensing after an obstruent coda
+ assert_eq!(sung("학교"), "hak.k˭jo"); // tensing after an obstruent coda
assert_eq!(sung("사랑해"), "sa.ɾaŋ.ɦɛ");
assert_eq!(sung("닭"), "tak");
assert_eq!(sung("의사"), "ɰi.sa");