Skip to content

Commit b2b1c22

Browse files
committed
feat: add custom terms
1 parent d8c404a commit b2b1c22

File tree

7 files changed

+48
-21
lines changed

7 files changed

+48
-21
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ VideoLingo is an all-in-one video translation, localization, and dubbing tool ai
1717
Key features:
1818
- 🎥 YouTube video download via yt-dlp
1919

20-
- **🎙️ Word-level subtitle recognition with WhisperX**
20+
- **🎙️ Word-level and Low-illusion subtitle recognition with WhisperX**
2121

22-
- **📝 NLP and GPT-based subtitle segmentation**
22+
- **📝 NLP and AI-powered subtitle segmentation**
2323

24-
- **📚 GPT-generated terminology for coherent translation**
24+
- **📚 Custom + AI-generated terminology for coherent translation**
2525

26-
- **🔄 3-step direct translation, reflection, and adaptation for professional-level quality**
26+
- **🔄 3-step Translate-Reflect-Adaptation for cinematic quality**
2727

28-
- **✅ Netflix-standard single-line subtitles only**
28+
- **✅ Netflix-standard, Single-line subtitles Only**
2929

30-
- **🗣️ Dubbing alignment with GPT-SoVITS and other methods**
30+
- **🗣️ Dubbing with GPT-SoVITS, Azure, OpenAI, and more**
3131

32-
- 🚀 One-click startup and output in Streamlit
32+
- 🚀 One-click startup and processing in Streamlit
3333

3434
- 📝 Detailed logging with progress resumption
3535

core/prompts_storage.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,34 @@ def get_split_prompt(sentence, num_parts = 2, word_limit = 20):
3737

