feat: align subtitles from first 10 seconds audio
This commit is contained in:
1 parent
93e06ca40a
commit
5228765473
11 files changed
+248
-22
No files matched your search
+17
-1
@@ -20,7 +20,9 @@ from .db import (
|
||||
upsert_video_subtitle,
|
||||
)
|
||||
from .deepseek_client import DeepSeekClient, DeepSeekError
|
||||
from .subtitle_alignment import align_first_sentence
|
||||
from .subtitle_ai import process_subtitles_with_ai
|
||||
from .subtitle_tools import clean_english_subtitle
|
||||
|
||||
|
||||
PROJECT_DIR = Path(__file__).resolve().parent.parent
|
||||
@@ -384,10 +386,24 @@ def api_process_video_subtitles(video_id: int) -> dict[str, object]:
|
||||
raise HTTPException(status_code=400, detail="请先上传英文字幕。")
|
||||
|
||||
try:
|
||||
client = DeepSeekClient(load_deepseek_config())
|
||||
timestamp_offset_seconds = 0.0
|
||||
alignment_note = "未执行首句校准。"
|
||||
cleaned_for_alignment = clean_english_subtitle(str(english_subtitle["content"]))
|
||||
video_path = upload_url_to_path(str(video.get("videoUrl") or ""))
|
||||
if video_path and cleaned_for_alignment.cues:
|
||||
alignment = align_first_sentence(video_path, cleaned_for_alignment.cues[0], client)
|
||||
timestamp_offset_seconds = alignment.offset_seconds if alignment.applied else 0.0
|
||||
alignment_note = alignment.note
|
||||
elif not video_path:
|
||||
alignment_note = "当前视频不是本地上传文件,已跳过自动首句校准。"
|
||||
|
||||
result = process_subtitles_with_ai(
|
||||
str(english_subtitle["content"]),
|
||||
DeepSeekClient(load_deepseek_config()),
|
||||
client,
|
||||
timestamp_offset_seconds=timestamp_offset_seconds,
|
||||
)
|
||||
result["report"]["alignment_note"] = alignment_note
|
||||
except (DeepSeekError, ValueError) as error:
|
||||
raise HTTPException(status_code=400, detail=str(error)) from error
|
||||
|
||||
|
||||
Reference in new issue
Block a user