forked from CSTR-Edinburgh/ophelia
-
Notifications
You must be signed in to change notification settings - Fork 8
/
prepare_acoustic_features.py
65 lines (46 loc) · 1.82 KB
/
prepare_acoustic_features.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
#! /usr/bin/env python2
'''
Based on code by kyubyong park at https://www.github.com/kyubyong/dc_tts
'''
from __future__ import print_function
import os
import sys
import glob
from argparse import ArgumentParser
from concurrent.futures import ProcessPoolExecutor
import numpy as np
import tqdm
from libutil import safe_makedir
from configuration import load_config
from utils import load_spectrograms
def proc(fpath, hp, extension):
if not os.path.isfile(fpath):
return
fname, mel, mag, full_mel = load_spectrograms(hp, fpath)
np.save("{}/{}".format(hp.coarse_audio_dir, fname.replace(extension, ".npy")), mel)
np.save("{}/{}".format(hp.full_audio_dir, fname.replace(extension, ".npy")), mag)
np.save("{}/{}".format(hp.full_mel_dir, fname.replace(extension, ".npy")), full_mel)
def main_work():
#################################################
# ============= Process command line ============
a = ArgumentParser()
a.add_argument('-c', dest='config', required=True, type=str)
a.add_argument('-ncores', default=1, type=int, help='Number of cores for parallel processing')
a.add_argument('-ext', dest='extension', default='.wav')
opts = a.parse_args()
# ===============================================
hp = load_config(opts.config)
extension=opts.extension
fpaths = sorted(glob.glob(hp.waveforms + '/*'+extension))
safe_makedir(hp.coarse_audio_dir)
safe_makedir(hp.full_audio_dir)
safe_makedir(hp.full_mel_dir)
executor = ProcessPoolExecutor(max_workers=opts.ncores)
futures = []
for fpath in fpaths:
futures.append(executor.submit(
proc, fpath, hp, extension))
proc_list = [future.result() for future in tqdm.tqdm(futures)]
if __name__=="__main__":
main_work()