You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
5.3 KiB
Markdown

A streaming digital human based on the Ernerf model realize audio video synchronous dialogue. It can basically achieve commercial effects.
基于ernerf模型的流式数字人实现音视频同步对话。基本可以达到商用效果
2 years ago
2 years ago
[![Watch the video]](/assets/demo.mp4)
2 years ago
## Features
1. 支持声音克隆
2. 支持大模型对话
3. 支持多种音频特征驱动wav2vec、hubert
4. 支持全身视频拼接
5. 支持rtmp和webrtc
2 years ago
## 1. Installation
2 years ago
2 years ago
Tested on Ubuntu 20.04, Python3.10, Pytorch 1.12 and CUDA 11.3
2 years ago
2 years ago
### 1.1 Install dependency
2 years ago
```bash
2 years ago
conda create -n nerfstream python=3.10
conda install pytorch==1.12.1 torchvision==0.13.1 cudatoolkit=11.3 -c pytorch
conda activate nerfstream
2 years ago
pip install -r requirements.txt
pip install "git+https://github.com/facebookresearch/pytorch3d.git"
pip install tensorflow-gpu==2.8.0
2 years ago
```
linux cuda环境搭建可以参考这篇文章 https://zhuanlan.zhihu.com/p/674972886
2 years ago
2 years ago
### 1.2 安装rtmpstream库
参照 https://github.com/lipku/python_rtmpstream
2 years ago
2 years ago
## 2. Run
2 years ago
2 years ago
### 2.1 运行rtmpserver (srs)
2 years ago
```
docker run --rm -it -p 1935:1935 -p 1985:1985 -p 8080:8080 registry.cn-hangzhou.aliyuncs.com/ossrs/srs:5
2 years ago
```
2 years ago
### 2.2 启动数字人:
2 years ago
```python
python app.py
2 years ago
```
如果访问不了huggingface在运行前
2 years ago
```
export HF_ENDPOINT=https://hf-mirror.com
2 years ago
```
1 year ago
运行成功后用vlc访问rtmp://serverip/live/livestream
2 years ago
1 year ago
用浏览器打开http://serverip:8010/echo.html, 在文本框输入任意文字,提交。数字人播报该段文字
2 years ago
## 3. More Usage
### 3.1 使用LLM模型进行数字人对话
2 years ago
1 year ago
目前借鉴数字人对话系统[LinlyTalker](https://github.com/Kedreamix/Linly-Talker)的方式LLM模型支持Chatgpt,Qwen和GeminiPro。需要在app.py中填入自己的api_key。
2 years ago
1 year ago
用浏览器打开http://serverip:8010/chat.html
1 year ago
### 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
1 year ago
运行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
```
1 year ago
然后运行其中ref.wav为需要克隆的声音文件
1 year ago
```
python app.py --tts xtts --REF_FILE data/ref.wav --TTS_SERVER http://localhost:9000
1 year ago
```
### 3.3 音频特征用hubert
如果训练模型时用的hubert提取音频特征用如下命令启动数字人
```
python app.py --asr_model facebook/hubert-large-ls960-ft
```
### 3.4 设置背景图片
```
python app.py --bg_img bg.jpg
```
### 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 全身视频的宽、高
- --W、--H 训练视频的宽、高
- ernerf训练第三步torso如果训练的不好在拼接处会有接缝。可以在上面的命令加上--torso_imgs data/xxx/torso_imgstorso不用模型推理直接用训练数据集里的torso图片。这种方式可能头颈处会有些人工痕迹。
1 year ago
### 3.6 webrtc
```
python app.py --transport webrtc
```
用浏览器打开http://serverip:8010/webrtc.html
2 years ago
## 4. Docker Run
2 years ago
不需要第1步的安装直接运行。
2 years ago
```
2 years ago
docker run --gpus all -it --network=host --rm registry.cn-hangzhou.aliyuncs.com/lipku/nerfstream:v1.3
2 years ago
```
1 year ago
srs的运行同2.1
2 years ago
## 5. Data flow
![](/assets/dataflow.png)
2 years ago
## 6. 数字人模型文件
可以替换成自己训练的模型(https://github.com/Fictionarry/ER-NeRF)
2 years ago
```python
.
├── data
1 year ago
│ ├── data_kf.json
│ ├── au.csv
2 years ago
│ ├── pretrained
2 years ago
│ └── └── ngp_kf.pth
2 years ago
```
## 7. 性能分析
2 years ago
1. 帧率
1 year ago
在Tesla T4显卡上测试整体fps为18左右如果去掉音视频编码推流帧率在20左右。用4090显卡可以达到40多帧/秒。
2 years ago
优化:新开一个线程运行音视频编码推流
2. 延时
整体延时3s左右
1tts延时1.7s左右目前用的edgetts需要将每句话转完后一次性输入可以优化tts改成流式输入
2wav2vec延时0.4s需要缓存18帧音频做计算
2 years ago
3srs转发延时设置srs服务器减少缓冲延时。具体配置可看 https://ossrs.net/lts/zh-cn/docs/v5/doc/low-latency, 配置了一个低延时版本
```python
docker run --rm -it -p 1935:1935 -p 1985:1985 -p 8080:8080 registry.cn-hangzhou.aliyuncs.com/lipku/srs:v1.1
```
2 years ago
## 8. TODO
2 years ago
- [x] 添加chatgpt实现数字人对话
1 year ago
- [x] 声音克隆
2 years ago
- [ ] 数字人静音时用一段视频代替
2 years ago
如果本项目对你有帮助帮忙点个star。也欢迎感兴趣的朋友一起来完善该项目。
1 year ago
Email: lipku@foxmail.com
1 year ago
微信公众号:数字人技术
![](https://mmbiz.qpic.cn/sz_mmbiz_jpg/l3ZibgueFiaeyfaiaLZGuMGQXnhLWxibpJUS2gfs8Dje6JuMY8zu2tVyU9n8Zx1yaNncvKHBMibX0ocehoITy5qQEZg/640?wxfrom=12&tp=wxpic&usePicPrefetch=1&wx_fmt=jpeg&from=appmsg)