瀏覽代碼

保存进度

Signed-off-by: allan716 <[email protected]>
allan716 4 年之前
父節點
當前提交
4f57a59e1d
共有 2 個文件被更改,包括 3 次插入3 次删除
  1. 2 2
      internal/pkg/sub_timeline_fixer/fft_aligner.go
  2. 1 1
      internal/pkg/sub_timeline_fixer/pipeline.go

+ 2 - 2
internal/pkg/sub_timeline_fixer/fft_aligner.go

@@ -37,8 +37,6 @@ func (f FFTAligner) Fit(refFloats, subFloats []float64) (int, float64) {
 // fit 返回 convolve
 func (f FFTAligner) fit(refFloats, subFloats []float64) []float64 {
 
-	// 先初始化一个 fft 共用实例
-	fftIns := fourier.NewFFT(1000)
 	// 计算出一维矩阵的长度
 	totalBits := math.Log2(float64(len(refFloats)) + float64(len(subFloats)))
 	totalLength := int(math.Pow(2, math.Ceil(totalBits)))
@@ -58,6 +56,8 @@ func (f FFTAligner) fit(refFloats, subFloats []float64) []float64 {
 	}
 	// 可选择的 FFT 实现 "github.com/brettbuddin/fourier"
 	//subFT := fourier.Forward()
+	// 先初始化一个 fft 共用实例
+	fftIns := fourier.NewFFT(len(power2Sub))
 	fftIns.Reset(len(power2Sub))
 	subFT := fftIns.Coefficients(nil, power2Sub)
 	// ----------------------------------------------------------

+ 1 - 1
internal/pkg/sub_timeline_fixer/pipeline.go

@@ -30,7 +30,6 @@ func (p Pipeline) FitGSS(infoBase, infoSrc *subparser.FileInfo) error {
 	if err != nil {
 		return err
 	}
-	fffAligner := NewFFTAligner(DefaultMaxOffsetSeconds, SampleRate)
 
 	framerateRatios := p.getFramerateRatios2Try()
 	for _, framerateRatio := range framerateRatios {
@@ -58,6 +57,7 @@ func (p Pipeline) FitGSS(infoBase, infoSrc *subparser.FileInfo) error {
 
 		optFunc := func(framerateRatio float64, isLastIter bool) float64 {
 
+			fffAligner := NewFFTAligner(DefaultMaxOffsetSeconds, SampleRate)
 			// 3. speech_extract	从字幕转换为 VAD 的语音检测信息
 			// 然后进行 base 与 src 匹配计算,将每一次变动 framerateRatio 计算得到的 偏移值和分数进行记录
 			bestOffset, score := fffAligner.Fit(baseUnitNew.GetVADFloatSlice(), tmpSrcInfoUnit.GetVADFloatSlice())