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
wip: desktop
沈浩e4ca85de00d9
diff --git a/.goreleaser.yaml b/.goreleaser.yamlindex 9784cb9d..129adef8 100644--- a/.goreleaser.yaml+++ b/.goreleaser.yaml@@ -1,19 +1,7 @@version: 2builds:- - id: server- main: ./cmd/server- binary: KrillinAI- env:- - CGO_ENABLED=0- goos:- - darwin- - linux- - windows- - id: desktop- main: ./cmd/desktop- binary: KrillinAI-Desktop- env:+ - env:- CGO_ENABLED=0goos:- darwin@@ -34,8 +22,6 @@ dockers:- "--label=org.opencontainers.image.revision={{.FullCommit}}"- "--label=org.opencontainers.image.version={{.Version}}"- "--label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_REPOSITORY_OWNER }}/{{.ProjectName}}"- ids:- - server- image_templates:- "ghcr.io/{{ tolower .Env.GITHUB_REPOSITORY_OWNER }}/{{ tolower .ProjectName }}:{{.Version}}-arm64"- "ghcr.io/{{ tolower .Env.GITHUB_REPOSITORY_OWNER }}/{{ tolower .ProjectName }}:latest-arm64"@@ -48,8 +34,6 @@ dockers:- "--label=org.opencontainers.image.revision={{.FullCommit}}"- "--label=org.opencontainers.image.version={{.Version}}"- "--label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_REPOSITORY_OWNER }}/{{.ProjectName}}"- ids:- - serverdocker_manifests:- name_template: ghcr.io/{{ tolower .Env.GITHUB_REPOSITORY_OWNER }}/{{ tolower .ProjectName }}:{{.Version}}@@ -74,9 +58,6 @@ archives:{{- else }}{{ .Arch }}{{ end }}{{- if .Arm }}v{{ .Arm }}{{ end }}{{- end }}- builds:- - server- - desktopchangelog:sort: asc@@ -85,4 +66,4 @@ changelog:- "^docs:"- "^test:"- "^chore:"- - "^ci:"+ - "^ci:"\ No newline at end of filediff --git a/internal/service/audio2subtitle.go b/internal/service/audio2subtitle.goindex 7eee2c96..c102e12a 100644--- a/internal/service/audio2subtitle.go+++ b/internal/service/audio2subtitle.go@@ -38,7 +38,7 @@ func (s Service) audioToSubtitle(ctx context.Context, stepParam *types.SubtitleTreturn fmt.Errorf("audioToSubtitle splitSrt error: %w", err)}// 更新字幕任务信息- storage.SubtitleTasks[stepParam.TaskId].ProcessPct = 95+ stepParam.TaskPtr.ProcessPct = 95return nil}@@ -85,7 +85,7 @@ func (s Service) splitAudio(ctx context.Context, stepParam *types.SubtitleTaskSt}// 更新字幕任务信息- storage.SubtitleTasks[stepParam.TaskId].ProcessPct = 20+ stepParam.TaskPtr.ProcessPct = 20log.GetLogger().Info("audioToSubtitle.splitAudio end", zap.String("task id", stepParam.TaskId))return nil@@ -147,8 +147,8 @@ func (s Service) audioToSrt(ctx context.Context, stepParam *types.SubtitleTaskStstepNumMu.Lock()stepNum++processPct := uint8(20 + 70*stepNum/(len(stepParam.SmallAudios)*2))+ stepParam.TaskPtr.ProcessPct = processPctstepNumMu.Unlock()- storage.SubtitleTasks[stepParam.TaskId].ProcessPct = processPct// 拆分字幕并翻译err = s.splitTextAndTranslate(stepParam.TaskId, stepParam.TaskBasePath, stepParam.TargetLanguage, stepParam.EnableModalFilter, audioFile)@@ -161,10 +161,9 @@ func (s Service) audioToSrt(ctx context.Context, stepParam *types.SubtitleTaskStstepNumMu.Lock()stepNum++processPct = uint8(20 + 70*stepNum/(len(stepParam.SmallAudios)*2))+ stepParam.TaskPtr.ProcessPct = processPctstepNumMu.Unlock()- storage.SubtitleTasks[stepParam.TaskId].ProcessPct = processPct-// 生成时间戳err = s.generateTimestamps(stepParam.TaskId, stepParam.TaskBasePath, stepParam.OriginLanguage, stepParam.SubtitleResultType, audioFile, stepParam.MaxWordOneLine)if err != nil {@@ -238,7 +237,7 @@ func (s Service) audioToSrt(ctx context.Context, stepParam *types.SubtitleTaskStstepParam.BilingualSrtFilePath = bilingualFile// 更新字幕任务信息- storage.SubtitleTasks[stepParam.TaskId].ProcessPct = 90+ stepParam.TaskPtr.ProcessPct = 90log.GetLogger().Info("audioToSubtitle.audioToSrt end", zap.Any("taskId", stepParam.TaskId))diff --git a/internal/service/get_video_info.go b/internal/service/get_video_info.goindex dd44fad9..0171a742 100644--- a/internal/service/get_video_info.go+++ b/internal/service/get_video_info.go@@ -57,17 +57,19 @@ func (s Service) getVideoInfo(ctx context.Context, stepParam *types.SubtitleTask}log.GetLogger().Debug("getVideoInfo translate video info result", zap.String("result", result))- storage.SubtitleTasks[stepParam.TaskId].Title = title- storage.SubtitleTasks[stepParam.TaskId].Description = description- storage.SubtitleTasks[stepParam.TaskId].OriginLanguage = string(stepParam.OriginLanguage)- storage.SubtitleTasks[stepParam.TaskId].TargetLanguage = string(stepParam.TargetLanguage)- storage.SubtitleTasks[stepParam.TaskId].ProcessPct = 10+ taskPtr := stepParam.TaskPtr++ taskPtr.Title = title+ taskPtr.Description = description+ taskPtr.OriginLanguage = string(stepParam.OriginLanguage)+ taskPtr.TargetLanguage = string(stepParam.TargetLanguage)+ taskPtr.ProcessPct = 10splitResult := strings.Split(result, "####")if len(splitResult) == 1 {- storage.SubtitleTasks[stepParam.TaskId].TranslatedTitle = splitResult[0]+ taskPtr.TranslatedTitle = splitResult[0]} else if len(splitResult) == 2 {- storage.SubtitleTasks[stepParam.TaskId].TranslatedTitle = splitResult[0]- storage.SubtitleTasks[stepParam.TaskId].TranslatedDescription = splitResult[1]+ taskPtr.TranslatedTitle = splitResult[0]+ taskPtr.TranslatedDescription = splitResult[1]} else {log.GetLogger().Error("getVideoInfo translate video info error split result length != 1 and 2", zap.Any("stepParam", stepParam), zap.Any("translate result", result), zap.Error(err))}diff --git a/internal/service/link2file.go b/internal/service/link2file.goindex 1cf6b588..ec6811f0 100644--- a/internal/service/link2file.go+++ b/internal/service/link2file.go@@ -22,7 +22,7 @@ func (s Service) linkToFile(ctx context.Context, stepParam *types.SubtitleTaskStlink := stepParam.LinkaudioPath := fmt.Sprintf("%s/%s", stepParam.TaskBasePath, types.SubtitleTaskAudioFileName)videoPath := fmt.Sprintf("%s/%s", stepParam.TaskBasePath, types.SubtitleTaskVideoFileName)- storage.SubtitleTasks[stepParam.TaskId].ProcessPct = 3+ stepParam.TaskPtr.ProcessPct = 3if strings.Contains(link, "local:") {// 本地文件videoPath = strings.ReplaceAll(link, "local:", "")@@ -78,7 +78,7 @@ func (s Service) linkToFile(ctx context.Context, stepParam *types.SubtitleTaskStlog.GetLogger().Info("linkToFile.unsupported link type", zap.Any("step param", stepParam))return errors.New("linkToFile error: unsupported link, only support youtube, bilibili and local file")}- storage.SubtitleTasks[stepParam.TaskId].ProcessPct = 6+ stepParam.TaskPtr.ProcessPct = 6stepParam.AudioFilePath = audioPathif !strings.HasPrefix(link, "local:") && stepParam.EmbedSubtitleVideoType != "none" {@@ -97,6 +97,6 @@ func (s Service) linkToFile(ctx context.Context, stepParam *types.SubtitleTaskSt}// 更新字幕任务信息- storage.SubtitleTasks[stepParam.TaskId].ProcessPct = 10+ stepParam.TaskPtr.ProcessPct = 10return nil}diff --git a/internal/service/srt2speech.go b/internal/service/srt2speech.goindex 544d21df..a06db68d 100644--- a/internal/service/srt2speech.go+++ b/internal/service/srt2speech.go@@ -135,7 +135,7 @@ func (s Service) srtFileToSpeech(ctx context.Context, stepParam *types.SubtitleT}stepParam.TtsResultFilePath = finalOutput// 更新字幕任务信息- storage.SubtitleTasks[stepParam.TaskId].ProcessPct = 98+ stepParam.TaskPtr.ProcessPct = 98log.GetLogger().Info("srtFileToSpeech success", zap.String("task id", stepParam.TaskId))return nil}diff --git a/internal/service/subtitle_service.go b/internal/service/subtitle_service.goindex faa96c51..24303c78 100644--- a/internal/service/subtitle_service.go+++ b/internal/service/subtitle_service.go@@ -74,11 +74,13 @@ func (s Service) StartSubtitleTask(req dto.StartVideoSubtitleTaskReq) (*dto.Star}// 创建任务- storage.SubtitleTasks[taskId] = &types.SubtitleTask{+ taskPtr := &types.SubtitleTask{TaskId: taskId,VideoSrc: req.Url,Status: types.SubtitleTaskStatusProcessing,}+ storage.SubtitleTasks.Store(taskId, taskPtr)+var ttsVoiceCode stringif req.TtsVoiceCode == types.SubtitleTaskTtsVoiceCodeLongyu {ttsVoiceCode = "longyu"@@ -102,6 +104,7 @@ func (s Service) StartSubtitleTask(req dto.StartVideoSubtitleTaskReq) (*dto.StarstepParam := types.SubtitleTaskStepParam{TaskId: taskId,+ TaskPtr: taskPtr,TaskBasePath: taskBasePath,Link: req.Url,SubtitleResultType: resultType,@@ -128,7 +131,7 @@ func (s Service) StartSubtitleTask(req dto.StartVideoSubtitleTaskReq) (*dto.Starbuf := make([]byte, size)buf = buf[:runtime.Stack(buf, false)]log.GetLogger().Error("autoVideoSubtitle panic", zap.Any("panic:", r), zap.Any("stack:", buf))- storage.SubtitleTasks[taskId].Status = types.SubtitleTaskStatusFailed+ stepParam.TaskPtr.Status = types.SubtitleTaskStatusFailed}}()// 新版流程:链接->本地音频文件->视频信息获取(若有)->本地字幕文件->语言合成->视频合成->字幕文件链接生成@@ -136,44 +139,44 @@ func (s Service) StartSubtitleTask(req dto.StartVideoSubtitleTaskReq) (*dto.Starerr = s.linkToFile(ctx, &stepParam)if err != nil {log.GetLogger().Error("StartVideoSubtitleTask linkToFile err", zap.Any("req", req), zap.Error(err))- storage.SubtitleTasks[stepParam.TaskId].Status = types.SubtitleTaskStatusFailed- storage.SubtitleTasks[stepParam.TaskId].FailReason = err.Error()+ stepParam.TaskPtr.Status = types.SubtitleTaskStatusFailed+ stepParam.TaskPtr.FailReason = err.Error()return}// 暂时不加视频信息//err = s.getVideoInfo(ctx, &stepParam)//if err != nil {// log.GetLogger().Error("StartVideoSubtitleTask getVideoInfo err", zap.Any("req", req), zap.Error(err))- // storage.SubtitleTasks[stepParam.TaskId].Status = types.SubtitleTaskStatusFailed- // storage.SubtitleTasks[stepParam.TaskId].FailReason = "get video info error"+ // stepParam.TaskPtr.Status = types.SubtitleTaskStatusFailed+ // stepParam.TaskPtr.FailReason = "get video info error"// return//}err = s.audioToSubtitle(ctx, &stepParam)if err != nil {log.GetLogger().Error("StartVideoSubtitleTask audioToSubtitle err", zap.Any("req", req), zap.Error(err))- storage.SubtitleTasks[stepParam.TaskId].Status = types.SubtitleTaskStatusFailed- storage.SubtitleTasks[stepParam.TaskId].FailReason = err.Error()+ stepParam.TaskPtr.Status = types.SubtitleTaskStatusFailed+ stepParam.TaskPtr.FailReason = err.Error()return}err = s.srtFileToSpeech(ctx, &stepParam)if err != nil {log.GetLogger().Error("StartVideoSubtitleTask srtFileToSpeech err", zap.Any("req", req), zap.Error(err))- storage.SubtitleTasks[stepParam.TaskId].Status = types.SubtitleTaskStatusFailed- storage.SubtitleTasks[stepParam.TaskId].FailReason = err.Error()+ stepParam.TaskPtr.Status = types.SubtitleTaskStatusFailed+ stepParam.TaskPtr.FailReason = err.Error()return}err = s.embedSubtitles(ctx, &stepParam)if err != nil {log.GetLogger().Error("StartVideoSubtitleTask embedSubtitles err", zap.Any("req", req), zap.Error(err))- storage.SubtitleTasks[stepParam.TaskId].Status = types.SubtitleTaskStatusFailed- storage.SubtitleTasks[stepParam.TaskId].FailReason = err.Error()+ stepParam.TaskPtr.Status = types.SubtitleTaskStatusFailed+ stepParam.TaskPtr.FailReason = err.Error()return}err = s.uploadSubtitles(ctx, &stepParam)if err != nil {log.GetLogger().Error("StartVideoSubtitleTask uploadSubtitles err", zap.Any("req", req), zap.Error(err))- storage.SubtitleTasks[stepParam.TaskId].Status = types.SubtitleTaskStatusFailed- storage.SubtitleTasks[stepParam.TaskId].FailReason = err.Error()+ stepParam.TaskPtr.Status = types.SubtitleTaskStatusFailed+ stepParam.TaskPtr.FailReason = err.Error()return}@@ -186,29 +189,30 @@ func (s Service) StartSubtitleTask(req dto.StartVideoSubtitleTaskReq) (*dto.Star}func (s Service) GetTaskStatus(req dto.GetVideoSubtitleTaskReq) (*dto.GetVideoSubtitleTaskResData, error) {- task := storage.SubtitleTasks[req.TaskId]- if task == nil {+ task, ok := storage.SubtitleTasks.Load(req.TaskId)+ if !ok || task == nil {return nil, errors.New("任务不存在")}- if task.Status == types.SubtitleTaskStatusFailed {- return nil, fmt.Errorf("任务失败,原因:%s", task.FailReason)+ taskPtr := task.(*types.SubtitleTask)+ if taskPtr.Status == types.SubtitleTaskStatusFailed {+ return nil, fmt.Errorf("任务失败,原因:%s", taskPtr.FailReason)}return &dto.GetVideoSubtitleTaskResData{- TaskId: task.TaskId,- ProcessPercent: task.ProcessPct,+ TaskId: taskPtr.TaskId,+ ProcessPercent: taskPtr.ProcessPct,VideoInfo: &dto.VideoInfo{- Title: task.Title,- Description: task.Description,- TranslatedTitle: task.TranslatedTitle,- TranslatedDescription: task.TranslatedDescription,+ Title: taskPtr.Title,+ Description: taskPtr.Description,+ TranslatedTitle: taskPtr.TranslatedTitle,+ TranslatedDescription: taskPtr.TranslatedDescription,},- SubtitleInfo: lo.Map(task.SubtitleInfos, func(item types.SubtitleInfo, _ int) *dto.SubtitleInfo {+ SubtitleInfo: lo.Map(taskPtr.SubtitleInfos, func(item types.SubtitleInfo, _ int) *dto.SubtitleInfo {return &dto.SubtitleInfo{Name: item.Name,DownloadUrl: item.DownloadUrl,}}),- TargetLanguage: task.TargetLanguage,- SpeechDownloadUrl: task.SpeechDownloadUrl,+ TargetLanguage: taskPtr.TargetLanguage,+ SpeechDownloadUrl: taskPtr.SpeechDownloadUrl,}, nil}diff --git a/internal/service/upload_subtitle.go b/internal/service/upload_subtitle.goindex 5994c6c5..7470bc70 100644--- a/internal/service/upload_subtitle.go+++ b/internal/service/upload_subtitle.go@@ -4,7 +4,6 @@ import ("context""fmt""go.uber.org/zap"- "krillin-ai/internal/storage""krillin-ai/internal/types""krillin-ai/log""krillin-ai/pkg/util"@@ -31,12 +30,13 @@ func (s Service) uploadSubtitles(ctx context.Context, stepParam *types.SubtitleT})}// 更新字幕任务信息- storage.SubtitleTasks[stepParam.TaskId].SubtitleInfos = subtitleInfos- storage.SubtitleTasks[stepParam.TaskId].Status = types.SubtitleTaskStatusSuccess- storage.SubtitleTasks[stepParam.TaskId].ProcessPct = 100+ taskPtr := stepParam.TaskPtr+ taskPtr.SubtitleInfos = subtitleInfos+ taskPtr.Status = types.SubtitleTaskStatusSuccess+ taskPtr.ProcessPct = 100// 配音文件if stepParam.TtsResultFilePath != "" {- storage.SubtitleTasks[stepParam.TaskId].SpeechDownloadUrl = "/api/file/" + stepParam.TtsResultFilePath+ taskPtr.SpeechDownloadUrl = "/api/file/" + stepParam.TtsResultFilePath}return nil}diff --git a/internal/storage/subtitle_task.go b/internal/storage/subtitle_task.goindex db6c9689..c425a0e5 100644--- a/internal/storage/subtitle_task.go+++ b/internal/storage/subtitle_task.go@@ -1,5 +1,7 @@package storage-import "krillin-ai/internal/types"+import (+ "sync"+)-var SubtitleTasks = make(map[string]*types.SubtitleTask)+var SubtitleTasks = sync.Map{} // task id -> SubtitleTask,用于接口查询数据diff --git a/internal/types/subtitle_task.go b/internal/types/subtitle_task.goindex 1d64c759..99d41c9c 100644--- a/internal/types/subtitle_task.go+++ b/internal/types/subtitle_task.go@@ -234,6 +234,7 @@ type SubtitleFileInfo struct {type SubtitleTaskStepParam struct {TaskId string+ TaskPtr *SubtitleTask // 和storage里面对应TaskBasePath stringLink stringAudioFilePath string