diff-svc/pre_hubert.py

21 lines
698 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
from pathlib import Path
import numpy as np
from tqdm import tqdm
from infer_tools import infer_tool
from preprocessing.hubertinfer import HubertEncoder
# hubert_mode可选——"soft_hubert"、"cn_hubert"
hubert_model = HubertEncoder(hubert_mode='soft_hubert')
# 自动搜索batch文件夹下所有wav文件可自行更改路径
wav_paths = infer_tool.get_end_file("./batch", "wav")
with tqdm(total=len(wav_paths)) as p_bar:
p_bar.set_description('Processing')
for wav_path in wav_paths:
npy_path = Path(wav_path).with_suffix(".npy")
if not os.path.exists(npy_path):
np.save(str(npy_path), hubert_model.encode(wav_path))
p_bar.update(1)