Skip to content

Commit

Permalink
发布 0.3.0 版本
Browse files Browse the repository at this point in the history
1.支持语气词过滤、自定义文本过滤、自定义正则过滤功能;【生成字幕】 、【字幕处理】 功能均支持。
2.支持翻译更多语种(法语、德语、西班牙语、俄语、意大利语、泰语)
3.优化【生成字幕】功能翻译失败时,程序将强行关闭翻译,直接生成原始语言的字幕文件,降低失败损失
4.修复部分日语识别不出字幕文件 bug
  • Loading branch information
wxbool committed Jul 25, 2020
1 parent e983068 commit edfae07
Show file tree
Hide file tree
Showing 11 changed files with 913 additions and 95 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

这是一个可以识别视频语音自动生成字幕SRT文件的开源软件工具。<br />适用于快速、批量的为媒体(视频/音频)生成中/英文字幕、文本文件的业务场景。

0.2.9 版本将会使用以下接口:
0.3.0 版本将会使用以下接口:
- 阿里云 [OSS对象存储](https://www.aliyun.com/product/oss?spm=5176.12825654.eofdhaal5.13.e9392c4aGfj5vj&aly_as=K11FcpO8)
- 阿里云 [录音文件识别](https://ai.aliyun.com/nls/filetrans?spm=5176.12061031.1228726.1.47fe3cb43I34mn)
- 百度翻译开放平台 [翻译API](http://api.fanyi.baidu.com/api/trans/product/index)
Expand All @@ -25,7 +25,7 @@ CLI(命令行)版本:[https://github.com/wxbool/video-srt](https://github.

- 识别**视频/音频**的语音生成字幕文件(支持中英互译,双语字幕)
- 提取**视频/音频**的语音文本
- 批量翻译、编码SRT字幕文件
- 批量翻译、过滤处理/编码SRT字幕文件


<a name="b89d37d3"></a>
Expand All @@ -36,7 +36,8 @@ CLI(命令行)版本:[https://github.com/wxbool/video-srt](https://github.
- 支持多任务多文件批量处理
- 支持视频、音频常见多种格式文件
- 支持同时输出字幕SRT文件、LRC文件、普通文本3种类型
- 支持字幕中英互译、双语字幕输出
- 支持语气词过滤、自定义文本过滤、正则过滤等,使软件生成的字幕更加精准
- 支持字幕中英互译、双语字幕输出,及日语、韩语、法语、德语、西班牙语、俄语、意大利语、泰语等
- 支持多翻译引擎(百度翻译、腾讯云翻译)
- 支持批量翻译、编码SRT字幕文件

Expand All @@ -45,8 +46,8 @@ CLI(命令行)版本:[https://github.com/wxbool/video-srt](https://github.

<a name="e66a66f1"></a>
##### 下载地址:
- (v0.2.9.5)(含ffmpeg依赖) [点我下载](http://file.viggo.site/video-srt/0.2.9.5/video-srt-gui-ffmpeg-0.2.9.5-x64.zip)
- (v0.2.9.5)(不含ffmpeg依赖) [点我下载](http://file.viggo.site/video-srt/0.2.9.5/video-srt-gui-0.2.9.5-x64.zip)
- (v0.3.0)(含ffmpeg依赖) [点我下载](http://file.viggo.site/video-srt/0.3.0/video-srt-gui-ffmpeg-0.3.0-x64.zip)
- (v0.3.0)(不含ffmpeg依赖) [点我下载](http://file.viggo.site/video-srt/0.3.0/video-srt-gui-0.3.0-x64.zip)
- (v0.2.6)(含ffmpeg依赖) [点我下载](http://file.viggo.site/video-srt/0.2.6/video-srt-gui-ffmpeg-0.2.6-x64.zip)
- (v0.2.6)(不含ffmpeg依赖) [点我下载](http://file.viggo.site/video-srt/0.2.6/video-srt-gui-0.2.6-x64.zip)

Expand All @@ -63,7 +64,7 @@ CLI(命令行)版本:[https://github.com/wxbool/video-srt](https://github.

- 先下载最新版本的软件包
- 然后用旧版本软件的 `data` 文件夹覆盖新版软件的 `data` 文件夹
- 0.2.6 升级至 0.2.9时,翻译设置无法直接兼容低版本,需要重新手动创建翻译引擎才能继续使用翻译功能
- 0.2.6 升级至 0.2.9 以上的版本时,由于翻译设置无法直接兼容低版本,可能需要重新在软件创建翻译引擎才能继续使用翻译功能

## FAQ
##### 1.为什么Linux和Mac不能用?
Expand Down
167 changes: 98 additions & 69 deletions app/aliyun/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
type AliyunAudioRecognitionResultBlock struct {
AliyunAudioRecognitionResult
Blocks []int
BlockEmptyTag bool
BlockEmptyHandle bool
}

//阿里云录音录音文件识别 - 智能分段处理
Expand Down Expand Up @@ -87,6 +89,10 @@ func AliyunAudioResultWordHandle(result [] byte , callback func (vresult *Aliyun
for _ , data := range value {
data.Blocks = GetTextBlock(data.Text)
data.Text = ReplaceStrs(data.Text , symbol , "")

if len(data.Blocks) == 0 {
data.BlockEmptyTag = true
}
}
}

Expand Down Expand Up @@ -144,101 +150,124 @@ func AliyunAudioResultWordHandle(result [] byte , callback func (vresult *Aliyun
flag := false
early := false

for t , B := range w.Blocks{
//fmt.Println("blockRune : " , blockRune , B , word.Word)
if ((blockRune >= B) || (blockRune + chineseNumberDiffLength >= B)) && B != -1 {
flag = true

//fmt.Println( w.Blocks )
//fmt.Println(B , lastBlock , (B - lastBlock) , word.Word)
//fmt.Println(w.Text)
//fmt.Println( block )
//fmt.Println("\n\n\n")

var thisText = ""
//容错机制
if t == (len(w.Blocks) - 1) {
thisText = SubString(w.Text , lastBlock , 10000)
} else {
//下个词提前结束
if i < len(value)-1 && value[i+1].BeginTime >= w.EndTime{
if !w.BlockEmptyTag {
for t , B := range w.Blocks{
//fmt.Println("blockRune : " , blockRune , B , word.Word)
if ((blockRune >= B) || (blockRune + chineseNumberDiffLength >= B)) && B != -1 {
flag = true

//fmt.Println( w.Blocks )
//fmt.Println(B , lastBlock , (B - lastBlock) , word.Word)
//fmt.Println(w.Text)
//fmt.Println( block )
//fmt.Println("\n\n\n")

var thisText = ""
//容错机制
if t == (len(w.Blocks) - 1) {
thisText = SubString(w.Text , lastBlock , 10000)
early = true
} else {
thisText = SubString(w.Text , lastBlock , (B - lastBlock))
//下个词提前结束
if i < len(value)-1 && value[i+1].BeginTime >= w.EndTime{
thisText = SubString(w.Text , lastBlock , 10000)
early = true
} else {
thisText = SubString(w.Text , lastBlock , (B - lastBlock))
}
}
}

lastBlock = B
if early == true {
//全部设置为-1
for vt,vb := range w.Blocks{
if vb != -1 {
w.Blocks[vt] = -1;
lastBlock = B
if early == true {
//全部设置为-1
for vt,vb := range w.Blocks{
if vb != -1 {
w.Blocks[vt] = -1;
}
}
} else {
w.Blocks[t] = -1
}
} else {
w.Blocks[t] = -1

vresult := &AliyunAudioRecognitionResult{
Text:thisText,
ChannelId:channel,
BeginTime:beginTime,
EndTime:word.EndTime,
SilenceDuration:w.SilenceDuration,
SpeechRate:w.SpeechRate,
EmotionValue:w.EmotionValue,
}
callback(vresult) //回调传参

blockBool = true
break
}
}

//fmt.Println("word.Word : " , word.Word)
//fmt.Println(block)

if FindSliceIntCount(w.Blocks , -1) == len(w.Blocks) {
//全部截取完成
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:word.EndTime,
EndTime:w.EndTime,
SilenceDuration:w.SilenceDuration,
SpeechRate:w.SpeechRate,
EmotionValue:w.EmotionValue,
}
callback(vresult) //回调传参

blockBool = true
break
}
}

//fmt.Println("word.Word : " , word.Word)
//fmt.Println(block)

if FindSliceIntCount(w.Blocks , -1) == len(w.Blocks) {
//全部截取完成
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 )

//fmt.Println( thisText )
//fmt.Println( block )
//fmt.Println( word.Word , beginTime, w.EndTime , flag , word.EndTime )
callback(vresult) //回调传参

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

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

//清除参数
block = ""
lastBlock = 0
blockBool = true

if w.BlockEmptyHandle == false {
vresult := &AliyunAudioRecognitionResult{
Text:w.Text,
ChannelId:w.ChannelId,
BeginTime:w.BeginTime,
EndTime:w.EndTime,
SilenceDuration:w.SilenceDuration,
SpeechRate:w.SpeechRate,
EmotionValue:w.EmotionValue,
}
callback(vresult) //回调传参
w.BlockEmptyHandle = true
}

}

}
}
}
Expand Down
38 changes: 38 additions & 0 deletions app/app_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,48 @@ package app

import (
"bytes"
"regexp"
"strconv"
"strings"
"videosrt/app/tool"
)


//语气词过滤
func ModalWordsFilter(s string , w string) string {
tmpText := strings.ReplaceAll(s , w , "")
if strings.TrimSpace(tmpText) == "" || tool.CheckOnlySymbolText(strings.TrimSpace(tmpText)) {
return ""
} else {
//尝试过滤重复语气词
compile, e := regexp.Compile(w + "{2,}")
if e != nil {
return s
}
return compile.ReplaceAllString(s , "")
}
}

//自定义规则过滤
func DefinedWordRuleFilter(s string , rule *AppDefinedFilterRule) string {
if rule.Way == FILTER_TYPE_STRING {
//文本过滤
s = strings.ReplaceAll(s , rule.Target , rule.Replace)
} else if rule.Way == FILTER_TYPE_REGX {
//正则过滤
compile, e := regexp.Compile(rule.Target)
if e != nil {
return s
}
s = compile.ReplaceAllString(s , rule.Replace)
}
if strings.TrimSpace(s) == "" || tool.CheckOnlySymbolText(strings.TrimSpace(s)) {
return ""
}
return s
}


//拼接字幕字符串
func MakeSubtitleText(index int , startTime int64 , endTime int64 , text string , translateText string , bilingualSubtitleSwitch bool , bilingualAsc bool) string {
var content bytes.Buffer
Expand Down
Loading

0 comments on commit edfae07

Please sign in to comment.