package main
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"log"
"runtime"
"strings"
"time"
. "videosrt/app"
"videosrt/app/ffmpeg"
"videosrt/app/tool"
)
//应用版本号
const APP_VERSION = "0.3.5"
var AppRootDir string
var mw *MyMainWindow
var (
outputSrtChecked *walk.CheckBox
outputLrcChecked *walk.CheckBox
outputTxtChecked *walk.CheckBox
globalFilterChecked *walk.CheckBox
definedFilterChecked *walk.CheckBox
)
func init() {
//设置可同时执行的最大CPU数
runtime.GOMAXPROCS(runtime.NumCPU())
//MY Window
mw = new(MyMainWindow)
AppRootDir = GetAppRootDir()
if AppRootDir == "" {
panic("应用根目录获取失败")
}
//校验ffmpeg环境
if e := ffmpeg.VailFfmpegLibrary(); e != nil {
//尝试自动引入 ffmpeg 环境
ffmpeg.VailTempFfmpegLibrary(AppRootDir)
}
}
func main() {
var taskFiles = new(TaskHandleFile)
var logText *walk.TextEdit
var operateEngineDb *walk.DataBinder
var operateTranslateEngineDb *walk.DataBinder
var operateTranslateDb *walk.DataBinder
var operateDb *walk.DataBinder
var operateFilter *walk.DataBinder
var operateFrom = new(OperateFrom)
var startBtn *walk.PushButton //生成字幕Btn
var startTranslateBtn *walk.PushButton //字幕翻译Btn
var engineOptionsBox *walk.ComboBox
var translateEngineOptionsBox *walk.ComboBox
var dropFilesEdit *walk.TextEdit
var appSetings = Setings.GetCacheAppSetingsData()
var appFilter = Filter.GetCacheAppFilterData()
//初始化展示配置
operateFrom.Init(appSetings)
//日志
var tasklog = NewTasklog(logText)
//字幕生成应用
var videosrt = NewApp(AppRootDir)
//注册日志事件
videosrt.SetLogHandler(func(s string, video string) {
baseName := tool.GetFileBaseName(video)
strs := strings.Join([]string{"【" , baseName , "】" , s} , "")
//追加日志
tasklog.AppendLogText(strs)
})
//字幕输出目录
videosrt.SetSrtDir(appSetings.SrtFileDir)
//注册[字幕生成]多任务
var multitask = NewVideoMultitask(appSetings.MaxConcurrency)
//字幕翻译应用
var srtTranslateApp = NewSrtTranslateApp(AppRootDir)
//注册日志回调事件
srtTranslateApp.SetLogHandler(func(s string, file string) {
baseName := tool.GetFileBaseName(file)
strs := strings.Join([]string{"【" , baseName , "】" , s} , "")
//追加日志
tasklog.AppendLogText(strs)
})
//文件输出目录
srtTranslateApp.SetSrtDir(appSetings.SrtFileDir)
//注册[字幕翻译]多任务
var srtTranslateMultitask = NewTranslateMultitask(appSetings.MaxConcurrency)
if err := (MainWindow{
AssignTo: &mw.MainWindow,
Icon:"./data/img/index.png",
Title: "VideoSrt - 一键字幕生成、字幕翻译小工具" + " - " + APP_VERSION,
Font:Font{Family: "微软雅黑", PointSize: 9},
ToolBar: ToolBar{
ButtonStyle: ToolBarButtonImageBeforeText,
Items: []MenuItem{
Menu{
Text:"打开",
Image: "./data/img/open.png",
Items: []MenuItem{
Action{
Image: "./data/img/media.png",
Text: "媒体文件",
OnTriggered: func() {
dlg := new(walk.FileDialog)
//选择待操作的文件列表
//dlg.FilePath = mw.prevFilePath
dlg.Filter = "Media Files (*.mp4;*.mpeg;*.mkv;*.wmv;*.avi;*.m4v;*.mov;*.flv;*.rmvb;*.3gp;*.f4v;*.mp3;*.wav;*.aac;*.wma;*.flac;*.m4a;*.srt)|*.mp4;*.mpeg;*.mkv;*.wmv;*.avi;*.m4v;*.mov;*.flv;*.rmvb;*.3gp;*.f4v;*.mp3;*.wav;*.aac;*.wma;*.flac;*.m4a;*.srt"
dlg.Title = "选择待操作的媒体文件"
ok, err := dlg.ShowOpenMultiple(mw);
if err != nil {
mw.NewErrormationTips("错误" , err.Error())
return
}
if ok == false {
return
}
//校验文件数量
if len(dlg.FilePaths) == 0 {
return
}
//检测文件列表
result , err := VaildateHandleFiles(dlg.FilePaths , true , true)
if err != nil {
mw.NewErrormationTips("错误" , err.Error())
return
}
taskFiles.Files = result
dropFilesEdit.SetText(strings.Join(result, "\r\n"))
},
},
},
},
Menu{
Text: "新建",
Image: "./data/img/new.png",
Items: []MenuItem{
Action{
Image: "./data/img/voice.png",
Text: "语音引擎(阿里云)",
OnTriggered: func() {
mw.RunSpeechEngineSetingDialog(mw , func() {
thisData := Engine.GetEngineOptionsSelects()
//校验选择的翻译引擎是否存在
_ , ok := Engine.GetEngineById(appSetings.CurrentEngineId)
if appSetings.CurrentEngineId == 0 || !ok {
appSetings.CurrentEngineId = thisData[0].Id
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
}
//重新加载选项
_ = engineOptionsBox.SetModel(thisData)
//重置index
engIndex := Engine.GetCurrentIndex(thisData , appSetings.CurrentEngineId)
if engIndex != -1 {
_ = engineOptionsBox.SetCurrentIndex(engIndex)
}
operateFrom.EngineId = appSetings.CurrentEngineId
})
},
},
Action{
Image: "./data/img/translate.png",
Text: "翻译引擎(百度翻译)",
OnTriggered: func() {
mw.RunBaiduTranslateEngineSetingDialog(mw , func() {
thisData := Translate.GetTranslateEngineOptionsSelects()
//校验选择的翻译引擎是否存在
_ , ok := Engine.GetEngineById(appSetings.CurrentEngineId)
if appSetings.CurrentTranslateEngineId == 0 || !ok {
appSetings.CurrentTranslateEngineId = thisData[0].Id
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
}
//重新加载选项
_ = translateEngineOptionsBox.SetModel(thisData)
//重置index
engIndex := Translate.GetCurrentTranslateEngineIndex(thisData , appSetings.CurrentTranslateEngineId)
if engIndex != -1 {
_ = translateEngineOptionsBox.SetCurrentIndex(engIndex)
}
operateFrom.TranslateEngineId = appSetings.CurrentTranslateEngineId
})
},
},
Action{
Image: "./data/img/translate.png",
Text: "翻译引擎(腾讯云)",
OnTriggered: func() {
mw.RunTengxunyunTranslateEngineSetingDialog(mw , func() {
thisData := Translate.GetTranslateEngineOptionsSelects()
if appSetings.CurrentTranslateEngineId == 0 {
appSetings.CurrentTranslateEngineId = thisData[0].Id
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
}
//重新加载选项
_ = translateEngineOptionsBox.SetModel(thisData)
//重置index
engIndex := Translate.GetCurrentTranslateEngineIndex(thisData , appSetings.CurrentTranslateEngineId)
if engIndex != -1 {
_ = translateEngineOptionsBox.SetCurrentIndex(engIndex)
}
operateFrom.TranslateEngineId = appSetings.CurrentTranslateEngineId
})
},
},
},
},
Menu{
Text: "设置",
Image: "./data/img/setings.png",
Items: []MenuItem{
Action{
Text: "OSS对象存储设置",
Image: "./data/img/oss.png",
OnTriggered: func() {
mw.RunObjectStorageSetingDialog(mw)
},
},
Action{
Text: "软件设置",
Image: "./data/img/app-setings.png",
OnTriggered: func() {
mw.RunAppSetingDialog(mw , func(setings *AppSetings) {
//更新配置
appSetings.MaxConcurrency = setings.MaxConcurrency
appSetings.SrtFileDir = setings.SrtFileDir
appSetings.CloseNewVersionMessage = setings.CloseNewVersionMessage
appSetings.CloseAutoDeleteOssTempFile = setings.CloseAutoDeleteOssTempFile
appSetings.CloseIntelligentBlockSwitch = setings.CloseIntelligentBlockSwitch
multitask.SetMaxConcurrencyNumber( setings.MaxConcurren
没有合适的资源?快使用搜索试试~ 我知道了~
VideoSrt 是用 Golang语言,基于 lxn/walk Windows-GUI 工具包开发
共43个文件
go:22个
png:14个
syso:1个
需积分: 5 2 下载量 47 浏览量
2023-08-05
09:56:54
上传
评论
收藏 67KB ZIP 举报
温馨提示
VideoSrt 是用 Golang语言,基于 lxn/walk Windows-GUI 工具包开发。这是一个可以识别视频语音自动生成字幕SRT文件的开源软件工具。适用于快速、批量的为媒体(视频/音频)生成中/英文字幕、文本文件的业务场景。0.3.5 版本将会使用以下接口:阿里云 OSS对象存储。阿里云 录音文件识别。百度翻译开放平台 翻译API。腾讯云 翻译API
资源推荐
资源详情
资源评论
收起资源包目录
video-srt-windows-master.zip (43个子文件)
video-srt-windows-master
go.mod 1KB
.github
workflows
go.yml 1KB
app
log.go 442B
ffmpeg
ffmpeg.go 1KB
event.go 27KB
app_tool.go 2KB
tool
chinese_simple.go 2KB
tool.go 5KB
version.go 2KB
aliyun
oss.go 2KB
tool.go 10KB
engine.go 9KB
task.go 2KB
translate
tengxunyun.go 3KB
baidu.go 3KB
task_tanslate.go 2KB
parse
tool.go 2KB
srt.go 3KB
srt.go 13KB
video.go 23KB
datacache
json.go 548B
cache.go 881B
data.go 16KB
data
img
new.png 292B
voice.png 551B
setings.png 374B
app.ico 1KB
app-setings.png 407B
about.png 400B
oss.png 376B
media.png 344B
index.png 438B
open.png 369B
translate.png 388B
gitee.png 297B
github.png 452B
muyan.png 491B
version.png 371B
LICENSE 18KB
main.manifest 875B
.gitignore 42B
rsrc.syso 2KB
main.go 32KB
共 43 条
- 1
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7367
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功