github开源推荐,主动字幕生成和字幕翻译工具——再也没有看不懂的片啦 ...

打印 上一主题 下一主题

主题 1601|帖子 1601|积分 4803

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x


1.简介

GitHub - qinL-cdy/auto_ai_subtitle
github上开源的一款字幕生成和字幕翻译的整合工具,可以根据视频中提取到的音频来转换成字幕,再根据须要将字幕举行翻译,基于whisper

2.结果



3.使用

1)安装ffmpeg
安装ffmpeg的教程比较多,就不具体先容了,Windows上安装完成后记得添加环境变量,最后在cmd中输入"ffmpeg –version",有相应打印即可
2)拉取代码
使用git拉取代码即可,没有git的可以参考网上资料安装一下
  1. git clone https://github.com/qinL-cdy/auto_ai_subtitle.git
复制代码
3)安装python依靠
使用pip安装相关依靠,当然前提是已经安装好python环境了
进入git下来的工程目录,可以看到有一个requirements.txt
在目录下执行
  1. pip install -r requirements.txt
复制代码
 这样pip就会主动安装所有须要的依靠了
4)填写配置信息
打开当前目录下的config.yaml文件,根据提示填写对应的信息,例如:
  1. #输入的视频文件
  2. input: D:\download\ChainsawMan-03.mp4
  3. #中间过程会生成的音频文件
  4. output: D:\download\ChainsawMan-03.mp3
  5. #生成的原始字幕文件
  6. srt_path: D:\download\ChainsawMan-03.srt
  7. #生成的翻译后的字幕文件
  8. srt_translate_path: D:\download\ChainsawMan-03-zh.srt
  9. #翻译时开启多少线程
  10. translate_threads: 10
  11. #翻译源语言
  12. from: ja
  13. #翻译目标语言
  14. to: zh
复制代码
5)执行程序
最后一步,使用python命令执行程序即可 
  1. python main.py
复制代码
6)其他用法
观察main.py文件:
  1. import yaml
  2. from script import translate_tool, audio_tool, whisper_tool
  3. if __name__ == '__main__':
  4.     with open('config.yaml', encoding='utf-8') as f:
  5.         config = yaml.load(f.read(), Loader=yaml.FullLoader)
  6.     print("audio extract begin")
  7.     audio_tool.audio_extract(config['input'], config['output'])
  8.     print("audio extract success")
  9.     print("whisper begin")
  10.     whisper_tool.do_whisper(config['output'], config['srt_path'])
  11.     print("whisper success")
  12.     print("translate begin")
  13.     translate_tool.do_translate(config['srt_path'], config['srt_translate_path'], config['from'], config['to'],
  14.                                 config['translate_threads'])
  15.     print("translate success")
  16.     print("success")
复制代码
可以看到脚本是由多个独立的调用步调组合而成的,所以也可以根据本身的须要调解来自定义执行某一个或多个功能
例如,只执行音频提取和字幕生成,但不举行翻译:
  1. import yaml
  2. from script import translate_tool, audio_tool, whisper_tool
  3. if __name__ == '__main__':
  4.     with open('config.yaml', encoding='utf-8') as f:
  5.         config = yaml.load(f.read(), Loader=yaml.FullLoader)
  6.     print("audio extract begin")
  7.     audio_tool.audio_extract(config['input'], config['output'])
  8.     print("audio extract success")
  9.     print("whisper begin")
  10.     whisper_tool.do_whisper(config['output'], config['srt_path'])
  11.     print("whisper success")
  12.     #print("translate begin")
  13.     #translate_tool.do_translate(config['srt_path'], config['srt_translate_path'], config['from'], config['to'],config['translate_threads'])
  14.     #print("translate success")
  15.     print("success")
复制代码
4.原理

1)音频提取
  1. import ffmpeg
  2. def audio_extract(input, output):
  3.     ffmpeg.input(input, vn=None).output(output).run()
复制代码
 使用了ffmpeg的能力,其中vn=None代表忽略视频,所以执行后只会输出对应的音频
2)字幕提取
字幕生成使用了openai开源的whisper
  1. def do_whisper(audio, srt_path):
  2.     model = whisper.load_model("base")
  3.     print("whisper working...")
  4.     result = model.transcribe(audio)
  5.     print("whisper execute success")
  6.     print("writing srt file...")
  7.     write_srt(result['segments'], srt_path)
  8.     print("write srt success")
复制代码
 这里只是用了最基本的模子,所以在精度上大概不敷高,使用者可以基于whisper开源的模子做进一步优化
3)字幕翻译
字幕翻译使用了常用的开源库translate,就不做进一步先容了,感兴趣可以检察相关资料


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

水军大提督

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表