Skip to content

Commit

Permalink
add voice translate
Browse files Browse the repository at this point in the history
  • Loading branch information
jianchang512 committed Oct 24, 2023
1 parent 30666ba commit fa619d0
Show file tree
Hide file tree
Showing 21 changed files with 573 additions and 278 deletions.
45 changes: 31 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# [English](./README_ENG.md)

# 使用方法
这是一个视频翻译工具,可将一种语言的视频翻译为另一种语言和配音的视频。
语音识别和文字翻译使用google接口,文字合成语音使用 Microsoft Edge tts,无需购买任何商业接口,也无需付费

# 使用预编译版本方法
0. 只可用于 win10 win11 系统
1. 从 release中下载最新版,解压,双击 sp.exe
2. 创建一个文件夹,里面存放 mp4视频(mkv,avi,mpg),从软件界面“原始视频目录”中选择该文件夹;“输出视频目录”如果不选择,则默认生成在同目录下的“_video_out”
3. 如果你所在地区无法直接访问google,需要在软件界面“网络连接代理”中设置代理,比如若使用 v2ray ,则填写 `http://127.0.0.1:10809`,若clash,则填写 `http://127.0.0.1:7890`. 如果你修改了默认端口或使用的其他代理软件,则按需填写
4. 根据你的电脑性能,可修改“并发翻译数量”,即同时执行翻译的视频任务。
5.显示字幕语种”:如果选择“双字幕”,那么在视频中将会以上层源语言、下层目标语言显示2个字幕
6.保留字幕文件”:如果选择“是”,那么下次执行时,如果存在字幕文件,将直接使用,会导致上方第5条切换不生效,除非手动删除字幕文件
5.配音选择”:选择目标语言后,可从配音选项中,选择配音角色
6.配音语速”:同样一句话在不同语言语音下,所需时间是不同的,因此配音后可能声画字幕不同步,可以调整此处语速,负数代表降速,正数代表加速播放。
7. 点击“开始执行”,会先检测能否连接google服务,若可以,则正式执行,右侧会显示当前进度,底部白色文本框内显示详细日志
8. 建议统一使用mp4格式,处理速度快,网络兼容性好
9. 软合成字幕:字幕作为单独文件嵌入视频,可再次提取出,如果播放器支持,可在播放器字幕管理中启用或禁用字幕;
硬合成字幕:字幕直接嵌入视频内容,不可再次提取,不依赖播放器,均可显示字幕。
9. 采用软合成字幕:字幕作为单独文件嵌入视频,可再次提取出,如果播放器支持,可在播放器字幕管理中启用或禁用字幕;
10. 默认会在“原始视频目录”下生成同名的字幕文件“视频名.srt”
11. 对于无法识别的语音将直接复制原语音

# 源码部署方式

# 源码部署修改

1. 电脑安装好 python 3.9+
2. `git clone https://github.com/jianchang512/pyvideotrans`
Expand All @@ -23,20 +28,32 @@
6. `python sp.py`
7. 本地打包 ` pyinstaller -w sp.py`

# 截图
# 软件预览截图

![](./images/1.png)
![](./images/2.png)
![](./images/3.png)

# 原视频
![](./images/raw.mp4)
<video width="640" height="480" controls>
<source src="./images/raw.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>

![](./tmp/7.gif)
![](./tmp/2.jpg)
![](./tmp/3.jpg)
![](./tmp/4.jpg)
![](./tmp/5.jpg)

# 翻译后的视频
<video width="640" height="480" controls>
<source src="./images/new.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>

# 可能的问题

> 在使用httpx和 googletrans 配置代理时可能报错,将 googletrans 包下 client.py 57 行左右改为 `proxies 类型 改为 httpcore.SyncHTTPProxy`

# 鸣谢
# 致谢

> 本程序依赖这些开源项目
Expand All @@ -46,6 +63,6 @@
4. googletrans
5. httpx
6. SpeechRecognition

7. edge-tts


63 changes: 63 additions & 0 deletions README_ENG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# [简体中文](./README_ENG.md)

This is a video translation tool that can translate videos in one language to another language and add voice-over to the video.
Speech recognition and text translation are done using the Google API, and text-to-speech synthesis is done using Microsoft Edge TTS without the need to purchase any commercial interfaces or pay any fees.

# Instructions for Using the Pre-compiled Version
0. Only available for Windows 10 and Windows 11 systems.
1. Download the latest version from the release, unzip it, and double-click on sp.exe.
2. Create a folder to store the mp4 video (mkv, avi, mpg) and select this folder as the "Original Video Directory" in the software interface. If you do not select the "Output Video Directory," it will be generated by default in the same directory as "_video_out."
3. If you cannot directly access Google from your region, you need to set up a proxy in the "Network Connection Proxy" section of the software interface. For example, if you are using V2Ray, enter `http://127.0.0.1:10809`, or if you are using Clash, enter `http://127.0.0.1:7890`. If you have modified the default port or are using other proxy software, fill it in as needed.
4. Depending on the performance of your computer, you can modify the "Concurrent Translation Quantity" to specify the number of video tasks to be translated simultaneously.
5. "Voice-over Selection": After selecting the target language, you can choose a voice-over character from the voice-over options.
6. "Voice-over Speed": The time required for the same sentence in different language voices varies, so the subtitles may be out of sync after voice-over. You can adjust the speed here, where negative values represent a slowdown and positive values represent a faster playback.
7. Click "Start Execution." It will first check whether it can connect to Google services. If it can, it will proceed with the execution. The current progress will be displayed on the right side, and detailed logs will be displayed in the white text box at the bottom.
8. It is recommended to use the MP4 format for better processing speed and network compatibility.
9. Utilize soft-encoded subtitles: Embed subtitles as separate files in the video, which can be extracted again. If supported by the player, you can enable or disable subtitles in the player's subtitle management section.
10. By default, a subtitle file with the same name as the video will be generated in the "Original Video Directory" as "video_name.srt."
11. Unrecognized voices will be copied directly.

# Deployment and Modification of Source Code

1. Install Python 3.9+ on your computer.
2. `git clone https://github.com/jianchang512/pyvideotrans`
3. `cd pyvideotrans`
4. `pip install -r requirements.txt`
5. Unzip ffmpeg.zip into the root directory.
6. `python sp.py`
7. To package locally, use `pyinstaller -w sp.py`.

# Software Preview Screenshots

![](./images/1.png)
![](./images/2.png)
![](./images/3.png)

# Original Video
![](./images/raw.mp4)
<video width="640" height="480" controls>
<source src="./images/raw.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>

# Translated Video
<video width="640" height="480" controls>
<source src="./images/new.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>

# Possible Issues

> When using httpx and setting up proxies with googletrans, you may encounter an error. In the googletrans package, at around line 57 in client.py, change the `proxies` type to `httpcore.SyncHTTPProxy`.
# Acknowledgements

> This program relies on the following open-source projects:
1. pydub
2. ffmpeg
3. pysimpleGUI
4. googletrans
5. httpx
6. SpeechRecognition
7. edge-tts
Loading

0 comments on commit fa619d0

Please sign in to comment.