调整配置参数,进行集中管理

This commit is contained in:
Downupanddownup 2024-04-25 17:36:13 +08:00
parent 926dd6b34a
commit d20bd37965
7 changed files with 66 additions and 32 deletions

View File

@ -44,4 +44,3 @@ def get_config():
if __name__ == '__main__':
print(_config.print())
print(_config.get_base('reference_audio_dir'))

View File

@ -0,0 +1,42 @@
import Ref_Audio_Selector.config.config_manager as config_manager
config = config_manager.get_config()
# [Base]
# 参考音频目录
reference_audio_dir = config.get_base('reference_audio_dir')
# [AudioSample]
# list转换待选参考音频目录
list_to_convert_reference_audio_dir = config.get_audio_sample('list_to_convert_reference_audio_dir')
# 音频相似度目录
audio_similarity_dir = config.get_audio_sample('audio_similarity_dir')
# [Inference]
# 默认测试文本位置
default_test_text_path = config.get_inference('default_test_text_path')
# 推理音频目录
inference_audio_dir = config.get_inference('inference_audio_dir')
# 推理音频文本聚合目录
inference_audio_text_aggregation_dir = config.get_inference('inference_audio_text_aggregation_dir')
# 推理音频情绪聚合目录
inference_audio_emotion_aggregation_dir = config.get_inference('inference_audio_emotion_aggregation_dir')
# [ResultCheck]
# asr输出文件
asr_filename = config.get_result_check('asr_filename')
# 文本相似度输出目录
text_similarity_output_dir = config.get_result_check('text_similarity_output_dir')
# 文本情绪平均相似度报告文件名
text_emotion_average_similarity_report_filename = config.get_result_check('text_emotion_average_similarity_report_filename')
# 文本相似度按情绪聚合明细文件名
text_similarity_by_emotion_detail_filename = config.get_result_check('text_similarity_by_emotion_detail_filename')
# 文本相似度按文本聚合明细文件名
text_similarity_by_text_detail_filename = config.get_result_check('text_similarity_by_text_detail_filename')
# [AudioConfig]
# 默认模板文件位置
default_template_path = config.get_audio_config('default_template_path')
# 参考音频配置文件名
reference_audio_config_filename = config.get_audio_config('reference_audio_config_filename')

View File

