Skip to content

Commit 8864018

Browse files
authored
Merge pull request Huanshere#74 from Huanshere/funasr
Chinese Support! and a whole bunch of upgrade!
2 parents 1e7b68a + f9c972b commit 8864018

27 files changed

+577
-380
lines changed

README.en.md

Lines changed: 97 additions & 52 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,70 +30,82 @@ VideoLingo 是一站式视频翻译本地化配音工具,旨在生成 Netflix
3030

3131
- **✅ 按照 Netflix 标准检查单行长度,绝无双行字幕**
3232

33-
- 🗣️ 使用 GPT-SoVITS 等方法进行高质量的对齐配音
33+
- **🗣️ 使用 GPT-SoVITS 等方法进行高质量的对齐配音**
3434

3535
- 🚀 整合包一键启动,在 streamlit 中一键出片
3636

3737
## 🎥 效果演示
3838

3939
<table>
4040
<tr>
41-
<td width="33%">
41+
<td width="25%">
4242

4343
### 俄语翻译
4444
---
4545
https://github.com/user-attachments/assets/25264b5b-6931-4d39-948c-5a1e4ce42fa7
4646

4747
</td>
48-
<td width="33%">
48+
<td width="25%">
4949

5050
### GPT-SoVITS
5151
---
5252
https://github.com/user-attachments/assets/47d965b2-b4ab-4a0b-9d08-b49a7bf3508c
5353

5454
</td>
55-
<td width="33%">
55+
<td width="25%">
5656

5757
### Fish TTS 丁真
5858
---
5959
https://github.com/user-attachments/assets/e7bb9090-d2ef-4261-9dc5-56bd67dc710d
6060

61+
</td>
62+
<td width="25%">
63+
64+
### OAITTS
65+
---
66+
https://github.com/user-attachments/assets/85c64f8c-06cf-4af9-b153-ee9d2897b768
67+
6168
</td>
6269
</tr>
6370
</table>
6471

6572
### 语言支持:
6673

67-
当前输入语言支持和示例(暂不支持中文输入)
74+
当前输入语言支持和示例:
6875

