1, add voice volume

2, code optimization
This commit is contained in:
harry
2024-04-05 11:06:03 +08:00
parent 416a446b5e
commit ebe47d2507
6 changed files with 41 additions and 12 deletions

View File

@@ -98,6 +98,7 @@ class VideoParams:
video_language: Optional[str] = "" # auto detect video_language: Optional[str] = "" # auto detect
voice_name: Optional[str] = "" voice_name: Optional[str] = ""
voice_volume: Optional[float] = 1.0
bgm_type: Optional[str] = "random" bgm_type: Optional[str] = "random"
bgm_file: Optional[str] = "" bgm_file: Optional[str] = ""
bgm_volume: Optional[float] = 0.2 bgm_volume: Optional[float] = 0.2
@@ -231,18 +232,18 @@ class VideoTermsResponse(BaseResponse):
} }
class BgmListResponse(BaseResponse): class BgmRetrieveResponse(BaseResponse):
class Config: class Config:
json_schema_extra = { json_schema_extra = {
"example": { "example": {
"status": 200, "status": 200,
"message": "success", "message": "success",
"data": { "data": {
"bgm_list": [ "files": [
{ {
"filename": "output000.mp3", "name": "output013.mp3",
"size": 2249517, "size": 1891269,
"filepath": "C:\\Users\\cathy\\Desktop\\MoneyPrinterTurbo\\resource\\songs\\output000.mp3" "file": "/MoneyPrinterTurbo/resource/songs/output013.mp3"
} }
] ]
} }
@@ -257,7 +258,7 @@ class BgmUploadResponse(BaseResponse):
"status": 200, "status": 200,
"message": "success", "message": "success",
"data": { "data": {
"uploaded_path": "/root/home/MoneyPrinterTurbo/resource/songs/example.mp3" "file": "/MoneyPrinterTurbo/resource/songs/example.mp3"
} }
}, },
} }

View File

