@@ -444,19 +444,31 @@ func (s Service) splitAudio(ctx context.Context, stepParam *types.SubtitleTaskSt
444
444
func (s Service ) audioToSrt (ctx context.Context , stepParam * types.SubtitleTaskStepParam ) error {
445
445
log .GetLogger ().Info ("audioToSubtitle.audioToSrt start" , zap .Any ("taskId" , stepParam .TaskId ))
446
446
var (
447
+ cancel context.CancelFunc
447
448
stepNum = 0
448
449
parallelControlChan = make (chan struct {}, config .Conf .App .TranslateParallelNum )
449
- eg errgroup.Group
450
+ eg * errgroup.Group
450
451
stepNumMu sync.Mutex
451
452
err error
452
453
)
454
+ ctx , cancel = context .WithCancel (ctx )
455
+ defer cancel ()
456
+ eg , ctx = errgroup .WithContext (ctx )
453
457
for _ , audioFileItem := range stepParam .SmallAudios {
454
458
parallelControlChan <- struct {}{}
455
459
audioFile := audioFileItem
456
460
eg .Go (func () error {
457
461
defer func () {
458
462
<- parallelControlChan
463
+ if r := recover (); r != nil {
464
+ log .GetLogger ().Error ("audioToSubtitle.audioToSrt panic recovered" , zap .Any ("recover" , r ))
465
+ }
459
466
}()
467
+ select {
468
+ case <- ctx .Done ():
469
+ return ctx .Err ()
470
+ default :
471
+ }
460
472
// 语音转文字
461
473
var transcriptionData * types.TranscriptionData
462
474
for i := 0 ; i < 3 ; i ++ {
@@ -470,6 +482,7 @@ func (s Service) audioToSrt(ctx context.Context, stepParam *types.SubtitleTaskSt
470
482
}
471
483
}
472
484
if err != nil {
485
+ cancel ()
473
486
log .GetLogger ().Error ("audioToSubtitle.audioToSrt.Transcription err" , zap .Any ("stepParam" , stepParam ), zap .Error (err ))
474
487
return err
475
488
}
@@ -486,6 +499,7 @@ func (s Service) audioToSrt(ctx context.Context, stepParam *types.SubtitleTaskSt
486
499
// 拆分字幕并翻译
487
500
err = s .splitTextAndTranslate (stepParam .TaskId , stepParam .TaskBasePath , stepParam .TargetLanguage , stepParam .EnableModalFilter , audioFile )
488
501
if err != nil {
502
+ cancel ()
489
503
log .GetLogger ().Error ("audioToSubtitle.audioToSrt.splitTextAndTranslate err" , zap .Any ("stepParam" , stepParam ), zap .Error (err ))
490
504
return err
491
505
}
@@ -500,6 +514,7 @@ func (s Service) audioToSrt(ctx context.Context, stepParam *types.SubtitleTaskSt
500
514
// 生成时间戳
501
515
err = s .generateTimestamps (stepParam .TaskId , stepParam .TaskBasePath , stepParam .OriginLanguage , stepParam .SubtitleResultType , audioFile )
502
516
if err != nil {
517
+ cancel ()
503
518
log .GetLogger ().Error ("audioToSubtitle.audioToSrt.generateTimestamps err" , zap .Any ("stepParam" , stepParam ), zap .Error (err ))
504
519
return err
505
520
}
@@ -676,7 +691,7 @@ func getSentenceTimestamps(words []types.Word, sentence string, lastTs float64,
676
691
var srtSt types.SrtSentence
677
692
var sentenceWordList []string
678
693
sentenceWords := make ([]types.Word , 0 )
679
- if language == types .LanguageNameEnglish || language == types .LanguageNameGerman { // 处理方式不同
694
+ if language == types .LanguageNameEnglish || language == types .LanguageNameGerman || language == types . LanguageNameTurkish { // 处理方式不同
680
695
sentenceWordList = util .SplitSentence (sentence )
681
696
if len (sentenceWordList ) == 0 {
682
697
return srtSt , sentenceWords , 0 , fmt .Errorf ("sentence is empty" )
0 commit comments