6976
| 输入语言 | 支持程度 | 翻译demo | 配音demo |
7077
|---------|---------|---------|----------|
71-
| 🇬🇧🇺🇸 英语 | 🤩 | [英转中](https://github.com/user-attachments/assets/127373bb-c152-4b7a-8d9d-e586b2c62b4b) | TODO |
72-
| 🇷🇺 俄语 | 😊 | [俄转中](https://github.com/user-attachments/assets/25264b5b-6931-4d39-948c-5a1e4ce42fa7) | TODO |
73-
| 🇫🇷 法语 | 🤩 | [法转日](https://github.com/user-attachments/assets/3ce068c7-9854-4c72-ae77-f2484c7c6630) | TODO |
74-
| 🇩🇪 德语 | 🤩 | [德转中](https://github.com/user-attachments/assets/07cb9d21-069e-4725-871d-c4d9701287a3) | TODO |
75-
| 🇮🇹 意大利语 | 🤩 | [意转中](https://github.com/user-attachments/assets/f1f893eb-dad3-4460-aaf6-10cac999195e) | TODO |
76-
| 🇪🇸 西班牙语 | 🤩 | [西转中](https://github.com/user-attachments/assets/c1d28f1c-83d2-4f13-a1a1-859bd6cc3553) | TODO |
77-
| 🇯🇵 日语 | 😐 | [日转中](https://github.com/user-attachments/assets/856c3398-2da3-4e25-9c36-27ca2d1f68c2) | TODO |
78-
| 🇨🇳 中文 | 😖 || TODO |
78+
| 英语 | 🤩 | [英转中](https://github.com/user-attachments/assets/127373bb-c152-4b7a-8d9d-e586b2c62b4b) | TODO |
79+
| 俄语 | 😊 | [俄转中](https://github.com/user-attachments/assets/25264b5b-6931-4d39-948c-5a1e4ce42fa7) | TODO |
80+
| 法语 | 🤩 | [法转日](https://github.com/user-attachments/assets/3ce068c7-9854-4c72-ae77-f2484c7c6630) | TODO |
81+
| 德语 | 🤩 | [德转中](https://github.com/user-attachments/assets/07cb9d21-069e-4725-871d-c4d9701287a3) | TODO |
82+
| 意大利语 | 🤩 | [意转中](https://github.com/user-attachments/assets/f1f893eb-dad3-4460-aaf6-10cac999195e) | TODO |
83+
| 西班牙语 | 🤩 | [西转中](https://github.com/user-attachments/assets/c1d28f1c-83d2-4f13-a1a1-859bd6cc3553) | TODO |
84+
| 日语 | 😐 | [日转中](https://github.com/user-attachments/assets/856c3398-2da3-4e25-9c36-27ca2d1f68c2) | TODO |
85+
| 中文* | 🤩 | [中转英](https://github.com/user-attachments/assets/48f746fe-96ff-47fd-bd23-59e9202b495c) | [罗翔老师脱口秀](https://github.com/user-attachments/assets/85c64f8c-06cf-4af9-b153-ee9d2897b768) |
86+
> *中文需单独配置whisperX模型,见源码安装
7987
8088
翻译语言支持大模型会的所有语言,配音语言取决于选取的TTS方法。
8189

8290
## 🚀 一键整合包 for Windows
8391

8492
### 注意事项:
8593

86-
1. 整合包使用的是 CPU 版本的 torch,大小约 **2.5G**
87-
2. 在配音步骤使用 UVR5 降噪时,CPU 版本会显著慢于 GPU 加速的 torch。
94+
1. 整合包使用的是 CPU 版本的 torch,大小约 **2.6G**
95+
2. 在配音步骤使用 UVR5 进行人声分离时,CPU 版本会显著慢于 GPU 加速的 torch。
8896
3. 整合包**仅支持通过 API 调用 whisperXapi ☁️**,不支持本地运行 whisperX 💻。
97+
4. 整合包使用的 whisperXapi 不支持中文转录,若需要使用中文,请从源码安装使用本地运行的 whisperX 💻。
98+
5. 整合包在转录步骤尚未进行 UVR5 人声分离,不建议使用 BGM 较嘈杂的视频。
8999

90100
如果需要以下功能,请从源码安装(需要Nvidia显卡以及至少 **20G** 硬盘空间):
101+
- 输入语言为中文
91102
- 本地运行 whisperX 💻
92-
- 使用 GPU 加速的 UVR5 降噪
103+
- 使用 GPU 加速的 UVR5 人声分离
104+
- 转录 BGM 较嘈杂的视频
93105

94106
### 下载和使用说明
95107

96-
1. 下载 `v1.2.0` 一键整合包(750M): [直接下载](https://vip.123pan.cn/1817874751/8158115) | [度盘备用](https://pan.baidu.com/s/1H_3PthZ3R3NsjS0vrymimg?pwd=ra64)
108+
1. 下载 `v1.3` 一键整合包(800M): [直接下载](https://vip.123pan.cn/1817874751/8187706) | [度盘备用](https://pan.baidu.com/s/1H_3PthZ3R3NsjS0vrymimg?pwd=ra64)
97109

98110
2. 解压后双击运行文件夹中的 `一键启动.bat`
99111

@@ -112,7 +124,7 @@ https://github.com/user-attachments/assets/e7bb9090-d2ef-4261-9dc5-56bd67dc710d
112124
| deepseek-coder | [deepseek](https://platform.deepseek.com/api_keys) | https://api.deepseek.com | ¥2 / 1M tokens | 😲 |
113125
> 注:云雾api 还支持 openai 的 tts-1 接口,可在配音步骤选用。
114126
115-
> 提醒:deepseek在翻译过程有极低的概率错误,若出错请更换sonnet...
127+
> 提醒:deepseek在翻译过程有极低的概率错误,若出错请更换claude 3.5 sonnet模型
116128
117129
#### 常见问题
118130

@@ -146,7 +158,7 @@ VideoLingo 使用 WhisperX 进行语音识别,支持本地部署和云端api
146158
| 方案 | 缺点 |
147159
|:-----|:-----|
148160
| **whisperX 🖥️** | • 安装CUDA 🛠️<br>• 下载模型 📥<br>• 高显存 💾 |
149-
| **whisperXapi ☁️ (推荐)** | • 需梯子 🕵️‍♂️<br>• Visa卡 💳 |
161+
| **whisperXapi ☁️** | • 需梯子 🕵️‍♂️<br>• Visa卡 💳<br>• **中文效果差** 🚫 |
150162

151163
#### 获取令牌
152164
-[Replicate](https://replicate.com/account/api-tokens) 注册并绑定 Visa 卡支付方式,获取令牌
@@ -166,6 +178,12 @@ VideoLingo提供了多种tts接入方式,以下是对比(如不使用配音
166178
- **Azure TTS 可在QQ群公告获取测试 key** 或自行在 [官网](https://learn.microsoft.com/zh-cn/azure/ai-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-python) 注册充值;
167179
- **Fish TTS 可在QQ群公告获取测试 key** 或自行在 [官网](https://fish.audio/zh-CN/go-api/) 注册充值
168180

181+
<details>
182+
<summary>OpenAI 声音怎么选?</summary>
183+
184+
声音列表可以在 [官网](https://platform.openai.com/docs/guides/text-to-speech/voice-options) 找到,例如 `alloy`, `echo`, `nova``fable` 等,在 `config.py` 中修改 `OAI_VOICE` 即可。
185+
186+
</details>
169187
<details>
170188
<summary>Azure 声音怎么选?</summary>
171189

@@ -209,7 +227,7 @@ VideoLingo提供了多种tts接入方式,以下是对比(如不使用配音
209227
vits_weights_path: SoVITS_weights_v2/Huanyu_v2_e10_s150.pth
210228
```
211229
- 参考方法 a,在和 `yaml` 文件同个目录下,放入后续使用的参考音频,命名为 `你喜欢的英文角色名_参考音频的文字内容.wav` 或 `.mp3`,例如 `Huanyuv2_你好,这是一条测试音频.wav`,程序会自动识别并使用。
212-
- ⚠️ 警告:**请使用英文命名 `角色名`** ,否则会出现错误。 `参考音频的文字内容` 可以使用中文。
230+
- ⚠️ 警告:**请使用英文命名 `角色名`** ,否则会出现错误。 `参考音频的文字内容` 可以使用中文。目前仍处于测试版,可能产生报错。
213231

214232

215233
```
@@ -248,20 +266,20 @@ VideoLingo提供了多种tts接入方式,以下是对比(如不使用配音
248266
249267
### 安装步骤
250268
251-
支持Win, Mac, Linux。遇到问题可以把整个步骤丢给 GPT 问问~
269+
需要一定的 python 基础,支持Win, Mac, Linux。遇到问题可以把整个步骤丢给 GPT 问问~
252270
253-
1. 打开 Anaconda Powershell Prompt 并切换到桌面目录:
271+
1. 打开 Anaconda Prompt 并切换到桌面目录:
254272
```bash
255273
cd desktop
256274
```
257275

258-
2. 克隆项目
276+
2. 克隆项目并切换至项目目录
259277
```bash
260278
git clone https://github.com/Huanshere/VideoLingo.git
261279
cd VideoLingo
262280
```
263281

264-
3. 配置虚拟环境(必须 3.10.0):
282+
3. 创建并激活虚拟环境(**必须 3.10.0**):
265283
```bash
266284
conda create -n videolingo python=3.10.0 -y
267285
conda activate videolingo
@@ -271,21 +289,33 @@ VideoLingo提供了多种tts接入方式,以下是对比(如不使用配音
271289
```bash
272290
python install.py
273291
```
274-
根据提示选择所需的 Whisper 项目,脚本将自动安装相应的 torch 和 whisper 版本
292+
根据提示选择所需的 Whisper 方法,脚本将自动安装相应的 torch 和 whisper 版本
275293

276-
注意:Mac 用户需根据提示手动安装 ffmpeg
294+
5. 仅对于需要使用中文转录的用户:
295+
296+
请手动下载 Belle-whisper-large-v3-zh-punct 模型([度盘链接](https://pan.baidu.com/s/1NyNtkEM0EMsjdCovncsx0w?pwd=938n)),并将其覆盖在项目根目录的 `_model_cache` 文件夹下
277297

278-
5. 🎉 输入命令或点击 `一键启动.bat` 启动 Streamlit 应用:
298+
6. 🎉 输入命令或点击 `一键启动.bat` 启动 Streamlit 应用:
279299
```bash
280300
streamlit run st.py
281301
```
282302

283-
6. 在弹出网页的侧边栏中设置key,并注意选择whisper方法
303+
7. 在弹出网页的侧边栏中设置key,并注意选择whisper方法
284304

285305
![settings](https://github.com/user-attachments/assets/3d99cf63-ab89-404c-ae61-5a8a3b27d840)
286306

307+
8. (可选)更多进阶设置可以在 `config.py` 中手动修改
308+
287309
<!-- 本项目采用结构化模块开发,可按顺序逐个运行 `core\step__.py`,技术文档: [中文](./docs/README_guide_zh.md) | [英文](./docs/README_guide_en.md)(待更新) -->
288310

311+
## ⚠️ 注意事项
312+
313+
1. UVR5 对内存要求较高,16G 内存处理极限是 30min, 32GB 内存处理极限是 50min,请谨慎尝试长视频。
314+
315+
2. 翻译步骤极小可能出现 'phrase' 错误,遇到请反馈。
316+
317+
3. 配音功能质量不稳定,为最佳质量,请尽量选择适合原视频的 TTS 语速,例如 OAITTS 语速较快,FishTTS 语速请试听后选择。
318+
289319
## 📄 许可证
290320

291321
本项目采用 Apache 2.0 许可证。使用本项目时,请遵循以下规定:
@@ -300,6 +330,7 @@ VideoLingo提供了多种tts接入方式,以下是对比(如不使用配音
300330
- [yt-dlp](https://github.com/yt-dlp/yt-dlp)
301331
- [json_repair](https://github.com/mangiucugna/json_repair)
302332
- [GPT-SoVITS](https://github.com/RVC-Boss/GPT-SoVITS)
333+
- [BELLE](https://github.com/LianjiaTech/BELLE)
303334

304335
## 📬 联系我们
305336

config.example.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
MODEL = 'claude-3-5-sonnet-20240620'
77

88
# Replicate API 设置
9-
REPLICATE_API_TOKEN = 'YOUR_API_TOKEN'
9+
REPLICATE_API_TOKEN = 'YOUR_REPLICATE_API_TOKEN'
1010

1111
# 语言设置,写入prompt中,用自然语言描述即可
1212
TARGET_LANGUAGE = '简体中文'
1313

1414
## 字幕设置
1515
# *每行字幕的最大长度 字母数量
16-
MAX_SUB_LENGTH = 75
16+
MAX_SUB_LENGTH = 70
1717
# *翻译字幕比源字幕字号更大一些,会影响切割字幕的参考长度
18-
TARGET_SUB_MULTIPLIER = 1.2
18+
TARGET_SUB_MULTIPLIER = 1.1
1919

2020
# 视频分辨率 [0x0, 640x360, 1920x1080] 0x0会生成一个0秒的黑色视频占位
2121
RESOLUTION = '640x360'
@@ -30,8 +30,8 @@
3030
# Whisper 设置 [whisperx, whisperxapi]
3131
WHISPER_METHOD = 'whisperxapi'
3232

33-
# *Whisper 指定识别语言 [auto, en, ...] auto为自动检测,en为强制转译为英文
34-
WHISPER_LANGUAGE = 'auto'
33+
# Whisper 指定识别语言 [en, zh, auto] auto为自动检测,en为强制转译为英文
34+
WHISPER_LANGUAGE = 'en'
3535

3636
# *llm 多线程访问数量
3737
MAX_WORKERS = 6
@@ -52,10 +52,8 @@
5252
OAI_TTS_API_BASE_URL = 'https://yunwu.zeabur.app'
5353

5454
# Azure 配置
55-
# API文档及申请:https://learn.microsoft.com/zh-cn/azure/ai-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-python
56-
# voice列表见:https://learn.microsoft.com/zh-cn/azure/ai-services/speech-service/language-support?tabs=tts#prebuilt-neural-voices
5755
# 在线体验voice:https://speech.microsoft.com/portal/voicegallery
58-
AZURE_KEY = 'YOUR_API_KEY'
56+
AZURE_KEY = 'YOUR_AZURE_KEY'
5957
AZURE_REGION = 'eastasia'
6058
AZURE_VOICE = 'zh-CN-XiaoxiaoMultilingualNeural' # 推荐女声 'zh-CN-XiaoxiaoMultilingualNeural' 男声 "zh-CN-YunyiMultilingualNeural"
6159

@@ -65,9 +63,9 @@
6563
REFER_MODE = 3
6664

6765
# FishTTS API
68-
FISH_TTS_API_KEY = 'YOUR_API_KEY'
66+
FISH_TTS_API_KEY = 'YOUR_FISH_TTS_API_KEY'
6967
# FishTTS 角色 确保在下方存在
70-
FISH_TTS_CHARACTER = '丁真'
68+
FISH_TTS_CHARACTER = 'AD学姐'
7169
# *FishTTS角色列表 "角色名" : "角色ID"
7270
FISH_TTS_CHARACTER_ID_DICT = {
7371
'AD学姐': '7f92f8afb8ec43bf81429cc1c9199cb1',
@@ -79,10 +77,8 @@
7977
'邓紫棋': '3b55b3d84d2f453a98d8ca9bb24182d6',
8078
'郭德纲': '7c66db6e457c4d53b1fe428a8c547953',
8179
}
82-
# *FishTTS 音量增益,官方模型一般音量偏小,建议增益1.5
83-
FISH_TTS_VOLUME = 1.5
8480

85-
# *音频的速度范围控制,实测1~1.35 之间效果自然
81+
# *音频的速度范围
8682
MIN_SPEED_FACTOR = 1
8783
MAX_SPEED_FACTOR = 1.35
8884
NORMAL_SPEED_FACTOR = 1.2 # 认为的正常语速
@@ -94,6 +90,8 @@
9490

9591
# 压制配音视频中原始人声音量 0.1=10% or 0
9692
ORIGINAL_VOLUME = 0.1
93+
# *压制配音音量 1.5=150%, 大部分配音原音都较小
94+
DUB_VOLUME = 1.5
9795

9896
## ======================== 额外设定 请勿修改 ======================== ##
9997
# Whisper 模型目录
@@ -114,9 +112,7 @@
114112
"es": "es_core_news_md",
115113
"de": "de_core_news_md",
116114
"it": "it_core_news_md",
117-
118-
# Not supported
119-
# "zh": "zh_core_web_md",
115+
"zh": "zh_core_web_md",
120116
}
121117

122118
# 使用空格分割的语言

core/all_tts_functions/azure_tts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ def azure_tts(text, savepath):
2222
print(f"Error: {speech_synthesis_result.cancellation_details.error_details}")
2323
return False
2424

25-
# azure_tts("你好,世界!", "output/audio/azure_tts.wav")
25+
if __name__ == "__main__":
26+
azure_tts("你好,世界!", "output/audio/azure_tts.wav")

core/all_tts_functions/fish_tts.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
from pathlib import Path
33
import os, sys
44
from rich import print as rprint
5-
import soundfile as sf
6-
import librosa
7-
import io
8-
import numpy as np
9-
import pydub
5+
from moviepy.editor import AudioFileClip
106
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
117

8+
129
def fish_tts(text, save_path):
13-
from config import FISH_TTS_API_KEY, FISH_TTS_CHARACTER, FISH_TTS_CHARACTER_ID_DICT, FISH_TTS_VOLUME
10+
from config import FISH_TTS_API_KEY, FISH_TTS_CHARACTER, FISH_TTS_CHARACTER_ID_DICT
1411
if FISH_TTS_CHARACTER not in FISH_TTS_CHARACTER_ID_DICT:
1512
raise ValueError(f"Character '{FISH_TTS_CHARACTER}' not found in FISH_TTS_CHARACTER_ID_DICT")
1613
id = FISH_TTS_CHARACTER_ID_DICT[FISH_TTS_CHARACTER]
@@ -35,12 +32,19 @@ def fish_tts(text, save_path):
3532
wav_file_path = Path(save_path).with_suffix('.wav')
3633
wav_file_path.parent.mkdir(parents=True, exist_ok=True)
3734

38-
# Convert mp3 to wav using pydub, otherwise it cannot read the duration
39-
audio = pydub.AudioSegment.from_file(io.BytesIO(response.content), format="mp3")
40-
41-
# Adjust volume
42-
audio = audio + (10 * np.log10(FISH_TTS_VOLUME))
43-
audio.export(wav_file_path, format="wav")
35+
# Save the MP3 content to a temporary file
36+
temp_mp3_path = wav_file_path.with_suffix('.mp3')
37+
with open(temp_mp3_path, 'wb') as temp_file:
38+
temp_file.write(response.content)
39+
40+
# Convert mp3 to wav using moviepy
41+
audio_clip = AudioFileClip(str(temp_mp3_path))
42+
audio_clip.write_audiofile(str(wav_file_path))
43+
audio_clip.close()
44+
45+
# Remove the temporary MP3 file
46+
os.remove(temp_mp3_path)
47+
4448
rprint(f"[bold green]Converted audio saved to {wav_file_path}[/bold green]")
4549
break
4650
else:

core/all_tts_functions/gpt_sovits_tts.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
from pathlib import Path
2-
import json
32
import requests
43
from rich import print as rprint
54
import os, sys
65
import subprocess
76
import socket
87
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
9-
import time
108
def check_lang(text_lang, prompt_lang):
119
if any(lang in text_lang.lower() for lang in ['zh', 'cn', '中文']):
1210
text_lang = 'zh'

core/all_tts_functions/openai_tts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ def openai_tts(text, save_path):
2525

2626
print(f"Audio saved to {speech_file_path}")
2727

28-
# Example usage
29-
# openai_tts("今天是个好日子,适合做点人们喜欢的东西!", "output/audio/tmp/test.wav")
28+
if __name__ == "__main__":
29+
openai_tts("今天是个好日子,适合做点人们喜欢的东西!", "output/audio/tmp/test.wav")

0 commit comments

Comments
 (0)