Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.
TypeScript agent-skillscodex-clideskop-appdubbingimage-generationlocalizationskillsttsvideo-editingvideo-generationvideo-transcriptionvideo-translation
fix: wrong CN subtitles in vertical embed video
沈浩22738a6381ea
diff --git a/internal/service/audio2subtitle.go b/internal/service/audio2subtitle.goindex 7c5ff702..3ee09404 100644--- a/internal/service/audio2subtitle.go+++ b/internal/service/audio2subtitle.go@@ -469,8 +469,8 @@ func getSentenceTimestamps(words []types.Word, sentence string, lastTs float64,return srtSt, sentenceWords, 0, fmt.Errorf("sentence is empty")}- sentenceWords := make([]types.Word, 0)-+ // 这里的sentence words不是字面上连续的,而是可能有重复,可读连续的用下面的readable+ readableSentenceWords := make([]types.Word, 0)thisLastTs := lastTssentenceWordIndex := 0wordNow := words[sentenceWordIndex]@@ -492,9 +492,10 @@ func getSentenceTimestamps(words []types.Word, sentence string, lastTs float64,}// 对于sentence每个词,已经尝试找到了它的[]Word- beginWordIndex, endWordIndex := jumpFindMaxIncreasingSubArray(sentenceWords)+ var beginWordIndex, endWordIndex int+ beginWordIndex, endWordIndex, readableSentenceWords = jumpFindMaxIncreasingSubArray(sentenceWords)if (endWordIndex - beginWordIndex) == 0 {- return srtSt, sentenceWords, 0, fmt.Errorf("no valid sentence")+ return srtSt, readableSentenceWords, 0, fmt.Errorf("no valid sentence")}beginWord := sentenceWords[beginWordIndex]@@ -509,7 +510,7 @@ func getSentenceTimestamps(words []types.Word, sentence string, lastTs float64,thisLastTs = endWord.End}- return srtSt, sentenceWords, thisLastTs, nil+ return srtSt, readableSentenceWords, thisLastTs, nil}}@@ -551,9 +552,9 @@ func findMaxIncreasingSubArray(words []types.Word) (int, int) {}// 跳跃(非连续)找到 Num 值递增的最大子数组-func jumpFindMaxIncreasingSubArray(words []types.Word) (int, int) {+func jumpFindMaxIncreasingSubArray(words []types.Word) (int, int, []types.Word) {if len(words) == 0 {- return -1, -1+ return -1, -1, nil}// dp[i] 表示以 words[i] 结束的递增子数组的长度@@ -561,7 +562,7 @@ func jumpFindMaxIncreasingSubArray(words []types.Word) (int, int) {// prev[i] 用来记录与当前递增子数组相连的前一个元素的索引prev := make([]int, len(words))- // 初始化,所有的 dp[i] 都是1,因为每个元素本身就是一个长度为1的子数组+ // 初始化,所有的 dp[i] 都是 1,因为每个元素本身就是一个长度为 1 的子数组for i := 0; i < len(words); i++ {dp[i] = 1prev[i] = -1@@ -592,7 +593,7 @@ func jumpFindMaxIncreasingSubArray(words []types.Word) (int, int) {// 如果未找到递增子数组,直接返回if endIdx == -1 {- return -1, -1+ return -1, -1, nil}// 回溯找到子数组的起始索引@@ -601,8 +602,18 @@ func jumpFindMaxIncreasingSubArray(words []types.Word) (int, int) {startIdx = prev[startIdx]}- // 返回找到的最长递增子数组的起始和结束索引- return startIdx, endIdx+ // 构造结果子数组+ result := []types.Word{}+ for i := startIdx; i != -1; i = prev[i] {+ result = append(result, words[i])+ }++ // 由于是从后往前构造的子数组,需要反转+ for i, j := 0, len(result)-1; i < j; i, j = i+1, j-1 {+ result[i], result[j] = result[j], result[i]+ }++ return startIdx, endIdx, result}func (s Service) generateTimestamps(taskId, basePath string, originLanguage types.StandardLanguageName,