2023-12-28 13:11:18 +08:00
|
|
|
|
A streaming digital human based on the Ernerf model, realize audio video synchronous dialogue. It can basically achieve commercial effects.
|
|
|
|
|
基于ernerf模型的流式数字人,实现音视频同步对话。基本可以达到商用效果
|
2023-12-19 09:41:52 +08:00
|
|
|
|
|
2024-05-26 18:07:22 +08:00
|
|
|
|
[ernerf效果](https://www.bilibili.com/video/BV1PM4m1y7Q2/) [musetalk效果](https://www.bilibili.com/video/BV1gm421N7vQ/)
|
2023-12-19 09:41:52 +08:00
|
|
|
|
|
2024-03-31 12:01:28 +08:00
|
|
|
|
## Features
|
2024-05-26 18:07:22 +08:00
|
|
|
|
1. 支持多种数字人模型: ernerf、musetalk
|
|
|
|
|
2. 支持声音克隆
|
2024-03-31 12:01:28 +08:00
|
|
|
|
3. 支持多种音频特征驱动:wav2vec、hubert
|
|
|
|
|
4. 支持全身视频拼接
|
2024-04-21 18:19:24 +08:00
|
|
|
|
5. 支持rtmp和webrtc
|
2024-05-04 10:10:41 +08:00
|
|
|
|
6. 支持视频编排:不说话时播放自定义视频
|
2024-05-26 18:07:22 +08:00
|
|
|
|
7. 支持大模型对话
|
2024-03-31 12:01:28 +08:00
|
|
|
|
|
2024-01-13 20:12:08 +08:00
|
|
|
|
## 1. Installation
|
2023-12-19 09:41:52 +08:00
|
|
|
|
|
2024-01-13 20:12:08 +08:00
|
|
|
|
Tested on Ubuntu 20.04, Python3.10, Pytorch 1.12 and CUDA 11.3
|
2023-12-19 09:41:52 +08:00
|
|
|
|
|
2024-01-13 20:12:08 +08:00
|
|
|
|
### 1.1 Install dependency
|
2023-12-19 09:41:52 +08:00
|
|
|
|
|
2023-12-28 13:11:18 +08:00
|
|
|
|
```bash
|
2024-01-06 21:17:34 +08:00
|
|
|
|
conda create -n nerfstream python=3.10
|
|
|
|
|
conda activate nerfstream
|
2024-05-19 18:32:40 +08:00
|
|
|
|
conda install pytorch==1.12.1 torchvision==0.13.1 cudatoolkit=11.3 -c pytorch
|
2023-12-19 09:41:52 +08:00
|
|
|
|
pip install -r requirements.txt
|
|
|
|
|
pip install "git+https://github.com/facebookresearch/pytorch3d.git"
|
2023-12-28 13:11:18 +08:00
|
|
|
|
pip install tensorflow-gpu==2.8.0
|
2024-05-19 18:32:40 +08:00
|
|
|
|
pip install --upgrade "protobuf<=3.20.1"
|
2024-05-29 08:46:15 +08:00
|
|
|
|
pip install --upgrade "edge-tts<=6.1.11"
|
2023-12-19 09:41:52 +08:00
|
|
|
|
```
|
2024-05-19 18:32:40 +08:00
|
|
|
|
安装常见问题[FAQ](/assets/faq.md)
|
2023-12-28 13:11:18 +08:00
|
|
|
|
linux cuda环境搭建可以参考这篇文章 https://zhuanlan.zhihu.com/p/674972886
|
2023-12-19 09:41:52 +08:00
|
|
|
|
|
|
|
|
|
|
2024-05-02 20:32:28 +08:00
|
|
|
|
## 2. Quick Start
|
|
|
|
|
默认采用webrtc推流到srs
|
2024-01-13 20:12:08 +08:00
|
|
|
|
### 2.1 运行rtmpserver (srs)
|
2023-12-19 09:41:52 +08:00
|
|
|
|
```
|
2024-05-02 20:32:28 +08:00
|
|
|
|
export CANDIDATE='<服务器外网ip>'
|
|
|
|
|
docker run --rm --env CANDIDATE=$CANDIDATE \
|
|
|
|
|
-p 1935:1935 -p 8080:8080 -p 1985:1985 -p 8000:8000/udp \
|
|
|
|
|
registry.cn-hangzhou.aliyuncs.com/ossrs/srs:5 \
|
|
|
|
|
objs/srs -c conf/rtc.conf
|
2023-12-19 09:41:52 +08:00
|
|
|
|
```
|
|
|
|
|
|
2024-01-13 20:12:08 +08:00
|
|
|
|
### 2.2 启动数字人:
|
2023-12-19 09:41:52 +08:00
|
|
|
|
|
2023-12-28 13:11:18 +08:00
|
|
|
|
```python
|
|
|
|
|
python app.py
|
2023-12-19 09:41:52 +08:00
|
|
|
|
```
|
|
|
|
|
|
2023-12-28 13:11:18 +08:00
|
|
|
|
如果访问不了huggingface,在运行前
|
2023-12-19 09:41:52 +08:00
|
|
|
|
```
|
2023-12-28 13:11:18 +08:00
|
|
|
|
export HF_ENDPOINT=https://hf-mirror.com
|
2023-12-19 09:41:52 +08:00
|
|
|
|
```
|
|
|
|
|
|
2024-05-02 20:32:28 +08:00
|
|
|
|
用浏览器打开http://serverip:8010/rtcpush.html, 在文本框输入任意文字,提交。数字人播报该段文字
|
|
|
|
|
备注:服务端需要开放端口 tcp:8000,8010,1985; udp:8000
|
2024-01-28 07:58:46 +08:00
|
|
|
|
|
2024-03-31 12:01:28 +08:00
|
|
|
|
## 3. More Usage
|
2024-03-23 18:15:35 +08:00
|
|
|
|
### 3.1 使用LLM模型进行数字人对话
|
2024-01-28 07:58:46 +08:00
|
|
|
|
|
2024-04-14 19:08:25 +08:00
|
|
|
|
目前借鉴数字人对话系统[LinlyTalker](https://github.com/Kedreamix/Linly-Talker)的方式,LLM模型支持Chatgpt,Qwen和GeminiPro。需要在app.py中填入自己的api_key。
|
2024-01-28 07:58:46 +08:00
|
|
|
|
|
2024-05-02 20:32:28 +08:00
|
|
|
|
用浏览器打开http://serverip:8010/rtcpushchat.html
|
2024-02-25 19:00:10 +08:00
|
|
|
|
|
2024-04-21 18:19:24 +08:00
|
|
|
|
### 3.2 声音克隆
|
|
|
|
|
可以任意选用下面两种服务,推荐用gpt-sovits
|
|
|
|
|
#### 3.2.1 gpt-sovits
|
|
|
|
|
服务部署参照[gpt-sovits](/tts/README.md)
|
|
|
|
|
运行
|
|
|
|
|
```
|
|
|
|
|
python app.py --tts gpt-sovits --TTS_SERVER http://127.0.0.1:5000 --CHARACTER test --EMOTION default
|
|
|
|
|
```
|
|
|
|
|
#### 3.2.2 xtts
|
2024-02-25 19:00:10 +08:00
|
|
|
|
运行xtts服务,参照 https://github.com/coqui-ai/xtts-streaming-server
|
|
|
|
|
```
|
|
|
|
|
docker run --gpus=all -e COQUI_TOS_AGREED=1 --rm -p 9000:80 ghcr.io/coqui-ai/xtts-streaming-server:latest
|
|
|
|
|
```
|
2024-02-25 19:10:12 +08:00
|
|
|
|
然后运行,其中ref.wav为需要克隆的声音文件
|
2024-02-25 19:00:10 +08:00
|
|
|
|
```
|
2024-04-21 18:19:24 +08:00
|
|
|
|
python app.py --tts xtts --REF_FILE data/ref.wav --TTS_SERVER http://localhost:9000
|
2024-02-25 19:00:10 +08:00
|
|
|
|
```
|
2024-03-23 18:15:35 +08:00
|
|
|
|
|
|
|
|
|
### 3.3 音频特征用hubert
|
|
|
|
|
如果训练模型时用的hubert提取音频特征,用如下命令启动数字人
|
|
|
|
|
```
|
|
|
|
|
python app.py --asr_model facebook/hubert-large-ls960-ft
|
|
|
|
|
```
|
2024-03-23 21:13:21 +08:00
|
|
|
|
|
|
|
|
|
### 3.4 设置背景图片
|
|
|
|
|
```
|
2024-05-26 11:10:03 +08:00
|
|
|
|
python app.py --bg_img bc.jpg
|
2024-03-23 21:13:21 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 3.5 全身视频拼接
|
|
|
|
|
#### 3.5.1 切割训练用的视频
|
|
|
|
|
```
|
|
|
|
|
ffmpeg -i fullbody.mp4 -vf crop="400:400:100:5" train.mp4
|
|
|
|
|
```
|
|
|
|
|
用train.mp4训练模型
|
|
|
|
|
#### 3.5.2 提取全身图片
|
|
|
|
|
```
|
|
|
|
|
ffmpeg -i fullbody.mp4 -vf fps=25 -qmin 1 -q:v 1 -start_number 0 data/fullbody/img/%d.jpg
|
|
|
|
|
```
|
|
|
|
|
#### 3.5.2 启动数字人
|
|
|
|
|
```
|
|
|
|
|
python app.py --fullbody --fullbody_img data/fullbody/img --fullbody_offset_x 100 --fullbody_offset_y 5 --fullbody_width 580 --fullbody_height 1080 --W 400 --H 400
|
|
|
|
|
```
|
|
|
|
|
- --fullbody_width、--fullbody_height 全身视频的宽、高
|
2024-03-31 12:01:28 +08:00
|
|
|
|
- --W、--H 训练视频的宽、高
|
|
|
|
|
- ernerf训练第三步torso如果训练的不好,在拼接处会有接缝。可以在上面的命令加上--torso_imgs data/xxx/torso_imgs,torso不用模型推理,直接用训练数据集里的torso图片。这种方式可能头颈处会有些人工痕迹。
|
2024-04-14 19:08:25 +08:00
|
|
|
|
|
2024-05-04 10:10:41 +08:00
|
|
|
|
### 3.6 不说话时用自定义视频替代
|
|
|
|
|
- 提取自定义视频图片
|
|
|
|
|
```
|
|
|
|
|
ffmpeg -i silence.mp4 -vf fps=25 -qmin 1 -q:v 1 -start_number 0 data/customvideo/img/%d.png
|
|
|
|
|
```
|
|
|
|
|
- 运行数字人
|
|
|
|
|
```
|
|
|
|
|
python app.py --customvideo --customvideo_img data/customvideo/img --customvideo_imgnum 100
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 3.7 webrtc p2p
|
2024-04-27 18:08:57 +08:00
|
|
|
|
此种模式不需要srs
|
2024-04-14 19:08:25 +08:00
|
|
|
|
```
|
|
|
|
|
python app.py --transport webrtc
|
|
|
|
|
```
|
|
|
|
|
用浏览器打开http://serverip:8010/webrtc.html
|
|
|
|
|
|
2024-05-04 10:10:41 +08:00
|
|
|
|
### 3.8 rtmp推送到srs
|
2024-05-02 20:32:28 +08:00
|
|
|
|
- 安装rtmpstream库
|
|
|
|
|
参照 https://github.com/lipku/python_rtmpstream
|
|
|
|
|
|
|
|
|
|
- 启动srs
|
2024-04-27 18:08:57 +08:00
|
|
|
|
```
|
2024-05-02 20:32:28 +08:00
|
|
|
|
docker run --rm -it -p 1935:1935 -p 1985:1985 -p 8080:8080 registry.cn-hangzhou.aliyuncs.com/ossrs/srs:5
|
2024-04-27 18:08:57 +08:00
|
|
|
|
```
|
2024-05-04 10:10:41 +08:00
|
|
|
|
- 运行数字人
|
2024-05-02 20:32:28 +08:00
|
|
|
|
```python
|
|
|
|
|
python app.py --transport rtmp --push_url 'rtmp://localhost/live/livestream'
|
2024-04-27 18:08:57 +08:00
|
|
|
|
```
|
2024-05-02 20:32:28 +08:00
|
|
|
|
用浏览器打开http://serverip:8010/echo.html
|
2024-05-26 11:10:03 +08:00
|
|
|
|
|
|
|
|
|
### 3.9 模型用musetalk
|
|
|
|
|
暂不支持rtmp推送
|
|
|
|
|
- 安装依赖库
|
|
|
|
|
```bash
|
|
|
|
|
conda install ffmpeg
|
|
|
|
|
pip install --no-cache-dir -U openmim
|
|
|
|
|
mim install mmengine
|
|
|
|
|
mim install "mmcv>=2.0.1"
|
|
|
|
|
mim install "mmdet>=3.1.0"
|
|
|
|
|
mim install "mmpose>=1.1.0"
|
|
|
|
|
```
|
|
|
|
|
- 下载模型
|
|
|
|
|
下载MuseTalk运行需要的模型,提供一个下载地址 https://caiyun.139.com/m/i?2eAjs2nXXnRgr 提取码:qdg2
|
|
|
|
|
解压后,将models下文件拷到本项目的models下
|
|
|
|
|
下载数字人模型,链接: https://caiyun.139.com/m/i?2eAjs8optksop 提取码:3mkt, 解压后将整个文件夹拷到本项目的data/avatars下
|
|
|
|
|
- 运行
|
|
|
|
|
python app.py --model musetalk --transport webrtc
|
|
|
|
|
用浏览器打开http://serverip:8010/webrtc.html
|
|
|
|
|
可以设置--batch_size 提高显卡利用率,设置--avatar_id 运行不同的数字人
|
|
|
|
|
#### 替换成自己的数字人
|
|
|
|
|
```bash
|
|
|
|
|
git clone https://github.com/TMElyralab/MuseTalk.git
|
|
|
|
|
cd MuseTalk
|
|
|
|
|
修改configs/inference/realtime.yaml,将preparation改为True
|
|
|
|
|
python -m scripts.realtime_inference --inference_config configs/inference/realtime.yaml
|
|
|
|
|
运行后将results/avatars下文件拷到本项目的data/avatars下
|
|
|
|
|
```
|
2024-01-13 20:15:09 +08:00
|
|
|
|
|
2024-03-23 18:15:35 +08:00
|
|
|
|
## 4. Docker Run
|
2024-01-13 20:12:08 +08:00
|
|
|
|
不需要第1步的安装,直接运行。
|
2024-01-07 14:19:21 +08:00
|
|
|
|
```
|
2024-01-13 20:12:08 +08:00
|
|
|
|
docker run --gpus all -it --network=host --rm registry.cn-hangzhou.aliyuncs.com/lipku/nerfstream:v1.3
|
2024-01-07 14:19:21 +08:00
|
|
|
|
```
|
2024-05-19 18:32:40 +08:00
|
|
|
|
docker版本已经不是最新代码,可以作为一个空环境,把最新代码拷进去运行。
|
|
|
|
|
另外提供autodl镜像:https://www.codewithgpu.com/i/lipku/metahuman-stream/base
|
2024-01-07 14:19:21 +08:00
|
|
|
|
|
2024-03-23 18:15:35 +08:00
|
|
|
|
## 5. Data flow
|
2023-12-28 13:11:18 +08:00
|
|
|
|
![](/assets/dataflow.png)
|
2023-12-19 09:41:52 +08:00
|
|
|
|
|
2024-03-23 18:15:35 +08:00
|
|
|
|
## 6. 数字人模型文件
|
2023-12-28 13:11:18 +08:00
|
|
|
|
可以替换成自己训练的模型(https://github.com/Fictionarry/ER-NeRF)
|
2023-12-19 09:41:52 +08:00
|
|
|
|
```python
|
|
|
|
|
.
|
|
|
|
|
├── data
|
2024-02-25 19:00:10 +08:00
|
|
|
|
│ ├── data_kf.json
|
|
|
|
|
│ ├── au.csv
|
2023-12-19 09:41:52 +08:00
|
|
|
|
│ ├── pretrained
|
2024-01-28 07:58:46 +08:00
|
|
|
|
│ └── └── ngp_kf.pth
|
2023-12-19 09:41:52 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
2024-03-23 18:15:35 +08:00
|
|
|
|
## 7. 性能分析
|
2024-01-13 20:12:08 +08:00
|
|
|
|
1. 帧率
|
2024-03-02 11:30:53 +08:00
|
|
|
|
在Tesla T4显卡上测试整体fps为18左右,如果去掉音视频编码推流,帧率在20左右。用4090显卡可以达到40多帧/秒。
|
2024-01-13 20:12:08 +08:00
|
|
|
|
优化:新开一个线程运行音视频编码推流
|
|
|
|
|
2. 延时
|
2024-04-05 08:55:21 +08:00
|
|
|
|
整体延时3s左右
|
|
|
|
|
(1)tts延时1.7s左右,目前用的edgetts,需要将每句话转完后一次性输入,可以优化tts改成流式输入
|
|
|
|
|
(2)wav2vec延时0.4s,需要缓存18帧音频做计算
|
2024-05-02 20:32:28 +08:00
|
|
|
|
(3)srs转发延时,设置srs服务器减少缓冲延时。具体配置可看 https://ossrs.net/lts/zh-cn/docs/v5/doc/low-latency
|
2024-01-13 20:12:08 +08:00
|
|
|
|
|
2024-03-23 18:15:35 +08:00
|
|
|
|
## 8. TODO
|
2024-01-28 07:58:46 +08:00
|
|
|
|
- [x] 添加chatgpt实现数字人对话
|
2024-02-25 19:00:10 +08:00
|
|
|
|
- [x] 声音克隆
|
2024-05-04 10:10:41 +08:00
|
|
|
|
- [x] 数字人静音时用一段视频代替
|
2024-05-26 18:07:22 +08:00
|
|
|
|
- [x] MuseTalk
|
|
|
|
|
- [ ] SyncTalk
|
2023-12-19 09:41:52 +08:00
|
|
|
|
|
2023-12-28 13:11:18 +08:00
|
|
|
|
如果本项目对你有帮助,帮忙点个star。也欢迎感兴趣的朋友一起来完善该项目。
|
2024-03-02 11:30:53 +08:00
|
|
|
|
Email: lipku@foxmail.com
|
2024-05-19 18:32:40 +08:00
|
|
|
|
知识星球: https://t.zsxq.com/7NMyO
|
2024-03-02 11:52:25 +08:00
|
|
|
|
微信公众号:数字人技术
|
|
|
|
|
![](https://mmbiz.qpic.cn/sz_mmbiz_jpg/l3ZibgueFiaeyfaiaLZGuMGQXnhLWxibpJUS2gfs8Dje6JuMY8zu2tVyU9n8Zx1yaNncvKHBMibX0ocehoITy5qQEZg/640?wxfrom=12&tp=wxpic&usePicPrefetch=1&wx_fmt=jpeg&from=appmsg)
|