Skip to content

Commit

Permalink
Merge pull request #466 from harry0703/dev
Browse files Browse the repository at this point in the history
fixed: subtitle generation failure
  • Loading branch information
harry0703 authored Jul 26, 2024
2 parents c22ef5f + 5ed98d3 commit edc4df6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def save_config():
"project_description",
"<a href='https://github.com/harry0703/MoneyPrinterTurbo'>https://github.com/harry0703/MoneyPrinterTurbo</a>",
)
project_version = _cfg.get("project_version", "1.2.0")
project_version = _cfg.get("project_version", "1.2.1")
reload_debug = False

imagemagick_path = app.get("imagemagick_path", "")
Expand Down
25 changes: 20 additions & 5 deletions app/services/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
from os import path

from edge_tts import SubMaker
from loguru import logger

from app.config import config
Expand Down Expand Up @@ -87,10 +88,10 @@ def generate_audio(task_id, params, video_script):
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.
""".strip()
)
return None, None
return None, None, None

audio_duration = math.ceil(voice.get_audio_duration(sub_maker))
return audio_file, audio_duration
return audio_file, audio_duration, sub_maker


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


def generate_final_videos(
task_id, params, downloaded_videos, audio_file, subtitle_path
task_id, params, downloaded_videos, audio_file, subtitle_path
):
final_video_paths = []
combined_video_paths = []
Expand Down Expand Up @@ -209,6 +210,9 @@ def start(task_id, params: VideoParams, stop_at: str = "video"):
logger.info(f"start task: {task_id}, stop_at: {stop_at}")
sm.state.update_task(task_id, state=const.TASK_STATE_PROCESSING, progress=5)

if type(params.video_concat_mode) is str:
params.video_concat_mode = VideoConcatMode(params.video_concat_mode)

# 1. Generate script
video_script = generate_script(task_id, params)
if not video_script:
Expand Down Expand Up @@ -242,7 +246,7 @@ def start(task_id, params: VideoParams, stop_at: str = "video"):
sm.state.update_task(task_id, state=const.TASK_STATE_PROCESSING, progress=20)

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

# 4. Generate subtitle
subtitle_path = generate_subtitle(task_id, params, video_script, None, audio_file)
subtitle_path = generate_subtitle(task_id, params, video_script, sub_maker, audio_file)

if stop_at == "subtitle":
sm.state.update_task(
Expand Down Expand Up @@ -318,3 +322,14 @@ def start(task_id, params: VideoParams, stop_at: str = "video"):
task_id, state=const.TASK_STATE_COMPLETE, progress=100, **kwargs
)
return kwargs


if __name__ == "__main__":
task_id = "task_id"
params = VideoParams(
video_subject="金钱的作用",
voice_name="zh-CN-XiaoyiNeural-Female",
voice_rate=1.0,

)
start(task_id, params, stop_at="video")

0 comments on commit edc4df6

Please sign in to comment.