Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.
TypeScript agent-skillscodex-clideskop-appdubbingimage-generationlocalizationskillsttsvideo-editingvideo-generationvideo-transcriptionvideo-translation
fix: prepare audio for subtitle fallback
wulien87eb6dea43c1
diff --git a/internal/pipeline/subtitle.go b/internal/pipeline/subtitle.goindex 0b8fc4c9..2779448b 100644--- a/internal/pipeline/subtitle.go+++ b/internal/pipeline/subtitle.go@@ -62,6 +62,10 @@ func GenerateSubtitles(ctx context.Context, svc StageService, req SubtitleRequesreturn failSubtitleStage(req, manifest, ErrorKindRetryable, "platform_caption_failed", err)}manifest.Warnings = append(manifest.Warnings, "平台字幕不可用,回退到转录")+ stepParam.VttSwitch = false+ if err := svc.PrepareMedia(ctx, stepParam); err != nil {+ return failSubtitleStage(req, manifest, ErrorKindRetryable, "prepare_audio_fallback_failed", err)+ }}if err := svc.GenerateSubtitlesFromAudio(ctx, stepParam); err != nil {@@ -102,16 +106,17 @@ func subtitleStepParam(req SubtitleRequest) *types.SubtitleTaskStepParam {Status: types.SubtitleTaskStatusProcessing,}return &types.SubtitleTaskStepParam{- TaskId: req.TaskID,- TaskPtr: taskPtr,- TaskBasePath: req.Workdir,- Link: req.Input,- SubtitleResultType: resultType,- OriginLanguage: types.StandardLanguageCode(req.OriginLang),- TargetLanguage: types.StandardLanguageCode(req.TargetLang),- UserUILanguage: types.StandardLanguageCode(userLang),- MaxWordOneLine: maxWordOneLine,- VttSwitch: true,+ TaskId: req.TaskID,+ TaskPtr: taskPtr,+ TaskBasePath: req.Workdir,+ Link: req.Input,+ SubtitleResultType: resultType,+ OriginLanguage: types.StandardLanguageCode(req.OriginLang),+ TargetLanguage: types.StandardLanguageCode(req.TargetLang),+ UserUILanguage: types.StandardLanguageCode(userLang),+ MaxWordOneLine: maxWordOneLine,+ VttSwitch: isYouTubeInput(req.Input) && req.CaptionSource != CaptionSourceWhisper,+ EmbedSubtitleVideoType: "none",}}@@ -176,5 +181,5 @@ func subtitleResponse(ok bool, req SubtitleRequest, manifest *Manifest, captionSfunc isYouTubeInput(input string) bool {normalized := strings.ToLower(strings.TrimSpace(input))- return strings.Contains(normalized, "youtube.com") || strings.Contains(normalized, "youtu.be")+ return strings.Contains(normalized, "youtube.com")}diff --git a/internal/pipeline/subtitle_test.go b/internal/pipeline/subtitle_test.goindex 2f084714..ce7c5777 100644--- a/internal/pipeline/subtitle_test.go+++ b/internal/pipeline/subtitle_test.go@@ -12,10 +12,12 @@ type fakeStageService struct {downloadErr errorprocessErr errorcalls []string+ prepareVTT []bool}-func (f *fakeStageService) PrepareMedia(context.Context, *types.SubtitleTaskStepParam) error {+func (f *fakeStageService) PrepareMedia(_ context.Context, p *types.SubtitleTaskStepParam) error {f.calls = append(f.calls, "prepare")+ f.prepareVTT = append(f.prepareVTT, p.VttSwitch)return nil}@@ -64,9 +66,12 @@ func TestGenerateSubtitlesFallsBackToAudioWhenAnySourceFails(t *testing.T) {if !resp.OK {t.Fatalf("OK = false, want true")}- if got := fake.calls; len(got) != 3 || got[0] != "prepare" || got[1] != "download-youtube" || got[2] != "audio" {+ if got := fake.calls; len(got) != 4 || got[0] != "prepare" || got[1] != "download-youtube" || got[2] != "prepare" || got[3] != "audio" {t.Fatalf("calls = %v", got)}+ if got := fake.prepareVTT; len(got) != 2 || got[0] != true || got[1] != false {+ t.Fatalf("prepare VttSwitch values = %v, want [true false]", got)+ }}func TestGenerateSubtitlesManualDoesNotFallback(t *testing.T) {@@ -96,7 +101,7 @@ func TestGenerateSubtitlesYouTubeCaptionsDoNotUseAudio(t *testing.T) {dir := t.TempDir()fake := &fakeStageService{}req := SubtitleRequest{- Input: "https://youtu.be/abc",+ Input: "https://www.youtube.com/watch?v=abc",Workdir: dir,TaskID: "demo",OriginLang: "en",@@ -139,4 +144,7 @@ func TestGenerateSubtitlesWhisperSkipsYouTubeDownload(t *testing.T) {if got := fake.calls; len(got) != 2 || got[0] != "prepare" || got[1] != "audio" {t.Fatalf("calls = %v", got)}+ if got := fake.prepareVTT; len(got) != 1 || got[0] != false {+ t.Fatalf("prepare VttSwitch values = %v, want [false]", got)+ }}