Files
ViGent/Docs/DevLogs/Day2.md
2026-01-16 16:27:30 +08:00

201 lines
5.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Day 2 - MuseTalk 集成与服务器部署
**日期**2026-01-14
**开发环境**Windows 11 (本地) / Ubuntu 24.04 (服务器)
**目标平台**Dell R730 (GPU1: RTX 3090 用于 MuseTalk)
---
## 🎯 今日目标
1. 端口配置(解决端口冲突)
2. MuseTalk 服务器部署
3. MuseTalk 完整集成测试
---
## 🔧 端口配置
### 问题描述
服务器上 8000 端口被 `xiaozhi-server` 占用3000 端口被 `LunaTV` 占用。
### 解决方案
| 服务 | 原端口 | 新端口 |
|------|--------|--------|
| 后端 API | 8000 | **8006** |
| 前端 UI | 3000 | **3002** |
### 修改的文件
- `frontend/src/app/page.tsx` - API_BASE
- `frontend/src/app/publish/page.tsx` - API_BASE
- `frontend/next.config.ts` - rewrite destination
- `README.md` - 访问地址
- `Docs/DEPLOY_MANUAL.md` - 部署命令和验证步骤
**状态**:✅ 已完成
---
## 🔧 MuseTalk 服务器部署
### 环境配置
```bash
# 创建 conda 环境
conda create -n musetalk python=3.10 -y
conda activate musetalk
# 安装 PyTorch (CUDA 12.1)
pip install torch==2.1.0 --index-url https://download.pytorch.org/whl/cu121
pip install torchvision --index-url https://download.pytorch.org/whl/cu121
# 安装 MuseTalk 依赖
pip install -r requirements.txt
pip install openmim
mim install mmengine mmcv mmdet
# mmpose 安装问题 (chumpy 编译失败)
pip install mmpose --no-deps
pip install xtcocotools munkres json_tricks
```
### 模型权重下载
```bash
huggingface-cli download TMElyralab/MuseTalk --local-dir ./models/musetalk
huggingface-cli download stabilityai/sd-vae-ft-mse --local-dir ./models/sd-vae-ft-mse
huggingface-cli download openai/whisper-tiny --local-dir ./models/whisper
```
**状态**:✅ 完成(权重 ~7GB 已下载)
---
## 🔧 前端 API 请求问题
### 问题描述
前端请求 `http://127.0.0.1:8006` 失败,浏览器把 127.0.0.1 解析到本地机器而非服务器。
### 解决方案
改用动态 API 地址:
```typescript
const API_BASE = typeof window !== 'undefined'
? `http://${window.location.hostname}:8006`
: 'http://localhost:8006';
```
**状态**:✅ 已修复
---
## 🔧 venv/conda 环境隔离
### 问题描述
后端使用 Python venvMuseTalk 使用 conda 环境,无法直接 import。
### 解决方案
重写 `lipsync_service.py`,通过 subprocess 调用 conda 环境:
```python
self.conda_python = Path.home() / "ProgramFiles" / "miniconda3" / "envs" / "musetalk" / "bin" / "python"
cmd = [str(self.conda_python), "-m", "scripts.inference", ...]
env["CUDA_VISIBLE_DEVICES"] = str(self.gpu_id) # 使用 GPU1
subprocess.run(cmd, cwd=str(self.musetalk_dir), env=env, ...)
```
**状态**:✅ 代码已完成
---
## 🔧 模型权重路径问题
### 问题描述
健康检查返回 `weights: False`
### 原因
huggingface-cli 下载后目录结构是嵌套的:
- 期望:`models/musetalkV15/`
- 实际:`models/musetalk/musetalkV15/`
### 修复
```python
# 修复后
required_dirs = [
self.musetalk_dir / "models" / "musetalk" / "musetalkV15",
self.musetalk_dir / "models" / "whisper",
]
```
**状态**:✅ 已修复,健康检查返回 `ready: True`
---
## 🚨 遗留问题MuseTalk 未被调用
### 现象
视频生成成功,但日志显示未调用 MuseTalk 推理。
### 诊断结果
1. **健康检查通过**
```json
{"conda_env": true, "weights": true, "gpu": true, "gpu_name": "NVIDIA GeForce RTX 3090", "ready": true}
```
2. **代码逻辑问题**(已修复但未验证):
```python
# 之前 check_health() 返回字典if 判断永远为 True
if await lipsync.check_health(): # 返回 dict非 bool
# 修复后
health = await lipsync.check_health()
if health.get("ready", False): # 正确检查
```
3. **服务器代码同步问题**
- 本地代码已修改
- 服务器可能未完全拉取最新代码
### 待验证
1. 重启后端进程(当前进程可能还在用旧代码)
2. 观察终端日志是否显示 `[LipSync] Starting MuseTalk inference...`
3. 如果日志显示但推理失败,检查 subprocess 调用错误
---
## ✅ 今日完成
1. ✅ 端口配置8000→8006, 3000→3002
2. ✅ MuseTalk conda 环境安装
3. ✅ 模型权重下载 (~7GB)
4. ✅ 前端动态 API 地址
5. ✅ lipsync_service.py subprocess 调用方式
6. ✅ 模型权重路径修复
7. ✅ 健康检查功能验证
8. ✅ videos.py check_health() 返回值检查修复
9. ✅ 服务器代码同步验证
---
## ❌ 未完成
1. ❌ MuseTalk 实际推理调用(代码已就绪,需重启后端验证)
2. ❌ 端到端唇形同步测试
3. ❌ 社交媒体发布测试
---
## 📋 明日首要任务
```bash
# 1. 重启后端
cd /home/rongye/ProgramFiles/ViGent/backend
source venv/bin/activate
uvicorn app.main:app --host 0.0.0.0 --port 8006
# 2. 生成视频,观察终端日志
# 应该看到:
# [LipSync] Health check: {'ready': True, ...}
# [LipSync] Starting MuseTalk inference...
# 3. 如果推理失败,检查 subprocess 输出
```