You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PaddleSpeech/third_party/python-pinyin/tests/contrib/test_tone_convert.py

217 lines
5.5 KiB

E2E/Streaming Transformer/Conformer ASR (#578) * add cmvn and label smoothing loss layer * add layer for transformer * add glu and conformer conv * add torch compatiable hack, mask funcs * not hack size since it exists * add test; attention * add attention, common utils, hack paddle * add audio utils * conformer batch padding mask bug fix #223 * fix typo, python infer fix rnn mem opt name error and batchnorm1d, will be available at 2.0.2 * fix ci * fix ci * add encoder * refactor egs * add decoder * refactor ctc, add ctc align, refactor ckpt, add warmup lr scheduler, cmvn utils * refactor docs * add fix * fix readme * fix bugs, refactor collator, add pad_sequence, fix ckpt bugs * fix docstring * refactor data feed order * add u2 model * refactor cmvn, test * add utils * add u2 config * fix bugs * fix bugs * fix autograd maybe has problem when using inplace operation * refactor data, build vocab; add format data * fix text featurizer * refactor build vocab * add fbank, refactor feature of speech * refactor audio feat * refactor data preprare * refactor data * model init from config * add u2 bins * flake8 * can train * fix bugs, add coverage, add scripts * test can run * fix data * speed perturb with sox * add spec aug * fix for train * fix train logitc * fix logger * log valid loss, time dataset process * using np for speed perturb, remove some debug log of grad clip * fix logger * fix build vocab * fix logger name * using module logger as default * fix * fix install * reorder imports * fix board logger * fix logger * kaldi fbank and mfcc * fix cmvn and print prarams * fix add_eos_sos and cmvn * fix cmvn compute * fix logger and cmvn * fix subsampling, label smoothing loss, remove useless * add notebook test * fix log * fix tb logger * multi gpu valid * fix log * fix log * fix config * fix compute cmvn, need paddle 2.1 * add cmvn notebook * fix layer tools * fix compute cmvn * add rtf * fix decoding * fix layer tools * fix log, add avg script * more avg and test info * fix dataset pickle problem; using 2.1 paddle; num_workers can > 0; ckpt save in exp dir;fix setup.sh; * add vimrc * refactor tiny script, add transformer and stream conf * spm demo; librisppech scripts and confs * fix log * add librispeech scripts * refactor data pipe; fix conf; fix u2 default params * fix bugs * refactor aishell scripts * fix test * fix cmvn * fix s0 scripts * fix ds2 scripts and bugs * fix dev & test dataset filter * fix dataset filter * filter dev * fix ckpt path * filter test, since librispeech will cause OOM, but all test wer will be worse, since mismatch train with test * add comment * add syllable doc * fix ds2 configs * add doc * add pypinyin tools * fix decoder using blank_id=0 * mmseg with pybind11 * format code
4 years ago
from pytest import mark
from pypinyin.contrib.tone_convert import (
tone_to_normal,
tone_to_tone2,
tone2_to_tone,
tone_to_tone3,
tone3_to_tone,
tone2_to_normal,
tone2_to_tone3,
tone3_to_tone2,
tone3_to_normal,
to_normal,
to_tone,
to_tone2,
to_tone3, )
@mark.parametrize('pinyin,result', [
['zhōng', 'zhong'],
['ān', 'an'],
['yuè', 'yue'],
['er', 'er'],
['', 'nv'],
['ā', 'a'],
['a', 'a'],
])
def test_tone_to_normal(pinyin, result):
assert tone_to_normal(pinyin) == result
assert to_normal(pinyin) == result
assert to_normal(result) == result
@mark.parametrize('pinyin,v_to_u,result', [
['', False, 'nv'],
['', True, ''],
])
def test_tone_to_normal_with_v_to_u(pinyin, v_to_u, result):
assert tone_to_normal(pinyin, v_to_u=v_to_u) == result
assert to_normal(pinyin, v_to_u=v_to_u) == result
@mark.parametrize('pinyin,result', [
['zhōng', 'zho1ng'],
['ān', 'a1n'],
['yuè', 'yue4'],
['er', 'er'],
['', 'nv3'],
['ā', 'a1'],
['a', 'a'],
['shang', 'shang'],
])
def test_tone_tone2(pinyin, result):
assert tone_to_tone2(pinyin) == result
assert to_tone2(pinyin) == result
assert tone2_to_tone(result) == pinyin
assert to_tone(result) == pinyin
assert to_tone(pinyin) == pinyin
assert to_tone2(result) == result
@mark.parametrize('pinyin,neutral_tone_with_5,result', [
['shang', False, 'shang'],
['shang', True, 'sha5ng'],
])
def test_tone_tone2_with_neutral_tone_with_5(pinyin, neutral_tone_with_5,
result):
assert tone_to_tone2(
pinyin, neutral_tone_with_5=neutral_tone_with_5) == result
assert to_tone2(pinyin, neutral_tone_with_5=neutral_tone_with_5) == result
assert tone2_to_tone(result) == pinyin
assert to_tone(result) == pinyin
@mark.parametrize('pinyin,v_to_u,result', [
['', False, 'nv3'],
['', True, 'nü3'],
])
def test_tone_tone2_with_v_to_u(pinyin, v_to_u, result):
assert tone_to_tone2(pinyin, v_to_u=v_to_u) == result
assert to_tone2(pinyin, v_to_u=v_to_u) == result
assert tone2_to_tone(result) == pinyin
assert to_tone(result) == pinyin
@mark.parametrize('pinyin,result', [
['zhōng', 'zhong1'],
['ān', 'an1'],
['yuè', 'yue4'],
['er', 'er'],
['', 'nv3'],
['ā', 'a1'],
['a', 'a'],
['shang', 'shang'],
])
def test_tone_tone3(pinyin, result):
assert tone_to_tone3(pinyin) == result
assert to_tone3(pinyin) == result
assert tone3_to_tone(result) == pinyin
assert to_tone(result) == pinyin
assert to_tone(pinyin) == pinyin
assert to_tone3(result) == result
@mark.parametrize('pinyin,neutral_tone_with_5,result', [
['shang', False, 'shang'],
['shang', True, 'shang5'],
])
def test_tone_tone3_with_neutral_tone_with_5(pinyin, neutral_tone_with_5,
result):
assert tone_to_tone3(
pinyin, neutral_tone_with_5=neutral_tone_with_5) == result
assert to_tone3(pinyin, neutral_tone_with_5=neutral_tone_with_5) == result
assert tone3_to_tone(result) == pinyin
assert to_tone(result) == pinyin
@mark.parametrize('pinyin,v_to_u,result', [
['', False, 'nv3'],
['', True, 'nü3'],
])
def test_tone_tone3_with_v_to_u(pinyin, v_to_u, result):
assert tone_to_tone3(pinyin, v_to_u=v_to_u) == result
assert to_tone3(pinyin, v_to_u=v_to_u) == result
assert tone3_to_tone(result) == pinyin
assert to_tone(result) == pinyin
@mark.parametrize('pinyin,result', [
['zho1ng', 'zhong1'],
['a1n', 'an1'],
['yue4', 'yue4'],
['er', 'er'],
['nv3', 'nv3'],
['nü3', 'nü3'],
['a1', 'a1'],
['a', 'a'],
['shang', 'shang'],
['sha5ng', 'shang5'],
])
def test_tone2_tone3(pinyin, result):
assert tone2_to_tone3(pinyin) == result
assert to_tone3(pinyin) == result
assert tone3_to_tone2(result) == pinyin
assert to_tone2(result) == pinyin
assert to_tone2(pinyin) == pinyin
@mark.parametrize('pinyin,result', [
['zho1ng', 'zhong'],
['a1n', 'an'],
['yue4', 'yue'],
['er', 'er'],
['nv3', 'nv'],
['nü3', ''],
['a1', 'a'],
['a', 'a'],
['shang', 'shang'],
['sha5ng', 'shang'],
])
def test_tone2_to_normal(pinyin, result):
assert tone2_to_normal(pinyin) == result
assert to_normal(pinyin) == result
assert to_normal(result) == result
@mark.parametrize('pinyin,v_to_u,result', [
['nv3', False, 'nv'],
['nv3', True, ''],
['nü3', False, ''],
['nü3', True, ''],
])
def test_tone2_to_normal_with_v_to_u(pinyin, v_to_u, result):
assert tone2_to_normal(pinyin, v_to_u=v_to_u) == result
assert to_normal(pinyin, v_to_u=v_to_u) == result
assert to_normal(result) == result
@mark.parametrize('pinyin,result', [
['zhong1', 'zhong'],
['an1', 'an'],
['yue4', 'yue'],
['er', 'er'],
['nv3', 'nv'],
['nü3', ''],
['a1', 'a'],
['a', 'a'],
['shang', 'shang'],
['shang5', 'shang'],
])
def test_tone3_to_normal(pinyin, result):
assert tone3_to_normal(pinyin) == result
assert to_normal(pinyin) == result
@mark.parametrize('pinyin,v_to_u,result', [
['nv3', False, 'nv'],
['nv3', True, ''],
['nü3', False, ''],
['nü3', True, ''],
])
def test_tone3_to_normal_with_v_to_u(pinyin, v_to_u, result):
assert tone3_to_normal(pinyin, v_to_u=v_to_u) == result
assert to_normal(pinyin, v_to_u=v_to_u) == result