From ade5d641e83c960afa78ad50429bf391d5b17217 Mon Sep 17 00:00:00 2001 From: litagin02 Date: Mon, 8 Jan 2024 16:21:36 +0900 Subject: [PATCH 1/2] Fix bug: add missing get_style_vector function --- style_gen.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/style_gen.py b/style_gen.py index 7f74243..12dab20 100644 --- a/style_gen.py +++ b/style_gen.py @@ -7,8 +7,9 @@ import torch from tqdm import tqdm import utils -from config import config +from common.log import logger from common.stdout_wrapper import SAFE_STDOUT +from config import config warnings.filterwarnings("ignore", category=UserWarning) from pyannote.audio import Inference, Model @@ -19,12 +20,16 @@ device = torch.device(config.style_gen_config.device) inference.to(device) +# 推論時にインポートするために短いが関数を書く +def get_style_vector(wav_path): + return inference(wav_path) + + def save_style_vector(wav_path): try: - style_vec = inference(wav_path) + style_vec = get_style_vector(wav_path) except Exception as e: - print(f"\nError occurred with file: {wav_path}") - print(e) + logger.error(f"\nError occurred with file: {wav_path}, Details:\n{e}\n") raise np.save(f"{wav_path}.npy", style_vec) # `test.wav` -> `test.wav.npy` 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.") From fb43a178a38b88ec6942ba97770eead3a8de6955 Mon Sep 17 00:00:00 2001 From: litagin02 Date: Mon, 8 Jan 2024 16:22:32 +0900 Subject: [PATCH 2/2] Fix bug: add missing get_style_vector function --- common/tts_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/tts_model.py b/common/tts_model.py index f83a806..307c6c3 100644 --- a/common/tts_model.py +++ b/common/tts_model.py @@ -61,9 +61,9 @@ class Model: def get_style_vector_from_audio( self, audio_path: str, weight: float = 1.0 ) -> np.ndarray: - from style_gen import extract_style_vector + from style_gen import get_style_vector - xvec = extract_style_vector(audio_path) + xvec = get_style_vector(audio_path) mean = self.style_vectors[0] xvec = mean + (xvec - mean) * weight return xvec