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: concurrent tasks do not interrupt when an error occurs
沈浩1605ec81ce93
diff --git a/internal/service/subtitle_service.go b/internal/service/subtitle_service.goindex 2893c601..edae6551 100644--- a/internal/service/subtitle_service.go+++ b/internal/service/subtitle_service.go@@ -444,19 +444,31 @@ func (s Service) splitAudio(ctx context.Context, stepParam *types.SubtitleTaskStfunc (s Service) audioToSrt(ctx context.Context, stepParam *types.SubtitleTaskStepParam) error {log.GetLogger().Info("audioToSubtitle.audioToSrt start", zap.Any("taskId", stepParam.TaskId))var (+ cancel context.CancelFuncstepNum = 0parallelControlChan = make(chan struct{}, config.Conf.App.TranslateParallelNum)- eg errgroup.Group+ eg *errgroup.GroupstepNumMu sync.Mutexerr error)+ ctx, cancel = context.WithCancel(ctx)+ defer cancel()+ eg, ctx = errgroup.WithContext(ctx)for _, audioFileItem := range stepParam.SmallAudios {parallelControlChan <- struct{}{}audioFile := audioFileItemeg.Go(func() error {defer func() {<-parallelControlChan+ if r := recover(); r != nil {+ log.GetLogger().Error("audioToSubtitle.audioToSrt panic recovered", zap.Any("recover", r))+ }}()+ select {+ case <-ctx.Done():+ return ctx.Err()+ default:+ }// 语音转文字var transcriptionData *types.TranscriptionDatafor i := 0; i < 3; i++ {@@ -470,6 +482,7 @@ func (s Service) audioToSrt(ctx context.Context, stepParam *types.SubtitleTaskSt}}if err != nil {+ cancel()log.GetLogger().Error("audioToSubtitle.audioToSrt.Transcription err", zap.Any("stepParam", stepParam), zap.Error(err))return err}@@ -486,6 +499,7 @@ func (s Service) audioToSrt(ctx context.Context, stepParam *types.SubtitleTaskSt// 拆分字幕并翻译err = s.splitTextAndTranslate(stepParam.TaskId, stepParam.TaskBasePath, stepParam.TargetLanguage, stepParam.EnableModalFilter, audioFile)if err != nil {+ cancel()log.GetLogger().Error("audioToSubtitle.audioToSrt.splitTextAndTranslate err", zap.Any("stepParam", stepParam), zap.Error(err))return err}@@ -500,6 +514,7 @@ func (s Service) audioToSrt(ctx context.Context, stepParam *types.SubtitleTaskSt// 生成时间戳err = s.generateTimestamps(stepParam.TaskId, stepParam.TaskBasePath, stepParam.OriginLanguage, stepParam.SubtitleResultType, audioFile)if err != nil {+ cancel()log.GetLogger().Error("audioToSubtitle.audioToSrt.generateTimestamps err", zap.Any("stepParam", stepParam), zap.Error(err))return err}