fix_result.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package sub_timeline_fixer
  2. import (
  3. "github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
  4. "github.com/emirpasic/gods/maps/treemap"
  5. "github.com/grd/stat"
  6. "sync"
  7. )
  8. type FixResult struct {
  9. StartVADIndex int
  10. EndVADIndex int
  11. OldMean float64
  12. OldSD float64
  13. NewMean float64
  14. NewSD float64
  15. Per float64 // 占比
  16. OP OverParts // 越接处信息
  17. }
  18. func (f FixResult) InRange(baseTimeDouble, timeStartDouble float64) (bool, float64) {
  19. if baseTimeDouble+float64(f.StartVADIndex) <= timeStartDouble &&
  20. baseTimeDouble+float64(f.EndVADIndex) >= timeStartDouble {
  21. // 在当前的范围内
  22. if f.OP.Has == true {
  23. // 这里需要特殊处理,因为这个越接处,还需要二分
  24. if timeStartDouble <= baseTimeDouble+float64(f.StartVADIndex)+f.OP.XLen {
  25. return true, f.OP.XMean
  26. } else {
  27. return true, f.OP.YMean
  28. }
  29. } else {
  30. // 无需特殊处理
  31. return true, f.NewMean
  32. }
  33. } else if baseTimeDouble+float64(f.StartVADIndex) > timeStartDouble {
  34. // 小于当前的范围
  35. return true, f.NewMean
  36. } else if timeStartDouble > baseTimeDouble+float64(f.EndVADIndex) {
  37. // 大于当前的范围
  38. return true, f.NewMean
  39. } else {
  40. return false, 0
  41. }
  42. }
  43. // MatchInfo 匹配的信息
  44. type MatchInfo struct {
  45. StartDiffTimeList []float64
  46. StartDiffTimeMap *treemap.Map
  47. StartDiffTimeListEx stat.Float64Slice
  48. }
  49. // WindowInfo 滑动窗体信息
  50. type WindowInfo struct {
  51. BaseAudioFloatList []float64 // 基准 VAD
  52. BaseUnit *sub_helper.SubUnit // 基准 VAD
  53. SrcUnit *sub_helper.SubUnit // 需要匹配的 VAD
  54. MatchedTimes int // 匹配上的次数
  55. SrcWindowLen int // 滑动窗体长度
  56. SrcSlideStartIndex int // 滑动起始索引
  57. SrcSlideLen int // 滑动距离
  58. OneStep int // 每次滑动的长度
  59. }
  60. // InputData 修复函数传入多线程的数据结构
  61. type InputData struct {
  62. BaseUnit sub_helper.SubUnit // 基准 VAD
  63. BaseAudioVADList []float64 // 基准 VAD
  64. SrcUnit sub_helper.SubUnit // 需要匹配的 VAD
  65. OffsetIndex int // 滑动窗体的移动偏移索引
  66. Wg *sync.WaitGroup // 并发锁
  67. }
  68. // SubVADBlockInfo 字幕分块信息
  69. type SubVADBlockInfo struct {
  70. Index int
  71. StartIndex int
  72. EndIndex int
  73. }
  74. /*
  75. OverParts 总长度 D = XLen + YLen
  76. */
  77. type OverParts struct {
  78. Has bool // 是否有越接处
  79. XLen float64 // 分段处长度
  80. YLen float64 // 分段处长度
  81. XMean float64 // X 段的 Mean 值
  82. YMean float64 // Y 段的 Mean 值
  83. }