Skip to content

Commit

Permalink
优化英文字幕智能分段处理
Browse files Browse the repository at this point in the history
  • Loading branch information
wxbool committed Nov 20, 2019
1 parent 3aa9d3d commit 1410d8f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
Binary file modified video-srt.exe
Binary file not shown.
60 changes: 47 additions & 13 deletions videosrt/aliyun/cloud/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func AliyunAudioResultWordHandle(result [] byte , callback func (vresult *Aliyun

var symbol = []string{"?","。",",","!",";","?",".",",","!"}
//数据集处理
for _,value := range audioResult {
for _ , value := range audioResult {
for _ , data := range value {
data.Blocks = GetTextBlock(data.Text)
data.Text = ReplaceStrs(data.Text , symbol , "")
Expand Down Expand Up @@ -111,29 +111,29 @@ func AliyunAudioResultWordHandle(result [] byte , callback func (vresult *Aliyun
if word.ChannelId != channel {
continue
}
for _ , w := range p {
for windex , w := range p {
if word.BeginTime >= w.BeginTime && word.EndTime <= w.EndTime {
flag := false
for t , B := range w.Blocks{
if blockRune >= B && B != -1 {
//fmt.Println(blockRune , B , lastBlock , (B - lastBlock))
if (blockRune >= B) && B != -1 {
flag = true

//fmt.Println( block )
//fmt.Println( w.Text )
//fmt.Println( w.Blocks )
//fmt.Println( blockRune , B , lastBlock , (B - lastBlock) )

var thisText = ""
//容错机制
if t == (len(w.Blocks) - 1) {
thisText = SubString(block , lastBlock , blockRune)
thisText = SubString(w.Text , lastBlock , 10000)
} else {
thisText = SubString(block , lastBlock , (B - lastBlock))
thisText = SubString(w.Text , lastBlock , (B - lastBlock))
}

lastBlock = B
w.Blocks[t] = -1

//fmt.Println("thisText" , thisText)
//fmt.Println("BeginTime" , beginTime)
//fmt.Println("EndTime" , word.EndTime)
//fmt.Println("w.Blocks" , w.Blocks)
//fmt.Println("\n\n")

vresult := &AliyunAudioRecognitionResult{
Text:thisText,
ChannelId:channel,
Expand All @@ -155,6 +155,40 @@ func AliyunAudioResultWordHandle(result [] byte , callback func (vresult *Aliyun
block = ""
lastBlock = 0
}

//容错机制
if FindSliceIntCount(w.Blocks , -1) == (len(w.Blocks)-1) && flag == false {
var thisText = SubString(w.Text , lastBlock , 10000)

w.Blocks[len(w.Blocks) - 1] = -1
//vresult
vresult := &AliyunAudioRecognitionResult{
Text:thisText,
ChannelId:channel,
BeginTime:beginTime,
EndTime:w.EndTime,
SilenceDuration:w.SilenceDuration,
SpeechRate:w.SpeechRate,
EmotionValue:w.EmotionValue,
}

//fmt.Println( thisText )
//fmt.Println( block )
//fmt.Println( word.Word , beginTime, w.EndTime , flag , word.EndTime )

callback(vresult) //回调传参

//覆盖下一段落的时间戳
if windex < (len(p)-1) {
beginTime = p[windex+1].BeginTime
} else {
beginTime = w.EndTime
}

//清除参数
block = ""
lastBlock = 0
}
}
}
}
Expand Down Expand Up @@ -214,7 +248,7 @@ func IndexRunes(strs string , olds []rune) int {
}

func GetTextBlock(strs string) ([]int) {
var symbol_zhcn = []rune{'?','。',',','!',';'}
var symbol_zhcn = []rune{'?','。',',','!',';','?','.',',','!'}
//var symbol_en = []rune{'?','.',',','!'}
strsRune := []rune(strs)

Expand Down
4 changes: 1 addition & 3 deletions videosrt/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ func ReadConfig (cfg string) *VideoSrt {
panic(e);
} else {
appconfig := &VideoSrt{}
//取消
//appconfig.Ffmpeg.Os = file.GetMust("ffmpeg.os" , "")


//AliyunOss
appconfig.AliyunOss.Endpoint = file.GetMust("aliyunOss.endpoint" , "")
appconfig.AliyunOss.AccessKeyId = file.GetMust("aliyunOss.accessKeyId" , "")
Expand Down

0 comments on commit 1410d8f

Please sign in to comment.