Skip to content

Commit

Permalink
支持 百度翻译【个人标准版】 配置
Browse files Browse the repository at this point in the history
  • Loading branch information
wxbool committed Dec 27, 2019
1 parent a3fc1f5 commit 333c2ea
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
15 changes: 15 additions & 0 deletions app/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ type AliyunOssCache struct {
aliyun.AliyunOss
}

//百度翻译账号认证类型选项
type BaiduAuthTypeSelects struct {
Id int
Name string
}

//软件翻译接口 - 缓存结构
type TranslateCache struct {
translate.BaiduTranslate //百度翻译
Expand Down Expand Up @@ -233,6 +239,15 @@ func GetCurrentIndex(data []*EngineSelects , id int) int {
}


//获取 百度翻译账号认证类型
func GetBaiduTranslateAuthenTypeOptionsSelects() []*BaiduAuthTypeSelects {
return []*BaiduAuthTypeSelects{
&BaiduAuthTypeSelects{Id:translate.ACCOUNT_COMMON_AUTHEN , Name:"标准版"},
&BaiduAuthTypeSelects{Id:translate.ACCOUNT_SENIOR_AUTHEN , Name:"高级版"},
}
}


//获取 输出文件选项列表
func GetOutputOptionsSelects() []*OutputSelects {
return []*OutputSelects{
Expand Down
16 changes: 16 additions & 0 deletions app/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"strings"
"videosrt/app/tool"
"videosrt/app/translate"
)

type MyMainWindow struct {
Expand Down Expand Up @@ -421,6 +422,10 @@ func (mw *MyMainWindow) RunTranslateSetingDialog(owner walk.Form) {

translateData = GetCacheTranslateSettings() //查询缓存数据

if translateData.AuthenType == 0 {
translateData.AuthenType = translate.ACCOUNT_SENIOR_AUTHEN //默认账户认证类型
}

Dialog{
AssignTo: &dlg,
Title: "翻译设置",
Expand Down Expand Up @@ -461,6 +466,17 @@ func (mw *MyMainWindow) RunTranslateSetingDialog(owner walk.Form) {
MinSize:Size{Width:100 , Height:20},
},

Label{
Text: "账号认证类型:",
},
ComboBox{
ColumnSpan: 3,
Value: Bind("AuthenType", SelRequired{}),
BindingMember: "Id",
DisplayMember: "Name",
Model: GetBaiduTranslateAuthenTypeOptionsSelects(),
},

Label{
Text: "AppId:",
},
Expand Down
5 changes: 5 additions & 0 deletions app/translate/baidu.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
type BaiduTranslate struct {
AppId string //appid
AppSecret string //appsecret
AuthenType int //账号认证类型
}

//百度翻译结果集
Expand All @@ -29,6 +30,10 @@ type BaiduTranslateResult struct {
//常量
const (
TRANS_API string = "https://fanyi-api.baidu.com/api/trans/vip/translate"

//账号认证类型
ACCOUNT_COMMON_AUTHEN int = 1 //标准版
ACCOUNT_SENIOR_AUTHEN int = 2 //高级版
)


Expand Down
27 changes: 23 additions & 4 deletions app/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func NewApp(appDir string) *VideoSrt {
app.AppDir = appDir
app.OutputType = OUTPUT_SRT
app.OutputEncode = OUTPUT_ENCODE_UTF8 //默认输出文件编码

app.BaiduTranslate.AuthenType = translate.ACCOUNT_SENIOR_AUTHEN; //默认百度翻译账号认证类型
return app
}

Expand All @@ -68,6 +70,9 @@ func (app *VideoSrt) InitConfig(oss *AliyunOssCache , engine *AliyunEngineCache
//translate
app.BaiduTranslate.AppId = trans.AppId
app.BaiduTranslate.AppSecret = trans.AppSecret
if trans.AuthenType != 0 {
app.BaiduTranslate.AuthenType = trans.AuthenType
}
app.AutoTranslation = trans.AutoTranslation
app.BilingualSubtitles = trans.BilingualSubtitles
}
Expand Down Expand Up @@ -331,6 +336,10 @@ func AliyunAudioResultMakeSubtitleFile(app *VideoSrt , video string , AudioResul
//日志
if app.AutoTranslation || app.BilingualSubtitles {
app.Log("字幕翻译处理中 ..." , video)

if app.BaiduTranslate.AuthenType == translate.ACCOUNT_COMMON_AUTHEN {
app.Log("你使用的是 “标准版” 账号,翻译速度较慢,请耐心等待 ..." , video)
}
}

//根据音轨,输出文件
Expand Down Expand Up @@ -377,8 +386,13 @@ func AliyunAudioResultMakeSubtitleFile(app *VideoSrt , video string , AudioResul
}
datastr = transResult.TransResultDst //译文

//休眠100毫秒
time.Sleep(time.Millisecond * 100)
if app.BaiduTranslate.AuthenType == translate.ACCOUNT_COMMON_AUTHEN {
//休眠900毫秒
time.Sleep(time.Millisecond * 900)
} else {
//休眠100毫秒
time.Sleep(time.Millisecond * 100)
}
} else {
datastr = data.Text
}
Expand Down Expand Up @@ -429,8 +443,13 @@ func MakeSubtitleText(app *VideoSrt, index int , startTime int64 , endTime int64
content.WriteString("\r\n")
content.WriteString(other)

//休眠100毫秒
time.Sleep(time.Millisecond * 100)
if app.BaiduTranslate.AuthenType == translate.ACCOUNT_COMMON_AUTHEN {
//休眠900毫秒
time.Sleep(time.Millisecond * 900)
} else {
//休眠100毫秒
time.Sleep(time.Millisecond * 100)
}
} else {
content.WriteString(text)
}
Expand Down

0 comments on commit 333c2ea

Please sign in to comment.