1 Star 0 Fork 6

麦高/so-vits-svc

forked from 大海/so-vits-svc 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
resample.py 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
Miuzarte 提交于 2023-04-09 12:47 . fix #97
import os
import argparse
import librosa
import numpy as np
from multiprocessing import Pool, cpu_count
from scipy.io import wavfile
from tqdm import tqdm
def process(item):
spkdir, wav_name, args = item
# speaker 's5', 'p280', 'p315' are excluded,
speaker = spkdir.replace("\\", "/").split("/")[-1]
wav_path = os.path.join(args.in_dir, speaker, wav_name)
if os.path.exists(wav_path) and '.wav' in wav_path:
os.makedirs(os.path.join(args.out_dir2, speaker), exist_ok=True)
wav, sr = librosa.load(wav_path, sr=None)
wav, _ = librosa.effects.trim(wav, top_db=20)
peak = np.abs(wav).max()
if peak > 1.0:
wav = 0.98 * wav / peak
wav2 = librosa.resample(wav, orig_sr=sr, target_sr=args.sr2)
wav2 /= max(wav2.max(), -wav2.min())
save_name = wav_name
save_path2 = os.path.join(args.out_dir2, speaker, save_name)
wavfile.write(
save_path2,
args.sr2,
(wav2 * np.iinfo(np.int16).max).astype(np.int16)
)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--sr2", type=int, default=44100, help="sampling rate")
parser.add_argument("--in_dir", type=str, default="./dataset_raw", help="path to source dir")
parser.add_argument("--out_dir2", type=str, default="./dataset/44k", help="path to target dir")
args = parser.parse_args()
processs = 30 if cpu_count() > 60 else (cpu_count()-2 if cpu_count() > 4 else 1)
pool = Pool(processes=processs)
for speaker in os.listdir(args.in_dir):
spk_dir = os.path.join(args.in_dir, speaker)
if os.path.isdir(spk_dir):
print(spk_dir)
for _ in tqdm(pool.imap_unordered(process, [(spk_dir, i, args) for i in os.listdir(spk_dir) if i.endswith("wav")])):
pass
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/MaiGao886/so-vits-svc.git
[email protected]:MaiGao886/so-vits-svc.git
MaiGao886
so-vits-svc
so-vits-svc
4.0-Vec768-Layer12

搜索帮助