From a23421f71cbb63cba2c2bb002a80d0ea2c23a956 Mon Sep 17 00:00:00 2001 From: Akira Mizuno Date: Wed, 13 Oct 2021 19:18:36 +0800 Subject: [PATCH] Add multiprocessing to accelerate preprocess. --- preprocess.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/preprocess.py b/preprocess.py index bde9367..0b60bcb 100644 --- a/preprocess.py +++ b/preprocess.py @@ -1,7 +1,7 @@ #! python # -*- coding: utf-8 -*- -# Author: kun -# @Time: 2019-07-23 14:26 +# Author: kun, winlaic +# @Time: 2021-10-13 19:17 import librosa @@ -11,6 +11,9 @@ from pprint import pprint import librosa.display import time +from multiprocessing import Pool +from tqdm import tqdm +from functools import partial def load_wavs(wav_dir, sr): @@ -53,23 +56,20 @@ def world_encode_spectral_envelop(sp, fs, dim=24): return coded_sp -def world_encode_data(wave, fs, frame_period=5.0, coded_dim=24): - f0s = list() - timeaxes = list() - sps = list() - aps = list() - coded_sps = list() - for wav in wave: - f0, timeaxis, sp, ap = world_decompose(wav=wav, +def world_encode_single_data(wav, fs, frame_period, coded_dim): + f0, timeaxis, sp, ap = world_decompose(wav=wav, fs=fs, frame_period=frame_period) - coded_sp = world_encode_spectral_envelop(sp=sp, fs=fs, dim=coded_dim) - f0s.append(f0) - timeaxes.append(timeaxis) - sps.append(sp) - aps.append(ap) - coded_sps.append(coded_sp) - return f0s, timeaxes, sps, aps, coded_sps + coded_sp = world_encode_spectral_envelop(sp=sp, fs=fs, dim=coded_dim) + return f0, timeaxis, sp, ap, coded_sp + +def world_encode_data(wave, fs, frame_period=5.0, coded_dim=24): + wrapped = partial(world_encode_single_data, fs=fs, frame_period=frame_period, coded_dim=coded_dim) + with Pool(16) as pool: + ret = list(tqdm(pool.imap(wrapped, wave), total=len(wave))) + + return list(map(list, zip(*ret))) + def logf0_statistics(f0s):