Skip to content

Commit

Permalink
applied black
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Thor committed Apr 26, 2022
1 parent ec518cc commit 91d48d9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions egs2/TEMPLATE/asr1/pyscripts/utils/convert_text_to_phn.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,24 @@ def main():
text = {line.split()[0]: " ".join(line.split()[1:]) for line in lines}
if cleaner is not None:
text = {k: cleaner(v) for k, v in text.items()}
with tqdm_joblib(tqdm(total=len(text.values()), desc="Phonemizing")) as progress_bar:
with tqdm_joblib(
tqdm(total=len(text.values()), desc="Phonemizing")
) as progress_bar:
phns_list = Parallel(n_jobs=args.nj)(
[delayed(phoneme_tokenizer.text2tokens)(sentence) for sentence in text.values()]
[
delayed(phoneme_tokenizer.text2tokens)(sentence)
for sentence in text.values()
]
)
with codecs.open(args.out_text, "w", encoding="utf8") as g:
for utt_id, phns in zip(text.keys(), phns_list):
g.write(f"{utt_id} " + " ".join(phns) + "\n")


@contextlib.contextmanager
def tqdm_joblib(tqdm_object):
"""Context manager to patch joblib to report into tqdm progress bar given as argument"""

class TqdmBatchCompletionCallback(parallel.BatchCompletionCallBack):
def __call__(self, *args, **kwargs):
tqdm_object.update(n=self.batch_size)
Expand All @@ -60,5 +67,6 @@ def __call__(self, *args, **kwargs):
parallel.BatchCompletionCallBack = old_batch_callback
tqdm_object.close()


if __name__ == "__main__":
main()

0 comments on commit 91d48d9

Please sign in to comment.