@ -8,7 +8,7 @@ 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.delete_inference_with_ref as delete_inference_with_ref
import Ref_Audio_Selector.common.common as common
import Ref_Audio_Selector.config.config_manager as config_manager
import Ref_Audio_Selector.config.config_params as params
from tools.i18n.i18n import I18nAuto
from config import python_exec, is_half
from tools import my_utils
@ -16,7 +16,6 @@ from tools.asr.config import asr_dict
from subprocess import Popen
i18n = I18nAuto()
config = config_manager.get_config()
p_similarity = None
p_asr = None
@ -32,7 +31,7 @@ def check_base_info(text_work_space_dir):
# 从list文件提取参考音频
def convert_from_list(text_work_space_dir, text_list_input):
ref_audio_all = os.path.join(text_work_space_dir,
config.get_audio_sample('list_to_convert_reference_audio_dir'))
params.list_to_convert_reference_audio_dir)
text_convert_from_list_info = f"转换成功:生成目录{ref_audio_all}"
text_sample_dir = ref_audio_all
try:
@ -51,7 +50,7 @@ def start_similarity_analysis(work_space_dir, sample_dir, base_voice_path, need_
similarity_list = None
similarity_file_dir = None
similarity_dir = os.path.join(work_space_dir, config.get_audio_sample('audio_similarity_dir'))
similarity_dir = os.path.join(work_space_dir, params.audio_similarity_dir)
os.makedirs(similarity_dir, exist_ok=True)
base_voice_file_name = common.get_filename_without_extension(base_voice_path)
@ -82,7 +81,7 @@ def start_similarity_analysis(work_space_dir, sample_dir, base_voice_path, need_
# 基于一个基准音频,从参考音频目录中进行分段抽样
def sample(text_work_space_dir, text_sample_dir, text_base_voice_path,
text_subsection_num, text_sample_num, checkbox_similarity_output):
ref_audio_dir = os.path.join(text_work_space_dir, config.get_base('reference_audio_dir'))
ref_audio_dir = os.path.join(text_work_space_dir, params.reference_audio_dir)
text_sample_info = f"抽样成功:生成目录{ref_audio_dir}"
try:
check_base_info(text_work_space_dir)
@ -117,9 +116,9 @@ def sample(text_work_space_dir, text_sample_dir, text_base_voice_path,
def model_inference(text_work_space_dir, text_model_inference_voice_dir, text_url,
text_text, text_ref_path, text_ref_text, text_emotion,
text_test_content):
inference_dir = os.path.join(text_work_space_dir, config.get_inference('inference_audio_dir'))
text_asr_audio_dir = os.path.join(inference_dir,
config.get_inference('inference_audio_text_aggregation_dir'))
inference_dir = os.path.join(text_work_space_dir, params.inference_audio_dir)
text_asr_audio_dir = os.path.join(inference_dir,
params.inference_audio_text_aggregation_dir)
text_model_inference_info = f"推理成功:生成目录{inference_dir}"
try:
check_base_info(text_work_space_dir)
@ -202,7 +201,7 @@ def open_asr(asr_inp_dir, asr_opt_dir, asr_model, asr_model_size, asr_lang):
output_dir_abs = os.path.abspath(asr_opt_dir)
output_file_name = os.path.basename(asr_inp_dir)
# 构造输出文件路径
output_file_path = os.path.join(output_dir_abs, f'{config.get_result_check("asr_filename")}.list')
output_file_path = os.path.join(output_dir_abs, f'{params.asr_filename}.list')
return output_file_path
else:
@ -212,7 +211,7 @@ def open_asr(asr_inp_dir, asr_opt_dir, asr_model, asr_model_size, asr_lang):
# 对asr生成的文件与原本的文本内容进行相似度分析
def text_similarity_analysis(text_work_space_dir,
text_text_similarity_analysis_path):
similarity_dir = os.path.join(text_work_space_dir, config.get_result_check('text_similarity_output_dir'))
similarity_dir = os.path.join(text_work_space_dir, params.text_similarity_output_dir)
text_text_similarity_analysis_info = f"相似度分析成功:生成目录{similarity_dir}"
try:
check_base_info(text_work_space_dir)
@ -289,7 +288,7 @@ def sync_ref_audio(text_work_space_dir, text_sync_ref_audio_dir,
# 根据模板和参考音频目录,生成参考音频配置内容
def create_config(text_work_space_dir, text_template, text_sync_ref_audio_dir2):
config_file = os.path.join(text_work_space_dir, f'{config.get_audio_config("reference_audio_config_filename")}.json')
config_file = os.path.join(text_work_space_dir, f'{params.reference_audio_config_filename}.json')
text_create_config_info = f"配置生成成功:生成文件{config_file}"
try:
check_base_info(text_work_space_dir)
@ -359,7 +358,7 @@ with gr.Blocks() as app:
text_emotion.input(whole_url, [text_url, text_text, text_ref_path, text_ref_text, text_emotion],
[text_whole_url])
gr.Markdown(value=i18n("2.2配置待推理文本一句一行不要太多10条即可"))
default_test_content_path = config.get_inference('default_test_text_path')
default_test_content_path = params.default_test_text_path
text_test_content = gr.Text(label=i18n("请输入待推理文本路径"), value=default_test_content_path)
gr.Markdown(value=i18n("2.3:启动推理服务,如果还没启动的话"))
gr.Markdown(value=i18n("2.4:开始批量推理,这个过程比较耗时,可以去干点别的"))
@ -427,7 +426,7 @@ with gr.Blocks() as app:
text_sync_inference_audio_dir], [text_sync_ref_info])
with gr.Accordion("第四步:生成参考音频配置文本", open=False):
gr.Markdown(value=i18n("4.1:编辑模板"))
default_template_path = config.get_audio_config('default_template_path')
default_template_path = params.default_template_path
default_template_content = common.read_file(default_template_path)
text_template_path = gr.Text(label=i18n("模板文件路径"), value=default_template_path, interactive=False)
text_template = gr.Text(label=i18n("模板内容"), value=default_template_content, lines=10)

View File

@ -3,10 +3,9 @@
import argparse
import os
import traceback
import Ref_Audio_Selector.config.config_manager as config_manager
import Ref_Audio_Selector.config.config_params as params
from tqdm import tqdm
from funasr import AutoModel
config = config_manager.get_config()
path_asr = 'tools/asr/models/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch'
path_vad = 'tools/asr/models/speech_fsmn_vad_zh-cn-16k-common-pytorch'
@ -85,7 +84,7 @@ def execute_asr_multi_level_dir(input_folder, output_folder, model_size, languag
os.makedirs(output_dir_abs, exist_ok=True)
# 构造输出文件路径
output_file_path = os.path.join(output_dir_abs, f'{config.get_result_check("asr_filename")}.list')
output_file_path = os.path.join(output_dir_abs, f'{params.asr_filename}.list')
# 将输出写入文件
with open(output_file_path, "w", encoding="utf-8") as f:

View File

@ -1,11 +1,9 @@
import os
import requests
import itertools
import Ref_Audio_Selector.config.config_manager as config_manager
import Ref_Audio_Selector.config.config_params as params
from urllib.parse import urlparse, parse_qs, urlencode, urlunparse, quote
config = config_manager.get_config()
class URLComposer:
def __init__(self, base_url, emotion_param_name, text_param_name, ref_path_param_name, ref_text_param_name):
@ -80,9 +78,9 @@ def generate_audio_files(url_composer, text_list, emotion_list, output_dir_path)
os.makedirs(output_dir, exist_ok=True)
# Create subdirectories for text and emotion categories
text_subdir = os.path.join(output_dir, config.get_inference('inference_audio_text_aggregation_dir'))
text_subdir = os.path.join(output_dir, params.inference_audio_text_aggregation_dir)
os.makedirs(text_subdir, exist_ok=True)
emotion_subdir = os.path.join(output_dir, config.get_inference('inference_audio_emotion_aggregation_dir'))
emotion_subdir = os.path.join(output_dir, params.inference_audio_emotion_aggregation_dir)
os.makedirs(emotion_subdir, exist_ok=True)
# 计算笛卡尔积

View File

@ -1,9 +1,8 @@
import os
import shutil
import Ref_Audio_Selector.common.common as common
import Ref_Audio_Selector.config.config_manager as config_manager
import Ref_Audio_Selector.config.config_params as params
config = config_manager.get_config()
def remove_matching_audio_files_in_text_dir(text_dir, emotions_list):
count = 0
@ -53,8 +52,8 @@ def delete_emotion_subdirectories(emotion_dir, emotions_list):
def sync_ref_audio(ref_audio_dir, inference_audio_dir):
ref_audio_manager = common.RefAudioListManager(ref_audio_dir)
ref_list = ref_audio_manager.get_ref_audio_list()
text_dir = os.path.join(inference_audio_dir, config.get_inference('inference_audio_text_aggregation_dir'))
emotion_dir = os.path.join(inference_audio_dir, config.get_inference('inference_audio_emotion_aggregation_dir'))
text_dir = os.path.join(inference_audio_dir, params.inference_audio_text_aggregation_dir)
emotion_dir = os.path.join(inference_audio_dir, params.inference_audio_emotion_aggregation_dir)
delete_text_wav_num = remove_matching_audio_files_in_text_dir(text_dir, ref_list)
delete_emotion_dir_num = delete_emotion_subdirectories(emotion_dir, ref_list)
return delete_text_wav_num, delete_emotion_dir_num

View File

@ -3,11 +3,9 @@ import argparse
from collections import defaultdict
from operator import itemgetter
import Ref_Audio_Selector.tool.text_comparison.text_comparison as text_comparison
import Ref_Audio_Selector.config.config_manager as config_manager
import Ref_Audio_Selector.config.config_params as params
import Ref_Audio_Selector.common.common as common
config = config_manager.get_config()
def parse_asr_file(file_path):
output = []
@ -100,19 +98,19 @@ def process(asr_file_path, output_dir, similarity_enlarge_boundary):
average_similarity_list = calculate_average_similarity_by_emotion(records)
average_similarity_file = os.path.join(output_dir,
f'{config.get_result_check("text_emotion_average_similarity_report_filename")}.txt')
f'{params.text_emotion_average_similarity_report_filename}.txt')
average_similarity_content = \
'\n'.join([f"{item['average_similarity_score']}|{item['emotion']}" for item in average_similarity_list])
common.write_text_to_file(average_similarity_content, average_similarity_file)
emotion_detail_list = group_and_sort_by_field(records, 'emotion')
emotion_detail_file = os.path.join(output_dir, f'{config.get_result_check("emotion_group_detail")}.txt')
emotion_detail_file = os.path.join(output_dir, f'{params.text_similarity_by_emotion_detail_filename}.txt')
format_list_to_text(emotion_detail_list, emotion_detail_file)
original_text_detail_list = group_and_sort_by_field(records, 'original_text')
original_text_detail_file = os.path.join(output_dir, f'{config.get_result_check("text_group_detail")}.txt')
original_text_detail_file = os.path.join(output_dir, f'{params.text_similarity_by_text_detail_filename}.txt')
format_list_to_text(original_text_detail_list, original_text_detail_file)
print('文本相似度分析完成。')