mirror of
https://github.com/RVC-Boss/GPT-SoVITS.git
synced 2025-04-05 19:41:56 +08:00
调整项目结构,修复随机采样bug
This commit is contained in:
parent
6cb3c15448
commit
27325f4cf9
@ -6,8 +6,8 @@ import gradio as gr
|
||||
|
||||
from Ref_Audio_Selector.config_param.log_config import logger
|
||||
|
||||
import Ref_Audio_Selector.tool.model_manager as model_manager
|
||||
import Ref_Audio_Selector.tool.audio_similarity as audio_similarity
|
||||
import Ref_Audio_Selector.common.model_manager as model_manager
|
||||
import Ref_Audio_Selector.tool.audio_sample as audio_sample
|
||||
import Ref_Audio_Selector.tool.audio_inference as audio_inference
|
||||
import Ref_Audio_Selector.tool.audio_config as audio_config
|
||||
import Ref_Audio_Selector.tool.audio_check as audio_check
|
||||
@ -58,12 +58,12 @@ def convert_from_list(text_work_space_dir, text_role, text_list_input):
|
||||
ref_audio_all = os.path.join(base_role_dir,
|
||||
params.list_to_convert_reference_audio_dir)
|
||||
|
||||
time_consuming, _ = time_util.time_monitor(audio_similarity.convert_from_list)(text_list_input, ref_audio_all)
|
||||
time_consuming, _ = time_util.time_monitor(audio_sample.convert_from_list)(text_list_input, ref_audio_all)
|
||||
|
||||
text_convert_from_list_info = f"耗时:{time_consuming:0.1f}秒;转换成功:生成目录{ref_audio_all}"
|
||||
text_sample_dir = ref_audio_all
|
||||
|
||||
# audio_similarity.convert_from_list(text_list_input, ref_audio_all)
|
||||
# audio_sample.convert_from_list(text_list_input, ref_audio_all)
|
||||
except Exception as e:
|
||||
logger.error("发生异常: \n%s", traceback.format_exc())
|
||||
text_convert_from_list_info = f"发生异常:{e}"
|
||||
@ -92,11 +92,11 @@ def start_similarity_analysis(work_space_dir, sample_dir, base_voice_path, need_
|
||||
p_similarity = Popen(cmd, shell=True)
|
||||
p_similarity.wait()
|
||||
|
||||
similarity_list = audio_similarity.parse_similarity_file(similarity_file)
|
||||
similarity_list = audio_sample.parse_similarity_file(similarity_file)
|
||||
|
||||
if need_similarity_output:
|
||||
similarity_file_dir = os.path.join(similarity_dir, base_voice_file_name)
|
||||
audio_similarity.copy_and_move(similarity_file_dir, similarity_list)
|
||||
audio_sample.copy_and_move(similarity_file_dir, similarity_list)
|
||||
|
||||
p_similarity = None
|
||||
return similarity_list, similarity_file, similarity_file_dir
|
||||
@ -137,7 +137,7 @@ def sample(text_work_space_dir, text_role, text_sample_dir, text_base_voice_path
|
||||
if similarity_list is None:
|
||||
raise Exception("相似度分析失败")
|
||||
|
||||
audio_similarity.sample(ref_audio_dir, similarity_list, slider_subsection_num, slider_sample_num)
|
||||
audio_sample.sample(ref_audio_dir, similarity_list, slider_subsection_num, slider_sample_num)
|
||||
|
||||
except Exception as e:
|
||||
logger.error("发生异常: \n%s", traceback.format_exc())
|
||||
|
@ -85,11 +85,14 @@ def sample(output_audio_dir, similarity_list, subsection_num, sample_num):
|
||||
end = (i + 1) * step
|
||||
end = min(end, len(similarity_list)) # 防止最后一段越界
|
||||
|
||||
num = min(sample_num, len(similarity_list[start:end]))
|
||||
# 创建子列表
|
||||
subsection = similarity_list[start:end]
|
||||
# 在子列表上随机打乱
|
||||
random.shuffle(subsection)
|
||||
|
||||
# 随机采样
|
||||
random.shuffle(similarity_list[start:end])
|
||||
sampled_subsection = similarity_list[start:start + num]
|
||||
# 从打乱后的子列表中抽取相应数量的个体
|
||||
num = min(sample_num, len(subsection))
|
||||
sampled_subsection = subsection[:num]
|
||||
|
||||
# 创建并进入子目录
|
||||
subdir_name = f'emotion_{i + 1}'
|
||||
@ -143,7 +146,7 @@ def copy_and_move(output_audio_directory, similarity_scores):
|
||||
for item in similarity_scores:
|
||||
# 构造新的文件名
|
||||
base_name = os.path.basename(item['wav_path'])[:-4] # 去掉.wav扩展名
|
||||
new_name = f"{item['score']*10000:04.0f}-{base_name}.wav"
|
||||
new_name = f"{item['score'] * 10000:04.0f}-{base_name}.wav"
|
||||
|
||||
# 新文件的完整路径
|
||||
new_path = os.path.join(output_audio_directory, new_name)
|
Loading…
x
Reference in New Issue
Block a user