Skip to content

Commit

Permalink
1.优化软件界面,操作更方便
Browse files Browse the repository at this point in the history
2.支持输出LRC文件
  • Loading branch information
wxbool committed Dec 29, 2019
1 parent 2ce52ac commit e4465bb
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 67 deletions.
61 changes: 60 additions & 1 deletion app/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ var oss,translates,engine,setings *datacache.AppCache

//输出文件类型
const(
OUTPUT_SRT = 1 //字幕文件
OUTPUT_SRT = 1 //字幕SRT文件
OUTPUT_STRING = 2 //普通文本
OUTPUT_LRC = 3 //LRC文本
)

//输出文件编码
Expand All @@ -40,8 +41,66 @@ func init() {
//设置表单
type OperateFrom struct {
EngineId int

OutputSrt bool
OutputLrc bool
OutputTxt bool

OutputType int
OutputEncode int //输出文件编码
SoundTrack int //输出音轨
}

func (from *OperateFrom) Init(setings *AppSetings) {
if setings.CurrentEngineId != 0 {
from.EngineId = setings.CurrentEngineId
}
if setings.OutputType == 0 {
from.OutputType = OUTPUT_SRT
from.OutputSrt = true
} else {
from.OutputType = setings.OutputType
if setings.OutputType == OUTPUT_SRT {
from.OutputSrt = true
}
if setings.OutputType == OUTPUT_STRING {
from.OutputTxt = true
}
if setings.OutputType == OUTPUT_LRC {
from.OutputLrc = true
}
}
if setings.OutputEncode == 0 {
from.OutputEncode = OUTPUT_ENCODE_UTF8 //默认编码
} else {
from.OutputEncode = setings.OutputEncode
}
from.SoundTrack = setings.SoundTrack
}

func (from *OperateFrom) LoadOutputType(t int) {
if OUTPUT_SRT != t {
from.OutputSrt = false
}
if OUTPUT_LRC != t {
from.OutputLrc = false
}
if OUTPUT_STRING != t {
from.OutputTxt = false
}

if from.OutputSrt {
from.OutputType = OUTPUT_SRT
} else if from.OutputLrc {
from.OutputType = OUTPUT_LRC
} else if from.OutputTxt {
from.OutputType = OUTPUT_STRING
} else {
from.OutputType = 0
}
}


//引擎选项
type EngineSelects struct {
Id int
Expand Down
34 changes: 0 additions & 34 deletions app/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,40 +64,6 @@ func(mw *MyMainWindow) RunAppSetingDialog(owner walk.Form , confirmCall func(*Ap
Composite{
Layout: Grid{Columns: 2},
Children: []Widget{

//输出文件类型
Label{
Text: "输出文件类型:",
},
ComboBox{
Value: Bind("OutputType", SelRequired{}),
BindingMember: "Id",
DisplayMember: "Name",
Model: GetOutputOptionsSelects(),
},

//输出文件编码
Label{
Text: "输出文件编码:",
},
ComboBox{
Value: Bind("OutputEncode", SelRequired{}),
BindingMember: "Id",
DisplayMember: "Name",
Model: GetOutputEncodeOptionsSelects(),
},


Label{
Text: "输出音轨:",
},
ComboBox{
Value: Bind("SoundTrack", SelRequired{}),
BindingMember: "Id",
DisplayMember: "Name",
Model: GetSoundTrackSelects(),
},

Label{
Text: "任务处理并发数:",
},
Expand Down
33 changes: 31 additions & 2 deletions app/tool/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func GetIntRandomNumber(min int64 , max int64) int64 {
}

//字幕时间戳转换
func SubtitleTimeMillisecond(time int64) string {
func SubtitleTimeMillisecond(time int64 , showMillisecond bool) string {
var miao int64 = 0
var min int64 = 0
var hours int64 = 0
Expand All @@ -138,7 +138,36 @@ func SubtitleTimeMillisecond(time int64) string {
var hoursText = RepeatStr(strconv.FormatInt(hours , 10) , "0" , 2 , true)
var millisecondText = RepeatStr(strconv.FormatInt(millisecond , 10) , "0" , 3 , true)

return hoursText + ":" + minText + ":" + miaoText + "," + millisecondText
if showMillisecond {
return hoursText + ":" + minText + ":" + miaoText + "," + millisecondText
}
return hoursText + ":" + minText + ":" + miaoText
}



//歌词时间戳转换
func MusicLrcTextMillisecond(time int64) string {
var miao int64 = 0
var min int64 = 0
var millisecond int64 = 0

millisecond = (time % 1000)
miao = (time / 1000)

if miao > 59 {
min = (time / 1000) / 60
miao = miao % 60
}

millisecond = millisecond / 10

//00:00:06,770
var miaoText = RepeatStr(strconv.FormatInt(miao , 10) , "0" , 2 , true)
var minText = RepeatStr(strconv.FormatInt(min , 10) , "0" , 2 , true)
var millisecondText = RepeatStr(strconv.FormatInt(millisecond , 10) , "0" , 2 , true)

return minText + ":" + miaoText + ":" + millisecondText
}


Expand Down
42 changes: 34 additions & 8 deletions app/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path"
"strconv"
"strings"
"time"
"videosrt/app/aliyun"
"videosrt/app/ffmpeg"
Expand Down Expand Up @@ -154,10 +155,10 @@ func (app *VideoSrt) Run(video string) {
}()

//智能分段校验
if app.OutputType == OUTPUT_SRT {
app.IntelligentBlock = true
} else {
if app.OutputType == OUTPUT_STRING {
app.IntelligentBlock = false //非输出字幕文件 关闭智能分段
} else {
app.IntelligentBlock = true
}

if video == "" {
Expand Down Expand Up @@ -356,8 +357,10 @@ func AliyunAudioResultMakeSubtitleFile(app *VideoSrt , video string , AudioResul
//输出文件类型
if app.OutputType == OUTPUT_SRT {
thisfile += ".srt"
} else {
} else if app.OutputType == OUTPUT_STRING {
thisfile += ".txt"
} else if app.OutputType == OUTPUT_LRC {
thisfile += ".lrc"
}

file, e := os.Create(thisfile)
Expand All @@ -372,6 +375,11 @@ func AliyunAudioResultMakeSubtitleFile(app *VideoSrt , video string , AudioResul
}
}

//歌词头
if app.OutputType == OUTPUT_LRC {
_,_ = file.WriteString("[ar:]\r\n[ti:]\r\n[al:]\r\n[by:]\r\n")
}

index := 0
for _ , data := range result {
var linestr string
Expand All @@ -397,17 +405,23 @@ func AliyunAudioResultMakeSubtitleFile(app *VideoSrt , video string , AudioResul
datastr = data.Text
}

datastr = strings.TrimSpace(datastr)

//拼接文本
if app.OutputType == OUTPUT_SRT {
linestr = MakeSubtitleText(app , index , data.BeginTime , data.EndTime , datastr , app.BilingualSubtitles)
} else {
} else if app.OutputType == OUTPUT_STRING {
linestr = MakeText(index , data.BeginTime , data.EndTime , datastr)
} else if app.OutputType == OUTPUT_LRC {
linestr = MakeMusicLrcText(index , data.BeginTime , data.EndTime , datastr)
}

if _, e = file.WriteString(linestr);e != nil {
panic(e)
}
index++
}

//close
_ = file.Close()
}
Expand All @@ -419,9 +433,9 @@ func MakeSubtitleText(app *VideoSrt, index int , startTime int64 , endTime int64
var content bytes.Buffer
content.WriteString(strconv.Itoa(index))
content.WriteString("\r\n")
content.WriteString(tool.SubtitleTimeMillisecond(startTime))
content.WriteString(tool.SubtitleTimeMillisecond(startTime , true))
content.WriteString(" --> ")
content.WriteString(tool.SubtitleTimeMillisecond(endTime))
content.WriteString(tool.SubtitleTimeMillisecond(endTime , true))
content.WriteString("\r\n")

//双语字幕
Expand Down Expand Up @@ -460,11 +474,23 @@ func MakeSubtitleText(app *VideoSrt, index int , startTime int64 , endTime int64
}


//拼接文本
//拼接文本格式
func MakeText(index int , startTime int64 , endTime int64 , text string) string {
var content bytes.Buffer
content.WriteString(text)
content.WriteString("\r\n")
content.WriteString("\r\n")
return content.String()
}


//拼接歌词文本
func MakeMusicLrcText(index int , startTime int64 , endTime int64 , text string) string {
var content bytes.Buffer
content.WriteString("[")
content.WriteString(tool.MusicLrcTextMillisecond(startTime))
content.WriteString("]")
content.WriteString(text)
content.WriteString("\r\n")
return content.String()
}
Loading

0 comments on commit e4465bb

Please sign in to comment.