Git Product home page Git Product logo

youtube-streaming-translator-python's Introduction

实时翻译油管直播

开发中 v0.01
测试开发于Python >= 3.6

本脚本使用谷歌云语音转文字api谷歌云翻译api/百度翻译实现对油管直播的实时字幕与翻译。

使用方法

0. 克隆本仓库

git clone github.com/azuse/youtube-streaming-translator-python
cd youtube-streaming-translator-python

1. 安装依赖库

sudo apt-get install libsm6 libxrender1 libxext-dev
pip install -r requirements.txt

注1:安装pyaudio报错,需要自己编译安装portaudio:cannot-install-pyaudio-gcc-error

注2:从noise_reduction中复制了降噪功能,降噪功能需要安装SOX,不需要使用可以把代码直接注释掉。

2. 添加谷歌api key到Path中

Linux&Mac

export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"

Windows CMD

set GOOGLE_APPLICATION_CREDENTIALS=[PATH]

Windows PowerShell

$env:GOOGLE_APPLICATION_CREDENTIALS="[PATH]"

例: export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"

3. *使用百度翻译API

脚本可以选择使用百度翻译API或谷歌翻译API,使用百度翻译API需要:

  • 把翻译函数中的baidu设置为baidu=True(目前在245行)
  • baiduapi.py中设置自己的APP IDSECRET KEY

4. 修改代理

  • 不使用代理: 直接运行
  • 使用代理:
    Ubuntu/Linux
    export http_proxy=http://127.0.0.1:7890
    export https_proxy=http://127.0.0.1:7890
    Windows
    set http_proxy=http://127.0.0.0.1:7890
    set https_proxy=http://127.0.0.0.1:7890

5. 修改直播地址

url = "https://www.youtube.com/watch?v=ylFDswiFduE"中的地址修改为您需要翻译的直播地址

注:如果地址不是直播的话,程序会自动开始下载完整视频(应该会提示报错)

6. 启动脚本

python main.google.py

7. 脚本输出

最后一行输出数字分别代表:
开始下载的视频片段数 下载完成的视频片段数 下载失败的视频片段数 开始转码的视频片段数 转码完成已经发向谷歌API的片段数 从谷歌API收到回复(翻译完成)的片段数

8. 浏览器输出

脚本会自动在0.0.0.0:5000上开一个http服务器,同时在0.0.0.0:5001和0.0.0.0:5002上开socket服务器。 访问http://127.0.0.1:5000http://你的服务器ip:5000会打开显示字幕用的网页,网页分别从5001和5002的socket读取日文与中文字幕。 网页的CSS有待优化,目前只是一个测试效果。

9. *Chunksize

油管的直播是以1s左右时间一段.ts文件的格式传输的,在将视频段转为音频后,可以决定要把多少段视频合在一起送给谷歌的流式音频识别API,决定多少段合并在一起的变量叫chunksize

如果设置为较小的值(1),每次音频识别API可能只会返回一个词,日译中效果不好;如果设置为较大值(10),意味着每10s才会更新一次字幕;

所以chunksize的大小对识别效果有很大影响,目前感觉设置为4效果较好,每4s一个片段。但是,如果一句话跨越两个4s片段,流式音频识别API对于两个连起来的片段很多时候还是会拆成两句话来识别,导致中间内容丢失。

效果

使用OBS加载浏览器效果(推荐自己优化CSS)

开发计划

  • 使用Flask添加Web前端,方便OBS直接从浏览器将字幕加载到转播中
  • 优化前端CSS和JS
  • 调教语音转文字和翻译
  • 解决代理问题
  • 增加百度翻译api
  • 增加彩云小译API 增加IBM watson API

youtube-streaming-translator-python's People

Contributors

azuse avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.