mirror of
https://github.com/linyqh/NarratoAI.git
synced 2025-12-11 18:42:49 +00:00
feat(audio): 本地测试-1
- 调整背景音乐音量默认值为 0.3- 优化任务服务中的音量配置逻辑 - 更新视频生成服务,移除默认音量配置- 在 WebUI 中添加原声音量设置并更新相关参数
This commit is contained in:
parent
11a4cf0900
commit
e3b5fa4d0e
Binary file not shown.
@ -335,7 +335,7 @@ def start_subclip(task_id: str, params: VideoClipParams, subclip_path_videos: di
|
||||
volume_config = {
|
||||
'original': params.original_volume, # 原声音量80%
|
||||
'bgm': params.bgm_volume, # BGM音量20%
|
||||
'narration': params.tts_volume # 解说音量100%
|
||||
'narration': params.tts_volume or params.voice_volume, # 解说音量100%
|
||||
}
|
||||
font_path = utils.font_dir(params.font_name)
|
||||
video.generate_video_v3(
|
||||
|
||||
@ -280,11 +280,11 @@ def calculate_subtitle_position(position, video_height: int, text_height: int =
|
||||
def generate_video_v3(
|
||||
video_path: str,
|
||||
subtitle_style: dict,
|
||||
volume_config: dict,
|
||||
subtitle_path: Optional[str] = None,
|
||||
bgm_path: Optional[str] = None,
|
||||
narration_path: Optional[str] = None,
|
||||
output_path: str = "output.mp4",
|
||||
volume_config: dict = None,
|
||||
font_path: Optional[str] = None
|
||||
) -> None:
|
||||
"""
|
||||
@ -315,17 +315,6 @@ def generate_video_v3(
|
||||
if not os.path.exists(video_path):
|
||||
raise FileNotFoundError(f"视频文件不存在: {video_path}")
|
||||
|
||||
# 设置默认音量配置
|
||||
default_volume = {
|
||||
'original': 1.0, # 原声音量
|
||||
'bgm': 0.3, # BGM音量
|
||||
'narration': 1.0 # 解说音量
|
||||
}
|
||||
|
||||
# 更新音量配置
|
||||
if volume_config:
|
||||
default_volume.update(volume_config)
|
||||
|
||||
# 加载视频
|
||||
video = VideoFileClip(video_path)
|
||||
subtitle_clips = []
|
||||
@ -405,8 +394,9 @@ def generate_video_v3(
|
||||
audio_clips = []
|
||||
|
||||
# 添加原声(设置音量)
|
||||
logger.debug(f"音量配置: {volume_config}")
|
||||
if video.audio is not None:
|
||||
original_audio = video.audio.volumex(default_volume['original'])
|
||||
original_audio = video.audio.volumex(volume_config['original'])
|
||||
audio_clips.append(original_audio)
|
||||
|
||||
# 添加BGM(如果提供)
|
||||
@ -416,12 +406,12 @@ def generate_video_v3(
|
||||
bgm = loop_audio_clip(bgm, video.duration)
|
||||
else:
|
||||
bgm = bgm.subclip(0, video.duration)
|
||||
bgm = bgm.volumex(default_volume['bgm'])
|
||||
bgm = bgm.volumex(volume_config['bgm'])
|
||||
audio_clips.append(bgm)
|
||||
|
||||
# 添加解说音频(如果提供)
|
||||
if narration_path:
|
||||
narration = AudioFileClip(narration_path).volumex(default_volume['narration'])
|
||||
narration = AudioFileClip(narration_path).volumex(volume_config['narration'])
|
||||
audio_clips.append(narration)
|
||||
|
||||
# 合成最终视频(包含字幕)
|
||||
|
||||
@ -208,5 +208,5 @@ def get_audio_params():
|
||||
'voice_pitch': st.session_state.get('voice_pitch', 1.0),
|
||||
'bgm_type': st.session_state.get('bgm_type', 'random'),
|
||||
'bgm_file': st.session_state.get('bgm_file', ''),
|
||||
'bgm_volume': st.session_state.get('bgm_volume', 0.2),
|
||||
'bgm_volume': st.session_state.get('bgm_volume', 0.3),
|
||||
}
|
||||
|
||||
@ -50,11 +50,13 @@ def render_video_config(tr, params):
|
||||
step=0.01,
|
||||
help=tr("Adjust the volume of the original audio")
|
||||
)
|
||||
st.session_state['original_volume'] = params.original_volume
|
||||
|
||||
|
||||
def get_video_params():
|
||||
"""获取视频参数"""
|
||||
return {
|
||||
'video_aspect': st.session_state.get('video_aspect', VideoAspect.portrait.value),
|
||||
'video_quality': st.session_state.get('video_quality', '1080p')
|
||||
'video_quality': st.session_state.get('video_quality', '1080p'),
|
||||
'original_volume': st.session_state.get('original_volume', 0.7)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user