File size: 12,620 Bytes
a9536c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# AI-RVC 一键 AI 翻唱 (Colab)\n",
    "\n",
    "[Open in Colab](https://colab.research.google.com/github/mason369/AI-RVC/blob/master/AI_RVC_Colab.ipynb)\n",
    "\n",
    "这是 AI-RVC 的 Google Colab 运行入口。Notebook 会创建独立 Python 3.10 环境,再运行项目安装脚本,避免 Colab 默认 Python 版本变化影响 `fairseq==0.12.2`。\n",
    "\n",
    "当前处理链路模型:\n",
    "\n",
    "| 环节 | 默认模型 |\n",
    "|------|----------|\n",
    "| 人声分离 | `ensemble:vocal_rvc` |\n",
    "| 卡拉OK分离 | `ensemble:karaoke` |\n",
    "| 去混响 / DeEcho | `dereverb_mel_band_roformer_anvuew_sdr_19.1729.ckpt` |\n",
    "| 内容特征 | `hubert_base.pt` |\n",
    "| F0 音高 | `rmvpe.pt` |\n",
    "| VC 推理 | RVC v2 `.pth` + 可选 FAISS `.index` |\n",
    "\n",
    "使用前请在 Colab 菜单选择:`代码执行程序 -> 更改运行时类型 -> T4 GPU`,然后按顺序运行每个单元格。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. 检查 Colab 运行时\n",
    "\n",
    "确认当前机器有 GPU,并显示 Colab 默认 Python。后续实际安装会使用独立 Python 3.10 环境。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "import subprocess\n",
    "\n",
    "print('Colab 默认 Python:', sys.version)\n",
    "print('\\nGPU 信息:')\n",
    "subprocess.run(['nvidia-smi'], check=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 克隆或刷新仓库\n",
    "\n",
    "如果 `/content/AI-RVC` 已存在,会重置到 GitHub `master` 分支,确保 Colab 环境和仓库最新代码一致。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "set -euo pipefail\n",
    "cd /content\n",
    "if [ -d AI-RVC/.git ]; then\n",
    "  git -C AI-RVC fetch origin master\n",
    "  git -C AI-RVC reset --hard origin/master\n",
    "else\n",
    "  git clone https://github.com/mason369/AI-RVC.git AI-RVC\n",
    "fi\n",
    "cd /content/AI-RVC\n",
    "git rev-parse --short HEAD\n",
    "ls -la"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. 创建 Python 3.10 环境并安装依赖\n",
    "\n",
    "这个步骤会安装 `uv`,用它准备 Python 3.10,然后调用项目自带 `install.py --no-run`。如果任何依赖安装失败,单元格会直接停止并显示错误。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "set -euo pipefail\n",
    "cd /content/AI-RVC\n",
    "\n",
    "sudo apt-get update -y\n",
    "sudo apt-get install -y ffmpeg build-essential python3-dev curl git\n",
    "\n",
    "if ! command -v uv >/dev/null 2>&1; then\n",
    "  curl -LsSf https://astral.sh/uv/install.sh | sh\n",
    "fi\n",
    "export PATH=\"$HOME/.local/bin:$PATH\"\n",
    "uv --version\n",
    "uv python install 3.10\n",
    "uv venv --seed --python 3.10 venv310\n",
    "PY=/content/AI-RVC/venv310/bin/python\n",
    "$PY --version\n",
    "$PY -m pip --version\n",
    "$PY -m pip install --upgrade pip\n",
    "$PY -m pip install torch torchaudio --index-url https://download.pytorch.org/whl/cu126\n",
    "$PY - <<'PY'\n",
    "import torch\n",
    "print('Torch:', torch.__version__)\n",
    "print('CUDA available:', torch.cuda.is_available())\n",
    "if not torch.cuda.is_available():\n",
    "    raise RuntimeError('GPU PyTorch install completed but CUDA is not available.')\n",
    "print('CUDA:', torch.version.cuda)\n",
    "print('GPU:', torch.cuda.get_device_name(0))\n",
    "PY\n",
    "uv run --python 3.10 python install.py --no-run"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. 严格验证依赖与默认模型配置\n",
    "\n",
    "这里会确认关键包、Python 版本、CUDA、Colab 默认分离模型、卡拉OK模型、DeEcho模型都符合当前项目配置。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "set -euo pipefail\n",
    "cd /content/AI-RVC\n",
    "PY=/content/AI-RVC/venv310/bin/python\n",
    "$PY - <<'PY'\n",
    "import importlib.metadata as md\n",
    "import sys\n",
    "import torch\n",
    "from infer.separator import (\n",
    "    ROFORMER_DEFAULT_MODEL,\n",
    "    KARAOKE_DEFAULT_MODEL,\n",
    "    ROFORMER_DEREVERB_DEFAULT_MODEL,\n",
    ")\n",
    "\n",
    "assert sys.version_info[:2] == (3, 10), sys.version\n",
    "print('Python:', sys.version)\n",
    "print('Torch:', torch.__version__)\n",
    "print('CUDA available:', torch.cuda.is_available())\n",
    "if not torch.cuda.is_available():\n",
    "    raise RuntimeError('Colab runtime did not provide CUDA. Please switch runtime type to T4 GPU and rerun.')\n",
    "\n",
    "expected = {\n",
    "    'audio-separator': '0.44.1',\n",
    "    'fairseq': '0.12.2',\n",
    "    'gradio': '3.50.2',\n",
    "}\n",
    "for dist, minimum in expected.items():\n",
    "    version = md.version(dist)\n",
    "    print(f'{dist}: {version}')\n",
    "\n",
    "assert ROFORMER_DEFAULT_MODEL == 'ensemble:vocal_rvc', ROFORMER_DEFAULT_MODEL\n",
    "assert KARAOKE_DEFAULT_MODEL == 'ensemble:karaoke', KARAOKE_DEFAULT_MODEL\n",
    "assert ROFORMER_DEREVERB_DEFAULT_MODEL == 'dereverb_mel_band_roformer_anvuew_sdr_19.1729.ckpt', ROFORMER_DEREVERB_DEFAULT_MODEL\n",
    "\n",
    "import faiss  # noqa: F401\n",
    "from audio_separator.separator import Separator  # noqa: F401\n",
    "import fairseq  # noqa: F401\n",
    "print('Dependency and model default checks passed.')\n",
    "PY"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5. 下载基础模型\n",
    "\n",
    "下载 HuBERT、RMVPE、UVR5 HP2 等必需模型。模型会保存到仓库的 `assets/` 目录。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "set -euo pipefail\n",
    "cd /content/AI-RVC\n",
    "PY=/content/AI-RVC/venv310/bin/python\n",
    "$PY tools/download_models.py\n",
    "$PY - <<'PY'\n",
    "from tools.download_models import REQUIRED_MODELS, check_model\n",
    "missing = [name for name in REQUIRED_MODELS if not check_model(name)]\n",
    "if missing:\n",
    "    raise RuntimeError('Missing required models: ' + ', '.join(missing))\n",
    "print('Required models are present:', ', '.join(REQUIRED_MODELS))\n",
    "PY"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6. 可选:查看或下载声线模型\n",
    "\n",
    "处理链路模型已经在前面准备好。这里的 `.pth` 声线模型是 RVC 目标音色,不属于分离 / F0 / HuBERT 等处理模型。可以先下载一个示例模型,也可以跳过后在 Web UI 中下载。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "set -euo pipefail\n",
    "cd /content/AI-RVC\n",
    "PY=/content/AI-RVC/venv310/bin/python\n",
    "$PY - <<'PY'\n",
    "from tools.character_models import list_available_characters, list_available_series\n",
    "print('Available series:')\n",
    "for series in list_available_series():\n",
    "    print(' -', series)\n",
    "chars = list_available_characters()\n",
    "print('\\nFirst 20 voice models:')\n",
    "for char in chars[:20]:\n",
    "    print(f\" - {char['name']}: {char.get('display', char.get('description', ''))}\")\n",
    "print('\\nTotal:', len(chars))\n",
    "PY"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Optional: download one example voice model.\n",
    "# Change character_name as needed, then run this cell.\n",
    "\n",
    "# %%bash\n",
    "# set -euo pipefail\n",
    "# cd /content/AI-RVC\n",
    "# PY=/content/AI-RVC/venv310/bin/python\n",
    "# $PY - <<'PY'\n",
    "# from tools.character_models import download_character_model\n",
    "# character_name = 'rin'\n",
    "# if not download_character_model(character_name):\n",
    "#     raise RuntimeError(f'Failed to download voice model: {character_name}')\n",
    "# print(f'Downloaded voice model: {character_name}')\n",
    "# PY"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7. 全模式处理矩阵验证\n",
    "\n",
    "上传一段含有人声的短音乐文件到 `/content/input_audio.*`,或把自己的文件路径填到 `INPUT_AUDIO`。此步骤会下载示例声线模型 `rin`,然后依次验证 RoFormer、Karaoke、Demucs、UVR5、官方 1:1、官方唱歌修复等处理模式。任何模式失败都会停止并在 JSON 里保留 traceback。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Upload a short vocal music file, then set INPUT_AUDIO to its path.\n",
    "# Example after upload: INPUT_AUDIO = '/content/input_audio.wav'\n",
    "INPUT_AUDIO = '/content/input_audio.wav'\n",
    "\n",
    "from pathlib import Path\n",
    "if not Path(INPUT_AUDIO).exists():\n",
    "    raise FileNotFoundError(\n",
    "        f'Missing test audio: {INPUT_AUDIO}. Upload a short vocal music file to this path before running the matrix.'\n",
    "    )\n",
    "print('Matrix input:', INPUT_AUDIO, Path(INPUT_AUDIO).stat().st_size, 'bytes')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "set -euo pipefail\n",
    "cd /content/AI-RVC\n",
    "PY=/content/AI-RVC/venv310/bin/python\n",
    "$PY - <<'PY'\n",
    "from tools.character_models import download_character_model\n",
    "if not download_character_model('rin'):\n",
    "    raise RuntimeError('Failed to download voice model: rin')\n",
    "print('Voice model ready: rin')\n",
    "PY\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "set -euo pipefail\n",
    "cd /content/AI-RVC\n",
    "PY=/content/AI-RVC/venv310/bin/python\n",
    "$PY tools/run_mode_matrix.py \\\n",
    "  --input /content/input_audio.wav \\\n",
    "  --output-dir /content/AI-RVC/outputs/mode_matrix_colab \\\n",
    "  --require-cuda\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 8. 启动 Web UI\n",
    "\n",
    "运行后 Colab 会输出 Gradio 公共链接。打开链接即可使用 AI-RVC Web UI。此单元格会再次检查环境和必需模型。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "set -euo pipefail\n",
    "cd /content/AI-RVC\n",
    "PY=/content/AI-RVC/venv310/bin/python\n",
    "$PY run.py --host 0.0.0.0 --port 7860 --share"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 常见问题\n",
    "\n",
    "| 问题 | 处理方式 |\n",
    "|------|----------|\n",
    "| `nvidia-smi` 失败 | 在 Colab 菜单选择 GPU 运行时后重新运行 |\n",
    "| `fairseq` 安装失败 | 确认本 notebook 的第 3 步使用了 Python 3.10 环境 |\n",
    "| `CUDA out of memory` | 换短音频,或在 UI 中降低处理负载 / 切换分离器 |\n",
    "| 模型下载失败 | 重新运行第 5 步;如果 Hugging Face 限流,可稍后再试或配置 token |\n",
    "\n",
    "本项目仅供学习研究和个人娱乐用途,请勿用于商业用途、欺诈、冒充他人或侵犯权益的场景。"
   ]
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "gpuType": "T4",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}