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
feat: add whisper.cpp and thinking model support
LI TIANCHENG29a79b862b41
diff --git a/config/config-example.toml b/config/config-example.tomlindex 05ea9978..5b081656 100644--- a/config/config-example.toml+++ b/config/config-example.toml@@ -2,7 +2,7 @@segment_duration = 5 # 音频切分处理间隔,单位:分钟,建议值:5-10,如果视频中话语较少可以适当提高translate_parallel_num = 5 # 并发进行模型转录和翻译的数量上限,建议值:5,如果使用了本地模型,该项自动不生效proxy = "" # 网络代理地址,格式如http://127.0.0.1:7890,可不填- transcribe_provider = "openai" # 语音识别,当前可选值:openai,fasterwhisper,whisperkit,aliyun。(fasterwhisper不支持macOS,whisperkit只支持M芯片macOS)+ transcribe_provider = "openai" # 语音识别,当前可选值:openai,fasterwhisper,whisperkit,whisper.cpp,aliyun。(fasterwhisper不支持macOS,whisperkit只支持M芯片)llm_provider = "openai" # LLM,当前可选值:openai,aliyun[server]@@ -13,6 +13,7 @@[local_model]fasterwhisper = "large-v2" # fasterwhisper的本地模型可选值:tiny,medium,large-v2,建议medium及以上whisperkit = "large-v2" # whisperkit的本地模型可选值:large-v2+ whispercpp = "large-v2" # whisper.cpp的本地模型[openai]base_url = "" # OpenAI API 自定义base url,可配合转发站密钥使用,留空为默认API地址diff --git a/config/config.go b/config/config.goindex 5b1240b2..c1825410 100644--- a/config/config.go+++ b/config/config.go@@ -29,6 +29,7 @@ type Server struct {type LocalModel struct {Fasterwhisper string `toml:"fasterwhisper"`Whisperkit string `toml:"whisperkit"`+ Whispercpp string `toml:"whispercpp"`}type OpenAiWhisper struct {@@ -87,6 +88,7 @@ var Conf = Config{LocalModel: LocalModel{Fasterwhisper: "large-v2",Whisperkit: "large-v2",+ Whispercpp: "large-v2",},}@@ -103,6 +105,7 @@ func validateConfig() error {return errors.New("检测到开启了fasterwhisper,但模型选型配置不正确,请检查配置")}case "whisperkit":+ Conf.App.TranslateParallelNum = 1if runtime.GOOS != "darwin" {log.GetLogger().Error("whisperkit只支持macos", zap.String("当前系统", runtime.GOOS))return fmt.Errorf("whisperkit只支持macos")@@ -110,6 +113,14 @@ func validateConfig() error {if Conf.LocalModel.Whisperkit != "large-v2" {return errors.New("检测到开启了whisperkit,但模型选型配置不正确,请检查配置")}+ case "whispercpp":+ if runtime.GOOS != "windows" { // 当前先仅支持win,模型仅支持large-v2,最小化产品+ log.GetLogger().Error("whispercpp only support windows", zap.String("current os", runtime.GOOS))+ return fmt.Errorf("whispercpp only support windows")+ }+ if Conf.LocalModel.Whispercpp != "large-v2" {+ return errors.New("检测到开启了whisper.cpp,但模型选型配置不正确,请检查配置")+ }case "aliyun":if Conf.Aliyun.Speech.AccessKeyId == "" || Conf.Aliyun.Speech.AccessKeySecret == "" || Conf.Aliyun.Speech.AppKey == "" {return errors.New("使用阿里云语音服务需要配置相关密钥")@@ -142,7 +153,10 @@ func LoadConfig() {return} else {log.GetLogger().Info("已找到配置文件,从配置文件中加载配置")- _, err = toml.DecodeFile(configPath, &Conf)+ if _, err = toml.DecodeFile(configPath, &Conf); err != nil {+ log.GetLogger().Error("加载配置文件失败", zap.Error(err))+ return+ }}}diff --git a/internal/deps/checker.go b/internal/deps/checker.goindex aa6d49ee..582f3c9d 100644--- a/internal/deps/checker.go+++ b/internal/deps/checker.go@@ -8,6 +8,7 @@ import ("krillin-ai/pkg/util""os""os/exec"+ "path/filepath""runtime""go.uber.org/zap"@@ -52,6 +53,17 @@ func CheckDependency() error {return err}}+ if config.Conf.App.TranscribeProvider == "whispercpp" {+ if err = checkWhispercpp(); err != nil {+ log.GetLogger().Error("whispercpp环境准备失败", zap.Error(err))+ return err+ }+ err = checkModel("whispercpp")+ if err != nil {+ log.GetLogger().Error("whispercpp本地模型环境准备失败", zap.Error(err))+ return err+ }+ }return nil}@@ -303,6 +315,72 @@ func checkFasterWhisper() error {return nil}+// 检测whisperkit+func checkWhisperKit() error {+ cmd := exec.Command("which", "whisperkit-cli")+ err := cmd.Run()+ if err != nil {+ log.GetLogger().Info("没有找到whisperkit-cli,即将开始自动安装")+ cmd = exec.Command("brew", "install", "whisperkit-cli")+ output, err := cmd.CombinedOutput()+ if err != nil {+ log.GetLogger().Error("whisperkit-cli 安装失败", zap.String("info", string(output)), zap.Error(err))+ return err+ }+ log.GetLogger().Info("whisperkit-cli 安装成功")+ }+ storage.WhisperKitPath = "whisperkit-cli"+ log.GetLogger().Info("检测到whisperkit-cli已安装")+ return nil+}++// 检测whispercpp+func checkWhispercpp() error {+ var (+ filePath string+ err error+ )+ if runtime.GOOS == "windows" {+ filePath = filepath.Join("bin", "whispercpp", "whisper-cli.exe")+ } else {+ return fmt.Errorf("whisper.cpp不支持你当前的操作系统: %s,请选择其它transcription provider", runtime.GOOS)+ }+ if _, err = os.Stat(filePath); os.IsNotExist(err) {+ log.GetLogger().Info("没有找到whispercpp,即将开始自动下载,文件较大请耐心等待")+ err = os.MkdirAll("bin", 0755)+ if err != nil {+ log.GetLogger().Error("创建./bin目录失败", zap.Error(err))+ return err+ }+ var downloadUrl string+ if runtime.GOOS == "windows" {+ downloadUrl = "https://modelscope.cn/models/Maranello/KrillinAI_dependency_cn/resolve/master/whispercpp-windows-cuda.zip"+ }+ zipFilePath := filepath.Join("bin", "whispercpp-windows-cuda.zip")+ err = util.DownloadFile(downloadUrl, zipFilePath, config.Conf.App.Proxy)+ if err != nil {+ log.GetLogger().Error("下载whispercpp失败", zap.Error(err))+ return err+ }+ log.GetLogger().Info("开始解压whispercpp")+ err = util.Unzip(zipFilePath, filepath.Join("bin", "whispercpp")+string(filepath.Separator))+ if err != nil {+ log.GetLogger().Error("解压whispercpp失败", zap.Error(err))+ return err+ }+ }+ if runtime.GOOS != "windows" {+ err = os.Chmod(filePath, 0755)+ if err != nil {+ log.GetLogger().Error("设置文件权限失败", zap.Error(err))+ return err+ }+ }+ storage.WhispercppPath = filePath+ log.GetLogger().Info("whispercpp检查完成", zap.String("路径", filePath))+ return nil+}+// 检测本地模型func checkModel(whisperType string) error {var err error@@ -336,9 +414,22 @@ func checkModel(whisperType string) error {}log.GetLogger().Info("模型下载完成", zap.String("路径", modelPath))}+ case "whispercpp":+ model = config.Conf.LocalModel.Whispercpp+ modelPath = fmt.Sprintf("./models/whispercpp/ggml-%s.bin", model)+ if _, err = os.Stat(modelPath); os.IsNotExist(err) {+ log.GetLogger().Info(fmt.Sprintf("没有找到whisper.cpp模型%s,即将开始自动下载", modelPath))+ downloadUrl := fmt.Sprintf("https://gitcode.com/hf_mirrors/ai-gitcode/whisper.cpp/blob/main/ggml-%s.bin", model)+ err = util.DownloadFile(downloadUrl, fmt.Sprintf("./models/whispercpp/ggml-%s.bin", model), config.Conf.App.Proxy)+ if err != nil {+ log.GetLogger().Info("下载whisper.cpp模型失败", zap.Error(err))+ return err+ }+ log.GetLogger().Info("whisper.cpp模型下载完成", zap.String("路径", modelPath))+ }case "whisperkit":model = config.Conf.LocalModel.Whisperkit- modelPath = "./models/whisperkit/openai_whisper-large-v2"+ modelPath = fmt.Sprintf("./models/whisperkit/openai_whisper-%s", model)files, _ := os.ReadDir(modelPath)if len(files) == 0 {log.GetLogger().Info("没有找到whisperkit模型,即将开始自动下载")@@ -360,22 +451,3 @@ func checkModel(whisperType string) error {log.GetLogger().Info("模型检查完成", zap.String("路径", modelPath))return nil}--// 检测whisperkit-func checkWhisperKit() error {- cmd := exec.Command("which", "whisperkit-cli")- err := cmd.Run()- if err != nil {- log.GetLogger().Info("没有找到whisperkit-cli,即将开始自动安装")- cmd = exec.Command("brew", "install", "whisperkit-cli")- output, err := cmd.CombinedOutput()- if err != nil {- log.GetLogger().Error("whisperkit-cli 安装失败", zap.String("info", string(output)), zap.Error(err))- return err- }- log.GetLogger().Info("whisperkit-cli 安装成功")- }- storage.WhisperKitPath = "whisperkit-cli"- log.GetLogger().Info("检测到whisperkit-cli已安装")- return nil-}diff --git a/internal/desktop/subtitle.go b/internal/desktop/subtitle.goindex 4e882181..ff117e4c 100644--- a/internal/desktop/subtitle.go+++ b/internal/desktop/subtitle.go@@ -53,7 +53,7 @@ type SubtitleManager struct {func NewSubtitleManager(window fyne.Window) *SubtitleManager {return &SubtitleManager{window: window,- sourceLang: "zh_cn",+ sourceLang: "en",targetLang: "zh_cn",bilingualEnabled: true,bilingualPosition: 1,diff --git a/internal/desktop/ui.go b/internal/desktop/ui.goindex 766b25bc..a007a2d6 100644--- a/internal/desktop/ui.go+++ b/internal/desktop/ui.go@@ -167,7 +167,7 @@ func createAppConfigGroup() *fyne.Container {appProxyEntry := StyledEntry("网络代理地址")appProxyEntry.Bind(binding.BindString(&config.Conf.App.Proxy))- appTranscribeProviderEntry := StyledSelect([]string{"openai", "fasterwhisper", "whisperkit", "aliyun"}, func(s string) {+ appTranscribeProviderEntry := StyledSelect([]string{"openai", "fasterwhisper", "whispercpp", "whisperkit", "aliyun"}, func(s string) {config.Conf.App.TranscribeProvider = s})appTranscribeProviderEntry.SetSelected(config.Conf.App.TranscribeProvider)@@ -227,8 +227,14 @@ func createLocalModelGroup() *fyne.Container {})localModelWhisperkitEntry.SetSelected(config.Conf.LocalModel.Whisperkit)+ localModelWhispercppEntry := StyledSelect([]string{"large-v2"}, func(s string) {+ config.Conf.LocalModel.Whisperkit = s+ })+ localModelWhispercppEntry.SetSelected(config.Conf.LocalModel.Whispercpp)+form := widget.NewForm(widget.NewFormItem("Fasterwhisper模型 Model", localModelFasterwhisperEntry),+ widget.NewFormItem("Whispercpp模型 Model", localModelWhispercppEntry),widget.NewFormItem("Whisperkit模型 Model", localModelWhisperkitEntry),)diff --git a/internal/service/audio2subtitle.go b/internal/service/audio2subtitle.goindex 2e4dd8c4..6d4f93c0 100644--- a/internal/service/audio2subtitle.go+++ b/internal/service/audio2subtitle.go@@ -17,6 +17,7 @@ import ("runtime/debug""strconv""strings"+ "regexp""sync""go.uber.org/zap"@@ -831,8 +832,10 @@ func (s Service) splitTextAndTranslate(taskId, baseTaskPath string, targetLanguasplitContent = ""} else {// 最多尝试4次获取有效的翻译结果- for i := 0; i < 4; i++ {+ for i := range 4 {splitContent, err = s.ChatCompleter.ChatCompletion(splitPrompt + audioFile.TranscriptionData.Text)+ re := regexp.MustCompile(`(?s)<think>.*?</think>`)+ splitContent = strings.TrimSpace(re.ReplaceAllString(splitContent, ""))if err != nil {log.GetLogger().Warn("audioToSubtitle splitTextAndTranslate ChatCompletion error, retrying...",zap.Any("taskId", taskId), zap.Int("attempt", i+1), zap.Error(err))@@ -844,6 +847,10 @@ func (s Service) splitTextAndTranslate(taskId, baseTaskPath string, targetLanguabreak}+ // save splitContent to a file+ originTextFileName := filepath.Join(baseTaskPath, "error_output.txt")+ os.WriteFile(originTextFileName, []byte(splitContent), 0644)+log.GetLogger().Warn("audioToSubtitle splitTextAndTranslate invalid response format or content mismatch, retrying...",zap.Any("taskId", taskId), zap.Int("attempt", i+1))err = fmt.Errorf("invalid split content format or content mismatch, audio file num: %d", audioFile.Num)@@ -887,6 +894,7 @@ func isValidSplitContent(splitContent, originalText string) bool {lines := strings.Split(splitContent, "\n")if len(lines) < 3 { // 至少需要一个完整的块+ //log.GetLogger().Warn("audioToSubtitle invaild Format, not enough lines", zap.Any("splitContent", splitContent))return false}@@ -903,7 +911,7 @@ func isValidSplitContent(splitContent, originalText string) bool {// 检查是否为序号行if _, err := strconv.Atoi(line); err == nil {if i+2 >= len(lines) {- log.GetLogger().Warn("audioToSubtitle invaild Format", zap.Any("splitContent", splitContent), zap.Any("line", line))+ log.GetLogger().Warn("audioToSubtitle invaild Format, block is not complete", zap.Any("splitContent", splitContent), zap.Any("line", line))return false}// 收集原文行(第三行),并去除方括号@@ -917,7 +925,7 @@ func isValidSplitContent(splitContent, originalText string) bool {}if !isValidFormat || len(originalLines) == 0 {- log.GetLogger().Warn("audioToSubtitle invaild Format", zap.Any("splitContent", splitContent))+ log.GetLogger().Warn("audioToSubtitle invaild Format, original line misiing", zap.Any("splitContent", splitContent))return false}@@ -926,6 +934,6 @@ func isValidSplitContent(splitContent, originalText string) bool {originalTextLength := len(strings.TrimSpace(originalText))combinedLength := len(strings.TrimSpace(combinedOriginal))- // 允许200字符的误差- return math.Abs(float64(originalTextLength-combinedLength)) <= 200+ // 允许300字符的误差+ return math.Abs(float64(originalTextLength-combinedLength)) <= 300}diff --git a/internal/service/init.go b/internal/service/init.goindex f2ff3569..7b42006b 100644--- a/internal/service/init.go+++ b/internal/service/init.go@@ -6,6 +6,7 @@ import ("krillin-ai/log""krillin-ai/pkg/aliyun""krillin-ai/pkg/fasterwhisper"+ "krillin-ai/pkg/whispercpp""krillin-ai/pkg/openai""krillin-ai/pkg/whisper""krillin-ai/pkg/whisperkit"@@ -32,6 +33,8 @@ func NewService() *Service {transcriber = aliyun.NewAsrClient(config.Conf.Aliyun.Bailian.ApiKey)case "fasterwhisper":transcriber = fasterwhisper.NewFastwhisperProcessor(config.Conf.LocalModel.Fasterwhisper)+ case "whispercpp":+ transcriber = whispercpp.NewWhispercppProcessor(config.Conf.LocalModel.Whispercpp)case "whisperkit":transcriber = whisperkit.NewWhisperKitProcessor(config.Conf.LocalModel.Whisperkit)}diff --git a/internal/storage/bin.go b/internal/storage/bin.goindex 0ea6c84a..78653531 100644--- a/internal/storage/bin.go+++ b/internal/storage/bin.go@@ -6,4 +6,5 @@ var (YtdlpPath stringFasterwhisperPath stringWhisperKitPath string+ WhispercppPath string)diff --git a/internal/types/subtitle_task.go b/internal/types/subtitle_task.goindex 99d41c9c..6515b691 100644--- a/internal/types/subtitle_task.go+++ b/internal/types/subtitle_task.go@@ -24,11 +24,11 @@ var SplitTextPrompt = `你是一个语言处理专家,专注于自然语言处1. 将原句翻译为%s,确保译文流畅、自然,达到专业翻译水平。2. 严格依据标点符号(逗号、句号、问号等)将内容拆分成单独的句子,并依据以下规则确保拆分粒度合理:- - 每个分句长度不得超过25个单词或50个字符(以较短者为准)。- - 对于复杂句(如包含多个并列或从属结构),需要根据连词(例如 "and", "but", "which", "when")进一步拆分。+ - 每个句子在保证句意完整的情况下尽可能短,长度尽量不得超过15个字。+ - 可以根据连词(例如 "and", "but", "which", "when", "so", "所以", "但是", "因此", "考虑到" 等)进一步拆分句子,避免语句太长。3. 对每个拆分的句子分别翻译,确保不遗漏或修改任何字词。4. 将每对翻译后的句子与原句用独立编号表示,并分别以方括号[]包裹内容。-5. 输出的翻译与原文一一对应,严格按照原文顺序呈现。+5. 输出的翻译与原文应保持对应,严格按照原文顺序呈现,不得有错位,且原文尽可能使用原文。翻译输出应采用如下格式:**正常翻译的示例(注意每块3部分,每个部分都独占一行,空格分块)**:@@ -51,11 +51,11 @@ var SplitTextPromptWithModalFilter = `你是一个语言处理专家,专注于1. 将原句翻译为%s,确保译文流畅、自然,达到专业翻译水平。2. 严格依据标点符号(逗号、句号、问号等)将内容拆分成单独的句子,并依据以下规则确保拆分粒度合理:- - 每个分句长度不得超过25个单词或50个字符(以较短者为准)。- - 对于复杂句(如包含多个并列或从属结构),需要根据连词(例如 "and", "but", "which", "when")进一步拆分。+ - 每个句子在保证句意完整的情况下尽可能短,长度尽量不得超过15个字。+ - 可以根据连词(例如 "and", "but", "which", "when", "so", "所以", "但是", "因此", "考虑到" 等)进一步拆分句子,避免语句太长。3. 对每个拆分的句子分别翻译,确保不遗漏或修改任何字词。4. 将每对翻译后的句子与原句用独立编号表示,并分别以方括号[]包裹内容。-5. 输出的翻译与原文一一对应,严格按照原文顺序呈现。+5. 输出的翻译与原文应保持对应,严格按照原文顺序呈现,不得有错位,且原文尽可能使用原文。6. 忽略文本中的语气词,比如"Oh" "Ah" "Wow"等等。翻译输出应采用如下格式:diff --git a/internal/types/whispercpp.go b/internal/types/whispercpp.gonew file mode 100644index 00000000..3785b424--- /dev/null+++ b/internal/types/whispercpp.go@@ -0,0 +1,57 @@+package types++type WhispercppOutput struct {+ SystemInfo string `json:"systeminfo"`+ Model struct {+ Type string `json:"type"`+ Multilingual bool `json:"multilingual"`+ Vocab int `json:"vocab"`+ Audio struct {+ Ctx int `json:"ctx"`+ State int `json:"state"`+ Head int `json:"head"`+ Layer int `json:"layer"`+ } `json:"audio"`+ Text struct {+ Ctx int `json:"ctx"`+ State int `json:"state"`+ Head int `json:"head"`+ Layer int `json:"layer"`+ } `json:"text"`+ Mels int `json:"mels"`+ Ftype int `json:"ftype"`+ } `json:"model"`+ Params struct {+ Model string `json:"model"`+ Language string `json:"language"`+ Translate bool `json:"translate"`+ } `json:"params"`+ Result struct {+ Language string `json:"language"`+ } `json:"result"`+ Transcription []struct {+ Timestamps struct {+ From string `json:"from"`+ To string `json:"to"`+ } `json:"timestamps"`+ Offsets struct {+ From int `json:"from"`+ To int `json:"to"`+ } `json:"offsets"`+ Text string `json:"text"`+ Tokens []struct {+ Text string `json:"text"`+ Timestamps struct {+ From string `json:"from"`+ To string `json:"to"`+ } `json:"timestamps"`+ Offsets struct {+ From int `json:"from"`+ To int `json:"to"`+ } `json:"offsets"`+ ID int `json:"id"`+ P float64 `json:"p"`+ TDtw int `json:"t_dtw"`+ } `json:"tokens"`+ } `json:"transcription"`+}diff --git a/pkg/whispercpp/init.go b/pkg/whispercpp/init.gonew file mode 100644index 00000000..1e8cdc89--- /dev/null+++ b/pkg/whispercpp/init.go@@ -0,0 +1,12 @@+package whispercpp++type WhispercppProcessor struct {+ WorkDir string // 生成中间文件的目录+ Model string+}++func NewWhispercppProcessor(model string) *WhispercppProcessor {+ return &WhispercppProcessor{+ Model: model,+ }+}diff --git a/pkg/whispercpp/transcription.go b/pkg/whispercpp/transcription.gonew file mode 100644index 00000000..804e5dcc--- /dev/null+++ b/pkg/whispercpp/transcription.go@@ -0,0 +1,125 @@+package whispercpp++import (+ "encoding/json"+ "fmt"+ "krillin-ai/internal/storage"+ "krillin-ai/internal/types"+ "krillin-ai/log"+ "krillin-ai/pkg/util"+ "os"+ "os/exec"+ "regexp"+ "strconv"+ "strings"++ "go.uber.org/zap"+)++func (c *WhispercppProcessor) Transcription(audioFile, language, workDir string) (*types.TranscriptionData, error) {+ name := util.ChangeFileExtension(audioFile, "")+ cmdArgs := []string{+ "-m", fmt.Sprintf("./models/whispercpp/ggml-%s.bin", c.Model),+ "--output-json-full",+ "--flash-attn",+ "--split-on-word",+ "--language", language,+ "--output-file", name,+ "--file", audioFile,+ }+ cmd := exec.Command(storage.WhispercppPath, cmdArgs...)+ log.GetLogger().Info("WhispercppProcessor转录开始", zap.String("cmd", cmd.String()))+ output, err := cmd.CombinedOutput()+ if err != nil && !strings.Contains(string(output), "output_json: saving output to") {+ log.GetLogger().Error("WhispercppProcessor cmd 执行失败", zap.String("output", string(output)), zap.Error(err))+ return nil, err+ }+ log.GetLogger().Info("WhispercppProcessor转录json生成完毕", zap.String("audio file", audioFile))++ var result types.WhispercppOutput+ fileData, err := os.Open(util.ChangeFileExtension(audioFile, ".json"))+ if err != nil {+ log.GetLogger().Error("WhispercppProcessor 打开json文件失败", zap.Error(err))+ return nil, err+ }+ defer fileData.Close()+ decoder := json.NewDecoder(fileData)+ if err = decoder.Decode(&result); err != nil {+ log.GetLogger().Error("WhispercppProcessor 解析json文件失败", zap.Error(err))+ return nil, err+ }++ var (+ transcriptionData types.TranscriptionData+ num int+ )+ for _, segment := range result.Transcription {+ transcriptionData.Text += strings.ReplaceAll(segment.Text, "—", " ") // 连字符处理,因为模型存在很多错误添加到连字符+ for _, word := range segment.Tokens {+ fromSec, err := parseTimestampToSeconds(word.Timestamps.From)+ if err != nil {+ log.GetLogger().Error("解析开始时间失败", zap.Error(err))+ return nil, err+ }++ toSec, err := parseTimestampToSeconds(word.Timestamps.To)+ if err != nil {+ log.GetLogger().Error("解析结束时间失败", zap.Error(err))+ return nil, err+ }+ regex := regexp.MustCompile(`^\[.*\]$`)+ if regex.MatchString(word.Text) {+ continue+ } else if strings.Contains(word.Text, "—") {+ // 对称切分+ mid := (fromSec + toSec) / 2+ seperatedWords := strings.Split(word.Text, "—")+ transcriptionData.Words = append(transcriptionData.Words, []types.Word{+ {+ Num: num,+ Text: util.CleanPunction(strings.TrimSpace(seperatedWords[0])),+ Start: fromSec,+ End: mid,+ },+ {+ Num: num + 1,+ Text: util.CleanPunction(strings.TrimSpace(seperatedWords[1])),+ Start: mid,+ End: toSec,+ },+ }...)+ num += 2+ } else {+ transcriptionData.Words = append(transcriptionData.Words, types.Word{+ Num: num,+ Text: util.CleanPunction(strings.TrimSpace(word.Text)),+ Start: fromSec,+ End: toSec,+ })+ num+++ }+ }+ }+ log.GetLogger().Info("WhispercppProcessor转录成功")+ return &transcriptionData, nil+}++// 新增时间戳转换函数+func parseTimestampToSeconds(timeStr string) (float64, error) {+ parts := strings.Split(timeStr, ",")+ if len(parts) != 2 {+ return 0, fmt.Errorf("invalid timestamp format: %s", timeStr)+ }++ timePart := strings.Split(parts[0], ":")+ if len(timePart) != 3 {+ return 0, fmt.Errorf("invalid time format: %s", parts[0])+ }++ hours, _ := strconv.Atoi(timePart[0])+ minutes, _ := strconv.Atoi(timePart[1])+ seconds, _ := strconv.Atoi(timePart[2])+ milliseconds, _ := strconv.Atoi(parts[1])++ return float64(hours*3600+minutes*60+seconds) + float64(milliseconds)/1000, nil+}