Skip to content

Commit edc4df6

Browse files
authored
Merge pull request #466 from harry0703/dev
fixed: subtitle generation failure
2 parents c22ef5f + 5ed98d3 commit edc4df6

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

app/config/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def save_config():
5656
"project_description",
5757
"<a href='https://github.com/harry0703/MoneyPrinterTurbo'>https://github.com/harry0703/MoneyPrinterTurbo</a>",
5858
)
59-
project_version = _cfg.get("project_version", "1.2.0")
59+
project_version = _cfg.get("project_version", "1.2.1")
6060
reload_debug = False
6161

6262
imagemagick_path = app.get("imagemagick_path", "")

app/services/task.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44
from os import path
55

6+
from edge_tts import SubMaker
67
from loguru import logger
78

89
from app.config import config
@@ -87,10 +88,10 @@ def generate_audio(task_id, params, video_script):
8788
2. check if the network is available. If you are in China, it is recommended to use a VPN and enable the global traffic mode.
8889
""".strip()
8990
)
90-
return None, None
91+
return None, None, None
9192

9293
audio_duration = math.ceil(voice.get_audio_duration(sub_maker))
93-
return audio_file, audio_duration
94+
return audio_file, audio_duration, sub_maker
9495

9596

9697
def generate_subtitle(task_id, params, video_script, sub_maker, audio_file):
@@ -157,7 +158,7 @@ def get_video_materials(task_id, params, video_terms, audio_duration):
157158

158159

159160
def generate_final_videos(
160-
task_id, params, downloaded_videos, audio_file, subtitle_path
161+
task_id, params, downloaded_videos, audio_file, subtitle_path
161162
):
162163
final_video_paths = []
163164
combined_video_paths = []
@@ -209,6 +210,9 @@ def start(task_id, params: VideoParams, stop_at: str = "video"):
209210
logger.info(f"start task: {task_id}, stop_at: {stop_at}")
210211
sm.state.update_task(task_id, state=const.TASK_STATE_PROCESSING, progress=5)
211212

213+
if type(params.video_concat_mode) is str:
214+
params.video_concat_mode = VideoConcatMode(params.video_concat_mode)
215+
212216
# 1. Generate script
213217
video_script = generate_script(task_id, params)
214218
if not video_script:
@@ -242,7 +246,7 @@ def start(task_id, params: VideoParams, stop_at: str = "video"):
242246
sm.state.update_task(task_id, state=const.TASK_STATE_PROCESSING, progress=20)
243247

244248
# 3. Generate audio
245-
audio_file, audio_duration = generate_audio(task_id, params, video_script)
249+
audio_file, audio_duration, sub_maker = generate_audio(task_id, params, video_script)
246250
if not audio_file:
247251
sm.state.update_task(task_id, state=const.TASK_STATE_FAILED)
248252
return
@@ -259,7 +263,7 @@ def start(task_id, params: VideoParams, stop_at: str = "video"):
259263
return {"audio_file": audio_file, "audio_duration": audio_duration}
260264

261265
# 4. Generate subtitle
262-
subtitle_path = generate_subtitle(task_id, params, video_script, None, audio_file)
266+
subtitle_path = generate_subtitle(task_id, params, video_script, sub_maker, audio_file)
263267

264268
if stop_at == "subtitle":
265269
sm.state.update_task(
@@ -318,3 +322,14 @@ def start(task_id, params: VideoParams, stop_at: str = "video"):
318322
task_id, state=const.TASK_STATE_COMPLETE, progress=100, **kwargs
319323
)
320324
return kwargs
325+
326+
327+
if __name__ == "__main__":
328+
task_id = "task_id"
329+
params = VideoParams(
330+
video_subject="金钱的作用",
331+
voice_name="zh-CN-XiaoyiNeural-Female",
332+
voice_rate=1.0,
333+
334+
)
335+
start(task_id, params, stop_at="video")

0 commit comments

Comments
 (0)