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
optimize subtitle
wuliendebbf4b358a4
diff --git a/internal/service/subtitle_service.go b/internal/service/subtitle_service.goindex 8ebb1f7b..dfb4cb0e 100644--- a/internal/service/subtitle_service.go+++ b/internal/service/subtitle_service.go@@ -729,20 +729,38 @@ func getSentenceTimestamps(words []types.Word, sentence string, lastTs float64,}if beginWordIndex > 0 {- for i := beginWordIndex - 1; i >= 0; i-- {- if beginWord.Num > 0 && strings.EqualFold(words[beginWord.Num-1].Text, sentenceWords[i].Text) {- beginWord = words[beginWord.Num-1]+ for i, j := beginWordIndex-1, beginWord.Num-1; i >= 0 && j >= 0; {+ if words[j].Text == "" {+ j--+ continue+ }+ if strings.EqualFold(words[j].Text, sentenceWords[i].Text) {+ beginWord = words[j]sentenceWords[i] = beginWord+ } else {+ break}++ i--+ j--}}if endWordIndex < len(sentenceWords) {- for i := endWordIndex; i < len(sentenceWords); i++ {- if endWord.Num+1 < len(words) && strings.EqualFold(words[endWord.Num+1].Text, sentenceWords[i].Text) {- endWord = words[endWord.Num+1]+ for i, j := endWordIndex, endWord.Num+1; i < len(sentenceWords) && j < len(words); {+ if words[j].Text == "" {+ j+++ continue+ }+ if strings.EqualFold(words[j].Text, sentenceWords[i].Text) {+ endWord = words[j]sentenceWords[i] = endWord+ } else {+ break}++ i+++ j++}}@@ -755,6 +773,9 @@ func getSentenceTimestamps(words []types.Word, sentence string, lastTs float64,}srtSt.Start = beginWord.Start+ if srtSt.Start < thisLastTs {+ srtSt.Start = thisLastTs+ }srtSt.End = endWord.Endif beginWord.Num != endWord.Num && endWord.End > thisLastTs {thisLastTs = endWord.End@@ -799,6 +820,9 @@ func getSentenceTimestamps(words []types.Word, sentence string, lastTs float64,endWord := sentenceWords[endWordIndex]srtSt.Start = beginWord.Start+ if srtSt.Start < thisLastTs {+ srtSt.Start = thisLastTs+ }srtSt.End = endWord.Endif beginWord.Num != endWord.Num && endWord.End > thisLastTs {thisLastTs = endWord.End@@ -928,7 +952,7 @@ func (s Service) generateTimestamps(taskId, basePath string, originLanguage typeoriginSentence stringstartWord types.WordendWord types.Word- shortSentenceWordNum int = 8 //控制单行英文的字数+ shortSentenceWordNum int = 12 //控制单行英文的字数)if len(sentenceWords) <= shortSentenceWordNum {@@ -940,13 +964,13 @@ func (s Service) generateTimestamps(taskId, basePath string, originLanguage typecontinue}- if len(sentenceWords) > 8 && len(sentenceWords) <= 16 {+ if len(sentenceWords) > 8 && len(sentenceWords) <= 2*shortSentenceWordNum {shortSentenceWordNum = len(sentenceWords)/2 + 1- } else if len(sentenceWords) > 16 && len(sentenceWords) <= 24 {+ } else if len(sentenceWords) > 2*shortSentenceWordNum && len(sentenceWords) <= 3*shortSentenceWordNum {shortSentenceWordNum = len(sentenceWords)/3 + 1- } else if len(sentenceWords) > 24 && len(sentenceWords) <= 32 {+ } else if len(sentenceWords) > 3*shortSentenceWordNum && len(sentenceWords) <= 4*shortSentenceWordNum {shortSentenceWordNum = len(sentenceWords)/4 + 1- } else if len(sentenceWords) > 32 && len(sentenceWords) <= 40 {+ } else if len(sentenceWords) > 4*shortSentenceWordNum && len(sentenceWords) <= 5*shortSentenceWordNum {shortSentenceWordNum = len(sentenceWords)/5 + 1}@@ -954,7 +978,7 @@ func (s Service) generateTimestamps(taskId, basePath string, originLanguage typefor _, word := range sentenceWords {if i == 1 || i%(shortSentenceWordNum+1) == 0 {startWord = word- if startWord.Start > endWord.End {+ if startWord.Start < endWord.End {startWord.Start = endWord.End}diff --git a/internal/types/subtitle_task.go b/internal/types/subtitle_task.goindex d29f5c4d..241d0de7 100644--- a/internal/types/subtitle_task.go+++ b/internal/types/subtitle_task.go@@ -26,8 +26,8 @@ var SplitTextPromptWithModalFilter = `你是一个语言处理专家,擅长翻- 将原句子翻译成 %s- 不要漏掉和修改原文的任何一个字,要做的仅是拆分和给出对应的翻译,然后用[]将句子包裹-- 优先根据标点符号进行拆分,尤其是逗号、句号、问号等终止符号,一定要拆分,确保每个句子完整的同时,尽量把句子拆短些。-- 拆分后的句子尽量不要超过15个单词。+- 根据标点符号进行拆分,逗号、句号、问号等终止符号,一定要拆分,确保每个句子完整的同时,把句子拆短些。+- 拆分后的句子不要超过15个单词。- 翻译的时候一定要将对应的原句子翻译完整,不要遗漏原句中的任何信息。- 忽略文本中的语气词,比如"Oh" "Ah" "Wow"等等。- 上方翻译的句子和下方原句一一对应,不要错乱。