Fix bug: add missing get_style_vector function

This commit is contained in:
litagin02
2024-01-08 16:21:36 +09:00
parent e61ec59580
commit ade5d641e8

View File

@@ -7,8 +7,9 @@ import torch
from tqdm import tqdm from tqdm import tqdm
import utils import utils
from config import config from common.log import logger
from common.stdout_wrapper import SAFE_STDOUT from common.stdout_wrapper import SAFE_STDOUT
from config import config
warnings.filterwarnings("ignore", category=UserWarning) warnings.filterwarnings("ignore", category=UserWarning)
from pyannote.audio import Inference, Model from pyannote.audio import Inference, Model
@@ -19,12 +20,16 @@ device = torch.device(config.style_gen_config.device)
inference.to(device) inference.to(device)
# 推論時にインポートするために短いが関数を書く
def get_style_vector(wav_path):
return inference(wav_path)
def save_style_vector(wav_path): def save_style_vector(wav_path):
try: try:
style_vec = inference(wav_path) style_vec = get_style_vector(wav_path)
except Exception as e: except Exception as e:
print(f"\nError occurred with file: {wav_path}") logger.error(f"\nError occurred with file: {wav_path}, Details:\n{e}\n")
print(e)
raise raise
np.save(f"{wav_path}.npy", style_vec) # `test.wav` -> `test.wav.npy` np.save(f"{wav_path}.npy", style_vec) # `test.wav` -> `test.wav.npy`
return style_vec return style_vec
@@ -69,4 +74,4 @@ if __name__ == "__main__":
) )
) )
print(f"Finished generating style vectors! total: {len(wavnames)} npy files.") logger.info(f"Finished generating style vectors! total: {len(wavnames)} npy files.")