@@ -1550,27 +1550,18 @@ func (v *AudioResponse) QueryGroup(uuid string) *AudioGroup {
15501550 return nil
15511551}
15521552
1553- func (v * AudioResponse ) FindAnySegmentMatchStarttime (starttime float64 ) * AudioSegment {
1554- for i , g := range v .Groups {
1555- var nextGroup * AudioGroup
1556- if i < len (v .Groups )- 1 {
1557- nextGroup = v .Groups [i + 1 ]
1558- }
1559- 1560- firstSegment , lastSegment := g .FirstSegment (), g .LastSegment ()
1561- if nextGroup != nil {
1562- lastSegment = nextGroup .LastSegment ()
1563- }
1564- 1565- if firstSegment == nil || lastSegment == nil {
1566- continue
1553+ func (v * AudioResponse ) MatchGroups (starttime float64 , max int ) []* AudioGroup {
1554+ var matched []* AudioGroup
1555+ for _ , g := range v .Groups {
1556+ if first := g .FirstSegment (); first != nil && starttime <= first .Start {
1557+ matched = append (matched , g )
15671558 }
15681559
1569- if firstSegment . OriginalStart <= starttime && starttime <= lastSegment . OriginalStart {
1570- return firstSegment
1560+ if len ( matched ) >= max {
1561+ break
15711562 }
15721563 }
1573- return nil
1564+ return matched
15741565}
15751566
15761567func (v * AudioResponse ) AppendSegment (resp openai.AudioResponse , starttime float64 ) {
@@ -1798,7 +1789,14 @@ func (v *SrsDubbingTask) Start(ctx context.Context) error {
17981789
17991790 // Whether force to generate ASR response.
18001791 if alwaysForceRegenerateASRResponse {
1801- v .AsrResponse = NewAudioResponse ()
1792+ v .AsrResponse = nil
1793+ }
1794+ 1795+ // Whether exists command file to regenerate ASR.
1796+ regenerateASR := path .Join (conf .Pwd , aiDubbingWorkDir , v .project .UUID , "regenerate.txt" )
1797+ if _ , err := os .Stat (regenerateASR ); err == nil {
1798+ os .Remove (regenerateASR )
1799+ v .AsrResponse = nil
18021800 }
18031801
18041802 if v .AsrResponse == nil {
@@ -1815,7 +1813,9 @@ func (v *SrsDubbingTask) Start(ctx context.Context) error {
18151813 break
18161814 }
18171815
1818- if v .AsrResponse .FindAnySegmentMatchStarttime (starttime ) != nil {
1816+ // If there are some matched groups about start time, do not generate the ASR for it.
1817+ ignoreIfMatched := 3
1818+ if matches := v .AsrResponse .MatchGroups (starttime , ignoreIfMatched * 2 ); len (matches ) > ignoreIfMatched {
18191819 continue
18201820 }
18211821
0 commit comments