@@ -229,6 +229,11 @@ def generate_video(video_path: str,
result = CompositeVideoClip(clips) result = CompositeVideoClip(clips)
audio = AudioFileClip(audio_path) audio = AudioFileClip(audio_path)
try:
audio = audio.volumex(params.voice_volume)
except Exception as e:
logger.warning(f"failed to set audio volume: {e}")
result = result.set_audio(audio) result = result.set_audio(audio)
temp_output_file = f"{output_file}.temp.mp4" temp_output_file = f"{output_file}.temp.mp4"
@@ -302,6 +307,8 @@ if __name__ == "__main__":
cfg.n_threads = 2 cfg.n_threads = 2
cfg.paragraph_number = 1 cfg.paragraph_number = 1
cfg.voice_volume = 3.0
generate_video(video_path=video_file, generate_video(video_path=video_file,
audio_path=audio_file, audio_path=audio_file,
subtitle_path=subtitle_file, subtitle_path=subtitle_file,

View File

@@ -224,7 +224,7 @@ with left_panel:
params.video_script = st.text_area( params.video_script = st.text_area(
tr("Video Script"), tr("Video Script"),
value=st.session_state['video_script'], value=st.session_state['video_script'],
height=180 height=280
) )
if st.button(tr("Generate Video Keywords"), key="auto_generate_terms"): if st.button(tr("Generate Video Keywords"), key="auto_generate_terms"):
if not params.video_script: if not params.video_script:
@@ -295,6 +295,8 @@ with middle_panel:
cfg['voice_name'] = voice_name cfg['voice_name'] = voice_name
save_config() save_config()
params.voice_volume = st.selectbox(tr("Speech Volume"),
options=[0.6, 0.8, 1.0, 1.2, 1.5, 2.0, 3.0, 4.0, 5.0], index=2)
bgm_options = [ bgm_options = [
(tr("No Background Music"), ""), (tr("No Background Music"), ""),
(tr("Random Background Music"), "random"), (tr("Random Background Music"), "random"),
@@ -373,6 +375,19 @@ if start_button:
logger.info(utils.to_json(params)) logger.info(utils.to_json(params))
scroll_to_bottom() scroll_to_bottom()
tm.start(task_id=task_id, params=params) result = tm.start(task_id=task_id, params=params)
video_files = result.get("videos", [])
st.success(tr("Video Generation Completed"))
try:
if video_files:
# center the video player
player_cols = st.columns(len(video_files) * 2 + 1)
for i, url in enumerate(video_files):
player_cols[i * 2 + 1].video(url)
except Exception as e:
pass
open_task_folder(task_id) open_task_folder(task_id)
logger.info(tr("Video Generation Completed")) logger.info(tr("Video Generation Completed"))
scroll_to_bottom()

View File

@@ -23,6 +23,7 @@
"Number of Videos Generated Simultaneously": "Anzahl der parallel generierten Videos", "Number of Videos Generated Simultaneously": "Anzahl der parallel generierten Videos",
"Audio Settings": "**Audio Einstellungen**", "Audio Settings": "**Audio Einstellungen**",
"Speech Synthesis": "Sprachausgabe", "Speech Synthesis": "Sprachausgabe",
"Speech Volume": "Lautstärke der Sprachausgabe",
"Male": "Männlich", "Male": "Männlich",
"Female": "Weiblich", "Female": "Weiblich",
"Background Music": "Hintergrundmusik", "Background Music": "Hintergrundmusik",
@@ -46,6 +47,7 @@
"Video Script and Subject Cannot Both Be Empty": "Das Video-Thema und Drehbuch dürfen nicht beide leer sein", "Video Script and Subject Cannot Both Be Empty": "Das Video-Thema und Drehbuch dürfen nicht beide leer sein",
"Generating Video": "Video wird erstellt, bitte warten...", "Generating Video": "Video wird erstellt, bitte warten...",
"Start Generating Video": "Beginne mit der Generierung", "Start Generating Video": "Beginne mit der Generierung",
"Video Generation Completed": "Video erfolgreich generiert" "Video Generation Completed": "Video erfolgreich generiert",
"You can download the generated video from the following links": "Sie können das generierte Video über die folgenden Links herunterladen"
} }
} }

View File

@@ -23,6 +23,7 @@
"Number of Videos Generated Simultaneously": "Number of Videos Generated Simultaneously", "Number of Videos Generated Simultaneously": "Number of Videos Generated Simultaneously",
"Audio Settings": "**Audio Settings**", "Audio Settings": "**Audio Settings**",
"Speech Synthesis": "Speech Synthesis Voice", "Speech Synthesis": "Speech Synthesis Voice",
"Speech Volume": "Speech Volume (1.0 represents 100%)",
"Male": "Male", "Male": "Male",
"Female": "Female", "Female": "Female",
"Background Music": "Background Music", "Background Music": "Background Music",
@@ -46,6 +47,7 @@
"Video Script and Subject Cannot Both Be Empty": "Video Subject and Video Script cannot both be empty", "Video Script and Subject Cannot Both Be Empty": "Video Subject and Video Script cannot both be empty",
"Generating Video": "Generating video, please wait...", "Generating Video": "Generating video, please wait...",
"Start Generating Video": "Start Generating Video", "Start Generating Video": "Start Generating Video",
"Video Generation Completed": "Video Generation Completed" "Video Generation Completed": "Video Generation Completed",
"You can download the generated video from the following links": "You can download the generated video from the following links"
} }
} }

View File

@@ -22,7 +22,8 @@
"Clip Duration": "视频片段最大时长(秒)", "Clip Duration": "视频片段最大时长(秒)",
"Number of Videos Generated Simultaneously": "同时生成视频数量", "Number of Videos Generated Simultaneously": "同时生成视频数量",
"Audio Settings": "**音频设置**", "Audio Settings": "**音频设置**",
"Speech Synthesis": "朗读声音", "Speech Synthesis": "朗读声音:red[尽量与文案语言保持一致]",
"Speech Volume": "朗读音量1.0表示100%",
"Male": "男性", "Male": "男性",
"Female": "女性", "Female": "女性",
"Background Music": "背景音乐", "Background Music": "背景音乐",
@@ -46,6 +47,7 @@
"Video Script and Subject Cannot Both Be Empty": "视频主题 和 视频文案,不能同时为空", "Video Script and Subject Cannot Both Be Empty": "视频主题 和 视频文案,不能同时为空",
"Generating Video": "正在生成视频,请稍候...", "Generating Video": "正在生成视频,请稍候...",
"Start Generating Video": "开始生成视频", "Start Generating Video": "开始生成视频",
"Video Generation Completed": "视频生成完成" "Video Generation Completed": "视频生成完成",
"You can download the generated video from the following links": "你可以从以下链接下载生成的视频"
} }
} }