diff --git a/examples/GANVocoder/preprocess.py b/examples/GANVocoder/preprocess.py index e536f595..9d60ce6e 100644 --- a/examples/GANVocoder/preprocess.py +++ b/examples/GANVocoder/preprocess.py @@ -25,74 +25,12 @@ import yaml from concurrent.futures import ThreadPoolExecutor from parakeet.data.get_feats import LogMelFBank +from parakeet.datasets.preprocess_utils import get_phn_dur +from parakeet.datasets.preprocess_utils import merge_silence from pathlib import Path from yacs.config import CfgNode -# speaker|utt_id|phn dur phn dur ... -def get_phn_dur(file_name): - ''' - read MFA duration.txt - Parameters - ---------- - file_name : str or Path - path of gen_duration_from_textgrid.py's result - Returns - ---------- - Dict - sentence: {'utt': ([char], [int])} - ''' - f = open(file_name, 'r') - sentence = {} - speaker_set = set() - for line in f: - line_list = line.strip().split('|') - utt = line_list[0] - speaker = line_list[1] - p_d = line_list[-1] - speaker_set.add(speaker) - phn_dur = p_d.split() - phn = phn_dur[::2] - dur = phn_dur[1::2] - assert len(phn) == len(dur) - sentence[utt] = (phn, [int(i) for i in dur], speaker) - f.close() - return sentence, speaker_set - - -def merge_silence(sentence): - ''' - merge silences, set - Parameters - ---------- - sentence : Dict - sentence: {'utt': (([char], [int]), str)} - ''' - for utt in sentence: - cur_phn, cur_dur, speaker = sentence[utt] - new_phn = [] - new_dur = [] - - # merge sp and sil - for i, p in enumerate(cur_phn): - if i > 0 and 'sil' == p and cur_phn[i - 1] in {"sil", "sp"}: - new_dur[-1] += cur_dur[i] - new_phn[-1] = 'sil' - else: - new_phn.append(p) - new_dur.append(cur_dur[i]) - - for i, (p, d) in enumerate(zip(new_phn, new_dur)): - if p in {"sp"}: - if d < 14: - new_phn[i] = 'sp' - else: - new_phn[i] = 'spl' - - assert len(new_phn) == len(new_dur) - sentence[utt] = [new_phn, new_dur, speaker] - - def process_sentence(config: Dict[str, Any], fp: Path, sentences: Dict, diff --git a/examples/fastspeech2/preprocess.py b/examples/fastspeech2/preprocess.py index 49716fb7..ff1d4dca 100644 --- a/examples/fastspeech2/preprocess.py +++ b/examples/fastspeech2/preprocess.py @@ -30,10 +30,10 @@ from parakeet.data.get_feats import LogMelFBank from parakeet.data.get_feats import Pitch from parakeet.datasets.preprocess_utils import compare_duration_and_mel_length -from parakeet.datasets.preprocess_utils import merge_silence from parakeet.datasets.preprocess_utils import get_input_token from parakeet.datasets.preprocess_utils import get_phn_dur from parakeet.datasets.preprocess_utils import get_spk_id_map +from parakeet.datasets.preprocess_utils import merge_silence from yacs.config import CfgNode diff --git a/examples/speedyspeech/preprocess.py b/examples/speedyspeech/preprocess.py index c0890489..647c9b36 100644 --- a/examples/speedyspeech/preprocess.py +++ b/examples/speedyspeech/preprocess.py @@ -27,9 +27,9 @@ from concurrent.futures import ThreadPoolExecutor from parakeet.data.get_feats import LogMelFBank from parakeet.datasets.preprocess_utils import compare_duration_and_mel_length -from parakeet.datasets.preprocess_utils import merge_silence from parakeet.datasets.preprocess_utils import get_phones_tones from parakeet.datasets.preprocess_utils import get_phn_dur +from parakeet.datasets.preprocess_utils import merge_silence from pathlib import Path from yacs.config import CfgNode