Browse Source

GetVADInfoFeatureFromSubNew 还有问题,需要解决两句话粘黏没有分割开的问题

Signed-off-by: allan716 <[email protected]>
allan716 3 years ago
parent
commit
504f075386

+ 1 - 0
.gitignore

@@ -57,3 +57,4 @@
 /internal/pkg/ffmpeg_helper/Logs
 /internal/pkg/sub_timeline_fixer/*.html
 /**/CSF-SubFixCache
+/CSF-DebugThings

+ 8 - 1
internal/pkg/debug_view/debug_view.go

@@ -2,11 +2,13 @@ package debug_view
 
 import (
 	"fmt"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/vad"
 	"github.com/go-echarts/go-echarts/v2/charts"
 	"github.com/go-echarts/go-echarts/v2/opts"
 	"os"
+	"path/filepath"
 )
 
 func SaveDebugChart(subUnit sub_helper.SubUnit, title, subTitle string) error {
@@ -39,8 +41,13 @@ func SaveDebugChartBase(vadList []vad.VADInfo, title, subTitle string) error {
 	// Put data into instance
 	line.SetXAxis(xAxis).
 		AddSeries("VAD", lineData)
+
+	rootDebugFolder, err := my_folder.GetRootDebugFolder()
+	if err != nil {
+		return err
+	}
 	// Where the magic happens
-	f, err := os.Create(title + "bar.html")
+	f, err := os.Create(filepath.Join(rootDebugFolder, title+".html"))
 	if err != nil {
 		return err
 	}

+ 12 - 9
internal/pkg/sub_helper/sub_helper.go

@@ -493,6 +493,7 @@ func GetVADInfoFeatureFromSubNew(fileInfo *subparser.FileInfo, SkipFrontAndEndPe
 	skipStartIndex := skipLen
 	skipEndIndex := vadLen - skipLen
 	// 现在需要从 fileInfo 的每一句对白也就对应一段连续的 VAD active = true 来进行改写,记得向下取整
+	lastDialogueIndex := 0
 	for index, dialogueEx := range fileInfo.DialoguesEx {
 
 		// 如果当前的这一句话,为空,或者进过正则表达式剔除特殊字符后为空,则跳过
@@ -524,15 +525,7 @@ func GetVADInfoFeatureFromSubNew(fileInfo *subparser.FileInfo, SkipFrontAndEndPe
 		if changeVADStartIndex < int(subStartTimeFloor10ms) {
 			continue
 		}
-
-		// 如果上一个对白的最后一个 OffsetIndex 链接着当前这一句的索引的 VAD 信息 active 是 true 就设置为 false
-		lastDialogueEndIndex := changeVADStartIndex - int(subStartTimeFloor10ms) - 1
-		if lastDialogueEndIndex >= 0 {
-			if subVADs[lastDialogueEndIndex].Active == true {
-				subVADs[lastDialogueEndIndex].Active = false
-			}
-		}
-		// 调整之前做好的整体 VAD 的信息,符合 VAD active = true
+		// 当前这句话的开始和结束信息
 		changerStartIndex := changeVADStartIndex - int(subStartTimeFloor10ms)
 		if changerStartIndex < 0 {
 			continue
@@ -541,9 +534,19 @@ func GetVADInfoFeatureFromSubNew(fileInfo *subparser.FileInfo, SkipFrontAndEndPe
 		if changerEndIndex < 0 {
 			continue
 		}
+		// TODO 还需要改,有问题
+		// 如果上一个对白的最后一个 OffsetIndex 连接着当前这一句的索引的 VAD 信息 active 是 true 就设置为 false
+		if lastDialogueIndex == changerStartIndex {
+			if lastDialogueIndex-1 >= 0 && subVADs[lastDialogueIndex-1].Active == true {
+				subVADs[lastDialogueIndex-1].Active = false
+			}
+		}
+		// 开始根据当前这句话进行 VAD 信息的设置
+		// 调整之前做好的整体 VAD 的信息,符合 VAD active = true
 		for i := changerStartIndex; i < changerEndIndex; i++ {
 			subVADs[i].Active = true
 		}
+		lastDialogueIndex = changerEndIndex
 	}
 
 	// 截取出来当前这一段

+ 3 - 17
internal/pkg/sub_timeline_fixer/fixer_test.go

@@ -743,20 +743,6 @@ func TestGetOffsetTimeV2_BaseAudio(t *testing.T) {
 			if bFind == false {
 				t.Fatal("sub not match")
 			}
-
-			_, err = timelineFixer.FixSubTimeline(infoSrc, 10, "c:\\tmp\\123.ass")
-			if err != nil {
-				t.Fatal(err)
-			}
-
-			bFind, infoSrc, err = subParserHub.DetermineFileTypeFromFile("c:\\tmp\\123.ass")
-			if err != nil {
-				t.Fatal(err)
-			}
-			if bFind == false {
-				t.Fatal("sub not match")
-			}
-
 			/*
 				这里发现一个梗,内置的英文字幕导出的时候,有可能需要合并多个 Dialogue,见
 				internal/pkg/sub_helper/sub_helper.go 中 MergeMultiDialogue4EngSubtitle 的实现
@@ -783,8 +769,8 @@ func TestGetOffsetTimeV2_BaseAudio(t *testing.T) {
 				return
 			}
 
-			debug_view.SaveDebugChartBase(audioVADInfos, "audioVADInfos", "audioVADInfos")
-			debug_view.SaveDebugChart(*srcUnitNew, "srcUnitNew", "srcUnitNew")
+			debug_view.SaveDebugChartBase(audioVADInfos, tt.name+" audioVADInfos", "audioVADInfos")
+			debug_view.SaveDebugChart(*srcUnitNew, tt.name+" srcUnitNew", "srcUnitNew")
 			if got != tt.want {
 				t.Errorf("GetOffsetTimeV2() got = %v, want %v", got, tt.want)
 			}
@@ -815,7 +801,7 @@ var timelineFixer = NewSubTimelineFixer(sub_timeline_fiexer.SubTimelineFixerConf
 	// V2
 	V2_SubOneUnitProcessTimeOut: 5 * 60,
 	V2_FrontAndEndPerBase:       0.15,
-	V2_FrontAndEndPerSrc:        0.2,
+	V2_FrontAndEndPerSrc:        0.0,
 	V2_WindowMatchPer:           0.7,
 	V2_CompareParts:             5,
 	V2_FixThreads:               3,