20
20
apply_prepost_silence ,
21
21
apply_speed_scale ,
22
22
apply_volume_scale ,
23
+ calc_frame_per_mora ,
23
24
calc_frame_per_phoneme ,
24
25
calc_frame_phoneme ,
25
26
calc_frame_pitch ,
@@ -353,24 +354,43 @@ def test_calc_frame_per_phoneme():
353
354
assert numpy .array_equal (frame_per_phoneme , true_frame_per_phoneme )
354
355
355
356
357
+ def test_calc_frame_per_mora ():
358
+ """Test `calc_frame_per_mora`."""
359
+ # Inputs
360
+ moras = [
361
+ _gen_mora (" " , None , None , " " , 2 * 0.01067 , 0.0 ), # 0.01067 [sec/frame]
362
+ _gen_mora ("コ" , "k" , 2 * 0.01067 , "o" , 4 * 0.01067 , 0.0 ),
363
+ _gen_mora ("ン" , None , None , "N" , 4 * 0.01067 , 0.0 ),
364
+ _gen_mora ("、" , None , None , "pau" , 2 * 0.01067 , 0.0 ),
365
+ _gen_mora ("ヒ" , "h" , 2 * 0.01067 , "i" , 4 * 0.01067 , 0.0 ),
366
+ _gen_mora ("ホ" , "h" , 4 * 0.01067 , "O" , 2 * 0.01067 , 0.0 ),
367
+ _gen_mora (" " , None , None , " " , 6 * 0.01067 , 0.0 ),
368
+ ]
369
+
370
+ # Expects
371
+ # Pre ko N pau hi hO Pst
372
+ true_frame_per_mora = [2 , 6 , 4 , 2 , 6 , 6 , 6 ]
373
+ true_frame_per_mora = numpy .array (true_frame_per_mora , dtype = numpy .int32 )
374
+
375
+ # Outputs
376
+ frame_per_phoneme = numpy .array (list (map (calc_frame_per_mora , moras )))
377
+
378
+ assert numpy .array_equal (frame_per_phoneme , true_frame_per_mora )
379
+
380
+
356
381
def test_calc_frame_pitch ():
357
382
"""Test `test_calc_frame_pitch`."""
358
383
# Inputs
359
384
query = _gen_query (pitchScale = 2.0 , intonationScale = 0.5 )
360
385
moras = [
361
- _gen_mora (" " , None , None , " " , 0.0 , 0.0 ),
362
- _gen_mora ("コ" , "k" , 0.0 , "o" , 0.0 , 50.0 ),
363
- _gen_mora ("ン" , None , None , "N" , 0.0 , 50.0 ),
364
- _gen_mora ("、" , None , None , "pau" , 0.0 , 0.0 ),
365
- _gen_mora ("ヒ" , "h" , 0.0 , "i" , 0.0 , 125.0 ),
366
- _gen_mora ("ホ" , "h" , 0.0 , "O" , 0.0 , 0.0 ),
367
- _gen_mora (" " , None , None , " " , 0.0 , 0.0 ),
386
+ _gen_mora (" " , None , None , " " , 1 * 0.01067 , 0.0 ),
387
+ _gen_mora ("コ" , "k" , 1 * 0.01067 , "o" , 2 * 0.01067 , 50.0 ),
388
+ _gen_mora ("ン" , None , None , "N" , 2 * 0.01067 , 50.0 ),
389
+ _gen_mora ("、" , None , None , "pau" , 1 * 0.01067 , 0.0 ),
390
+ _gen_mora ("ヒ" , "h" , 1 * 0.01067 , "i" , 2 * 0.01067 , 125.0 ),
391
+ _gen_mora ("ホ" , "h" , 2 * 0.01067 , "O" , 1 * 0.01067 , 0.0 ),
392
+ _gen_mora (" " , None , None , " " , 3 * 0.01067 , 0.0 ),
368
393
]
369
- phoneme_str = "pau k o N pau h i h O pau"
370
- phonemes = [OjtPhoneme (p ) for p in phoneme_str .split ()]
371
- # Pre k o N pau h i h O Pst
372
- frame_per_phoneme = [1 , 1 , 2 , 2 , 1 , 1 , 2 , 2 , 1 , 3 ]
373
- frame_per_phoneme = numpy .array (frame_per_phoneme , dtype = numpy .int32 )
374
394
375
395
# Expects - x4 value scaled -> mean=300 var x0.5 intonation scaling
376
396
# pau ko ko ko N N
@@ -382,7 +402,7 @@ def test_calc_frame_pitch():
382
402
true_f0 = numpy .array (true1_f0 + true2_f0 + true3_f0 , dtype = numpy .float32 )
383
403
384
404
# Outputs
385
- f0 = calc_frame_pitch (query , moras , phonemes , frame_per_phoneme )
405
+ f0 = calc_frame_pitch (query , moras )
386
406
387
407
assert numpy .array_equal (f0 , true_f0 )
388
408
@@ -461,7 +481,7 @@ def test_feat_to_framescale():
461
481
# Outputs
462
482
flatten_moras = apply_prepost_silence (flatten_moras , query )
463
483
frame_per_phoneme = calc_frame_per_phoneme (query , flatten_moras )
464
- f0 = calc_frame_pitch (query , flatten_moras , phoneme_data_list , frame_per_phoneme )
484
+ f0 = calc_frame_pitch (query , flatten_moras )
465
485
frame_phoneme = calc_frame_phoneme (phoneme_data_list , frame_per_phoneme )
466
486
467
487
assert numpy .array_equal (frame_phoneme , true_frame_phoneme )
0 commit comments