Datasets:
Update OmniVoice VI voices + Colab tools
Browse files- colab/Omivoice_VI_Colab.ipynb +45 -15
colab/Omivoice_VI_Colab.ipynb
CHANGED
|
@@ -6,13 +6,13 @@
|
|
| 6 |
"source": [
|
| 7 |
"# OmniVoice — Lồng tiếng tiếng Việt trên Colab\n",
|
| 8 |
"\n",
|
| 9 |
-
"
|
| 10 |
"\n",
|
| 11 |
-
"
|
|
|
|
|
|
|
| 12 |
"\n",
|
| 13 |
-
"**Yêu cầu:** Runtime **GPU** (T4+).
|
| 14 |
-
"\n",
|
| 15 |
-
"**Trước khi chạy:** sửa `HF_REPO` thành dataset Hugging Face bạn đã upload."
|
| 16 |
],
|
| 17 |
"id": "029da2d4"
|
| 18 |
},
|
|
@@ -28,9 +28,13 @@
|
|
| 28 |
"cell_type": "code",
|
| 29 |
"metadata": {},
|
| 30 |
"source": [
|
| 31 |
-
"#
|
| 32 |
"HF_REPO = \"STBack23/omnivoice-vi\"\n",
|
| 33 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
"DEFAULT_VOICE = \"ngoc_huyen\"\n",
|
| 35 |
"MERGE_MODE = \"native\" # native | cascade | fit | strict\n",
|
| 36 |
"NUM_STEP = 32"
|
|
@@ -96,9 +100,9 @@
|
|
| 96 |
" login(\"hf_xxxxxxxx\") # thay token của bạn\n",
|
| 97 |
" print(\"Đã login HF (token)\")"
|
| 98 |
],
|
| 99 |
-
"id": "e659ec6b",
|
| 100 |
"execution_count": null,
|
| 101 |
-
"outputs": []
|
|
|
|
| 102 |
},
|
| 103 |
{
|
| 104 |
"cell_type": "markdown",
|
|
@@ -224,12 +228,32 @@
|
|
| 224 |
"cell_type": "code",
|
| 225 |
"metadata": {},
|
| 226 |
"source": [
|
| 227 |
-
"from google.colab import
|
|
|
|
|
|
|
| 228 |
"\n",
|
| 229 |
-
"
|
| 230 |
-
"
|
| 231 |
-
"
|
| 232 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
],
|
| 234 |
"execution_count": null,
|
| 235 |
"outputs": [],
|
|
@@ -244,7 +268,9 @@
|
|
| 244 |
"result = speak.run_srt_pipeline(\n",
|
| 245 |
" profile_path,\n",
|
| 246 |
" SRT_PATH,\n",
|
|
|
|
| 247 |
" merge=True,\n",
|
|
|
|
| 248 |
" merge_mode=MERGE_MODE,\n",
|
| 249 |
" num_step=NUM_STEP,\n",
|
| 250 |
" model=MODEL,\n",
|
|
@@ -254,8 +280,12 @@
|
|
| 254 |
"print(result[\"log\"])\n",
|
| 255 |
"merged = result.get(\"merged_wav\")\n",
|
| 256 |
"if merged:\n",
|
| 257 |
-
" display(Audio(merged))\n",
|
| 258 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
],
|
| 260 |
"execution_count": null,
|
| 261 |
"outputs": [],
|
|
|
|
| 6 |
"source": [
|
| 7 |
"# OmniVoice — Lồng tiếng tiếng Việt trên Colab\n",
|
| 8 |
"\n",
|
| 9 |
+
"Notebook chạy [OmniVoice](https://huggingface.co/k2-fsa/OmniVoice) với **6 giọng Việt** và pipeline **SRT lồng tiếng** (`native`).\n",
|
| 10 |
"\n",
|
| 11 |
+
"**Luồng Drive (mặc định):**\n",
|
| 12 |
+
"1. Đặt file `.srt` vào **`MyDrive/Omivoice/`** (tên file cấu hình ở cell 0)\n",
|
| 13 |
+
"2. Chạy notebook → kết quả ghi lại **`MyDrive/Omivoice/`** (`*_merged.wav`, `output/...`)\n",
|
| 14 |
"\n",
|
| 15 |
+
"**Yêu cầu:** Runtime **GPU** (T4+)."
|
|
|
|
|
|
|
| 16 |
],
|
| 17 |
"id": "029da2d4"
|
| 18 |
},
|
|
|
|
| 28 |
"cell_type": "code",
|
| 29 |
"metadata": {},
|
| 30 |
"source": [
|
| 31 |
+
"# Hugging Face (giọng + speak.py)\n",
|
| 32 |
"HF_REPO = \"STBack23/omnivoice-vi\"\n",
|
| 33 |
"\n",
|
| 34 |
+
"# Google Drive — MyDrive/Omivoice/\n",
|
| 35 |
+
"DRIVE_FOLDER = \"Omivoice\"\n",
|
| 36 |
+
"SRT_FILE = \"input.srt\" # file SRT trong thư mục Omivoice (có thể \"video\" hoặc \"video.srt\")\n",
|
| 37 |
+
"\n",
|
| 38 |
"DEFAULT_VOICE = \"ngoc_huyen\"\n",
|
| 39 |
"MERGE_MODE = \"native\" # native | cascade | fit | strict\n",
|
| 40 |
"NUM_STEP = 32"
|
|
|
|
| 100 |
" login(\"hf_xxxxxxxx\") # thay token của bạn\n",
|
| 101 |
" print(\"Đã login HF (token)\")"
|
| 102 |
],
|
|
|
|
| 103 |
"execution_count": null,
|
| 104 |
+
"outputs": [],
|
| 105 |
+
"id": "e659ec6b"
|
| 106 |
},
|
| 107 |
{
|
| 108 |
"cell_type": "markdown",
|
|
|
|
| 228 |
"cell_type": "code",
|
| 229 |
"metadata": {},
|
| 230 |
"source": [
|
| 231 |
+
"from google.colab import drive\n",
|
| 232 |
+
"\n",
|
| 233 |
+
"drive.mount(\"/content/drive\")\n",
|
| 234 |
"\n",
|
| 235 |
+
"DRIVE_OMIVOICE = Path(\"/content/drive/MyDrive\") / DRIVE_FOLDER\n",
|
| 236 |
+
"DRIVE_OMIVOICE.mkdir(parents=True, exist_ok=True)\n",
|
| 237 |
+
"\n",
|
| 238 |
+
"srt_name = SRT_FILE if SRT_FILE.lower().endswith(\".srt\") else f\"{SRT_FILE}.srt\"\n",
|
| 239 |
+
"SRT_PATH = DRIVE_OMIVOICE / srt_name\n",
|
| 240 |
+
"\n",
|
| 241 |
+
"if not SRT_PATH.exists():\n",
|
| 242 |
+
" existing = sorted(DRIVE_OMIVOICE.glob(\"*.srt\"))\n",
|
| 243 |
+
" hint = \"\\n \".join(str(p.name) for p in existing) if existing else \"(chưa có file .srt)\"\n",
|
| 244 |
+
" raise FileNotFoundError(\n",
|
| 245 |
+
" f\"Không thấy {SRT_PATH}\\n\"\n",
|
| 246 |
+
" f\"Đặt file vào MyDrive/{DRIVE_FOLDER}/ hoặc sửa SRT_FILE.\\n\"\n",
|
| 247 |
+
" f\"Các file .srt hiện có:\\n {hint}\"\n",
|
| 248 |
+
" )\n",
|
| 249 |
+
"\n",
|
| 250 |
+
"MERGE_OUT = DRIVE_OMIVOICE / f\"{SRT_PATH.stem}_merged.wav\"\n",
|
| 251 |
+
"OUTPUT_DIR = DRIVE_OMIVOICE / \"output\" / PROFILE[\"slug\"] / SRT_PATH.stem\n",
|
| 252 |
+
"\n",
|
| 253 |
+
"print(f\"Drive: {DRIVE_OMIVOICE}\")\n",
|
| 254 |
+
"print(f\"Input: {SRT_PATH}\")\n",
|
| 255 |
+
"print(f\"Output: {MERGE_OUT}\")\n",
|
| 256 |
+
"print(f\"Cues: {OUTPUT_DIR}\")"
|
| 257 |
],
|
| 258 |
"execution_count": null,
|
| 259 |
"outputs": [],
|
|
|
|
| 268 |
"result = speak.run_srt_pipeline(\n",
|
| 269 |
" profile_path,\n",
|
| 270 |
" SRT_PATH,\n",
|
| 271 |
+
" output_dir=OUTPUT_DIR,\n",
|
| 272 |
" merge=True,\n",
|
| 273 |
+
" merge_output=MERGE_OUT,\n",
|
| 274 |
" merge_mode=MERGE_MODE,\n",
|
| 275 |
" num_step=NUM_STEP,\n",
|
| 276 |
" model=MODEL,\n",
|
|
|
|
| 280 |
"print(result[\"log\"])\n",
|
| 281 |
"merged = result.get(\"merged_wav\")\n",
|
| 282 |
"if merged:\n",
|
| 283 |
+
" display(Audio(str(merged)))\n",
|
| 284 |
+
"\n",
|
| 285 |
+
"print(\"\\n--- Đã lưu trên Drive ---\")\n",
|
| 286 |
+
"print(f\"WAV gộp: {result.get('merged_wav')}\")\n",
|
| 287 |
+
"print(f\"Từng cue: {result.get('output_dir')}\")\n",
|
| 288 |
+
"print(f\"SRT shifted: {result.get('shifted_srt')}\")"
|
| 289 |
],
|
| 290 |
"execution_count": null,
|
| 291 |
"outputs": [],
|