forked from PlayVoice/lora-svc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvc_preprocess_f0.py
51 lines (42 loc) · 1.38 KB
/
svc_preprocess_f0.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
import os
import numpy as np
import librosa
import pyworld
def compute_f0(path):
x, sr = librosa.load(path, sr=16000)
assert sr == 16000
f0, t = pyworld.dio(
x.astype(np.double),
fs=sr,
f0_ceil=900,
frame_period=1000 * 160 / sr,
)
f0 = pyworld.stonemask(x.astype(np.double), f0, t, fs=16000)
for index, pitch in enumerate(f0):
f0[index] = round(pitch, 1)
return f0
if __name__ == "__main__":
os.makedirs("filelists", exist_ok=True)
files = open("./filelists/train.txt", "w", encoding="utf-8")
rootPath = "./data_svc/waves/"
outPath = "./data_svc/pitch/"
os.makedirs(outPath, exist_ok=True)
for file in os.listdir(f"./{rootPath}"):
if file.endswith(".wav"):
file = file[:-4]
wav_path = f"./{rootPath}//{file}.wav"
featur_pit = compute_f0(wav_path)
np.save(
f"{outPath}//{file}.nsf",
featur_pit,
allow_pickle=False,
)
path_spk = "./data_svc/lora_speaker.npy"
path_wave = f"./data_svc/waves//{file}.wav"
path_pitch = f"./data_svc/pitch//{file}.nsf.npy"
path_whisper = f"./data_svc/whisper//{file}.ppg.npy"
print(
f"{path_wave}|{path_pitch}|{path_whisper}|{path_spk}",
file=files,
)
files.close()