3838
## ================================================================
3939
# @ step4_1_summarize.py
40-
def get_summary_prompt(source_content):
40+
def get_summary_prompt(source_content, custom_terms_json=None):
4141
src_lang = load_key("whisper.detected_language")
4242
tgt_lang = load_key("target_language")
43+
44+
# add custom terms note
45+
terms_note = ""
46+
if custom_terms_json:
47+
terms_list = []
48+
for term in custom_terms_json['terms']:
49+
terms_list.append(f"- {term['src']}: {term['tgt']} ({term['note']})")
50+
terms_note = "\n### Existing Terms\nPlease exclude these terms in your extraction:\n" + "\n".join(terms_list)
51+
4352
summary_prompt = f"""
4453
### Role
4554
You are a video translation expert and terminology consultant, specializing in {src_lang} comprehension and {tgt_lang} expression optimization.
4655
4756
### Task
4857
For the provided {src_lang} video text:
4958
1. Summarize main topic in two sentences
50-
2. Extract professional terms/names with {tgt_lang} translations
51-
3. Provide brief explanation for each term
59+
2. Extract professional terms/names with {tgt_lang} translations (excluding existing terms)
60+
3. Provide brief explanation for each term{terms_note}
5261
5362
### Steps
5463
1. Topic Summary:
5564
- Quick scan for general understanding
5665
- Write two sentences: first for main topic, second for key point
5766
2. Term Extraction:
58-
- Mark professional terms and names
67+
- Mark professional terms and names (excluding those listed in Existing Terms)
5968
- Provide {tgt_lang} translation or keep original
6069
- Add brief explanation
6170
- Keep abbreviations and proper nouns unchanged

core/step4_1_summarize.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
from core.ask_gpt import ask_gpt
44
from core.prompts_storage import get_summary_prompt
55
from core.config_utils import load_key
6+
import pandas as pd
67

78
TERMINOLOGY_JSON_PATH = 'output/log/terminology.json'
89
SENTENCE_TXT_PATH = 'output/log/sentence_splitbymeaning.txt'
10+
CUSTOM_TERMS_PATH = 'custom_terms.xlsx'
911

1012
def combine_chunks():
1113
"""Combine the text chunks identified by whisper into a single long text"""
@@ -33,7 +35,21 @@ def search_things_to_note_in_prompt(sentence):
3335

3436
def get_summary():
3537
src_content = combine_chunks()
36-
summary_prompt = get_summary_prompt(src_content)
38+
custom_terms = pd.read_excel(CUSTOM_TERMS_PATH)
39+
custom_terms_json = {
40+
"terms": [
41+
{
42+
"src": str(row.iloc[0]),
43+
"tgt": str(row.iloc[1]),
44+
"note": str(row.iloc[2])
45+
}
46+
for _, row in custom_terms.iterrows()
47+
]
48+
}
49+
if len(custom_terms) > 0:
50+
print(f"📖 Custom Terms Loaded: {len(custom_terms)} terms")
51+
print("📝 Terms Content:", json.dumps(custom_terms_json, indent=2, ensure_ascii=False))
52+
summary_prompt = get_summary_prompt(src_content, custom_terms_json)
3753
print("📝 Summarizing and extracting terminology ...")
3854

3955
def valid_summary(response_data):
@@ -46,6 +62,8 @@ def valid_summary(response_data):
4662
return {"status": "success", "message": "Summary completed"}
4763

4864
summary = ask_gpt(summary_prompt, response_json=True, valid_def=valid_summary, log_title='summary')
65+
if 'terms' in summary:
66+
summary['terms'].extend(custom_terms_json['terms'])
4967

5068
with open(TERMINOLOGY_JSON_PATH, 'w', encoding='utf-8') as f:
5169
json.dump(summary, f, ensure_ascii=False, indent=4)

custom_terms.xlsx

9.19 KB
Binary file not shown.

docs/pages/docs/start.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Before installing VideoLingo, ensure you have installed Git and Anaconda.
154154

155155
![tutorial](https://github.com/user-attachments/assets/983ba58b-5ae3-4132-90f5-6d48801465dd)
156156

157-
6. (Optional) More settings can be manually modified in `config.yaml`, watch command line output during operation
157+
6. (Optional) More settings can be manually modified in `config.yaml`, watch command line output during operation. To use custom terms, add them to `custom_terms.xlsx` before processing, e.g. `Baguette | French bread | Not just any bread!`.
158158

159159
## 🏭 Batch Mode (beta)
160160

docs/pages/docs/start.zh-CN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ VideoLingo提供了多种 tts 接入方式,以下是对比(如不使用配
4343
<details>
4444
<summary>OpenAI 声音怎么选?</summary>
4545

46-
声音列表可以在 [官��](https://platform.openai.com/docs/guides/text-to-speech/voice-options) 找到,例如 `alloy`, `echo`, `nova`等,在 `config.yaml` 中修改 `openai_tts.voice` 即可。
46+
声音列表可以在 [官网](https://platform.openai.com/docs/guides/text-to-speech/voice-options) 找到,例如 `alloy`, `echo`, `nova`等,在 `config.yaml` 中修改 `openai_tts.voice` 即可。
4747

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

9494

9595
```
@@ -160,7 +160,7 @@ VideoLingo 支持 Windows、macOS 和 Linux 系统,可使用 CPU 或 GPU 运
160160

161161
![tutorial](https://github.com/user-attachments/assets/983ba58b-5ae3-4132-90f5-6d48801465dd)
162162

163-
7. (可选)更多设置可以在 `config.yaml` 中手动修改,运行过程请注意命令行输出
163+
7. (可选)更多设置可以在 `config.yaml` 中手动修改,运行过程请注意命令行输出。如需使用自定义术语,请在处理前将术语添加到 `custom_terms.xlsx` 中,例如 `Biden | 登子 | 美国的瞌睡总统`
164164

165165
## 🏭 批量模式(beta)
166166

i18n/README.zh.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ VideoLingo 是一站式视频翻译本地化配音工具,能够一键生成 Ne
1919
主要特点和功能:
2020
- 🎥 使用 yt-dlp 从 Youtube 链接下载视频
2121

22-
- **🎙️ 使用 WhisperX 进行单词级时间轴字幕识别**
22+
- **🎙️ 使用 WhisperX 进行单词级和低幻觉字幕识别**
2323

24-
- **📝 使用 NLP 和 GPT 根据句意进行字幕分割**
24+
- **📝 使用 NLP 和 AI 进行字幕分割**
2525

26-
- **📚 GPT 总结提取术语知识库,上下文连贯翻译**
26+
- **📚 自定义 + AI 生成术语库,保证翻译连贯性**
2727

28-
- **🔄 三步直译、反思、意译,媲美字幕组精翻效果**
28+
- **🔄 三步直译、反思、意译,实现影视级翻译质量**
2929

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

32-
- **🗣️ 使用 GPT-SoVITS 等方法对齐克隆配音**
32+
- **🗣️ 支持 GPT-SoVITS、Azure、OpenAI 等多种配音方案**
3333

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

0 commit comments

Comments
 (0)