Skip to content

Turn one illustration into an animated 2D mesh avatar with a coding agent and a local editor

Test kana mora rules used for lip sync

mahi4244aee1770ce39
diff --git a/tests/lip-sync.test.ts b/tests/lip-sync.test.ts
index 6891971..cce2ad7 100644
--- a/tests/lip-sync.test.ts
+++ b/tests/lip-sync.test.ts
@@ -31,3 +31,34 @@ test('kana playback uses requested speed, loops, stops, and ignores unsupported
expect(motion.getLipSyncState().active).toBe(false);
motion.speakKana('漢字', { loop: true }); expect(motion.getLipSyncState().active).toBe(false);
});
+
+test('mora rules: youon merges, long vowels extend, sokuon inserts a short closure, bilabials close the lips', () => {
+ // small ya/yu/yo rewrite the preceding mora's vowel but keep its consonant onset
+ const youon = kanaToMoras('きゃしゅちょ');
+ expect(youon.map(m => m.vowel)).toEqual(['a', 'u', 'o']);
+ expect(youon.map(m => m.onset)).toEqual(['consonant', 'consonant', 'consonant']);
+ // a leading small kana with nothing to attach to is dropped
+ expect(kanaToMoras('ゃあ').map(m => m.vowel)).toEqual(['a']);
+
+ // 'ー' lengthens the previous mora instead of adding one; a leading 'ー' is ignored
+ const chouon = kanaToMoras('かーー', 0.1);
+ expect(chouon).toHaveLength(1);
+ expect(chouon[0].vowel).toBe('a');
+ expect(chouon[0].dur).toBeCloseTo(0.3);
+ expect(kanaToMoras('ーあ').map(m => m.vowel)).toEqual(['a']);
+ // the lengthened mora keeps the mouth on its vowel past a single mora
+ expect(sampleMoras(kanaToMoras('かー'), 0.2)?.vowel).toBe('a');
+ expect(sampleMoras(kanaToMoras('かき'), 0.2)?.vowel).toBe('i');
+
+ // 'っ' inserts a short closed mora between the surrounding sounds
+ const sokuon = kanaToMoras('あっち', 0.1);
+ expect(sokuon.map(m => m.vowel)).toEqual(['a', 'n', 'i']);
+ expect(sokuon[1].onset).toBeNull();
+ expect(sokuon[1].dur).toBeLessThan(0.1);
+
+ // m / b / p close the lips before the vowel
+ expect(kanaToMoras('まび').map(m => m.onset)).toEqual(['lips', 'lips']);
+
+ // sokuon, long marks, ん and small kana are all playable, so only other scripts are skipped
+ expect(skippedKanaCharacters('かっぷーんきゃA')).toEqual(['A']);
+});