Skip to content

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.

fix: preserve manifest outputs for tts

wulien61acd2d842c9
diff --git a/internal/pipeline/tts.go b/internal/pipeline/tts.go
index 1d636fbe..dc2f6dc5 100644
--- a/internal/pipeline/tts.go
+++ b/internal/pipeline/tts.go
@@ -30,9 +30,11 @@ func GenerateTTS(ctx context.Context, svc StageService, req TTSRequest) (Respons
}
manifest.TaskID = req.TaskID
manifest.Workdir = req.Workdir
+ existingOutputs := manifest.Outputs
if err := manifest.ApplyDefaultOutputs(); err != nil {
return ttsFailureResponse(req, manifest, ErrorKindInternal, "apply_outputs_failed", err), err
}
+ restoreOutputs(manifest, existingOutputs)
inputSRT := req.InputSRT
if inputSRT == "" {
@@ -89,6 +91,60 @@ func ttsManifest(req TTSRequest) (*Manifest, error) {
return nil, err
}
+func restoreOutputs(manifest *Manifest, existing Outputs) {
+ if existing.OriginVideo != "" {
+ manifest.Outputs.OriginVideo = existing.OriginVideo
+ }
+ if existing.OriginAudio != "" {
+ manifest.Outputs.OriginAudio = existing.OriginAudio
+ }
+ if existing.OriginSRT != "" {
+ manifest.Outputs.OriginSRT = existing.OriginSRT
+ }
+ if existing.TargetSRT != "" {
+ manifest.Outputs.TargetSRT = existing.TargetSRT
+ }
+ if existing.BilingualSRT != "" {
+ manifest.Outputs.BilingualSRT = existing.BilingualSRT
+ }
+ if existing.ShortOriginSRT != "" {
+ manifest.Outputs.ShortOriginSRT = existing.ShortOriginSRT
+ }
+ if existing.ShortOriginMixedSRT != "" {
+ manifest.Outputs.ShortOriginMixedSRT = existing.ShortOriginMixedSRT
+ }
+ if existing.TTSAudio != "" {
+ manifest.Outputs.TTSAudio = existing.TTSAudio
+ }
+ if existing.VideoWithTTS != "" {
+ manifest.Outputs.VideoWithTTS = existing.VideoWithTTS
+ }
+ if existing.HorizontalVideo != "" {
+ manifest.Outputs.HorizontalVideo = existing.HorizontalVideo
+ }
+ if existing.VerticalVideo != "" {
+ manifest.Outputs.VerticalVideo = existing.VerticalVideo
+ }
+ if existing.TransferredVideo != "" {
+ manifest.Outputs.TransferredVideo = existing.TransferredVideo
+ }
+ if existing.OriginCover != "" {
+ manifest.Outputs.OriginCover = existing.OriginCover
+ }
+ if existing.GeneratedCover != "" {
+ manifest.Outputs.GeneratedCover = existing.GeneratedCover
+ }
+ if existing.FinalCoverPrompt != "" {
+ manifest.Outputs.FinalCoverPrompt = existing.FinalCoverPrompt
+ }
+ if existing.OriginText != "" {
+ manifest.Outputs.OriginText = existing.OriginText
+ }
+ if existing.TargetText != "" {
+ manifest.Outputs.TargetText = existing.TargetText
+ }
+}
+
func failTTSStage(req TTSRequest, manifest *Manifest, code string, err error) (Response, error) {
if manifest != nil {
manifest.MarkStage(StageTTS, false, err.Error())
diff --git a/internal/pipeline/tts_test.go b/internal/pipeline/tts_test.go
index 226e8139..4646ab1d 100644
--- a/internal/pipeline/tts_test.go
+++ b/internal/pipeline/tts_test.go
@@ -2,6 +2,7 @@ package pipeline
import (
"context"
+ "encoding/json"
"os"
"path/filepath"
"testing"
@@ -42,3 +43,58 @@ func TestGenerateTTSExtractsBilingualTargetBeforeSpeech(t *testing.T) {
t.Fatalf("TtsSourceFilePath = %q, want %q", fake.lastSpeech.TtsSourceFilePath, extracted)
}
}
+
+func TestGenerateTTSUsesManifestTargetSRTWhenInputEmpty(t *testing.T) {
+ dir := t.TempDir()
+ customTarget := filepath.Join(dir, "custom_target.srt")
+ if err := os.WriteFile(customTarget, []byte("1\n00:00:00,000 --> 00:00:01,000\n你好\n\n"), 0644); err != nil {
+ t.Fatal(err)
+ }
+ manifest := NewManifest("demo", dir)
+ manifest.Outputs.TargetSRT = customTarget
+ manifest.FailedIndexes = []int{2}
+ data, err := json.Marshal(manifest)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(ManifestPath(dir), data, 0644); err != nil {
+ t.Fatal(err)
+ }
+
+ fake := &fakeStageService{}
+ req := TTSRequest{
+ Workdir: dir,
+ TaskID: "demo",
+ Video: "custom_video.mp4",
+ Voice: "voice-a",
+ VoiceCloneSource: "clone.wav",
+ }
+ resp, err := GenerateTTS(context.Background(), fake, req)
+ if err != nil {
+ t.Fatalf("GenerateTTS() error = %v", err)
+ }
+ if !resp.OK {
+ t.Fatalf("OK = false, want true")
+ }
+ if fake.lastSpeech == nil {
+ t.Fatalf("GenerateSpeechFromSRT was not called")
+ }
+ if fake.lastSpeech.TtsSourceFilePath != customTarget {
+ t.Fatalf("TtsSourceFilePath = %q, want %q", fake.lastSpeech.TtsSourceFilePath, customTarget)
+ }
+ if !fake.lastSpeech.EnableTts {
+ t.Fatalf("EnableTts = false, want true")
+ }
+ if fake.lastSpeech.InputVideoPath != "custom_video.mp4" {
+ t.Fatalf("InputVideoPath = %q", fake.lastSpeech.InputVideoPath)
+ }
+ if fake.lastSpeech.TtsVoiceCode != "voice-a" {
+ t.Fatalf("TtsVoiceCode = %q", fake.lastSpeech.TtsVoiceCode)
+ }
+ if fake.lastSpeech.VoiceCloneAudioUrl != "clone.wav" {
+ t.Fatalf("VoiceCloneAudioUrl = %q", fake.lastSpeech.VoiceCloneAudioUrl)
+ }
+ if len(resp.FailedIndexes) != 1 || resp.FailedIndexes[0] != 2 {
+ t.Fatalf("FailedIndexes = %v, want [2]", resp.FailedIndexes)
+ }
+}