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: failed to write srt_no_ts file

沈浩977a5caf48c0
diff --git a/internal/service/audio2subtitle.go b/internal/service/audio2subtitle.go
index c102e12a..ca2c38ab 100644
--- a/internal/service/audio2subtitle.go
+++ b/internal/service/audio2subtitle.go
@@ -856,14 +856,20 @@ func (s Service) splitTextAndTranslate(taskId, baseTaskPath string, targetLangua
}
// 保存不带时间戳的原始字幕
- originNoTsSrtFile := fmt.Sprintf("%s/%s", baseTaskPath, fmt.Sprintf(types.SubtitleTaskSplitSrtNoTimestampFileNamePattern, audioFile.Num))
- err = os.WriteFile(originNoTsSrtFile, []byte(splitContent), 0644)
+ originNoTsSrtFileName := filepath.Join(baseTaskPath, fmt.Sprintf(types.SubtitleTaskSplitSrtNoTimestampFileNamePattern, audioFile.Num))
+ originNoTsSrtFile, err := os.Create(originNoTsSrtFileName)
+ if err != nil {
+ log.GetLogger().Error("audioToSubtitle splitTextAndTranslate create srt file err", zap.Any("taskId", taskId), zap.Error(err))
+ return fmt.Errorf("audioToSubtitle splitTextAndTranslate create srt file err: %w", err)
+ }
+ defer originNoTsSrtFile.Sync()
+ defer originNoTsSrtFile.Close()
+ _, err = originNoTsSrtFile.WriteString(splitContent)
if err != nil {
log.GetLogger().Error("audioToSubtitle splitTextAndTranslate write originNoTsSrtFile err", zap.Any("taskId", taskId), zap.Error(err))
return fmt.Errorf("audioToSubtitle splitTextAndTranslate write originNoTsSrtFile err: %w", err)
}
-
- audioFile.SrtNoTsFile = originNoTsSrtFile
+ audioFile.SrtNoTsFile = originNoTsSrtFileName
return nil
}