Skip to content

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.

Improve translation quality

wulien69819f8174f1
diff --git a/internal/service/youtube_subtitle.go b/internal/service/youtube_subtitle.go
index c2bcf3cd..83c77d8e 100644
--- a/internal/service/youtube_subtitle.go
+++ b/internal/service/youtube_subtitle.go
@@ -432,9 +432,17 @@ func (s *YouTubeSubtitleService) cleanVttText(text string) string {
musicSymbolRegex := regexp.MustCompile(`[♪♫♬♩🎵🎶🎤🎧🎼🎹🎸🎺🎻🥁]`)
cleanedText = musicSymbolRegex.ReplaceAllString(cleanedText, "")
+ // 过滤 >> 符号(YouTube自动字幕的提示符号)
+ cleanedText = strings.ReplaceAll(cleanedText, ">>", "")
+
+ // 过滤常见的语气词(位于句首或独立出现时)
+ // 匹配 Um, Uh, Er, Ah, Oh, Mm, Hmm 等,支持大小写
+ fillerWordsRegex := regexp.MustCompile(`(?i)^\s*(um|uh|er|ah|oh|mm|hmm|hm|eh)\s*[,,]?\s*`)
+ cleanedText = fillerWordsRegex.ReplaceAllString(cleanedText, "")
+
// HTML实体解码映射
htmlEntities := map[string]string{
- ">>": ">>", // 大于号双引号
+ ">>": "", // 大于号双引号 - 直接过滤掉
">": ">", // 大于号
"&lt;&lt;": "<<", // 小于号双引号
"&lt;": "<", // 小于号
@@ -1973,6 +1981,11 @@ func (s *YouTubeSubtitleService) splitBySemanticBreaks(words []VttWord) []Senten
"after": true, "during": true,
}
+ // 关系代词需要更严格的判断(通常不应该分割)
+ relativePronouns := map[string]bool{
+ "who": true, "whom": true, "whose": true, "which": true, "that": true,
+ }
+
var sentences []Sentence
var currentWords []VttWord
minSentenceLength := 5 // 最小句子长度(单词数)
@@ -1992,7 +2005,34 @@ func (s *YouTubeSubtitleService) splitBySemanticBreaks(words []VttWord) []Senten
if !shouldBreak && contextualBreakWords[wordLower] && len(currentWords) >= minSentenceLength {
// 额外条件:确保前面有完整的主谓结构
if s.hasCompletePhrase(currentWords[:len(currentWords)-1]) {
- shouldBreak = true
+ // 检查分割后的长度是否满足要求
+ currentText := s.createSentenceFromWords(currentWords[:len(currentWords)-1]).Text
+ currentChars := util.CountEffectiveChars(currentText)
+
+ // 计算剩余部分的长度
+ remainingWords := words[i:]
+ remainingText := s.createSentenceFromWords(remainingWords).Text
+ remainingChars := util.CountEffectiveChars(remainingText)
+
+ // 只有当前部分和剩余部分都不超过限制时才分割
+ if currentChars <= config.Conf.App.MaxSentenceLength &&
+ remainingChars <= config.Conf.App.MaxSentenceLength {
+ shouldBreak = true
+ }
+ }
+ }
+
+ // 关系代词(who, which等)只在句子过长且有完整从句时才分割
+ if !shouldBreak && relativePronouns[wordLower] && len(currentWords) >= minSentenceLength*2 {
+ // 只有在当前部分已经很长的情况下才考虑在关系代词处分割
+ currentText := s.createSentenceFromWords(currentWords[:len(currentWords)-1]).Text
+ currentChars := util.CountEffectiveChars(currentText)
+
+ if currentChars > config.Conf.App.MaxSentenceLength {
+ // 确保前面有完整的主谓结构
+ if s.hasCompletePhrase(currentWords[:len(currentWords)-1]) {
+ shouldBreak = true
+ }
}
}
diff --git a/internal/types/subtitle_task.go b/internal/types/subtitle_task.go
index 333d0cda..5dd031bf 100644
--- a/internal/types/subtitle_task.go
+++ b/internal/types/subtitle_task.go
@@ -180,17 +180,20 @@ Requirements:
var SplitTextWithContextPrompt = `You are a professional subtitle translation expert.
-[STRICT TRANSLATION TASK]
+[TRANSLATION TASK]
**Objective**:
-Translate ONLY the "Target Sentence" below into %s.
-Use "Previous Sentences" ONLY to understand the context of referents (e.g. pronouns or ellipses), not to infer meaning.
+Translate the "Target Sentence" below into %s with natural, fluent expression.
+Use "Previous Sentences" to understand context and maintain coherence.
**Critical Rules**:
-1. OUTPUT MUST BE A SINGLE LINE: only the translation of the target sentence
-2. Do NOT infer or explain the meaning of the target sentence. Do NOT add any logical connections or causal phrases
-3. If the sentence is fragmentary or dependent (e.g. starts with "that"), KEEP IT THAT WAY in translation
-4. Do NOT complete or rewrite the sentence for fluency
-5. IGNORE the "Next Sentences" completely
+1. OUTPUT MUST BE A SINGLE LINE: only the translated text
+2. Translate naturally and idiomatically - avoid word-for-word literal translation
+3. Remove stuttering/repeated words (e.g., "I I I'm" → translate as "I'm")
+4. Filter out filler words (um, uh, er, ah, oh, mm, hmm, etc.) - do NOT translate them
+5. Use proper punctuation marks in the target language (for Chinese: use ,。!? not spaces)
+6. Keep the original meaning but express it smoothly and naturally in the target language
+7. If sentence is incomplete/fragmentary, keep it that way but translate fluently
+8. IGNORE the "Next Sentences" - they are for reference only
**Context**:
[Previous Sentences]
@@ -202,7 +205,7 @@ Use "Previous Sentences" ONLY to understand the context of referents (e.g. prono
[Next Sentences]
%s
-**Your output must be literal, minimal, and on a single line. Provide only the translation result:**`
+**Provide only the natural, fluent translation on a single line:**`
type SmallAudio struct {
AudioFile string