README.md 7.58 KB
Newer Older
liugh5's avatar
liugh5 committed
1
2
3
# sambert-hifigan_pytorch

## 论文
liugh5's avatar
update  
liugh5 committed
4
[RobuTrans: A Robust Transformer-Based Text-to-Speech Model](https://ojs.aaai.org/index.php/AAAI/article/view/6337)  
liugh5's avatar
liugh5 committed
5
6
7
8
9
10
11
12
[HiFi-GAN: Generative Adversarial Networks for Efficient and High Fidelity Speech Synthesis](https://arxiv.org/abs/2010.05646)

## 模型结构
韵律建模sambert声学模型:在语音合成领域,类似FastSpeech的Parallel模型是目前的主流,它针对基频(pitch)、能量(energy)和时长(duration)三种韵律表征分别建模。但是,该类模型普遍存在一些效果和性能上的问题,例如,独立建模时长、基频、能量,忽视了其内在联系;完全非自回归的网络结构,无法满足工业级实时合成需求;帧级别基频和能量预测不稳定。 因此达摩院语音实验室设计了SAMBERT,一种基于Parallel结构的改良版TTS模型,它具有以下优点:
1. Backbone采用Self-Attention-Mechanism(SAM),提升模型建模能力。
2. Encoder部分采用BERT进行初始化,引入更多文本信息,提升合成韵律。
3. Variance Adaptor对音素级别的韵律(基频、能量、时长)轮廓进行粗粒度的预测,再通过decoder进行帧级别细粒度的建模;并在时长预测时考虑到其与基频、能量的关联信息,结合自回归结构,进一步提升韵律自然度.
4. Decoder部分采用PNCA AR-Decoder[@li2020robutrans],自然支持流式合成。
liugh5's avatar
update  
liugh5 committed
13
![sambert.jpg](assets%2Fsambert.jpg)
liugh5's avatar
liugh5 committed
14
15
16
17

## 算法原理
如果需要进行迁移学习,那么需要先构建多说话人的声学模型,不同说话人是通过可训练的说话人编码(speaker embedding)进行区分的。给定新的一个说话人,一般通过随机初始化一个speaker embedding,然后再基于这个说话人的数据进行更新(见下图说话人空间1)。对于个性化语音合成来说,发音人的数据量比较少,学习难度很大,最终合成声音的相似度就无法保证。因此,我们采用说话人特征信息来表示每个说话人,此时,以少量说话人数据初始化的 speaker embedding 距离实际的目标说话人更近得多(见下图说话人空间2),学习难度小,此时合成声音的相似度就比较高。采用基于说话人特征信息的个性化语音合成,使得在20句条件下,依旧能够有较好的相似度。

liugh5's avatar
update  
liugh5 committed
18
![feature_space.png](assets%2Ffeature_space.png)
liugh5's avatar
liugh5 committed
19
20
21
22
模型框架主要由三个部分组成:
1.数据自动化处理和标注
2.韵律建模SAMBERT声学模型
3.基于说话人特征信息的个性化语音合成
liugh5's avatar
update  
liugh5 committed
23
![ptts.png](assets%2Fptts.png)
liugh5's avatar
liugh5 committed
24
25
26
27
28
29
30
## 环境配置

### Docker (方法一)

```
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk23.10-py38
# <your IMAGE ID>为以上拉取的docker的镜像ID替换
liugh5's avatar
update  
liugh5 committed
31
32
33
34
35
docker run -it -v /path/your_code_data/:/path/your_code_data/ -v /opt/hyhal:/opt/hyhal --shm-size=32G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name container_name imageID bash
cd /path/your_code_data/
```
KAN-TTS环境搭建:
```
liugh5's avatar
liugh5 committed
36
37
38
git clone -b develop https://github.com/alibaba-damo-academy/KAN-TTS.git
cd KAN-TTS
```
liugh5's avatar
update  
liugh5 committed
39
40
安装相应的python依赖库:
```
liugh5's avatar
update  
liugh5 committed
41
42
pip3 install -r requirements-f.txt -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html
pip3 install -r requirements.txt
liugh5's avatar
update  
liugh5 committed
43
44
45
46
47
48
49
50
```
### Dockerfile(方式二)
```
docker build -t <image_name> .
docker run -it -v /path/your_code_data/:/path/your_code_data/ -v /opt/hyhal:/opt/hyhal --shm-size=32G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name container_name image_name bash
cd /path/your_code_data/
```
之后参考方法一。
liugh5's avatar
update  
liugh5 committed
51
52
53

### Conda(方式三)

liugh5's avatar
update  
liugh5 committed
54
55
56
57
1. 创建conda虚拟环境:
```
conda create -n <env_name> python=3.8
```
liugh5's avatar
update  
liugh5 committed
58
59
2. 关于本项目DCU显卡所需的工具包、深度学习库等均可从[光合](https://www.hpccube.com/sso/login?service=https://developer.hpccube.com/tool/)开发者社区下载安装。  
DTK驱动:[dtk23.10](https://cancon.hpccube.com:65024/1/main/DTK-23.10)  
liugh5's avatar
update  
liugh5 committed
60
pytorch:[1.13.1](https://cancon.hpccube.com:65024/4/main/pytorch/dtk23.10)
liugh5's avatar
update  
liugh5 committed
61
`Tips:以上dtk驱动、python、paddle等DCU相关工具版本需要严格一一对应。`  
liugh5's avatar
liugh5 committed
62
63
之后参考方法一。  

liugh5's avatar
liugh5 committed
64
65
66
67
## 数据集

你可以从ModelScope下载经过阿里标准格式处理的AISHELL-3开源语音合成数据集,用来进行后续操作。如果你只有普通音频格式的数据,那么可以采用PTTS Autolabel自动化标注工具进行格式转换。

liugh5's avatar
update  
liugh5 committed
68
可参考的迷你[训练数据](https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/TTS/download_files/test_female.zip),下载后解压到到目录Data/ptts_spk0_wav下面。
liugh5's avatar
update  
liugh5 committed
69
数据集的目录结构如下:
liugh5's avatar
liugh5 committed
70

liugh5's avatar
update  
liugh5 committed
71
72
```
ptts_spk0_wav
liugh5's avatar
update  
liugh5 committed
73
74
75
├─ SSB00180007.wav
├─ SSB00180012.wav
├─ ......
liugh5's avatar
update  
liugh5 committed
76
77
78
79
80
81
82
83
84
85
```
数据预处理包括两步:
1. autolabel自动标注
```
python3 wav_to_label.py --wav_data Data/ptts_spk0_wav
```
2. 特征提取
```
bash feats_extract.sh
```
liugh5's avatar
update  
liugh5 committed
86
`注意修改相应的模型路径。`  
liugh5's avatar
update  
liugh5 committed
87
特征提取只需要运行一小段时间,提取完毕后你会在training_stage/test_male_ptts_feats目录下得到如下结构的文件:
liugh5's avatar
update  
liugh5 committed
88

liugh5's avatar
update  
liugh5 committed
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
```
├── am_train.lst
├── am_valid.lst
├── audio_config.yaml
├── badlist.txt
├── data_process_stdout.log
├── duration
├── energy
├── f0
├── frame_energy
├── frame_f0
├── frame_uv
├── mel
├── raw_duration
├── raw_metafile.txt
├── Script.xml
├── se
├── train.lst
├── valid.lst
└── wav
```
liugh5's avatar
liugh5 committed
110
111
112
113
## 训练

#### 单卡训练
```
liugh5's avatar
liugh5 committed
114
# 微调声学模型是配置驱动的,我们使用预训练模型中的speech_personal_sambert-hifigan_nsf_tts_zh-cn_pretrain_16k/basemodel_16k/sambert/config.yaml作为训练配置文件。 我们提供默认的PTTS 默认使用的finetune参数值,希望在basemodel的基础上继续微调 一定步数 并保存,即我们修改train_max_steps配置项。
liugh5's avatar
update  
liugh5 committed
115
# 完成配置项修改后,我们就可以使用以下命令训练声学模型了
liugh5's avatar
liugh5 committed
116
117
118
119
120
121
HIP_VISIBLE_DEVICES=0 python3 kantts/bin/train_sambert.py \
--model_config speech_personal_sambert-hifigan_nsf_tts_zh-cn_pretrain_16k/basemodel_16k/sambert/config.yaml \
--root_dir  training_stage/ptts_feats \
--stage_dir training_stage/ptts_sambert_ckpt \
--resume_path speech_personal_sambert-hifigan_nsf_tts_zh-cn_pretrain_16k/basemodel_16k/sambert/ckpt/checkpoint_*.pth
```
liugh5's avatar
update  
liugh5 committed
122
123
`注意修改相应的模型路径。`

liugh5's avatar
liugh5 committed
124
125
#### 单卡推理
```
liugh5's avatar
update  
liugh5 committed
126
# 想要合成的文本写入一个文件,test.txt,每句话按行分隔
liugh5's avatar
liugh5 committed
127
128
129
130
131
132
133
134
HIP_VISIBLE_DEVICES=0 python3 kantts/bin/text_to_wav.py \
--txt Data/test.txt \
--output_dir res/ptts_syn \
--res_zip speech_personal_sambert-hifigan_nsf_tts_zh-cn_pretrain_16k/resource.zip \
--am_ckpt training_stage/ptts_sambert_ckpt/ckpt/checkpoint_2402200.pth \
--voc_ckpt speech_personal_sambert-hifigan_nsf_tts_zh-cn_pretrain_16k/basemodel_16k/hifigan/ckpt/checkpoint_2400000.pth \
--se_file training_stage/ptts_feats/se/se.npy
```
liugh5's avatar
update  
liugh5 committed
135
136
`注意修改相应的模型路径。`

liugh5's avatar
liugh5 committed
137
## result
liugh5's avatar
update  
liugh5 committed
138
推理结果可在输出文件夹res/ptts_syn下找到克隆的语音文件。
liugh5's avatar
liugh5 committed
139

liugh5's avatar
liugh5 committed
140
## 精度  
liugh5's avatar
update  
liugh5 committed
141
配置项train_max_steps为2402201,测试结果如下:
liugh5's avatar
liugh5 committed
142

liugh5's avatar
update  
liugh5 committed
143
144
145
|  device   |  train_loss  | 
|:---------:|:----:|
| DCU Z100 | 0.4803. |
liugh5's avatar
liugh5 committed
146
147

## 应用场景
liugh5's avatar
liugh5 committed
148

liugh5's avatar
liugh5 committed
149
### 算法分类
liugh5's avatar
update  
liugh5 committed
150
151

`语音处理`
liugh5's avatar
liugh5 committed
152
153

### 热点应用行业
liugh5's avatar
update  
liugh5 committed
154
`制造,广媒,能源,医疗,家居,教育`
liugh5's avatar
liugh5 committed
155

liugh5's avatar
update  
liugh5 committed
156
157
158
159
160
### 预训练权重

```
git clone https://www.modelscope.cn/damo/speech_personal_sambert-hifigan_nsf_tts_zh-cn_pretrain_16k.git
```
liugh5's avatar
liugh5 committed
161
162
## 源码仓库及问题反馈

liugh5's avatar
update  
liugh5 committed
163
- https://developer.hpccube.com/codes/modelzoo/sambert-hifigan_pytorch
liugh5's avatar
liugh5 committed
164
165
166

## 参考资料

liugh5's avatar
update  
liugh5 committed
167
- [Modelscope - SambertHifigan](https://modelscope.cn/models/iic/speech_personal_sambert-hifigan_nsf_tts_zh-cn_pretrain_16k/summary)