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
Add VTT subtitles
wulien3bdbd01e55f1
diff --git a/internal/service/audio2subtitle.go b/internal/service/audio2subtitle.goindex 7cb3d8f7..41e4874a 100644--- a/internal/service/audio2subtitle.go+++ b/internal/service/audio2subtitle.go@@ -126,7 +126,7 @@ func (s Service) transcribeAudio(id int, audioFilePath string, language string,return transcriptionData, nil}-func (s Service) IsSplitUseSpace(language types.StandardLanguageCode) bool {+func IsSplitUseSpace(language types.StandardLanguageCode) bool {if language == types.LanguageNameSimplifiedChinese || language == types.LanguageNameTraditionalChinese ||language == types.LanguageNameJapanese || language == types.LanguageNameKorean || language == types.LanguageNameThai {return true@@ -141,7 +141,7 @@ func (s Service) splitTextAndTranslateV2(basePath, inputText string, originLang,return []*TranslatedItem{}, nil}// 补丁:whisper转录中文的时候很多句子后面不输出符号,导致上面基于符号的切分失效- if s.IsSplitUseSpace(originLang) {+ if IsSplitUseSpace(originLang) {newSentences := make([]string, 0)for _, sentence := range sentences {newSentences = append(newSentences, strings.Split(sentence, " ")...)diff --git a/internal/service/init.go b/internal/service/init.goindex 3ae62f39..1ad9176d 100644--- a/internal/service/init.go+++ b/internal/service/init.go@@ -66,7 +66,7 @@ func NewService() *Service {OssClient: aliyun.NewOssClient(config.Conf.Transcribe.Aliyun.Oss.AccessKeyId, config.Conf.Transcribe.Aliyun.Oss.AccessKeySecret, config.Conf.Transcribe.Aliyun.Oss.Bucket),VoiceCloneClient: aliyun.NewVoiceCloneClient(config.Conf.Tts.Aliyun.Speech.AccessKeyId, config.Conf.Tts.Aliyun.Speech.AccessKeySecret, config.Conf.Tts.Aliyun.Speech.AppKey),}- s.YouTubeSubtitleSrv = NewYouTubeSubtitleService(s)+ // s.YouTubeSubtitleSrv = NewYouTubeSubtitleService(s)return s}diff --git a/internal/service/test.vtt b/internal/service/test.vttnew file mode 100644index 00000000..f7790f34--- /dev/null+++ b/internal/service/test.vtt@@ -0,0 +1,904 @@+WEBVTT+Kind: captions+Language: en++00:00:00.080 --> 00:00:02.070 align:start position:0%++What<00:00:00.320><c> if</c><00:00:00.480><c> experts</c><00:00:00.960><c> use</c><00:00:01.120><c> a</c><00:00:01.360><c> specific</c><00:00:01.680><c> technique</c>++00:00:02.070 --> 00:00:02.080 align:start position:0%+What if experts use a specific technique+++00:00:02.080 --> 00:00:03.990 align:start position:0%+What if experts use a specific technique+to<00:00:02.240><c> master</c><00:00:02.639><c> skills</c><00:00:03.120><c> faster</c><00:00:03.520><c> than</c><00:00:03.679><c> everyone</c>++00:00:03.990 --> 00:00:04.000 align:start position:0%+to master skills faster than everyone+++00:00:04.000 --> 00:00:06.470 align:start position:0%+to master skills faster than everyone+else?<00:00:04.640><c> What</c><00:00:04.799><c> if</c><00:00:04.960><c> that</c><00:00:05.359><c> same</c><00:00:05.680><c> method</c><00:00:06.240><c> could</c>++00:00:06.470 --> 00:00:06.480 align:start position:0%+else? What if that same method could+++00:00:06.480 --> 00:00:08.310 align:start position:0%+else? What if that same method could+help<00:00:06.640><c> you</c><00:00:06.799><c> get</c><00:00:07.040><c> conversationally</c><00:00:07.839><c> confident</c>++00:00:08.310 --> 00:00:08.320 align:start position:0%+help you get conversationally confident+++00:00:08.320 --> 00:00:10.790 align:start position:0%+help you get conversationally confident+in<00:00:08.559><c> a</c><00:00:08.720><c> any</c><00:00:09.040><c> subject</c><00:00:09.440><c> in</c><00:00:09.679><c> just</c><00:00:09.840><c> a</c><00:00:10.000><c> few</c><00:00:10.160><c> months?</c>++00:00:10.790 --> 00:00:10.800 align:start position:0%+in a any subject in just a few months?+++00:00:10.800 --> 00:00:12.629 align:start position:0%+in a any subject in just a few months?+By<00:00:11.040><c> the</c><00:00:11.120><c> end</c><00:00:11.280><c> of</c><00:00:11.360><c> this</c><00:00:11.599><c> video,</c><00:00:12.160><c> you'll</c><00:00:12.400><c> have</c><00:00:12.480><c> a</c>++00:00:12.629 --> 00:00:12.639 align:start position:0%+By the end of this video, you'll have a+++00:00:12.639 --> 00:00:14.629 align:start position:0%+By the end of this video, you'll have a+four-step<00:00:13.120><c> system</c><00:00:13.440><c> for</c><00:00:13.679><c> learning</c><00:00:14.000><c> that</c><00:00:14.240><c> feels</c>++00:00:14.629 --> 00:00:14.639 align:start position:0%+four-step system for learning that feels+++00:00:14.639 --> 00:00:16.870 align:start position:0%+four-step system for learning that feels+almost<00:00:15.040><c> effortless.</c><00:00:15.759><c> But</c><00:00:16.000><c> first,</c><00:00:16.400><c> let's</c><00:00:16.720><c> talk</c>++00:00:16.870 --> 00:00:16.880 align:start position:0%+almost effortless. But first, let's talk+++00:00:16.880 --> 00:00:18.790 align:start position:0%+almost effortless. But first, let's talk+about<00:00:17.039><c> why</c><00:00:17.359><c> most</c><00:00:17.600><c> people</c><00:00:18.000><c> are</c><00:00:18.240><c> learning</c>++00:00:18.790 --> 00:00:18.800 align:start position:0%+about why most people are learning+++00:00:18.800 --> 00:00:20.550 align:start position:0%+about why most people are learning+completely<00:00:19.279><c> wrong.</c><00:00:19.920><c> Stop</c><00:00:20.240><c> what</c><00:00:20.400><c> you're</c>++00:00:20.550 --> 00:00:20.560 align:start position:0%+completely wrong. Stop what you're+++00:00:20.560 --> 00:00:21.910 align:start position:0%+completely wrong. Stop what you're+doing.<00:00:20.960><c> If</c><00:00:21.119><c> you're</c><00:00:21.279><c> highlighting</c><00:00:21.680><c> a</c>++00:00:21.910 --> 00:00:21.920 align:start position:0%+doing. If you're highlighting a+++00:00:21.920 --> 00:00:23.910 align:start position:0%+doing. If you're highlighting a+textbook,<00:00:22.560><c> close</c><00:00:22.800><c> it.</c><00:00:23.199><c> Most</c><00:00:23.359><c> of</c><00:00:23.519><c> us</c><00:00:23.680><c> try</c><00:00:23.840><c> to</c>++00:00:23.910 --> 00:00:23.920 align:start position:0%+textbook, close it. Most of us try to+++00:00:23.920 --> 00:00:25.750 align:start position:0%+textbook, close it. Most of us try to+learn<00:00:24.160><c> by</c><00:00:24.320><c> reading</c><00:00:24.560><c> and</c><00:00:24.800><c> rereading.</c><00:00:25.519><c> But</c>++00:00:25.750 --> 00:00:25.760 align:start position:0%+learn by reading and rereading. But+++00:00:25.760 --> 00:00:27.670 align:start position:0%+learn by reading and rereading. But+research<00:00:26.240><c> shows</c><00:00:26.560><c> that</c><00:00:26.880><c> just</c><00:00:27.119><c> rereading</c>++00:00:27.670 --> 00:00:27.680 align:start position:0%+research shows that just rereading+++00:00:27.680 --> 00:00:29.589 align:start position:0%+research shows that just rereading+something<00:00:28.080><c> is</c><00:00:28.320><c> one</c><00:00:28.480><c> of</c><00:00:28.560><c> the</c><00:00:28.800><c> least</c><00:00:29.119><c> effective</c>++00:00:29.589 --> 00:00:29.599 align:start position:0%+something is one of the least effective+++00:00:29.599 --> 00:00:31.750 align:start position:0%+something is one of the least effective+ways<00:00:29.920><c> to</c><00:00:30.240><c> remember</c><00:00:30.560><c> it.</c><00:00:30.960><c> The</c><00:00:31.119><c> returns</c><00:00:31.519><c> drop</c>++00:00:31.750 --> 00:00:31.760 align:start position:0%+ways to remember it. The returns drop+++00:00:31.760 --> 00:00:34.229 align:start position:0%+ways to remember it. The returns drop+off<00:00:32.079><c> dramatically</c><00:00:32.880><c> after</c><00:00:33.200><c> the</c><00:00:33.440><c> first</c><00:00:33.600><c> pass.</c>++00:00:34.229 --> 00:00:34.239 align:start position:0%+off dramatically after the first pass.+++00:00:34.239 --> 00:00:36.389 align:start position:0%+off dramatically after the first pass.+I've<00:00:34.480><c> coached</c><00:00:34.880><c> thousands</c><00:00:35.360><c> of</c><00:00:35.520><c> students</c><00:00:36.079><c> from</c>++00:00:36.389 --> 00:00:36.399 align:start position:0%+I've coached thousands of students from+++00:00:36.399 --> 00:00:38.389 align:start position:0%+I've coached thousands of students from+people<00:00:36.640><c> failing</c><00:00:37.040><c> their</c><00:00:37.280><c> classes</c><00:00:37.680><c> to</c><00:00:37.920><c> coders</c>++00:00:38.389 --> 00:00:38.399 align:start position:0%+people failing their classes to coders+++00:00:38.399 --> 00:00:40.389 align:start position:0%+people failing their classes to coders+trying<00:00:38.559><c> to</c><00:00:38.719><c> land</c><00:00:39.040><c> jobs</c><00:00:39.520><c> at</c><00:00:39.760><c> top</c><00:00:40.079><c> tech</c>++00:00:40.389 --> 00:00:40.399 align:start position:0%+trying to land jobs at top tech+++00:00:40.399 --> 00:00:42.150 align:start position:0%+trying to land jobs at top tech+companies.<00:00:41.120><c> But</c><00:00:41.280><c> before</c><00:00:41.520><c> I</c><00:00:41.760><c> found</c><00:00:41.920><c> this</c>++00:00:42.150 --> 00:00:42.160 align:start position:0%+companies. But before I found this+++00:00:42.160 --> 00:00:44.069 align:start position:0%+companies. But before I found this+system,<00:00:42.559><c> I</c><00:00:42.800><c> was</c><00:00:42.879><c> a</c><00:00:43.120><c> terrible</c><00:00:43.440><c> student.</c><00:00:43.840><c> I</c>++00:00:44.069 --> 00:00:44.079 align:start position:0%+system, I was a terrible student. I+++00:00:44.079 --> 00:00:46.630 align:start position:0%+system, I was a terrible student. I+failed<00:00:44.480><c> calculus</c><00:00:45.040><c> twice.</c><00:00:45.760><c> I'd</c><00:00:46.000><c> forget</c><00:00:46.320><c> what</c><00:00:46.480><c> I</c>++00:00:46.630 --> 00:00:46.640 align:start position:0%+failed calculus twice. I'd forget what I+++00:00:46.640 --> 00:00:48.709 align:start position:0%+failed calculus twice. I'd forget what I+read<00:00:47.039><c> just</c><00:00:47.360><c> 5</c><00:00:47.600><c> minutes</c><00:00:47.840><c> later.</c><00:00:48.399><c> Then</c><00:00:48.559><c> I</c>++00:00:48.709 --> 00:00:48.719 align:start position:0%+read just 5 minutes later. Then I+++00:00:48.719 --> 00:00:50.630 align:start position:0%+read just 5 minutes later. Then I+stumbled<00:00:49.120><c> on</c><00:00:49.280><c> a</c><00:00:49.520><c> method</c><00:00:49.760><c> that</c><00:00:50.079><c> goes</c><00:00:50.320><c> against</c>++00:00:50.630 --> 00:00:50.640 align:start position:0%+stumbled on a method that goes against+++00:00:50.640 --> 00:00:52.470 align:start position:0%+stumbled on a method that goes against+everything<00:00:51.120><c> schools</c><00:00:51.520><c> teach</c><00:00:51.680><c> us</c><00:00:52.079><c> and</c><00:00:52.320><c> it</c>++00:00:52.470 --> 00:00:52.480 align:start position:0%+everything schools teach us and it+++00:00:52.480 --> 00:00:54.549 align:start position:0%+everything schools teach us and it+changed<00:00:52.879><c> everything.</c><00:00:53.520><c> Here's</c><00:00:53.840><c> the</c><00:00:54.079><c> problem.</c>++00:00:54.549 --> 00:00:54.559 align:start position:0%+changed everything. Here's the problem.+++00:00:54.559 --> 00:00:55.830 align:start position:0%+changed everything. Here's the problem.+When<00:00:54.800><c> most</c><00:00:55.039><c> people</c><00:00:55.280><c> want</c><00:00:55.440><c> to</c><00:00:55.600><c> learn</c>++00:00:55.830 --> 00:00:55.840 align:start position:0%+When most people want to learn+++00:00:55.840 --> 00:00:57.350 align:start position:0%+When most people want to learn+something,<00:00:56.239><c> they</c><00:00:56.480><c> start</c><00:00:56.719><c> with</c><00:00:56.879><c> passive</c>++00:00:57.350 --> 00:00:57.360 align:start position:0%+something, they start with passive+++00:00:57.360 --> 00:00:59.270 align:start position:0%+something, they start with passive+consumption.<00:00:58.079><c> They</c><00:00:58.239><c> read</c><00:00:58.399><c> a</c><00:00:58.559><c> book</c><00:00:58.800><c> cover</c><00:00:59.039><c> to</c>++00:00:59.270 --> 00:00:59.280 align:start position:0%+consumption. They read a book cover to+++00:00:59.280 --> 00:01:01.349 align:start position:0%+consumption. They read a book cover to+cover.<00:00:59.760><c> They</c><00:01:00.000><c> watch</c><00:01:00.239><c> tutorials.</c><00:01:01.120><c> They</c>++00:01:01.349 --> 00:01:01.359 align:start position:0%+cover. They watch tutorials. They+++00:01:01.359 --> 00:01:02.790 align:start position:0%+cover. They watch tutorials. They+highlight<00:01:01.760><c> everything.</c><00:01:02.320><c> But</c><00:01:02.480><c> your</c><00:01:02.640><c> brain</c>++00:01:02.790 --> 00:01:02.800 align:start position:0%+highlight everything. But your brain+++00:01:02.800 --> 00:01:04.630 align:start position:0%+highlight everything. But your brain+isn't<00:01:03.120><c> a</c><00:01:03.280><c> hard</c><00:01:03.440><c> drive.</c><00:01:03.840><c> It</c><00:01:04.000><c> has</c><00:01:04.080><c> a</c><00:01:04.239><c> built-in</c>++00:01:04.630 --> 00:01:04.640 align:start position:0%+isn't a hard drive. It has a built-in+++00:01:04.640 --> 00:01:06.149 align:start position:0%+isn't a hard drive. It has a built-in+filter<00:01:04.960><c> for</c><00:01:05.119><c> what's</c><00:01:05.439><c> important.</c><00:01:05.920><c> And</c>++00:01:06.149 --> 00:01:06.159 align:start position:0%+filter for what's important. And+++00:01:06.159 --> 00:01:08.230 align:start position:0%+filter for what's important. And+passively<00:01:06.640><c> consuming</c><00:01:07.119><c> information</c><00:01:07.920><c> tells</c>++00:01:08.230 --> 00:01:08.240 align:start position:0%+passively consuming information tells+++00:01:08.240 --> 00:01:10.230 align:start position:0%+passively consuming information tells+that<00:01:08.560><c> filter,</c><00:01:08.960><c> "This</c><00:01:09.280><c> is</c><00:01:09.439><c> disposable."</c>++00:01:10.230 --> 00:01:10.240 align:start position:0%+that filter, "This is disposable."+++00:01:10.240 --> 00:01:12.149 align:start position:0%+that filter, "This is disposable."+Luckily,<00:01:10.640><c> you</c><00:01:10.799><c> can</c><00:01:10.880><c> hijack</c><00:01:11.360><c> that</c><00:01:11.520><c> filter.</c>++00:01:12.149 --> 00:01:12.159 align:start position:0%+Luckily, you can hijack that filter.+++00:01:12.159 --> 00:01:14.149 align:start position:0%+Luckily, you can hijack that filter.+Step<00:01:12.479><c> one,</c><00:01:12.799><c> the</c><00:01:13.040><c> prime</c><00:01:13.280><c> and</c><00:01:13.439><c> probe</c><00:01:13.760><c> method.</c>++00:01:14.149 --> 00:01:14.159 align:start position:0%+Step one, the prime and probe method.+++00:01:14.159 --> 00:01:16.070 align:start position:0%+Step one, the prime and probe method.+This<00:01:14.320><c> sounds</c><00:01:14.560><c> backwards.</c><00:01:15.200><c> Start</c><00:01:15.439><c> by</c><00:01:15.680><c> teaching</c>++00:01:16.070 --> 00:01:16.080 align:start position:0%+This sounds backwards. Start by teaching+++00:01:16.080 --> 00:01:17.830 align:start position:0%+This sounds backwards. Start by teaching+something<00:01:16.320><c> you</c><00:01:16.640><c> don't</c><00:01:16.799><c> know</c><00:01:16.960><c> yet.</c><00:01:17.520><c> Here's</c>++00:01:17.830 --> 00:01:17.840 align:start position:0%+something you don't know yet. Here's+++00:01:17.840 --> 00:01:20.230 align:start position:0%+something you don't know yet. Here's+how.<00:01:18.400><c> Before</c><00:01:18.640><c> you</c><00:01:18.880><c> read</c><00:01:19.040><c> a</c><00:01:19.200><c> single</c><00:01:19.439><c> page,</c><00:01:20.000><c> grab</c>++00:01:20.230 --> 00:01:20.240 align:start position:0%+how. Before you read a single page, grab+++00:01:20.240 --> 00:01:22.070 align:start position:0%+how. Before you read a single page, grab+a<00:01:20.400><c> piece</c><00:01:20.560><c> of</c><00:01:20.799><c> paper.</c><00:01:21.360><c> Write</c><00:01:21.600><c> down</c><00:01:21.759><c> everything</c>++00:01:22.070 --> 00:01:22.080 align:start position:0%+a piece of paper. Write down everything+++00:01:22.080 --> 00:01:24.070 align:start position:0%+a piece of paper. Write down everything+you<00:01:22.320><c> think</c><00:01:22.479><c> you</c><00:01:22.640><c> know</c><00:01:22.799><c> about</c><00:01:23.040><c> the</c><00:01:23.200><c> topic.</c><00:01:23.759><c> It</c>++00:01:24.070 --> 00:01:24.080 align:start position:0%+you think you know about the topic. It+++00:01:24.080 --> 00:01:25.429 align:start position:0%+you think you know about the topic. It+doesn't<00:01:24.240><c> matter</c><00:01:24.400><c> if</c><00:01:24.640><c> you're</c><00:01:24.880><c> wrong.</c><00:01:25.200><c> This</c>++00:01:25.429 --> 00:01:25.439 align:start position:0%+doesn't matter if you're wrong. This+++00:01:25.439 --> 00:01:27.590 align:start position:0%+doesn't matter if you're wrong. This+primes<00:01:25.840><c> your</c><00:01:26.000><c> brain,</c><00:01:26.400><c> creating</c><00:01:26.799><c> mental</c><00:01:27.119><c> hooks</c>++00:01:27.590 --> 00:01:27.600 align:start position:0%+primes your brain, creating mental hooks+++00:01:27.600 --> 00:01:29.590 align:start position:0%+primes your brain, creating mental hooks+to<00:01:27.840><c> hang</c><00:01:28.080><c> new</c><00:01:28.320><c> information</c><00:01:28.640><c> on.</c><00:01:29.040><c> It</c><00:01:29.280><c> forces</c>++00:01:29.590 --> 00:01:29.600 align:start position:0%+to hang new information on. It forces+++00:01:29.600 --> 00:01:31.830 align:start position:0%+to hang new information on. It forces+your<00:01:29.759><c> brain</c><00:01:30.000><c> to</c><00:01:30.159><c> ask,</c><00:01:30.640><c> "Is</c><00:01:30.960><c> this</c><00:01:31.200><c> right?"</c>++00:01:31.830 --> 00:01:31.840 align:start position:0%+your brain to ask, "Is this right?"+++00:01:31.840 --> 00:01:33.429 align:start position:0%+your brain to ask, "Is this right?"+Which<00:01:32.000><c> kickstarts</c><00:01:32.560><c> the</c><00:01:32.720><c> entire</c><00:01:33.119><c> learning</c>++00:01:33.429 --> 00:01:33.439 align:start position:0%+Which kickstarts the entire learning+++00:01:33.439 --> 00:01:36.069 align:start position:0%+Which kickstarts the entire learning+process.<00:01:34.159><c> Step</c><00:01:34.479><c> two,</c><00:01:34.960><c> turn</c><00:01:35.280><c> statements</c><00:01:35.680><c> into</c>++00:01:36.069 --> 00:01:36.079 align:start position:0%+process. Step two, turn statements into+++00:01:36.079 --> 00:01:37.749 align:start position:0%+process. Step two, turn statements into+questions.<00:01:36.720><c> Don't</c><00:01:36.880><c> just</c><00:01:37.040><c> read,</c><00:01:37.200><c> "Napoleon</c>++00:01:37.749 --> 00:01:37.759 align:start position:0%+questions. Don't just read, "Napoleon+++00:01:37.759 --> 00:01:40.230 align:start position:0%+questions. Don't just read, "Napoleon+invaded<00:01:38.240><c> Russia</c><00:01:38.479><c> in</c><00:01:38.720><c> 1812."</c><00:01:39.439><c> Ask,</c><00:01:39.759><c> "Why</c><00:01:40.079><c> did</c>++00:01:40.230 --> 00:01:40.240 align:start position:0%+invaded Russia in 1812." Ask, "Why did+++00:01:40.240 --> 00:01:42.230 align:start position:0%+invaded Russia in 1812." Ask, "Why did+he<00:01:40.400><c> invade?</c><00:01:40.880><c> What</c><00:01:41.040><c> was</c><00:01:41.119><c> his</c><00:01:41.360><c> plan?</c><00:01:41.759><c> What</c><00:01:42.000><c> went</c>++00:01:42.230 --> 00:01:42.240 align:start position:0%+he invade? What was his plan? What went+++00:01:42.240 --> 00:01:43.990 align:start position:0%+he invade? What was his plan? What went+wrong?"<00:01:42.640><c> Your</c><00:01:42.880><c> brain</c><00:01:43.119><c> is</c><00:01:43.280><c> wired</c><00:01:43.600><c> to</c><00:01:43.759><c> solve</c>++00:01:43.990 --> 00:01:44.000 align:start position:0%+wrong?" Your brain is wired to solve+++00:01:44.000 --> 00:01:46.310 align:start position:0%+wrong?" Your brain is wired to solve+puzzles,<00:01:44.640><c> not</c><00:01:44.799><c> just</c><00:01:45.040><c> store</c><00:01:45.360><c> facts.</c><00:01:45.840><c> Questions</c>++00:01:46.310 --> 00:01:46.320 align:start position:0%+puzzles, not just store facts. Questions+++00:01:46.320 --> 00:01:48.149 align:start position:0%+puzzles, not just store facts. Questions+turn<00:01:46.560><c> passive</c><00:01:47.040><c> learning</c><00:01:47.360><c> into</c><00:01:47.600><c> an</c><00:01:47.840><c> active</c>++00:01:48.149 --> 00:01:48.159 align:start position:0%+turn passive learning into an active+++00:01:48.159 --> 00:01:50.230 align:start position:0%+turn passive learning into an active+hunt<00:01:48.399><c> for</c><00:01:48.640><c> answers.</c><00:01:49.280><c> But</c><00:01:49.439><c> the</c><00:01:49.680><c> most</c><00:01:49.840><c> powerful</c>++00:01:50.230 --> 00:01:50.240 align:start position:0%+hunt for answers. But the most powerful+++00:01:50.240 --> 00:01:51.990 align:start position:0%+hunt for answers. But the most powerful+questions<00:01:50.880><c> are</c><00:01:51.040><c> the</c><00:01:51.280><c> ones</c><00:01:51.520><c> that</c><00:01:51.759><c> build</c>++00:01:51.990 --> 00:01:52.000 align:start position:0%+questions are the ones that build+++00:01:52.000 --> 00:01:54.389 align:start position:0%+questions are the ones that build+connections,<00:01:52.720><c> which</c><00:01:52.960><c> brings</c><00:01:53.280><c> the</c><00:01:53.520><c> next</c><00:01:53.680><c> step.</c>++00:01:54.389 --> 00:01:54.399 align:start position:0%+connections, which brings the next step.+++00:01:54.399 --> 00:01:56.630 align:start position:0%+connections, which brings the next step.+Step<00:01:54.720><c> three,</c><00:01:55.280><c> build</c><00:01:55.520><c> a</c><00:01:55.680><c> connection</c><00:01:56.079><c> web.</c><00:01:56.479><c> For</c>++00:01:56.630 --> 00:01:56.640 align:start position:0%+Step three, build a connection web. For+++00:01:56.640 --> 00:01:58.630 align:start position:0%+Step three, build a connection web. For+every<00:01:56.880><c> new</c><00:01:57.040><c> idea</c><00:01:57.280><c> you</c><00:01:57.520><c> learn,</c><00:01:57.920><c> ask,</c><00:01:58.320><c> "What</c>++00:01:58.630 --> 00:01:58.640 align:start position:0%+every new idea you learn, ask, "What+++00:01:58.640 --> 00:02:00.069 align:start position:0%+every new idea you learn, ask, "What+does<00:01:58.799><c> this</c><00:01:58.960><c> remind</c><00:01:59.280><c> me</c><00:01:59.360><c> of?"</c><00:01:59.680><c> Your</c><00:01:59.840><c> brain</c>++00:02:00.069 --> 00:02:00.079 align:start position:0%+does this remind me of?" Your brain+++00:02:00.079 --> 00:02:02.310 align:start position:0%+does this remind me of?" Your brain+learns<00:02:00.399><c> by</c><00:02:00.640><c> linking</c><00:02:00.960><c> new</c><00:02:01.200><c> information</c><00:02:01.680><c> to</c><00:02:01.920><c> old</c>++00:02:02.310 --> 00:02:02.320 align:start position:0%+learns by linking new information to old+++00:02:02.320 --> 00:02:04.230 align:start position:0%+learns by linking new information to old+information.<00:02:02.880><c> The</c><00:02:03.119><c> more</c><00:02:03.360><c> connections,</c><00:02:04.000><c> the</c>++00:02:04.230 --> 00:02:04.240 align:start position:0%+information. The more connections, the+++00:02:04.240 --> 00:02:06.149 align:start position:0%+information. The more connections, the+stronger<00:02:04.560><c> the</c><00:02:04.719><c> memory.</c><00:02:05.280><c> For</c><00:02:05.360><c> example,</c>++00:02:06.149 --> 00:02:06.159 align:start position:0%+stronger the memory. For example,+++00:02:06.159 --> 00:02:08.150 align:start position:0%+stronger the memory. For example,+learning<00:02:06.479><c> about</c><00:02:06.719><c> atoms,</c><00:02:07.360><c> connect</c><00:02:07.680><c> them</c><00:02:07.840><c> to</c><00:02:07.920><c> a</c>++00:02:08.150 --> 00:02:08.160 align:start position:0%+learning about atoms, connect them to a+++00:02:08.160 --> 00:02:09.990 align:start position:0%+learning about atoms, connect them to a+solar<00:02:08.479><c> system.</c><00:02:08.959><c> Learning</c><00:02:09.200><c> the</c><00:02:09.440><c> Spanish</c><00:02:09.759><c> word</c>++00:02:09.990 --> 00:02:10.000 align:start position:0%+solar system. Learning the Spanish word+++00:02:10.000 --> 00:02:12.550 align:start position:0%+solar system. Learning the Spanish word+bibliotecha,<00:02:11.120><c> it</c><00:02:11.360><c> sounds</c><00:02:11.520><c> like</c><00:02:11.840><c> Bible.</c><00:02:12.400><c> And</c>++00:02:12.550 --> 00:02:12.560 align:start position:0%+bibliotecha, it sounds like Bible. And+++00:02:12.560 --> 00:02:14.869 align:start position:0%+bibliotecha, it sounds like Bible. And+both<00:02:12.800><c> come</c><00:02:13.040><c> from</c><00:02:13.200><c> the</c><00:02:13.360><c> Greek</c><00:02:13.599><c> word</c><00:02:14.000><c> for</c><00:02:14.239><c> book.</c>++00:02:14.869 --> 00:02:14.879 align:start position:0%+both come from the Greek word for book.+++00:02:14.879 --> 00:02:16.470 align:start position:0%+both come from the Greek word for book.+Connect<00:02:15.200><c> it.</c><00:02:15.440><c> The</c><00:02:15.680><c> connections</c><00:02:16.160><c> don't</c><00:02:16.400><c> have</c>++00:02:16.470 --> 00:02:16.480 align:start position:0%+Connect it. The connections don't have+++00:02:16.480 --> 00:02:17.990 align:start position:0%+Connect it. The connections don't have+to<00:02:16.640><c> be</c><00:02:16.800><c> perfect.</c><00:02:17.280><c> They</c><00:02:17.440><c> just</c><00:02:17.599><c> have</c><00:02:17.760><c> to</c><00:02:17.920><c> make</c>++00:02:17.990 --> 00:02:18.000 align:start position:0%+to be perfect. They just have to make+++00:02:18.000 --> 00:02:20.390 align:start position:0%+to be perfect. They just have to make+sense<00:02:18.239><c> to</c><00:02:18.400><c> you.</c><00:02:18.720><c> Step</c><00:02:19.040><c> four,</c><00:02:19.680><c> the</c><00:02:19.920><c> reality</c>++00:02:20.390 --> 00:02:20.400 align:start position:0%+sense to you. Step four, the reality+++00:02:20.400 --> 00:02:22.550 align:start position:0%+sense to you. Step four, the reality+test.<00:02:21.120><c> You</c><00:02:21.360><c> have</c><00:02:21.440><c> to</c><00:02:21.599><c> use</c><00:02:21.760><c> your</c><00:02:22.000><c> knowledge,</c>++00:02:22.550 --> 00:02:22.560 align:start position:0%+test. You have to use your knowledge,+++00:02:22.560 --> 00:02:24.309 align:start position:0%+test. You have to use your knowledge,+especially<00:02:22.959><c> when</c><00:02:23.200><c> you</c><00:02:23.440><c> don't</c><00:02:23.599><c> feel</c><00:02:23.840><c> ready.</c>++00:02:24.309 --> 00:02:24.319 align:start position:0%+especially when you don't feel ready.+++00:02:24.319 --> 00:02:26.150 align:start position:0%+especially when you don't feel ready.+Learning<00:02:24.720><c> Spanish?</c><00:02:25.200><c> Try</c><00:02:25.360><c> to</c><00:02:25.520><c> order</c><00:02:25.760><c> a</c><00:02:25.920><c> coffee</c>++00:02:26.150 --> 00:02:26.160 align:start position:0%+Learning Spanish? Try to order a coffee+++00:02:26.160 --> 00:02:28.309 align:start position:0%+Learning Spanish? Try to order a coffee+on<00:02:26.400><c> day</c><00:02:26.560><c> one.</c><00:02:27.120><c> Learning</c><00:02:27.360><c> to</c><00:02:27.599><c> code?</c><00:02:28.080><c> Start</c>++00:02:28.309 --> 00:02:28.319 align:start position:0%+on day one. Learning to code? Start+++00:02:28.319 --> 00:02:30.150 align:start position:0%+on day one. Learning to code? Start+building<00:02:28.560><c> a</c><00:02:28.800><c> tiny</c><00:02:29.200><c> broken</c><00:02:29.680><c> project</c>++00:02:30.150 --> 00:02:30.160 align:start position:0%+building a tiny broken project+++00:02:30.160 --> 00:02:32.470 align:start position:0%+building a tiny broken project+immediately.<00:02:31.040><c> Studying</c><00:02:31.520><c> history?</c><00:02:32.160><c> Explain</c>++00:02:32.470 --> 00:02:32.480 align:start position:0%+immediately. Studying history? Explain+++00:02:32.480 --> 00:02:34.949 align:start position:0%+immediately. Studying history? Explain+it<00:02:32.720><c> to</c><00:02:32.800><c> a</c><00:02:33.040><c> friend.</c><00:02:33.519><c> This</c><00:02:33.680><c> is</c><00:02:33.840><c> called</c><00:02:34.239><c> desirable</c>++00:02:34.949 --> 00:02:34.959 align:start position:0%+it to a friend. This is called desirable+++00:02:34.959 --> 00:02:37.270 align:start position:0%+it to a friend. This is called desirable+difficulty.<00:02:35.920><c> Your</c><00:02:36.160><c> brain</c><00:02:36.400><c> learns</c><00:02:36.720><c> best</c><00:02:37.040><c> when</c>++00:02:37.270 --> 00:02:37.280 align:start position:0%+difficulty. Your brain learns best when+++00:02:37.280 --> 00:02:38.949 align:start position:0%+difficulty. Your brain learns best when+it<00:02:37.519><c> has</c><00:02:37.599><c> to</c><00:02:37.840><c> struggle</c><00:02:38.160><c> just</c><00:02:38.319><c> a</c><00:02:38.560><c> little</c><00:02:38.640><c> bit.</c>++00:02:38.949 --> 00:02:38.959 align:start position:0%+it has to struggle just a little bit.+++00:02:38.959 --> 00:02:40.630 align:start position:0%+it has to struggle just a little bit.+And<00:02:39.120><c> here's</c><00:02:39.440><c> one</c><00:02:39.599><c> more</c><00:02:39.840><c> quick</c><00:02:40.080><c> tip</c><00:02:40.319><c> to</c><00:02:40.480><c> make</c>++00:02:40.630 --> 00:02:40.640 align:start position:0%+And here's one more quick tip to make+++00:02:40.640 --> 00:02:42.470 align:start position:0%+And here's one more quick tip to make+all<00:02:40.800><c> of</c><00:02:40.959><c> this</c><00:02:41.200><c> permanent.</c><00:02:41.840><c> The</c><00:02:42.080><c> spacing</c>++00:02:42.470 --> 00:02:42.480 align:start position:0%+all of this permanent. The spacing+++00:02:42.480 --> 00:02:44.869 align:start position:0%+all of this permanent. The spacing+secret.<00:02:43.280><c> Don't</c><00:02:43.519><c> cram.</c><00:02:44.160><c> Space</c><00:02:44.480><c> out</c><00:02:44.640><c> your</c>++00:02:44.869 --> 00:02:44.879 align:start position:0%+secret. Don't cram. Space out your+++00:02:44.879 --> 00:02:46.869 align:start position:0%+secret. Don't cram. Space out your+review.<00:02:45.519><c> A</c><00:02:45.840><c> great</c><00:02:46.000><c> schedule</c><00:02:46.319><c> to</c><00:02:46.560><c> start</c><00:02:46.640><c> with</c>++00:02:46.869 --> 00:02:46.879 align:start position:0%+review. A great schedule to start with+++00:02:46.879 --> 00:02:49.670 align:start position:0%+review. A great schedule to start with+is<00:02:47.120><c> reviewing</c><00:02:47.519><c> after</c><00:02:47.920><c> 1</c><00:02:48.160><c> day,</c><00:02:48.640><c> then</c><00:02:48.959><c> 7</c><00:02:49.200><c> days,</c>++00:02:49.670 --> 00:02:49.680 align:start position:0%+is reviewing after 1 day, then 7 days,+++00:02:49.680 --> 00:02:51.750 align:start position:0%+is reviewing after 1 day, then 7 days,+then<00:02:50.000><c> 30</c><00:02:50.239><c> days.</c><00:02:50.720><c> This</c><00:02:50.959><c> method</c><00:02:51.280><c> works</c><00:02:51.519><c> with</c>++00:02:51.750 --> 00:02:51.760 align:start position:0%+then 30 days. This method works with+++00:02:51.760 --> 00:02:53.910 align:start position:0%+then 30 days. This method works with+your<00:02:51.920><c> brain's</c><00:02:52.400><c> natural</c><00:02:52.800><c> forgetting</c><00:02:53.280><c> curve.</c>++00:02:53.910 --> 00:02:53.920 align:start position:0%+your brain's natural forgetting curve.+++00:02:53.920 --> 00:02:55.270 align:start position:0%+your brain's natural forgetting curve.+Reviewing<00:02:54.400><c> right</c><00:02:54.640><c> as</c><00:02:54.800><c> you're</c><00:02:55.040><c> about</c><00:02:55.200><c> to</c>++00:02:55.270 --> 00:02:55.280 align:start position:0%+Reviewing right as you're about to+++00:02:55.280 --> 00:02:57.270 align:start position:0%+Reviewing right as you're about to+forget<00:02:55.680><c> something</c><00:02:56.000><c> tells</c><00:02:56.319><c> your</c><00:02:56.480><c> brain,</c><00:02:56.879><c> "Hey,</c>++00:02:57.270 --> 00:02:57.280 align:start position:0%+forget something tells your brain, "Hey,+++00:02:57.280 --> 00:02:58.949 align:start position:0%+forget something tells your brain, "Hey,+this<00:02:57.440><c> is</c><00:02:57.599><c> important."</c><00:02:58.080><c> and</c><00:02:58.239><c> locks</c><00:02:58.480><c> it</c><00:02:58.640><c> in</c><00:02:58.800><c> for</c>++00:02:58.949 --> 00:02:58.959 align:start position:0%+this is important." and locks it in for+++00:02:58.959 --> 00:03:00.790 align:start position:0%+this is important." and locks it in for+the<00:02:59.120><c> long</c><00:02:59.280><c> term.</c><00:02:59.680><c> I</c><00:02:59.920><c> get</c><00:03:00.080><c> emails</c><00:03:00.400><c> every</c><00:03:00.640><c> week</c>++00:03:00.790 --> 00:03:00.800 align:start position:0%+the long term. I get emails every week+++00:03:00.800 --> 00:03:02.630 align:start position:0%+the long term. I get emails every week+from<00:03:01.040><c> people</c><00:03:01.280><c> using</c><00:03:01.519><c> this</c><00:03:01.760><c> system,</c><00:03:02.239><c> students</c>++00:03:02.630 --> 00:03:02.640 align:start position:0%+from people using this system, students+++00:03:02.640 --> 00:03:05.030 align:start position:0%+from people using this system, students+finally<00:03:03.040><c> acing</c><00:03:03.440><c> their</c><00:03:03.680><c> exams,</c><00:03:04.400><c> professionals</c>++00:03:05.030 --> 00:03:05.040 align:start position:0%+finally acing their exams, professionals+++00:03:05.040 --> 00:03:07.030 align:start position:0%+finally acing their exams, professionals+learning<00:03:05.360><c> new</c><00:03:05.599><c> skills</c><00:03:05.840><c> to</c><00:03:06.080><c> change</c><00:03:06.319><c> careers.</c>++00:03:07.030 --> 00:03:07.040 align:start position:0%+learning new skills to change careers.+++00:03:07.040 --> 00:03:09.030 align:start position:0%+learning new skills to change careers.+The<00:03:07.280><c> results</c><00:03:07.599><c> are</c><00:03:07.760><c> incredibly</c><00:03:08.400><c> consistent,</c>++00:03:09.030 --> 00:03:09.040 align:start position:0%+The results are incredibly consistent,+++00:03:09.040 --> 00:03:11.190 align:start position:0%+The results are incredibly consistent,+but<00:03:09.200><c> it</c><00:03:09.440><c> all</c><00:03:09.599><c> comes</c><00:03:09.840><c> down</c><00:03:10.000><c> to</c><00:03:10.319><c> one</c><00:03:10.720><c> final</c>++00:03:11.190 --> 00:03:11.200 align:start position:0%+but it all comes down to one final+++00:03:11.200 --> 00:03:12.869 align:start position:0%+but it all comes down to one final+mindset<00:03:11.680><c> shift.</c><00:03:12.159><c> Stop</c><00:03:12.480><c> trying</c><00:03:12.640><c> to</c><00:03:12.800><c> be</c>++00:03:12.869 --> 00:03:12.879 align:start position:0%+mindset shift. Stop trying to be+++00:03:12.879 --> 00:03:14.949 align:start position:0%+mindset shift. Stop trying to be+perfect.<00:03:13.519><c> Start</c><00:03:13.760><c> trying</c><00:03:14.000><c> to</c><00:03:14.159><c> be</c><00:03:14.319><c> wrong.</c><00:03:14.720><c> The</c>++00:03:14.949 --> 00:03:14.959 align:start position:0%+perfect. Start trying to be wrong. The+++00:03:14.959 --> 00:03:17.030 align:start position:0%+perfect. Start trying to be wrong. The+fastest<00:03:15.360><c> learners</c><00:03:15.840><c> don't</c><00:03:16.080><c> avoid</c><00:03:16.480><c> mistakes.</c>++00:03:17.030 --> 00:03:17.040 align:start position:0%+fastest learners don't avoid mistakes.+++00:03:17.040 --> 00:03:18.869 align:start position:0%+fastest learners don't avoid mistakes.+They<00:03:17.200><c> hunt</c><00:03:17.440><c> for</c><00:03:17.599><c> them.</c><00:03:17.920><c> Every</c><00:03:18.159><c> mistake</c><00:03:18.560><c> is</c><00:03:18.720><c> a</c>++00:03:18.869 --> 00:03:18.879 align:start position:0%+They hunt for them. Every mistake is a+++00:03:18.879 --> 00:03:20.869 align:start position:0%+They hunt for them. Every mistake is a+bright<00:03:19.200><c> flashing</c><00:03:19.599><c> sign</c><00:03:20.000><c> showing</c><00:03:20.239><c> you</c><00:03:20.480><c> exactly</c>++00:03:20.869 --> 00:03:20.879 align:start position:0%+bright flashing sign showing you exactly+++00:03:20.879 --> 00:03:22.869 align:start position:0%+bright flashing sign showing you exactly+where<00:03:21.120><c> you</c><00:03:21.280><c> need</c><00:03:21.440><c> to</c><00:03:21.599><c> focus.</c><00:03:22.319><c> So,</c><00:03:22.480><c> here's</c><00:03:22.720><c> what</c>++00:03:22.869 --> 00:03:22.879 align:start position:0%+where you need to focus. So, here's what+++00:03:22.879 --> 00:03:24.949 align:start position:0%+where you need to focus. So, here's what+I<00:03:23.040><c> want</c><00:03:23.120><c> you</c><00:03:23.280><c> to</c><00:03:23.440><c> do.</c><00:03:23.920><c> Pick</c><00:03:24.239><c> one</c><00:03:24.480><c> thing</c><00:03:24.720><c> you</c>++00:03:24.949 --> 00:03:24.959 align:start position:0%+I want you to do. Pick one thing you+++00:03:24.959 --> 00:03:27.030 align:start position:0%+I want you to do. Pick one thing you+want<00:03:25.120><c> to</c><00:03:25.280><c> learn.</c><00:03:25.760><c> One,</c><00:03:26.239><c> write</c><00:03:26.480><c> down</c><00:03:26.720><c> what</c><00:03:26.879><c> you</c>++00:03:27.030 --> 00:03:27.040 align:start position:0%+want to learn. One, write down what you+++00:03:27.040 --> 00:03:29.509 align:start position:0%+want to learn. One, write down what you+think<00:03:27.200><c> you</c><00:03:27.440><c> know</c><00:03:27.599><c> about</c><00:03:27.760><c> it.</c><00:03:28.560><c> Two,</c><00:03:29.120><c> turn</c><00:03:29.360><c> it</c>++00:03:29.509 --> 00:03:29.519 align:start position:0%+think you know about it. Two, turn it+++00:03:29.519 --> 00:03:32.309 align:start position:0%+think you know about it. Two, turn it+into<00:03:29.760><c> a</c><00:03:30.000><c> few</c><00:03:30.159><c> key</c><00:03:30.400><c> questions.</c><00:03:31.200><c> Three,</c><00:03:31.840><c> go</c><00:03:32.080><c> find</c>++00:03:32.309 --> 00:03:32.319 align:start position:0%+into a few key questions. Three, go find+++00:03:32.319 --> 00:03:33.990 align:start position:0%+into a few key questions. Three, go find+the<00:03:32.560><c> answer</c><00:03:32.799><c> to</c><00:03:33.040><c> just</c><00:03:33.360><c> one</c><00:03:33.599><c> of</c><00:03:33.760><c> those</c>++00:03:33.990 --> 00:03:34.000 align:start position:0%+the answer to just one of those+++00:03:34.000 --> 00:03:36.309 align:start position:0%+the answer to just one of those+questions.<00:03:34.720><c> If</c><00:03:34.879><c> this</c><00:03:35.120><c> helped,</c><00:03:35.680><c> hit</c><00:03:35.920><c> that</c><00:03:36.080><c> like</c>++00:03:36.309 --> 00:03:36.319 align:start position:0%+questions. If this helped, hit that like+++00:03:36.319 --> 00:03:38.390 align:start position:0%+questions. If this helped, hit that like+button<00:03:36.720><c> and</c><00:03:37.040><c> subscribe</c><00:03:37.440><c> for</c><00:03:37.680><c> more</c><00:03:37.920><c> practical</c>++00:03:38.390 --> 00:03:38.400 align:start position:0%+button and subscribe for more practical+++00:03:38.400 --> 00:03:40.390 align:start position:0%+button and subscribe for more practical+learning<00:03:38.720><c> strategies.</c><00:03:39.440><c> In</c><00:03:39.599><c> the</c><00:03:39.760><c> next</c><00:03:40.000><c> video,</c>++00:03:40.390 --> 00:03:40.400 align:start position:0%+learning strategies. In the next video,+++00:03:40.400 --> 00:03:42.309 align:start position:0%+learning strategies. In the next video,+I'll<00:03:40.640><c> show</c><00:03:40.799><c> you</c><00:03:40.959><c> one</c><00:03:41.280><c> study</c><00:03:41.599><c> habit</c><00:03:42.000><c> that's</c>++00:03:42.309 --> 00:03:42.319 align:start position:0%+I'll show you one study habit that's+++00:03:42.319 --> 00:03:44.149 align:start position:0%+I'll show you one study habit that's+even<00:03:42.560><c> more</c><00:03:42.799><c> powerful</c><00:03:43.360><c> than</c><00:03:43.599><c> all</c><00:03:43.760><c> of</c><00:03:43.920><c> these</c>++00:03:44.149 --> 00:03:44.159 align:start position:0%+even more powerful than all of these+++00:03:44.159 --> 00:03:46.959 align:start position:0%+even more powerful than all of these+combined.+diff --git a/internal/service/translate.go b/internal/service/translate.gonew file mode 100644index 00000000..2ddcfd1b--- /dev/null+++ b/internal/service/translate.go@@ -0,0 +1,183 @@+package service++import (+ "encoding/json"+ "fmt"+ "krillin-ai/config"+ "krillin-ai/internal/types"+ "krillin-ai/log"+ "krillin-ai/pkg/openai"+ "krillin-ai/pkg/util"+ "strings"+ "sync"++ "go.uber.org/zap"+)++type Translator struct {+ chatCompleter types.ChatCompleter+}++func NewTranslator() *Translator {+ return &Translator{+ chatCompleter: openai.NewClient(config.Conf.Llm.BaseUrl, config.Conf.Llm.ApiKey, config.Conf.App.Proxy),+ }+}++func (t *Translator) SplitTextAndTranslate(basePath, inputText string, originLang, targetLang types.StandardLanguageCode, enableModalFilter bool, id int) ([]*TranslatedItem, error) {+ sentences := util.SplitTextSentences(inputText, config.Conf.App.MaxSentenceLength)+ if len(sentences) == 0 {+ return []*TranslatedItem{}, nil+ }+ // 补丁:whisper转录中文的时候很多句子后面不输出符号,导致上面基于符号的切分失效+ if IsSplitUseSpace(originLang) {+ newSentences := make([]string, 0)+ for _, sentence := range sentences {+ newSentences = append(newSentences, strings.Split(sentence, " ")...)+ }+ sentences = newSentences+ }++ shortSentences := make([]string, 0)+ //判断句子如果还是过长,就继续用大模型拆句+ for _, sentence := range sentences {+ if sentence == "" {+ continue+ }+ if util.CountEffectiveChars(sentence) <= config.Conf.App.MaxSentenceLength {+ shortSentences = append(shortSentences, sentence)+ continue+ }++ // 调用大模型进行分割+ log.GetLogger().Info("use llm split origin long sentence", zap.Any("sentence", sentence))+ splitItems, err := t.splitOriginLongSentence(sentence)+ if err != nil {+ log.GetLogger().Error("splitTranslateItem splitLongSentence error", zap.Error(err), zap.Any("sentence", sentence))+ }+ //拆完之后还长,就再拆一次+ for _, item := range splitItems {+ if util.CountEffectiveChars(item) <= config.Conf.App.MaxSentenceLength {+ shortSentences = append(shortSentences, item)+ continue+ }++ // 调用大模型进行分割+ log.GetLogger().Info("use llm split origin long sentence", zap.Any("item", item))+ splitItems, err := t.splitOriginLongSentence(item)+ if err != nil {+ log.GetLogger().Error("splitTranslateItem splitLongSentence error", zap.Error(err), zap.Any("item", item))+ }++ shortSentences = append(shortSentences, splitItems...)+ }+ }++ sentences = shortSentences++ var (+ signal = make(chan struct{}, config.Conf.App.TranslateParallelNum) // 控制最大并发数+ wg sync.WaitGroup+ results = make([]*TranslatedItem, len(sentences))+ // errChan = make(chan error, 1)+ // mutex sync.Mutex+ )++ for i, sentence := range sentences {+ wg.Add(1)+ signal <- struct{}{}++ go func(index int, originText string) {+ defer wg.Done()+ defer func() { <-signal }()++ contextSentenceNum := 3++ // 生成前面3个句子的string+ var previousSentences string+ if index > 0 {+ start := 0+ if index-contextSentenceNum > 0 {+ start = index - contextSentenceNum+ }+ for i := start; i < index; i++ {+ previousSentences += sentences[i] + "\n"+ }+ }++ // 生成后面3个句子的string+ var nextSentences string+ if index < len(sentences)-1 {+ end := len(sentences) - 1+ if index+contextSentenceNum < end {+ end = index + contextSentenceNum+ }+ for i := index + 1; i <= end; i++ {+ if i > index+1 {+ nextSentences += "\n"+ }+ nextSentences += sentences[i]+ }+ }++ prompt := fmt.Sprintf(types.SplitTextWithContextPrompt, types.GetStandardLanguageName(targetLang), previousSentences, originText, nextSentences)++ translatedText, err := t.chatCompleter.ChatCompletion(prompt)+ if err != nil {+ log.GetLogger().Error("splitTextAndTranslate llm translate error", zap.Error(err), zap.Any("original text", originText))+ results[index] = &TranslatedItem{+ OriginText: originText,+ TranslatedText: originText,+ }+ } else {+ translatedText = strings.TrimSpace(translatedText)+ results[index] = &TranslatedItem{+ OriginText: originText,+ TranslatedText: translatedText,+ }+ }+ }(i, sentence)+ }++ wg.Wait()++ return results, nil+}++func (t *Translator) splitOriginLongSentence(sentence string) ([]string, error) {+ prompt := fmt.Sprintf(types.SplitOriginLongSentencePrompt, sentence)++ var response string+ var err error+ shortSentences := make([]string, 0)+ // 尝试调用3次+ for i := range 3 {+ response, err = t.chatCompleter.ChatCompletion(prompt)+ if err != nil {+ log.GetLogger().Error("splitOriginLongSentence chat completion error", zap.Error(err), zap.String("sentence", sentence), zap.Any("time", i))+ continue+ }+ var splitResult struct {+ ShortSentences []struct {+ Text string `json:"text"`+ } `json:"short_sentences"`+ }++ cleanResponse := util.CleanMarkdownCodeBlock(response)+ if err = json.Unmarshal([]byte(cleanResponse), &splitResult); err != nil {+ log.GetLogger().Error("splitOriginLongSentence parse split result error", zap.Error(err), zap.Any("response", response))+ continue+ }++ for _, shortSentence := range splitResult.ShortSentences {+ shortSentences = append(shortSentences, shortSentence.Text)+ }+ break+ }++ if err != nil {+ return nil, fmt.Errorf("parse split result error: %w", err)+ }++ return shortSentences, nil+}diff --git a/internal/service/youtube_subtitle.go b/internal/service/youtube_subtitle.goindex f5f97ca6..2c1aa186 100644--- a/internal/service/youtube_subtitle.go+++ b/internal/service/youtube_subtitle.go@@ -40,6 +40,15 @@ type srtSubtitle struct {duration int64}+type YoutubeSubtitleReq struct {+ TaskBasePath string+ TaskId string+ URL string+ OriginLanguage string+ TargetLanguage string+ VttFile string+}+// translator defines the interface for text translation.type translator interface {splitTextAndTranslateV2(basePath, inputText string, originLang, targetLang types.StandardLanguageCode, enableModalFilter bool, id int) ([]*TranslatedItem, error)@@ -47,28 +56,30 @@ type translator interface {// YouTubeSubtitleService handles all operations related to YouTube subtitles.type YouTubeSubtitleService struct {- translator translator+ translator *Translator}// NewYouTubeSubtitleService creates a new YouTubeSubtitleService.-func NewYouTubeSubtitleService(translator translator) *YouTubeSubtitleService {+func NewYouTubeSubtitleService() *YouTubeSubtitleService {return &YouTubeSubtitleService{- translator: translator,+ translator: NewTranslator(),}}// Process handles the entire workflow for YouTube subtitles, from downloading to processing.-func (s *YouTubeSubtitleService) Process(ctx context.Context, stepParam *types.SubtitleTaskStepParam) error {+func (s *YouTubeSubtitleService) Process(ctx context.Context, req *YoutubeSubtitleReq) error {// 1. Download subtitle file- err := s.downloadYouTubeSubtitle(ctx, stepParam)+ vttFile, err := s.downloadYouTubeSubtitle(ctx, req)if err != nil {// Return error to let the caller handle fallback (e.g., audio transcription)return err}+ req.VttFile = vttFile+// 2. Process the downloaded subtitle file- log.GetLogger().Info("Successfully downloaded YouTube subtitles, processing...", zap.String("taskId", stepParam.TaskId))- err = s.processYouTubeSubtitle(ctx, stepParam)+ log.GetLogger().Info("Successfully downloaded YouTube subtitles, processing...", zap.String("taskId", req.TaskId))+ _, err = s.processYouTubeSubtitle(ctx, req)if err != nil {return fmt.Errorf("processYouTubeSubtitle err: %w", err)}@@ -76,142 +87,142 @@ func (s *YouTubeSubtitleService) Process(ctx context.Context, stepParam *types.Sreturn nil}-func (s *YouTubeSubtitleService) convertVttToSrtGo(inputPath, outputPath string) error {- contentBytes, err := os.ReadFile(inputPath)- if err != nil {- return fmt.Errorf("failed to read VTT file: %w", err)- }- content := string(contentBytes)- lines := strings.Split(content, "\n")-- // --- 1. Parse all VTT blocks ---- var vttBlocks []*vttBlock- timestampRegex := regexp.MustCompile(`^(\d{2}:\d{2}:\d{2})\.(\d{3})\s-->\s(\d{2}:\d{2}:\d{2})\.(\d{3})`)- tagRegex := regexp.MustCompile(`<[^>]*>`)- timingTagRegex := regexp.MustCompile(`<\d{2}:\d{2}:\d{2}\.\d{3}>`)-- for i := 0; i < len(lines); {- line := strings.TrimSpace(lines[i])- if line == "" || strings.HasPrefix(line, "WEBVTT") || strings.HasPrefix(line, "Kind:") || strings.HasPrefix(line, "Language:") {- i++- continue- }-- if matches := timestampRegex.FindStringSubmatch(line); len(matches) == 5 {- startTime := fmt.Sprintf("%s,%s", matches[1], matches[2])- endTime := fmt.Sprintf("%s,%s", matches[3], matches[4])-- i++- var subtitleLines []string- for i < len(lines) && strings.TrimSpace(lines[i]) != "" {- subtitleLines = append(subtitleLines, strings.TrimSpace(lines[i]))- i++- }-- if len(subtitleLines) > 0 {- block := &vttBlock{- startTime: startTime,- endTime: endTime,- lines: subtitleLines,- index: len(vttBlocks),- }- var cleanLines []string- for _, l := range block.lines {- cleanLine := strings.TrimSpace(tagRegex.ReplaceAllString(l, ""))- if cleanLine != "" {- cleanLines = append(cleanLines, cleanLine)- }- }- block.cleanLines = cleanLines- block.cleanText = strings.Join(cleanLines, " ")- block.hasTimingTags = timingTagRegex.MatchString(strings.Join(block.lines, " "))- vttBlocks = append(vttBlocks, block)- }- } else {- i++- }- }-- // --- 2. Identify candidate blocks ---- var candidateBlocks []*vttBlock- for _, block := range vttBlocks {- if !block.hasTimingTags && len(block.cleanLines) == 1 {- candidateBlocks = append(candidateBlocks, block)- }- }-- // --- 3. Build precise timeline ---- subtitlesMap := make(map[string]*srtSubtitle)- for _, sBlock := range candidateBlocks {- text := sBlock.cleanText- startTime := sBlock.startTime- endTime := sBlock.endTime-- // Search backwards for start time- for i := sBlock.index - 1; i >= 0; i-- {- pBlock := vttBlocks[i]- if util.IsTextMatch(text, pBlock.cleanText) {- startTime = pBlock.startTime- break- }- }-- // Search forwards for end time- for i := sBlock.index + 1; i < len(vttBlocks); i++ {- tBlock := vttBlocks[i]- if !tBlock.hasTimingTags && len(tBlock.cleanLines) >= 1 {- if tBlock.cleanLines[0] == text {- endTime = tBlock.startTime- break- }- }- }-- duration := util.TimeToMilliseconds(endTime) - util.TimeToMilliseconds(startTime)- if existing, ok := subtitlesMap[text]; !ok || duration > existing.duration {- subtitlesMap[text] = &srtSubtitle{- startTime: startTime,- endTime: endTime,- text: text,- duration: duration,- }- }- }-- // --- 4. Clean and sort ---- var finalSubtitles []*srtSubtitle- for _, sub := range subtitlesMap {- finalSubtitles = append(finalSubtitles, sub)- }- sort.Slice(finalSubtitles, func(i, j int) bool {- return util.TimeToMilliseconds(finalSubtitles[i].startTime) < util.TimeToMilliseconds(finalSubtitles[j].startTime)- })-- // Fix overlaps- if len(finalSubtitles) > 1 {- for i := 0; i < len(finalSubtitles)-1; i++ {- currentEndMs := util.TimeToMilliseconds(finalSubtitles[i].endTime)- nextStartMs := util.TimeToMilliseconds(finalSubtitles[i+1].startTime)-- if currentEndMs > nextStartMs {- adjustedEndMs := nextStartMs - 50- if adjustedEndMs > util.TimeToMilliseconds(finalSubtitles[i].startTime) {- finalSubtitles[i].endTime = util.MillisecondsToTime(adjustedEndMs)- }- }- }- }-- // --- 5. Write SRT file ---- var srtContent strings.Builder- for i, subtitle := range finalSubtitles {- srtContent.WriteString(fmt.Sprintf("%d\n", i+1))- srtContent.WriteString(fmt.Sprintf("%s --> %s\n", subtitle.startTime, subtitle.endTime))- srtContent.WriteString(subtitle.text + "\n\n")- }-- return os.WriteFile(outputPath, []byte(srtContent.String()), 0644)-}+// func (s *YouTubeSubtitleService) convertVttToSrt(inputPath, outputPath string) error {+// contentBytes, err := os.ReadFile(inputPath)+// if err != nil {+// return fmt.Errorf("failed to read VTT file: %w", err)+// }+// content := string(contentBytes)+// lines := strings.Split(content, "\n")++// // --- 1. Parse all VTT blocks ---+// var vttBlocks []*vttBlock+// timestampRegex := regexp.MustCompile(`^(\d{2}:\d{2}:\d{2})\.(\d{3})\s-->\s(\d{2}:\d{2}:\d{2})\.(\d{3})`)+// tagRegex := regexp.MustCompile(`<[^>]*>`)+// timingTagRegex := regexp.MustCompile(`<\d{2}:\d{2}:\d{2}\.\d{3}>`)++// for i := 0; i < len(lines); {+// line := strings.TrimSpace(lines[i])+// if line == "" || strings.HasPrefix(line, "WEBVTT") || strings.HasPrefix(line, "Kind:") || strings.HasPrefix(line, "Language:") {+// i+++// continue+// }++// if matches := timestampRegex.FindStringSubmatch(line); len(matches) == 5 {+// startTime := fmt.Sprintf("%s,%s", matches[1], matches[2])+// endTime := fmt.Sprintf("%s,%s", matches[3], matches[4])++// i+++// var subtitleLines []string+// for i < len(lines) && strings.TrimSpace(lines[i]) != "" {+// subtitleLines = append(subtitleLines, strings.TrimSpace(lines[i]))+// i+++// }++// if len(subtitleLines) > 0 {+// block := &vttBlock{+// startTime: startTime,+// endTime: endTime,+// lines: subtitleLines,+// index: len(vttBlocks),+// }+// var cleanLines []string+// for _, l := range block.lines {+// cleanLine := strings.TrimSpace(tagRegex.ReplaceAllString(l, ""))+// if cleanLine != "" {+// cleanLines = append(cleanLines, cleanLine)+// }+// }+// block.cleanLines = cleanLines+// block.cleanText = strings.Join(cleanLines, " ")+// block.hasTimingTags = timingTagRegex.MatchString(strings.Join(block.lines, " "))+// vttBlocks = append(vttBlocks, block)+// }+// } else {+// i+++// }+// }++// // --- 2. Identify candidate blocks ---+// var candidateBlocks []*vttBlock+// for _, block := range vttBlocks {+// if !block.hasTimingTags && len(block.cleanLines) == 1 {+// candidateBlocks = append(candidateBlocks, block)+// }+// }++// // --- 3. Build precise timeline ---+// subtitlesMap := make(map[string]*srtSubtitle)+// for _, sBlock := range candidateBlocks {+// text := sBlock.cleanText+// startTime := sBlock.startTime+// endTime := sBlock.endTime++// // Search backwards for start time+// for i := sBlock.index - 1; i >= 0; i-- {+// pBlock := vttBlocks[i]+// if util.IsTextMatch(text, pBlock.cleanText) {+// startTime = pBlock.startTime+// break+// }+// }++// // Search forwards for end time+// for i := sBlock.index + 1; i < len(vttBlocks); i++ {+// tBlock := vttBlocks[i]+// if !tBlock.hasTimingTags && len(tBlock.cleanLines) >= 1 {+// if tBlock.cleanLines[0] == text {+// endTime = tBlock.startTime+// break+// }+// }+// }++// duration := util.TimeToMilliseconds(endTime) - util.TimeToMilliseconds(startTime)+// if existing, ok := subtitlesMap[text]; !ok || duration > existing.duration {+// subtitlesMap[text] = &srtSubtitle{+// startTime: startTime,+// endTime: endTime,+// text: text,+// duration: duration,+// }+// }+// }++// // --- 4. Clean and sort ---+// var finalSubtitles []*srtSubtitle+// for _, sub := range subtitlesMap {+// finalSubtitles = append(finalSubtitles, sub)+// }+// sort.Slice(finalSubtitles, func(i, j int) bool {+// return util.TimeToMilliseconds(finalSubtitles[i].startTime) < util.TimeToMilliseconds(finalSubtitles[j].startTime)+// })++// // Fix overlaps+// if len(finalSubtitles) > 1 {+// for i := 0; i < len(finalSubtitles)-1; i++ {+// currentEndMs := util.TimeToMilliseconds(finalSubtitles[i].endTime)+// nextStartMs := util.TimeToMilliseconds(finalSubtitles[i+1].startTime)++// if currentEndMs > nextStartMs {+// adjustedEndMs := nextStartMs - 50+// if adjustedEndMs > util.TimeToMilliseconds(finalSubtitles[i].startTime) {+// finalSubtitles[i].endTime = util.MillisecondsToTime(adjustedEndMs)+// }+// }+// }+// }++// // --- 5. Write SRT file ---+// var srtContent strings.Builder+// for i, subtitle := range finalSubtitles {+// srtContent.WriteString(fmt.Sprintf("%d\n", i+1))+// srtContent.WriteString(fmt.Sprintf("%s --> %s\n", subtitle.startTime, subtitle.endTime))+// srtContent.WriteString(subtitle.text + "\n\n")+// }++// return os.WriteFile(outputPath, []byte(srtContent.String()), 0644)+// }func (s *YouTubeSubtitleService) parseVttTime(timeStr string) (float64, error) {// VTT format: HH:MM:SS.ms or MM:SS.ms@@ -347,13 +358,14 @@ func (s *YouTubeSubtitleService) parseVttToWords(vttPath string) ([]types.Word,endTime = blockEndTime}- words = append(words, types.Word{- Text: cleanedText,- Start: lastTime,- End: endTime,- Num: wordNum,- })- wordNum+++ // 分离标点符号和单词+ wordsFromText := s.extractWordsWithPunctuation(cleanedText, lastTime, endTime)+ for _, word := range wordsFromText {+ word.Num = wordNum+ words = append(words, word)+ wordNum+++ }+lastTime = endTime}}@@ -365,6 +377,88 @@ func (s *YouTubeSubtitleService) parseVttToWords(vttPath string) ([]types.Word,return words, nil}+// extractWordsWithPunctuation 分离文本中的单词和标点符号,保持时间戳信息+func (s *YouTubeSubtitleService) extractWordsWithPunctuation(text string, startTime, endTime float64) []types.Word {+ if text == "" {+ return nil+ }++ var result []types.Word++ // 定义标点符号的正则表达式+ punctRegex := regexp.MustCompile(`^(.*?)([.!?,:;])$`)++ // 检查文本是否以标点符号结尾+ if matches := punctRegex.FindStringSubmatch(text); len(matches) == 3 {+ wordPart := strings.TrimSpace(matches[1])+ punctPart := matches[2]++ // 如果有单词部分,先添加单词+ if wordPart != "" {+ // 计算单词的时间范围(占大部分时间)+ duration := endTime - startTime+ wordDuration := duration * 0.8 // 单词占80%的时间+ wordEndTime := startTime + wordDuration++ result = append(result, types.Word{+ Text: wordPart,+ Start: startTime,+ End: wordEndTime,+ })++ // 标点符号占剩余时间+ result = append(result, types.Word{+ Text: punctPart,+ Start: wordEndTime,+ End: endTime,+ })+ } else {+ // 只有标点符号+ result = append(result, types.Word{+ Text: punctPart,+ Start: startTime,+ End: endTime,+ })+ }+ } else {+ // 检查开头的标点符号+ leadingPunctRegex := regexp.MustCompile(`^([.!?,:;]+)(.*)$`)+ if matches := leadingPunctRegex.FindStringSubmatch(text); len(matches) == 3 {+ punctPart := matches[1]+ wordPart := strings.TrimSpace(matches[2])++ duration := endTime - startTime+ punctDuration := duration * 0.2 // 标点占20%的时间+ punctEndTime := startTime + punctDuration++ // 先添加标点符号+ result = append(result, types.Word{+ Text: punctPart,+ Start: startTime,+ End: punctEndTime,+ })++ // 如果有单词部分,再添加单词+ if wordPart != "" {+ result = append(result, types.Word{+ Text: wordPart,+ Start: punctEndTime,+ End: endTime,+ })+ }+ } else {+ // 没有标点符号,直接添加整个文本+ result = append(result, types.Word{+ Text: text,+ Start: startTime,+ End: endTime,+ })+ }+ }++ return result+}+// 判断文本是否标点稀缺func (s *YouTubeSubtitleService) isPunctuationSparse(text string) bool {trimmed := strings.TrimSpace(text)@@ -473,31 +567,22 @@ func (s *YouTubeSubtitleService) splitByWordPausesAndLimits(words []types.Word,}// 使用yt-dlp下载YouTube视频的字幕文件-func (s *YouTubeSubtitleService) downloadYouTubeSubtitle(ctx context.Context, stepParam *types.SubtitleTaskStepParam) error {- link := stepParam.Link- if !strings.Contains(link, "youtube.com") {- return fmt.Errorf("downloadYouTubeSubtitle: not a YouTube link")- }-- videoId, err := util.GetYouTubeID(link)- if err != nil {- log.GetLogger().Error("downloadYouTubeSubtitle.GetYouTubeID error", zap.Any("stepParam", stepParam), zap.Error(err))- return fmt.Errorf("downloadYouTubeSubtitle.GetYouTubeID error: %w", err)+func (s *YouTubeSubtitleService) downloadYouTubeSubtitle(ctx context.Context, req *YoutubeSubtitleReq) (string, error) {+ if !strings.Contains(req.URL, "youtube.com") {+ return "", fmt.Errorf("downloadYouTubeSubtitle: not a YouTube link")}- stepParam.Link = "https://www.youtube.com/watch?v=" + videoId-// 确定要下载的字幕语言- subtitleLang := util.MapLanguageForYouTube(string(stepParam.OriginLanguage))+ subtitleLang := util.MapLanguageForYouTube(req.OriginLanguage)// 构造yt-dlp命令参数- outputPattern := filepath.Join(stepParam.TaskBasePath, "%(title)s.%(ext)s")+ outputPattern := filepath.Join(req.TaskBasePath, "%(title)s.%(ext)s")cmdArgs := []string{"--write-auto-subs","--sub-langs", subtitleLang,"--skip-download","-o", outputPattern,- stepParam.Link,+ req.URL,}// 添加代理设置@@ -513,7 +598,7 @@ func (s *YouTubeSubtitleService) downloadYouTubeSubtitle(ctx context.Context, stcmdArgs = append(cmdArgs, "--ffmpeg-location", storage.FfmpegPath)}- log.GetLogger().Info("downloadYouTubeSubtitle starting", zap.Any("taskId", stepParam.TaskId), zap.Any("cmdArgs", cmdArgs))+ log.GetLogger().Info("downloadYouTubeSubtitle starting", zap.Any("taskId", req.TaskId), zap.Any("cmdArgs", cmdArgs))// 添加重试机制maxAttempts := 3@@ -521,7 +606,7 @@ func (s *YouTubeSubtitleService) downloadYouTubeSubtitle(ctx context.Context, stfor attempt := 0; attempt < maxAttempts; attempt++ {log.GetLogger().Info("Attempting to download YouTube subtitle",- zap.Any("taskId", stepParam.TaskId),+ zap.Any("taskId", req.TaskId),zap.Int("attempt", attempt+1),zap.Int("maxAttempts", maxAttempts))@@ -529,25 +614,22 @@ func (s *YouTubeSubtitleService) downloadYouTubeSubtitle(ctx context.Context, stoutput, err := cmd.CombinedOutput()if err == nil {- log.GetLogger().Info("downloadYouTubeSubtitle completed", zap.Any("taskId", stepParam.TaskId), zap.String("output", string(output)))+ log.GetLogger().Info("downloadYouTubeSubtitle completed", zap.Any("taskId", req.TaskId), zap.String("output", string(output)))// 查找下载的字幕文件- subtitleFile, err := s.findDownloadedSubtitleFile(stepParam.TaskBasePath, subtitleLang)+ subtitleFile, err := s.findDownloadedSubtitleFile(req.TaskBasePath, subtitleLang)if err != nil {- log.GetLogger().Error("downloadYouTubeSubtitle findDownloadedSubtitleFile error", zap.Any("stepParam", stepParam), zap.Error(err))- return fmt.Errorf("downloadYouTubeSubtitle findDownloadedSubtitleFile error: %w", err)+ log.GetLogger().Error("downloadYouTubeSubtitle findDownloadedSubtitleFile error", zap.Any("stepParam", req), zap.Error(err))+ return "", fmt.Errorf("downloadYouTubeSubtitle findDownloadedSubtitleFile error: %w", err)}- stepParam.OriginalSubtitleFilePath = subtitleFile- stepParam.TaskPtr.ProcessPct = 20-- log.GetLogger().Info("downloadYouTubeSubtitle found subtitle file", zap.Any("taskId", stepParam.TaskId), zap.String("subtitleFile", subtitleFile))- return nil+ log.GetLogger().Info("downloadYouTubeSubtitle found subtitle file", zap.Any("taskId", req.TaskId), zap.String("subtitleFile", subtitleFile))+ return subtitleFile, nil}lastErr = errlog.GetLogger().Warn("downloadYouTubeSubtitle attempt failed",- zap.Any("taskId", stepParam.TaskId),+ zap.Any("taskId", req.TaskId),zap.Int("attempt", attempt+1),zap.String("output", string(output)),zap.Error(err))@@ -558,8 +640,8 @@ func (s *YouTubeSubtitleService) downloadYouTubeSubtitle(ctx context.Context, st}}- log.GetLogger().Error("downloadYouTubeSubtitle failed after all attempts", zap.Any("stepParam", stepParam), zap.Error(lastErr))- return fmt.Errorf("downloadYouTubeSubtitle yt-dlp error after %d attempts: %w", maxAttempts, lastErr)+ log.GetLogger().Error("downloadYouTubeSubtitle failed after all attempts", zap.Any("req", req), zap.Error(lastErr))+ return "", fmt.Errorf("downloadYouTubeSubtitle yt-dlp error after %d attempts: %w", maxAttempts, lastErr)}// 查找下载的字幕文件@@ -594,60 +676,164 @@ func (s *YouTubeSubtitleService) findDownloadedSubtitleFile(taskBasePath, langua}// 处理YouTube字幕文件,转换为标准格式并进行翻译-func (s *YouTubeSubtitleService) processYouTubeSubtitle(ctx context.Context, stepParam *types.SubtitleTaskStepParam) error {- if stepParam.OriginalSubtitleFilePath == "" {- return fmt.Errorf("processYouTubeSubtitle: no original subtitle file found")+func (s *YouTubeSubtitleService) processYouTubeSubtitle(ctx context.Context, req *YoutubeSubtitleReq) (string, error) {+ if req.VttFile == "" {+ return "", fmt.Errorf("processYouTubeSubtitle: no original subtitle file found")}- log.GetLogger().Info("processYouTubeSubtitle starting", zap.Any("taskId", stepParam.TaskId), zap.String("subtitleFile", stepParam.OriginalSubtitleFilePath))+ log.GetLogger().Info("processYouTubeSubtitle start", zap.Any("taskId", req.TaskId), zap.String("subtitleFile", req.VttFile))+ originSrtFile := filepath.Join(req.TaskBasePath, "origin.srt")// 1. 转换VTT到SRT格式- srtFilePath, err := s.convertToSrtFormat(stepParam.OriginalSubtitleFilePath, stepParam.TaskBasePath)+ err := s.convertVttToSrt(req.VttFile, originSrtFile)if err != nil {- return fmt.Errorf("processYouTubeSubtitle convertToSrtFormat error: %w", err)+ return "", fmt.Errorf("processYouTubeSubtitle convertToSrtFormat error: %w", err)}- log.GetLogger().Info("processYouTubeSubtitle converted to SRT", zap.Any("taskId", stepParam.TaskId), zap.String("srtFile", srtFilePath))- stepParam.TaskPtr.ProcessPct = 30+ log.GetLogger().Info("processYouTubeSubtitle converted to SRT", zap.Any("taskId", req.TaskId), zap.String("srtFile", originSrtFile))- // 2. 翻译SRT文件- err = s.TranslateSrtFile(ctx, stepParam, srtFilePath)+ return "", nil+}++// 转换为SRT格式+func (s *YouTubeSubtitleService) convertVttToSrt(vttFile, srtFile string) error {+ contentBytes, err := os.ReadFile(vttFile)if err != nil {- return fmt.Errorf("processYouTubeSubtitle translateSrtFile error: %w", err)+ return fmt.Errorf("failed to read VTT file: %w", err)}+ content := string(contentBytes)+ lines := strings.Split(content, "\n")- stepParam.TaskPtr.ProcessPct = 90- log.GetLogger().Info("processYouTubeSubtitle completed", zap.Any("taskId", stepParam.TaskId))+ // --- 1. Parse all VTT blocks ---+ var vttBlocks []*vttBlock+ timestampRegex := regexp.MustCompile(`^(\d{2}:\d{2}:\d{2})\.(\d{3})\s-->\s(\d{2}:\d{2}:\d{2})\.(\d{3})`)+ tagRegex := regexp.MustCompile(`<[^>]*>`)+ timingTagRegex := regexp.MustCompile(`<\d{2}:\d{2}:\d{2}\.\d{3}>`)- err = splitSrt(stepParam)- if err != nil {- return fmt.Errorf("processYouTubeSubtitle splitSrt error: %w", err)+ for i := 0; i < len(lines); {+ line := strings.TrimSpace(lines[i])+ if line == "" || strings.HasPrefix(line, "WEBVTT") || strings.HasPrefix(line, "Kind:") || strings.HasPrefix(line, "Language:") {+ i+++ continue+ }++ if matches := timestampRegex.FindStringSubmatch(line); len(matches) == 5 {+ startTime := fmt.Sprintf("%s,%s", matches[1], matches[2])+ endTime := fmt.Sprintf("%s,%s", matches[3], matches[4])++ i+++ var subtitleLines []string+ for i < len(lines) && strings.TrimSpace(lines[i]) != "" {+ subtitleLines = append(subtitleLines, strings.TrimSpace(lines[i]))+ i+++ }++ if len(subtitleLines) > 0 {+ block := &vttBlock{+ startTime: startTime,+ endTime: endTime,+ lines: subtitleLines,+ index: len(vttBlocks),+ }+ var cleanLines []string+ for _, l := range block.lines {+ cleanLine := strings.TrimSpace(tagRegex.ReplaceAllString(l, ""))+ if cleanLine != "" {+ cleanLines = append(cleanLines, cleanLine)+ }+ }+ block.cleanLines = cleanLines+ block.cleanText = strings.Join(cleanLines, " ")+ block.hasTimingTags = timingTagRegex.MatchString(strings.Join(block.lines, " "))+ vttBlocks = append(vttBlocks, block)+ }+ } else {+ i+++ }}- return nil-}+ // --- 2. Identify candidate blocks ---+ var candidateBlocks []*vttBlock+ for _, block := range vttBlocks {+ if !block.hasTimingTags && len(block.cleanLines) == 1 {+ candidateBlocks = append(candidateBlocks, block)+ }+ }-// 转换为SRT格式-func (s *YouTubeSubtitleService) convertToSrtFormat(inputPath, taskBasePath string) (string, error) {- if strings.HasSuffix(inputPath, ".srt") {- return inputPath, nil+ // --- 3. Build precise timeline ---+ subtitlesMap := make(map[string]*srtSubtitle)+ for _, sBlock := range candidateBlocks {+ text := sBlock.cleanText+ startTime := sBlock.startTime+ endTime := sBlock.endTime++ // Search backwards for start time+ for i := sBlock.index - 1; i >= 0; i-- {+ pBlock := vttBlocks[i]+ if util.IsTextMatch(text, pBlock.cleanText) {+ startTime = pBlock.startTime+ break+ }+ }++ // Search forwards for end time+ for i := sBlock.index + 1; i < len(vttBlocks); i++ {+ tBlock := vttBlocks[i]+ if !tBlock.hasTimingTags && len(tBlock.cleanLines) >= 1 {+ if tBlock.cleanLines[0] == text {+ endTime = tBlock.startTime+ break+ }+ }+ }++ duration := util.TimeToMilliseconds(endTime) - util.TimeToMilliseconds(startTime)+ if existing, ok := subtitlesMap[text]; !ok || duration > existing.duration {+ subtitlesMap[text] = &srtSubtitle{+ startTime: startTime,+ endTime: endTime,+ text: text,+ duration: duration,+ }+ }}- if strings.HasSuffix(inputPath, ".vtt") {- outputPath := filepath.Join(taskBasePath, "converted_subtitle.srt")+ // --- 4. Clean and sort ---+ var finalSubtitles []*srtSubtitle+ for _, sub := range subtitlesMap {+ finalSubtitles = append(finalSubtitles, sub)+ }+ sort.Slice(finalSubtitles, func(i, j int) bool {+ return util.TimeToMilliseconds(finalSubtitles[i].startTime) < util.TimeToMilliseconds(finalSubtitles[j].startTime)+ })- log.GetLogger().Info("Converting VTT to SRT with internal Go function", zap.String("input", inputPath), zap.String("output", outputPath))+ // Fix overlaps+ if len(finalSubtitles) > 1 {+ for i := 0; i < len(finalSubtitles)-1; i++ {+ currentEndMs := util.TimeToMilliseconds(finalSubtitles[i].endTime)+ nextStartMs := util.TimeToMilliseconds(finalSubtitles[i+1].startTime)- if err := util.ConvertVttToSrtGo(inputPath, outputPath); err != nil {- log.GetLogger().Error("VTT to SRT conversion failed", zap.Error(err))- return "", fmt.Errorf("VTT to SRT conversion failed: %w", err)+ if currentEndMs > nextStartMs {+ adjustedEndMs := nextStartMs - 50+ if adjustedEndMs > util.TimeToMilliseconds(finalSubtitles[i].startTime) {+ finalSubtitles[i].endTime = util.MillisecondsToTime(adjustedEndMs)+ }+ }}+ }- log.GetLogger().Info("VTT to SRT conversion completed", zap.String("output", outputPath))- return outputPath, nil+ // --- 5. Write SRT file ---+ var srtContent strings.Builder+ for i, subtitle := range finalSubtitles {+ srtContent.WriteString(fmt.Sprintf("%d\n", i+1))+ srtContent.WriteString(fmt.Sprintf("%s --> %s\n", subtitle.startTime, subtitle.endTime))+ srtContent.WriteString(subtitle.text + "\n\n")}- return "", fmt.Errorf("unsupported subtitle format: %s", inputPath)+ os.WriteFile(srtFile, []byte(srtContent.String()), 0644)++ log.GetLogger().Info("VTT to SRT conversion completed", zap.String("output", srtFile))+ return nil}// TranslateSrtFile 翻译SRT文件@@ -676,7 +862,7 @@ func (s *YouTubeSubtitleService) TranslateSrtFile(ctx context.Context, stepParamstepParam.TaskPtr.ProcessPct = 40// 2. 解析VTT文件以获取单词级时间戳- utilWords, err := util.ParseVttToWords(stepParam.OriginalSubtitleFilePath)+ utilWords, err := util.ParseVttToWords(stepParam.VttFile)if err != nil {return fmt.Errorf("translateSrtFile parseVttToWords error: %w", err)}@@ -779,7 +965,7 @@ func (s *YouTubeSubtitleService) TranslateSrtFile(ctx context.Context, stepParamif useTimeAware && len(segmentWords) > 0 {preSentences := s.splitByWordPausesAndLimits(segmentWords, stepParam.OriginLanguage, config.Conf.App.MaxSentenceLength)for idx, sent := range preSentences {- items, err := s.translator.splitTextAndTranslateV2(stepParam.TaskBasePath, sent, stepParam.OriginLanguage, stepParam.TargetLanguage, stepParam.EnableModalFilter, i+idx)+ items, err := s.translator.SplitTextAndTranslate(stepParam.TaskBasePath, sent, stepParam.OriginLanguage, stepParam.TargetLanguage, stepParam.EnableModalFilter, i+idx)if err != nil {log.GetLogger().Warn("translate short sentence failed, skip", zap.Error(err), zap.String("sentence", sent))continue@@ -799,7 +985,7 @@ func (s *YouTubeSubtitleService) TranslateSrtFile(ctx context.Context, stepParam// 回退:按原有逻辑一次性切分+翻译if len(tempSrtBlocks) == 0 {- translatedItems, err := s.translator.splitTextAndTranslateV2(stepParam.TaskBasePath, segmentText, stepParam.OriginLanguage, stepParam.TargetLanguage, stepParam.EnableModalFilter, i)+ translatedItems, err := s.translator.SplitTextAndTranslate(stepParam.TaskBasePath, segmentText, stepParam.OriginLanguage, stepParam.TargetLanguage, stepParam.EnableModalFilter, i)if err != nil {log.GetLogger().Error("Failed to translate segment, skipping.", zap.Error(err), zap.Int("start_index", i))continuediff --git a/internal/service/youtube_subtitle_test.go b/internal/service/youtube_subtitle_test.goindex 629d13ff..c932724e 100644--- a/internal/service/youtube_subtitle_test.go+++ b/internal/service/youtube_subtitle_test.go@@ -20,24 +20,26 @@ func Test_YoutubeSubtitle(t *testing.T) {ProcessPct: 0,}config.Conf.App.MaxSentenceLength = 100-- _, err := s.YouTubeSubtitleSrv.convertToSrtFormat("/home/puji/KrillinAI/tasks/watch_vmdgIpmoF_dkxs/test.vtt", "/home/puji/KrillinAI/tasks/watch_vmdgIpmoF_dkxs/")+ vttFile := "D:/test_data/trans/vtt/test.vtt"+ _, err := s.YouTubeSubtitleSrv.convertVttToSrt(vttFile, "D:/test_data/trans/vtt/")if err != nil {t.Errorf("convertToSrtFormat() error = %v", err)return}- subtitleFile := "/home/puji/KrillinAI/tasks/watch_vmdgIpmoF_dkxs//converted_subtitle.srt"+ taskBasePath := "D:/test_data/trans/vtt/"+ originSrt := taskBasePath + "origin.srt"+ translatedSrt := taskBasePath + "translated.srt"// 执行测试err = s.YouTubeSubtitleSrv.TranslateSrtFile(context.Background(), &types.SubtitleTaskStepParam{- TaskId: "kgysZPHh",- TaskPtr: testTask, // 提供有效的 TaskPtr- OriginLanguage: "en",- TargetLanguage: "zh_cn",- TaskBasePath: "/home/puji/KrillinAI/tasks/watch_vmdgIpmoF_dkxs/",- OriginalSubtitleFilePath: "/home/puji/KrillinAI/tasks/watch_vmdgIpmoF_dkxs/test.vtt",- }, subtitleFile)+ TaskId: "kgysZPHh",+ TaskPtr: testTask, // 提供有效的 TaskPtr+ OriginLanguage: "en",+ TargetLanguage: "zh_cn",+ TaskBasePath: taskBasePath,+ VttFile: vttFile,+ }, translatedSrt)if err != nil {t.Errorf("TranslateSrtFile() error = %v, want nil", err)}diff --git a/internal/types/subtitle_task.go b/internal/types/subtitle_task.goindex 5e4ed794..648a1af9 100644--- a/internal/types/subtitle_task.go+++ b/internal/types/subtitle_task.go@@ -204,7 +204,6 @@ Use "Previous Sentences" ONLY to understand the context of referents (e.g. prono**Your output must be literal, minimal, and on a single line. Provide only the translation result:**`-type SmallAudio struct {AudioFile stringTranscriptionData *TranscriptionData@@ -301,7 +300,7 @@ type SubtitleTaskStepParam struct {TaskBasePath stringLink stringAudioFilePath string- OriginalSubtitleFilePath string // YouTube下载的原始字幕文件路径+ VttFile string // YouTube下载的原始字幕文件路径SubtitleResultType SubtitleResultTypeEnableModalFilter boolEnableTts booldiff --git a/pkg/util/youtube_subtitle_helper.go b/pkg/util/youtube_subtitle_helper.goindex 41c32e65..71d68f28 100644--- a/pkg/util/youtube_subtitle_helper.go+++ b/pkg/util/youtube_subtitle_helper.go@@ -10,7 +10,6 @@ import ("strings")-type Word struct {Text stringStart float64@@ -18,7 +17,6 @@ type Word struct {Num int}-func TimeToMilliseconds(timeStr string) int64 {timeStr = strings.Replace(timeStr, ",", ".", -1)timeParts := strings.Split(timeStr, ".")@@ -78,7 +76,7 @@ func IsTextMatch(textA, textB string) bool {return false}-func ConvertVttToSrtGo(inputPath, outputPath string) error {+func ConvertVttToSrt(inputPath, outputPath string) error {contentBytes, err := os.ReadFile(inputPath)if err != nil {return fmt.Errorf("failed to read VTT file: %w", err)