Skip to content
This repository has been archived by the owner on Sep 11, 2022. It is now read-only.

Commit

Permalink
change import order
Browse files Browse the repository at this point in the history
  • Loading branch information
yt605155624 committed Oct 13, 2021
1 parent 6a077c6 commit 0ff3593
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 66 deletions.
66 changes: 2 additions & 64 deletions examples/GANVocoder/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <eos>
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,
Expand Down
2 changes: 1 addition & 1 deletion examples/fastspeech2/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion examples/speedyspeech/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0ff3593

Please sign in to comment.