Commit
•
441f47e
0
Parent(s):
Duplicate from MarcusSu1216/XingTong
Browse filesCo-authored-by: Su <MarcusSu1216@users.noreply.huggingface.co>
This view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +34 -0
- .gitignore +153 -0
- LICENSE +21 -0
- README.md +14 -0
- README_zh_CN.md +241 -0
- app.py +75 -0
- cluster/__init__.py +29 -0
- cluster/train_cluster.py +89 -0
- configs/config.json +94 -0
- data_utils.py +155 -0
- filelists/test.txt +0 -0
- filelists/train.txt +989 -0
- filelists/val.txt +2 -0
- flask_api.py +60 -0
- flask_api_full_song.py +55 -0
- hubert/__init__.py +0 -0
- hubert/__pycache__/__init__.cpython-38.pyc +0 -0
- hubert/__pycache__/hubert_model.cpython-38.pyc +0 -0
- hubert/checkpoint_best_legacy_500.pt +3 -0
- hubert/hubert_model.py +222 -0
- hubert/hubert_model_onnx.py +217 -0
- hubert/put_hubert_ckpt_here +0 -0
- inference/__init__.py +0 -0
- inference/__pycache__/__init__.cpython-38.pyc +0 -0
- inference/__pycache__/infer_tool.cpython-38.pyc +0 -0
- inference/__pycache__/slicer.cpython-38.pyc +0 -0
- inference/infer_tool.py +355 -0
- inference/infer_tool_grad.py +160 -0
- inference/slicer.py +142 -0
- inference_main.py +137 -0
- logs/44k/G_32000.pth +3 -0
- logs/44k/G_55000.pth +3 -0
- logs/44k/G_62000.pth +3 -0
- logs/44k/config.json +94 -0
- logs/44k/kmeans_10000.pt +3 -0
- models.py +420 -0
- models_backup/123.txt +0 -0
- modules/__init__.py +0 -0
- modules/__pycache__/__init__.cpython-38.pyc +0 -0
- modules/__pycache__/attentions.cpython-38.pyc +0 -0
- modules/__pycache__/commons.cpython-38.pyc +0 -0
- modules/__pycache__/crepe.cpython-38.pyc +0 -0
- modules/__pycache__/enhancer.cpython-38.pyc +0 -0
- modules/__pycache__/losses.cpython-38.pyc +0 -0
- modules/__pycache__/mel_processing.cpython-38.pyc +0 -0
- modules/__pycache__/modules.cpython-38.pyc +0 -0
- modules/attentions.py +349 -0
- modules/commons.py +188 -0
- modules/crepe.py +327 -0
- modules/enhancer.py +105 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# Created by https://www.toptal.com/developers/gitignore/api/python
|
3 |
+
# Edit at https://www.toptal.com/developers/gitignore?templates=python
|
4 |
+
|
5 |
+
### Python ###
|
6 |
+
# Byte-compiled / optimized / DLL files
|
7 |
+
__pycache__/
|
8 |
+
*.py[cod]
|
9 |
+
*$py.class
|
10 |
+
|
11 |
+
# C extensions
|
12 |
+
*.so
|
13 |
+
|
14 |
+
# Distribution / packaging
|
15 |
+
.Python
|
16 |
+
build/
|
17 |
+
develop-eggs/
|
18 |
+
dist/
|
19 |
+
downloads/
|
20 |
+
eggs/
|
21 |
+
.eggs/
|
22 |
+
lib/
|
23 |
+
lib64/
|
24 |
+
parts/
|
25 |
+
sdist/
|
26 |
+
var/
|
27 |
+
wheels/
|
28 |
+
pip-wheel-metadata/
|
29 |
+
share/python-wheels/
|
30 |
+
*.egg-info/
|
31 |
+
.installed.cfg
|
32 |
+
*.egg
|
33 |
+
MANIFEST
|
34 |
+
|
35 |
+
# PyInstaller
|
36 |
+
# Usually these files are written by a python script from a template
|
37 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
38 |
+
*.manifest
|
39 |
+
*.spec
|
40 |
+
|
41 |
+
# Installer logs
|
42 |
+
pip-log.txt
|
43 |
+
pip-delete-this-directory.txt
|
44 |
+
|
45 |
+
# Unit test / coverage reports
|
46 |
+
htmlcov/
|
47 |
+
.tox/
|
48 |
+
.nox/
|
49 |
+
.coverage
|
50 |
+
.coverage.*
|
51 |
+
.cache
|
52 |
+
nosetests.xml
|
53 |
+
coverage.xml
|
54 |
+
*.cover
|
55 |
+
*.py,cover
|
56 |
+
.hypothesis/
|
57 |
+
.pytest_cache/
|
58 |
+
pytestdebug.log
|
59 |
+
|
60 |
+
# Translations
|
61 |
+
*.mo
|
62 |
+
*.pot
|
63 |
+
|
64 |
+
# Django stuff:
|
65 |
+
*.log
|
66 |
+
local_settings.py
|
67 |
+
db.sqlite3
|
68 |
+
db.sqlite3-journal
|
69 |
+
|
70 |
+
# Flask stuff:
|
71 |
+
instance/
|
72 |
+
.webassets-cache
|
73 |
+
|
74 |
+
# Scrapy stuff:
|
75 |
+
.scrapy
|
76 |
+
|
77 |
+
# Sphinx documentation
|
78 |
+
docs/_build/
|
79 |
+
doc/_build/
|
80 |
+
|
81 |
+
# PyBuilder
|
82 |
+
target/
|
83 |
+
|
84 |
+
# Jupyter Notebook
|
85 |
+
.ipynb_checkpoints
|
86 |
+
|
87 |
+
# IPython
|
88 |
+
profile_default/
|
89 |
+
ipython_config.py
|
90 |
+
|
91 |
+
# pyenv
|
92 |
+
.python-version
|
93 |
+
|
94 |
+
# pipenv
|
95 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
96 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
97 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
98 |
+
# install all needed dependencies.
|
99 |
+
#Pipfile.lock
|
100 |
+
|
101 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
102 |
+
__pypackages__/
|
103 |
+
|
104 |
+
# Celery stuff
|
105 |
+
celerybeat-schedule
|
106 |
+
celerybeat.pid
|
107 |
+
|
108 |
+
# SageMath parsed files
|
109 |
+
*.sage.py
|
110 |
+
|
111 |
+
# Environments
|
112 |
+
.env
|
113 |
+
.venv
|
114 |
+
env/
|
115 |
+
venv/
|
116 |
+
ENV/
|
117 |
+
env.bak/
|
118 |
+
venv.bak/
|
119 |
+
|
120 |
+
# Spyder project settings
|
121 |
+
.spyderproject
|
122 |
+
.spyproject
|
123 |
+
|
124 |
+
# Rope project settings
|
125 |
+
.ropeproject
|
126 |
+
|
127 |
+
# mkdocs documentation
|
128 |
+
/site
|
129 |
+
|
130 |
+
# mypy
|
131 |
+
.mypy_cache/
|
132 |
+
.dmypy.json
|
133 |
+
dmypy.json
|
134 |
+
|
135 |
+
# Pyre type checker
|
136 |
+
.pyre/
|
137 |
+
|
138 |
+
# pytype static type analyzer
|
139 |
+
.pytype/
|
140 |
+
|
141 |
+
# End of https://www.toptal.com/developers/gitignore/api/python
|
142 |
+
|
143 |
+
dataset
|
144 |
+
dataset_raw
|
145 |
+
raw
|
146 |
+
results
|
147 |
+
inference/chunks_temp.json
|
148 |
+
logs
|
149 |
+
hubert/checkpoint_best_legacy_500.pt
|
150 |
+
configs/config.json
|
151 |
+
filelists/test.txt
|
152 |
+
filelists/train.txt
|
153 |
+
filelists/val.txt
|
LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MIT License
|
2 |
+
|
3 |
+
Copyright (c) 2021 Jingyi Li
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in all
|
13 |
+
copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
+
SOFTWARE.
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: XingTong
|
3 |
+
emoji: ✨
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: yellow
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.19.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
duplicated_from: MarcusSu1216/XingTong
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
README_zh_CN.md
ADDED
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SoftVC VITS Singing Voice Conversion
|
2 |
+
|
3 |
+
[**English**](./README.md) | [**中文简体**](./README_zh_CN.md)
|
4 |
+
|
5 |
+
#### ✨ 改善了交互的一个分支推荐:[34j/so-vits-svc-fork](https://github.com/34j/so-vits-svc-fork)
|
6 |
+
|
7 |
+
#### ✨ 支持实时转换的一个客户端:[w-okada/voice-changer](https://github.com/w-okada/voice-changer)
|
8 |
+
|
9 |
+
## 📏 使用规约
|
10 |
+
|
11 |
+
# Warning:请自行解决数据集授权问题,禁止使用非授权数据集进行训练!任何由于使用非授权数据集进行训练造成的问题,需自行承担全部责任和后果!与仓库、仓库维护者、svc develop team 无关!
|
12 |
+
|
13 |
+
1. 本项目是基于学术交流目的建立,仅供交流与学习使用,并非为生产环境准备。
|
14 |
+
2. 任何发布到视频平台的基于 sovits 制作的视频,都必须要在简介明确指明用于变声器转换的输入源歌声、音频,例如:使用他人发布的视频 / 音频,通过分离的人声作为输入源进行转换的,必须要给出明确的原视频、音乐链接;若使用是自己的人声,或是使用其他歌声合成引擎合成的声音作为输入源进行转换的,也必须在简介加以说明。
|
15 |
+
3. 由输入源造成的侵权问题需自行承担全部责任和一切后果。使用其他商用歌声合成软件作为输入源时,请确保遵守该软件的使用条例,注意,许多歌声合成引擎使用条例中明确指明不可用于输入源进行转换!
|
16 |
+
4. 继续使用视为已同意本仓库 README 所述相关条例,本仓库 README 已进行劝导义务,不对后续可能存在问题负责。
|
17 |
+
5. 如将本仓库代码二次分发,或将由此项目产出的任何结果公开发表 (包括但不限于视频网站投稿),请注明原作者及代码来源 (此仓库)。
|
18 |
+
6. 如果将此项目用于任何其他企划,请提前联系并告知本仓库作者,十分感谢。
|
19 |
+
|
20 |
+
## 🆕 Update!
|
21 |
+
|
22 |
+
> 更新了4.0-v2模型,全部流程同4.0,相比4.0在部分场景下有一定提升,但也有些情况有退步,具体可移步[4.0-v2分支](https://github.com/svc-develop-team/so-vits-svc/tree/4.0-v2)
|
23 |
+
|
24 |
+
## 📝 模型简介
|
25 |
+
|
26 |
+
歌声音色转换模型,通过SoftVC内容编码器提取源音频语音特征,与F0同时输入VITS替换原本的文本输入达到歌声转换的效果。同时,更换声码器为 [NSF HiFiGAN](https://github.com/openvpi/DiffSinger/tree/refactor/modules/nsf_hifigan) 解决断音问题
|
27 |
+
|
28 |
+
### 🆕 4.0 版本更新内容
|
29 |
+
|
30 |
+
+ 特征输入更换为 [Content Vec](https://github.com/auspicious3000/contentvec)
|
31 |
+
+ 采样率统一使用44100hz
|
32 |
+
+ 由于更改了hop size等参数以及精简了部分模型结构,推理所需显存占用**大幅降低**,4.0版本44khz显存占用甚至小于3.0版本的32khz
|
33 |
+
+ 调整了部分代码结构
|
34 |
+
+ 数据集制作、训练过程和3.0保持一致,但模型完全不通用,数据集也需要全部重新预处理
|
35 |
+
+ 增加了可选项 1:vc模式自动预测音高f0,即转换语音时不需要手动输入变调key,男女声的调能自动转换,但仅限语音转换,该模式转换歌声会跑调
|
36 |
+
+ 增加了可选项 2:通过kmeans聚类方案减小音色泄漏,即使得音色更加像目标音色
|
37 |
+
|
38 |
+
## 💬 关于 Python 版本问题
|
39 |
+
|
40 |
+
我们在进行测试后,认为 Python 3.8.9 版本能够稳定地运行该项目
|
41 |
+
|
42 |
+
## 📥 预先下载的模型文件
|
43 |
+
|
44 |
+
#### **必须项**
|
45 |
+
|
46 |
+
+ contentvec :[checkpoint_best_legacy_500.pt](https://ibm.box.com/s/z1wgl1stco8ffooyatzdwsqn2psd9lrr)
|
47 |
+
+ 放在`hubert`目录下
|
48 |
+
|
49 |
+
```shell
|
50 |
+
# contentvec
|
51 |
+
http://obs.cstcloud.cn/share/obs/sankagenkeshi/checkpoint_best_legacy_500.pt
|
52 |
+
# 也可手动下载放在hubert目录
|
53 |
+
```
|
54 |
+
|
55 |
+
#### **可选项(强烈建议使用)**
|
56 |
+
|
57 |
+
+ 预训练底模文件: `G_0.pth` `D_0.pth`
|
58 |
+
+ 放在`logs/44k`目录下
|
59 |
+
|
60 |
+
从svc-develop-team(待定)或任何其他地方获取
|
61 |
+
|
62 |
+
虽然底模一般不会引起什么版权问题,但还是请注意一下,比如事先询问作者,又或者作者在模型描述中明确写明了可行的用途
|
63 |
+
|
64 |
+
## 📊 数据集准备
|
65 |
+
|
66 |
+
仅需要以以下文件结构将数据集放入dataset_raw目录即可
|
67 |
+
|
68 |
+
```
|
69 |
+
dataset_raw
|
70 |
+
├───speaker0
|
71 |
+
│ ├───xxx1-xxx1.wav
|
72 |
+
│ ├───...
|
73 |
+
│ └───Lxx-0xx8.wav
|
74 |
+
└───speaker1
|
75 |
+
├───xx2-0xxx2.wav
|
76 |
+
├───...
|
77 |
+
└───xxx7-xxx007.wav
|
78 |
+
```
|
79 |
+
|
80 |
+
可以自定义说话人名称
|
81 |
+
|
82 |
+
```
|
83 |
+
dataset_raw
|
84 |
+
└───suijiSUI
|
85 |
+
├───1.wav
|
86 |
+
├───...
|
87 |
+
└───25788785-20221210-200143-856_01_(Vocals)_0_0.wav
|
88 |
+
```
|
89 |
+
|
90 |
+
## 🛠️ 数据预处理
|
91 |
+
|
92 |
+
1. 重采样至44100Hz单声道
|
93 |
+
|
94 |
+
```shell
|
95 |
+
python resample.py
|
96 |
+
```
|
97 |
+
|
98 |
+
2. 自动划分训练集、验证集,以及自动生成配置文件
|
99 |
+
|
100 |
+
```shell
|
101 |
+
python preprocess_flist_config.py
|
102 |
+
```
|
103 |
+
|
104 |
+
3. 生成hubert与f0
|
105 |
+
|
106 |
+
```shell
|
107 |
+
python preprocess_hubert_f0.py
|
108 |
+
```
|
109 |
+
|
110 |
+
执行完以上步骤后 dataset 目录便是预处理完成的数据,可以删除 dataset_raw 文件夹了
|
111 |
+
|
112 |
+
#### 此时可以在生成的config.json修改部分参数
|
113 |
+
|
114 |
+
* `keep_ckpts`:训���时保留最后几个模型,`0`为保留所有,默认只保留最后`3`个
|
115 |
+
|
116 |
+
* `all_in_mem`:加载所有数据集到内存中,某些平台的硬盘IO过于低下、同时内存容量 **远大于** 数据集体积时可以启用
|
117 |
+
|
118 |
+
## 🏋️♀️ 训练
|
119 |
+
|
120 |
+
```shell
|
121 |
+
python train.py -c configs/config.json -m 44k
|
122 |
+
```
|
123 |
+
|
124 |
+
## 🤖 推理
|
125 |
+
|
126 |
+
使用 [inference_main.py](inference_main.py)
|
127 |
+
|
128 |
+
```shell
|
129 |
+
# 例
|
130 |
+
python inference_main.py -m "logs/44k/G_30400.pth" -c "configs/config.json" -n "君の知らない物語-src.wav" -t 0 -s "nen"
|
131 |
+
```
|
132 |
+
|
133 |
+
必填项部分
|
134 |
+
+ `-m` | `--model_path`:模型路径
|
135 |
+
+ `-c` | `--config_path`:配置文件路径
|
136 |
+
+ `-n` | `--clean_names`:wav 文件名列表,放在 raw 文件夹下
|
137 |
+
+ `-t` | `--trans`:音高调整,支持正负(半音)
|
138 |
+
+ `-s` | `--spk_list`:合成目标说话人名称
|
139 |
+
+ `-cl` | `--clip`:音频强制切片,默认0为自动切片,单位为秒/s
|
140 |
+
|
141 |
+
可选项部分:部分具体见下一节
|
142 |
+
+ `-lg` | `--linear_gradient`:两段音频切片的交叉淡入长度,如果强制切片后出现人声不连贯可调整该数值,如果连贯建议采用默认值0,单位为秒
|
143 |
+
+ `-fmp` | `--f0_mean_pooling`:是否对F0使用均值滤波器(池化),对部分哑音有改善。注意,启动该选项会导致推理速度下降,默认关闭
|
144 |
+
+ `-a` | `--auto_predict_f0`:语音转换自动预测音高,转换歌声时不要打开这个会严重跑调
|
145 |
+
+ `-cm` | `--cluster_model_path`:聚类模型路径,如果没有训练聚类则随便填
|
146 |
+
+ `-cr` | `--cluster_infer_ratio`:聚类方案占比,范围0-1,若没有训练聚类模型则默认0即可
|
147 |
+
|
148 |
+
## 🤔 可选项
|
149 |
+
|
150 |
+
如果前面的效果已经满意,或者没看明白下面在讲啥,那后面的内容都可以忽略,不影响模型使用(这些可选项影响比较小,可能在某些特定数据上有点效果,但大部分情况似乎都感知不太明显)
|
151 |
+
|
152 |
+
### 自动f0预测
|
153 |
+
|
154 |
+
4.0模型训练过程会训练一个f0预测器,对于语音转换可以开启自动音高预测,如果效果不好也可以使用手动的,但转换歌声时请不要启用此功能!!!会严重跑调!!
|
155 |
+
+ 在inference_main中设置auto_predict_f0为true即可
|
156 |
+
|
157 |
+
### 聚类音色泄漏控制
|
158 |
+
|
159 |
+
介绍:聚类方案可以减小音色泄漏,使得模型训练出来更像目标的音色(但其实不是特别明显),但是单纯的聚类方案会降低模型的咬字(会口齿不清)(这个很明显),本模型采用了融合的方式,可以线性控制聚类方案与非聚类方案的占比,也就是可以手动在"像目标音色" 和 "咬字清晰" 之间调整比例,找到合适的折中点。
|
160 |
+
|
161 |
+
使用聚类前面的已有步骤不用进行任何的变动,只需要额外训练一个聚类模型,虽然效果比较有限,但训练成本也比较低
|
162 |
+
|
163 |
+
+ 训练过程:
|
164 |
+
+ 使用cpu性能较好的机器训练,据我的经验在腾讯云6核cpu训练每个speaker需要约4分钟即可完成训练
|
165 |
+
+ 执行python cluster/train_cluster.py ,模型的输出会在 logs/44k/kmeans_10000.pt
|
166 |
+
+ 推理过程:
|
167 |
+
+ inference_main中指定cluster_model_path
|
168 |
+
+ inference_main中指定cluster_infer_ratio,0为完全不使用聚类,1为只使用聚类,通常设置0.5即可
|
169 |
+
|
170 |
+
### F0均值滤波
|
171 |
+
|
172 |
+
介绍:对F0进行均值滤波,可以有效的减少因音高推测波动造成的哑音(由于混响或和声等造成的哑音暂时不能消除)。该功能在部分歌曲上提升巨大,如果歌曲推理后出现哑音可以考虑开启。
|
173 |
+
+ 在inference_main中设置f0_mean_pooling为true即可
|
174 |
+
|
175 |
+
### [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1kv-3y2DmZo0uya8pEr1xk7cSB-4e_Pct?usp=sharing) [sovits4_for_colab.ipynb](https://colab.research.google.com/drive/1kv-3y2DmZo0uya8pEr1xk7cSB-4e_Pct?usp=sharing)
|
176 |
+
|
177 |
+
#### [23/03/16] 不再需要手动下载hubert
|
178 |
+
|
179 |
+
## 📤 Onnx导出
|
180 |
+
|
181 |
+
使用 [onnx_export.py](onnx_export.py)
|
182 |
+
+ 新建文件夹:`checkpoints` 并打开
|
183 |
+
+ 在`checkpoints`文件夹中新建一个文件夹作为项目文件夹,文件夹名为你的项目名称,比如`aziplayer`
|
184 |
+
+ 将你的模型更名为`model.pth`,配置文件更名为`config.json`,并放置到刚才创建的`aziplayer`文件夹下
|
185 |
+
+ 将 [onnx_export.py](onnx_export.py) 中`path = "NyaruTaffy"` 的 `"NyaruTaffy"` 修改为你的项目名称,`path = "aziplayer"`
|
186 |
+
+ 运行 [onnx_export.py](onnx_export.py)
|
187 |
+
+ 等待执行完毕,在你的项目文件夹下会生成一个`model.onnx`,即为导出的模型
|
188 |
+
|
189 |
+
### Onnx模型支持的UI
|
190 |
+
|
191 |
+
+ [MoeSS](https://github.com/NaruseMioShirakana/MoeSS)
|
192 |
+
+ 我去除了所有的训练用函数和一切复杂的转置,一行都没有保留,因为我认为只有去除了这些东西,才知道你用的是Onnx
|
193 |
+
+ 注意:Hubert Onnx模型请使用MoeSS提供的模型,目前无法自行导出(fairseq中Hubert有不少onnx不支持的算子和涉及到常量的东西,在导出时会报错或者导出的模型输入输出shape和结果都有问题��
|
194 |
+
[Hubert4.0](https://huggingface.co/NaruseMioShirakana/MoeSS-SUBModel)
|
195 |
+
|
196 |
+
## ☀️ 旧贡献者
|
197 |
+
|
198 |
+
因为某些原因原作者进行了删库处理,本仓库重建之初由于组织成员疏忽直接重新上传了所有文件导致以前的contributors全部木大,现在在README里重新添加一个旧贡献者列表
|
199 |
+
|
200 |
+
*某些成员已根据其个人意愿不将其列出*
|
201 |
+
|
202 |
+
<table>
|
203 |
+
<tr>
|
204 |
+
<td align="center"><a href="https://github.com/MistEO"><img src="https://avatars.githubusercontent.com/u/18511905?v=4" width="100px;" alt=""/><br /><sub><b>MistEO</b></sub></a><br /></td>
|
205 |
+
<td align="center"><a href="https://github.com/XiaoMiku01"><img src="https://avatars.githubusercontent.com/u/54094119?v=4" width="100px;" alt=""/><br /><sub><b>XiaoMiku01</b></sub></a><br /></td>
|
206 |
+
<td align="center"><a href="https://github.com/ForsakenRei"><img src="https://avatars.githubusercontent.com/u/23041178?v=4" width="100px;" alt=""/><br /><sub><b>しぐれ</b></sub></a><br /></td>
|
207 |
+
<td align="center"><a href="https://github.com/TomoGaSukunai"><img src="https://avatars.githubusercontent.com/u/25863522?v=4" width="100px;" alt=""/><br /><sub><b>TomoGaSukunai</b></sub></a><br /></td>
|
208 |
+
<td align="center"><a href="https://github.com/Plachtaa"><img src="https://avatars.githubusercontent.com/u/112609742?v=4" width="100px;" alt=""/><br /><sub><b>Plachtaa</b></sub></a><br /></td>
|
209 |
+
<td align="center"><a href="https://github.com/zdxiaoda"><img src="https://avatars.githubusercontent.com/u/45501959?v=4" width="100px;" alt=""/><br /><sub><b>zd小达</b></sub></a><br /></td>
|
210 |
+
<td align="center"><a href="https://github.com/Archivoice"><img src="https://avatars.githubusercontent.com/u/107520869?v=4" width="100px;" alt=""/><br /><sub><b>凍聲響世</b></sub></a><br /></td>
|
211 |
+
</tr>
|
212 |
+
</table>
|
213 |
+
|
214 |
+
## 📚 一些法律条例参考
|
215 |
+
|
216 |
+
#### 任何国家,地区,组织和个人使用此项目必须遵守以下法律
|
217 |
+
|
218 |
+
#### 《民法典》
|
219 |
+
|
220 |
+
##### 第一千零一十九条
|
221 |
+
|
222 |
+
任何组织或者个人不得以丑化、污损,或者利用信息技术手段伪造等方式侵害他人的肖像权。未经肖像权人同意,不得制作、使用、公开肖像权人的肖像,但是法律另有规定的除外。未经肖像权人同意,肖像作品权利人不得以发表、复制、发行、出租、展览等方式使用或者公开肖像权人的肖像。对自然人声音的保护,参照适用肖像权保护的有关规定。
|
223 |
+
|
224 |
+
##### 第一千零二十四条
|
225 |
+
|
226 |
+
【名誉权】民事主体享有名誉权。任何组织或者个人不得以侮辱、诽谤等方式侵害他人的名誉权。
|
227 |
+
|
228 |
+
##### 第一千零二十七条
|
229 |
+
|
230 |
+
【作品侵害名誉权】行为人发表的文学、艺术作品以真人真事或者特定人为描述对象,含有侮辱、诽谤内容,侵害他人名誉权的,受害人有权依法请求该行为人承担民事责任。行为人发表的文学、艺术作品不以特定人为描述对象,仅其中的情节与该特定人的情况相似的,不承担民事责任。
|
231 |
+
|
232 |
+
#### 《[中华人民共和国宪法](http://www.gov.cn/guoqing/2018-03/22/content_5276318.htm)》
|
233 |
+
|
234 |
+
#### 《[中华人民共和国刑法](http://gongbao.court.gov.cn/Details/f8e30d0689b23f57bfc782d21035c3.html?sw=中华人民共和国刑法)》
|
235 |
+
|
236 |
+
#### 《[中华人民共和国民法典](http://gongbao.court.gov.cn/Details/51eb6750b8361f79be8f90d09bc202.html)》
|
237 |
+
|
238 |
+
## 💪 感谢所有的贡献者
|
239 |
+
<a href="https://github.com/svc-develop-team/so-vits-svc/graphs/contributors" target="_blank">
|
240 |
+
<img src="https://contrib.rocks/image?repo=svc-develop-team/so-vits-svc" />
|
241 |
+
</a>
|
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import io
|
2 |
+
import os
|
3 |
+
|
4 |
+
os.system("wget -P hubert/ https://huggingface.co/spaces/MarcusSu1216/XingTong/blob/main/hubert/checkpoint_best_legacy_500.pt")
|
5 |
+
import gradio as gr
|
6 |
+
import librosa
|
7 |
+
import numpy as np
|
8 |
+
import soundfile
|
9 |
+
from inference.infer_tool import Svc
|
10 |
+
import logging
|
11 |
+
|
12 |
+
logging.getLogger('numba').setLevel(logging.WARNING)
|
13 |
+
logging.getLogger('markdown_it').setLevel(logging.WARNING)
|
14 |
+
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
15 |
+
logging.getLogger('matplotlib').setLevel(logging.WARNING)
|
16 |
+
|
17 |
+
model = Svc("logs/44k/G_55000.pth", "configs/config.json", cluster_model_path="logs/44k/kmeans_10000.pt")
|
18 |
+
|
19 |
+
def vc_fn(sid, input_audio, vc_transform, auto_f0,cluster_ratio, noise_scale):
|
20 |
+
if input_audio is None:
|
21 |
+
return "You need to upload an audio", None
|
22 |
+
sampling_rate, audio = input_audio
|
23 |
+
# print(audio.shape,sampling_rate)
|
24 |
+
duration = audio.shape[0] / sampling_rate
|
25 |
+
if duration > 100:
|
26 |
+
return "请上传小于100s的音频,需要转换长音频请本地进行转换", None
|
27 |
+
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
|
28 |
+
if len(audio.shape) > 1:
|
29 |
+
audio = librosa.to_mono(audio.transpose(1, 0))
|
30 |
+
if sampling_rate != 16000:
|
31 |
+
audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)
|
32 |
+
print(audio.shape)
|
33 |
+
out_wav_path = "temp.wav"
|
34 |
+
soundfile.write(out_wav_path, audio, 16000, format="wav")
|
35 |
+
print( cluster_ratio, auto_f0, noise_scale)
|
36 |
+
out_audio, out_sr = model.infer(sid, vc_transform, out_wav_path,
|
37 |
+
cluster_infer_ratio=cluster_ratio,
|
38 |
+
auto_predict_f0=auto_f0,
|
39 |
+
noice_scale=noise_scale
|
40 |
+
)
|
41 |
+
return "转换成功", (44100, out_audio.numpy())
|
42 |
+
|
43 |
+
|
44 |
+
app = gr.Blocks()
|
45 |
+
with app:
|
46 |
+
with gr.Tabs():
|
47 |
+
with gr.TabItem("介绍"):
|
48 |
+
gr.Markdown(value="""
|
49 |
+
星瞳_Official的语音在线合成,基于so-vits-svc-4.0生成。\n
|
50 |
+
|
51 |
+
使用须知:\n
|
52 |
+
1、请使用伴奏和声去除干净的人声素材,时长小于100秒,格式为mp3或wav。\n
|
53 |
+
2、去除伴奏推荐使用UVR5软件,B站上有详细教程。\n
|
54 |
+
3、条件不支持推荐使用以下几个去伴奏的网站:\n
|
55 |
+
https://vocalremover.org/zh/\n
|
56 |
+
https://tuanziai.com/vocal-remover/upload\n
|
57 |
+
https://www.lalal.ai/zh-hans/\n
|
58 |
+
4、在线版服务器为2核16G免费版,转换效率较慢请耐心等待。\n
|
59 |
+
5、使用此模型请标注作者:一闪一闪小星瞳,以及该项目地址。\n
|
60 |
+
6、有问题可以在B站私聊我反馈:https://space.bilibili.com/38523418\n
|
61 |
+
7、语音模型转换出的音频请勿用于商业化。
|
62 |
+
""")
|
63 |
+
spks = list(model.spk2id.keys())
|
64 |
+
sid = gr.Dropdown(label="音色", choices=["XT3.2"], value="XT3.2")
|
65 |
+
vc_input3 = gr.Audio(label="上传音频(长度建议小于100秒)")
|
66 |
+
vc_transform = gr.Number(label="变调(整数,可以正负,半音数量,升高八度就是12)", value=0)
|
67 |
+
cluster_ratio = gr.Number(label="聚类模型混合比例,0-1之间,默认为0不启用聚类,能提升音色相似度,但会导致咬字下降(如果使用建议0.5左右)", value=0)
|
68 |
+
auto_f0 = gr.Checkbox(label="自动f0预测,配合聚类模型f0预测效果更好,会导致变调功能失效(仅限转换语音,歌声不要勾选此项会究极跑调)", value=False)
|
69 |
+
noise_scale = gr.Number(label="noise_scale 建议不要动,会影响音质,玄学参数", value=0.4)
|
70 |
+
vc_submit = gr.Button("转换", variant="primary")
|
71 |
+
vc_output1 = gr.Textbox(label="Output Message")
|
72 |
+
vc_output2 = gr.Audio(label="Output Audio")
|
73 |
+
vc_submit.click(vc_fn, [sid, vc_input3, vc_transform,auto_f0,cluster_ratio, noise_scale], [vc_output1, vc_output2])
|
74 |
+
|
75 |
+
app.launch()
|
cluster/__init__.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import torch
|
3 |
+
from sklearn.cluster import KMeans
|
4 |
+
|
5 |
+
def get_cluster_model(ckpt_path):
|
6 |
+
checkpoint = torch.load(ckpt_path)
|
7 |
+
kmeans_dict = {}
|
8 |
+
for spk, ckpt in checkpoint.items():
|
9 |
+
km = KMeans(ckpt["n_features_in_"])
|
10 |
+
km.__dict__["n_features_in_"] = ckpt["n_features_in_"]
|
11 |
+
km.__dict__["_n_threads"] = ckpt["_n_threads"]
|
12 |
+
km.__dict__["cluster_centers_"] = ckpt["cluster_centers_"]
|
13 |
+
kmeans_dict[spk] = km
|
14 |
+
return kmeans_dict
|
15 |
+
|
16 |
+
def get_cluster_result(model, x, speaker):
|
17 |
+
"""
|
18 |
+
x: np.array [t, 256]
|
19 |
+
return cluster class result
|
20 |
+
"""
|
21 |
+
return model[speaker].predict(x)
|
22 |
+
|
23 |
+
def get_cluster_center_result(model, x,speaker):
|
24 |
+
"""x: np.array [t, 256]"""
|
25 |
+
predict = model[speaker].predict(x)
|
26 |
+
return model[speaker].cluster_centers_[predict]
|
27 |
+
|
28 |
+
def get_center(model, x,speaker):
|
29 |
+
return model[speaker].cluster_centers_[x]
|
cluster/train_cluster.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from glob import glob
|
3 |
+
from pathlib import Path
|
4 |
+
import torch
|
5 |
+
import logging
|
6 |
+
import argparse
|
7 |
+
import torch
|
8 |
+
import numpy as np
|
9 |
+
from sklearn.cluster import KMeans, MiniBatchKMeans
|
10 |
+
import tqdm
|
11 |
+
logging.basicConfig(level=logging.INFO)
|
12 |
+
logger = logging.getLogger(__name__)
|
13 |
+
import time
|
14 |
+
import random
|
15 |
+
|
16 |
+
def train_cluster(in_dir, n_clusters, use_minibatch=True, verbose=False):
|
17 |
+
|
18 |
+
logger.info(f"Loading features from {in_dir}")
|
19 |
+
features = []
|
20 |
+
nums = 0
|
21 |
+
for path in tqdm.tqdm(in_dir.glob("*.soft.pt")):
|
22 |
+
features.append(torch.load(path).squeeze(0).numpy().T)
|
23 |
+
# print(features[-1].shape)
|
24 |
+
features = np.concatenate(features, axis=0)
|
25 |
+
print(nums, features.nbytes/ 1024**2, "MB , shape:",features.shape, features.dtype)
|
26 |
+
features = features.astype(np.float32)
|
27 |
+
logger.info(f"Clustering features of shape: {features.shape}")
|
28 |
+
t = time.time()
|
29 |
+
if use_minibatch:
|
30 |
+
kmeans = MiniBatchKMeans(n_clusters=n_clusters,verbose=verbose, batch_size=4096, max_iter=80).fit(features)
|
31 |
+
else:
|
32 |
+
kmeans = KMeans(n_clusters=n_clusters,verbose=verbose).fit(features)
|
33 |
+
print(time.time()-t, "s")
|
34 |
+
|
35 |
+
x = {
|
36 |
+
"n_features_in_": kmeans.n_features_in_,
|
37 |
+
"_n_threads": kmeans._n_threads,
|
38 |
+
"cluster_centers_": kmeans.cluster_centers_,
|
39 |
+
}
|
40 |
+
print("end")
|
41 |
+
|
42 |
+
return x
|
43 |
+
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
+
|
47 |
+
parser = argparse.ArgumentParser()
|
48 |
+
parser.add_argument('--dataset', type=Path, default="./dataset/44k",
|
49 |
+
help='path of training data directory')
|
50 |
+
parser.add_argument('--output', type=Path, default="logs/44k",
|
51 |
+
help='path of model output directory')
|
52 |
+
|
53 |
+
args = parser.parse_args()
|
54 |
+
|
55 |
+
checkpoint_dir = args.output
|
56 |
+
dataset = args.dataset
|
57 |
+
n_clusters = 10000
|
58 |
+
|
59 |
+
ckpt = {}
|
60 |
+
for spk in os.listdir(dataset):
|
61 |
+
if os.path.isdir(dataset/spk):
|
62 |
+
print(f"train kmeans for {spk}...")
|
63 |
+
in_dir = dataset/spk
|
64 |
+
x = train_cluster(in_dir, n_clusters, verbose=False)
|
65 |
+
ckpt[spk] = x
|
66 |
+
|
67 |
+
checkpoint_path = checkpoint_dir / f"kmeans_{n_clusters}.pt"
|
68 |
+
checkpoint_path.parent.mkdir(exist_ok=True, parents=True)
|
69 |
+
torch.save(
|
70 |
+
ckpt,
|
71 |
+
checkpoint_path,
|
72 |
+
)
|
73 |
+
|
74 |
+
|
75 |
+
# import cluster
|
76 |
+
# for spk in tqdm.tqdm(os.listdir("dataset")):
|
77 |
+
# if os.path.isdir(f"dataset/{spk}"):
|
78 |
+
# print(f"start kmeans inference for {spk}...")
|
79 |
+
# for feature_path in tqdm.tqdm(glob(f"dataset/{spk}/*.discrete.npy", recursive=True)):
|
80 |
+
# mel_path = feature_path.replace(".discrete.npy",".mel.npy")
|
81 |
+
# mel_spectrogram = np.load(mel_path)
|
82 |
+
# feature_len = mel_spectrogram.shape[-1]
|
83 |
+
# c = np.load(feature_path)
|
84 |
+
# c = utils.tools.repeat_expand_2d(torch.FloatTensor(c), feature_len).numpy()
|
85 |
+
# feature = c.T
|
86 |
+
# feature_class = cluster.get_cluster_result(feature, spk)
|
87 |
+
# np.save(feature_path.replace(".discrete.npy", ".discrete_class.npy"), feature_class)
|
88 |
+
|
89 |
+
|
configs/config.json
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 200,
|
4 |
+
"eval_interval": 1000,
|
5 |
+
"seed": 1234,
|
6 |
+
"epochs": 10000,
|
7 |
+
"learning_rate": 0.0002,
|
8 |
+
"betas": [
|
9 |
+
0.8,
|
10 |
+
0.99
|
11 |
+
],
|
12 |
+
"eps": 1e-09,
|
13 |
+
"batch_size": 12,
|
14 |
+
"fp16_run": false,
|
15 |
+
"lr_decay": 0.999875,
|
16 |
+
"segment_size": 10240,
|
17 |
+
"init_lr_ratio": 1,
|
18 |
+
"warmup_epochs": 0,
|
19 |
+
"c_mel": 45,
|
20 |
+
"c_kl": 1.0,
|
21 |
+
"use_sr": true,
|
22 |
+
"max_speclen": 512,
|
23 |
+
"port": "8001",
|
24 |
+
"keep_ckpts": 0,
|
25 |
+
"all_in_mem": false
|
26 |
+
},
|
27 |
+
"data": {
|
28 |
+
"training_files": "filelists/train.txt",
|
29 |
+
"validation_files": "filelists/val.txt",
|
30 |
+
"max_wav_value": 32768.0,
|
31 |
+
"sampling_rate": 44100,
|
32 |
+
"filter_length": 2048,
|
33 |
+
"hop_length": 512,
|
34 |
+
"win_length": 2048,
|
35 |
+
"n_mel_channels": 80,
|
36 |
+
"mel_fmin": 0.0,
|
37 |
+
"mel_fmax": 22050
|
38 |
+
},
|
39 |
+
"model": {
|
40 |
+
"inter_channels": 192,
|
41 |
+
"hidden_channels": 192,
|
42 |
+
"filter_channels": 768,
|
43 |
+
"n_heads": 2,
|
44 |
+
"n_layers": 6,
|
45 |
+
"kernel_size": 3,
|
46 |
+
"p_dropout": 0.1,
|
47 |
+
"resblock": "1",
|
48 |
+
"resblock_kernel_sizes": [
|
49 |
+
3,
|
50 |
+
7,
|
51 |
+
11
|
52 |
+
],
|
53 |
+
"resblock_dilation_sizes": [
|
54 |
+
[
|
55 |
+
1,
|
56 |
+
3,
|
57 |
+
5
|
58 |
+
],
|
59 |
+
[
|
60 |
+
1,
|
61 |
+
3,
|
62 |
+
5
|
63 |
+
],
|
64 |
+
[
|
65 |
+
1,
|
66 |
+
3,
|
67 |
+
5
|
68 |
+
]
|
69 |
+
],
|
70 |
+
"upsample_rates": [
|
71 |
+
8,
|
72 |
+
8,
|
73 |
+
2,
|
74 |
+
2,
|
75 |
+
2
|
76 |
+
],
|
77 |
+
"upsample_initial_channel": 512,
|
78 |
+
"upsample_kernel_sizes": [
|
79 |
+
16,
|
80 |
+
16,
|
81 |
+
4,
|
82 |
+
4,
|
83 |
+
4
|
84 |
+
],
|
85 |
+
"n_layers_q": 3,
|
86 |
+
"use_spectral_norm": false,
|
87 |
+
"gin_channels": 256,
|
88 |
+
"ssl_dim": 256,
|
89 |
+
"n_speakers": 1
|
90 |
+
},
|
91 |
+
"spk": {
|
92 |
+
"XT3.2": 0
|
93 |
+
}
|
94 |
+
}
|
data_utils.py
ADDED
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import os
|
3 |
+
import random
|
4 |
+
import numpy as np
|
5 |
+
import torch
|
6 |
+
import torch.utils.data
|
7 |
+
|
8 |
+
import modules.commons as commons
|
9 |
+
import utils
|
10 |
+
from modules.mel_processing import spectrogram_torch, spec_to_mel_torch
|
11 |
+
from utils import load_wav_to_torch, load_filepaths_and_text
|
12 |
+
|
13 |
+
# import h5py
|
14 |
+
|
15 |
+
|
16 |
+
"""Multi speaker version"""
|
17 |
+
|
18 |
+
|
19 |
+
class TextAudioSpeakerLoader(torch.utils.data.Dataset):
|
20 |
+
"""
|
21 |
+
1) loads audio, speaker_id, text pairs
|
22 |
+
2) normalizes text and converts them to sequences of integers
|
23 |
+
3) computes spectrograms from audio files.
|
24 |
+
"""
|
25 |
+
|
26 |
+
def __init__(self, audiopaths, hparams, all_in_mem: bool = False):
|
27 |
+
self.audiopaths = load_filepaths_and_text(audiopaths)
|
28 |
+
self.max_wav_value = hparams.data.max_wav_value
|
29 |
+
self.sampling_rate = hparams.data.sampling_rate
|
30 |
+
self.filter_length = hparams.data.filter_length
|
31 |
+
self.hop_length = hparams.data.hop_length
|
32 |
+
self.win_length = hparams.data.win_length
|
33 |
+
self.sampling_rate = hparams.data.sampling_rate
|
34 |
+
self.use_sr = hparams.train.use_sr
|
35 |
+
self.spec_len = hparams.train.max_speclen
|
36 |
+
self.spk_map = hparams.spk
|
37 |
+
|
38 |
+
random.seed(1234)
|
39 |
+
random.shuffle(self.audiopaths)
|
40 |
+
|
41 |
+
self.all_in_mem = all_in_mem
|
42 |
+
if self.all_in_mem:
|
43 |
+
self.cache = [self.get_audio(p[0]) for p in self.audiopaths]
|
44 |
+
|
45 |
+
def get_audio(self, filename):
|
46 |
+
filename = filename.replace("\\", "/")
|
47 |
+
audio, sampling_rate = load_wav_to_torch(filename)
|
48 |
+
if sampling_rate != self.sampling_rate:
|
49 |
+
raise ValueError("{} SR doesn't match target {} SR".format(
|
50 |
+
sampling_rate, self.sampling_rate))
|
51 |
+
audio_norm = audio / self.max_wav_value
|
52 |
+
audio_norm = audio_norm.unsqueeze(0)
|
53 |
+
spec_filename = filename.replace(".wav", ".spec.pt")
|
54 |
+
|
55 |
+
# Ideally, all data generated after Mar 25 should have .spec.pt
|
56 |
+
if os.path.exists(spec_filename):
|
57 |
+
spec = torch.load(spec_filename)
|
58 |
+
else:
|
59 |
+
spec = spectrogram_torch(audio_norm, self.filter_length,
|
60 |
+
self.sampling_rate, self.hop_length, self.win_length,
|
61 |
+
center=False)
|
62 |
+
spec = torch.squeeze(spec, 0)
|
63 |
+
torch.save(spec, spec_filename)
|
64 |
+
|
65 |
+
spk = filename.split("/")[-2]
|
66 |
+
spk = torch.LongTensor([self.spk_map[spk]])
|
67 |
+
|
68 |
+
f0 = np.load(filename + ".f0.npy")
|
69 |
+
f0, uv = utils.interpolate_f0(f0)
|
70 |
+
f0 = torch.FloatTensor(f0)
|
71 |
+
uv = torch.FloatTensor(uv)
|
72 |
+
|
73 |
+
c = torch.load(filename+ ".soft.pt")
|
74 |
+
c = utils.repeat_expand_2d(c.squeeze(0), f0.shape[0])
|
75 |
+
|
76 |
+
|
77 |
+
lmin = min(c.size(-1), spec.size(-1))
|
78 |
+
assert abs(c.size(-1) - spec.size(-1)) < 3, (c.size(-1), spec.size(-1), f0.shape, filename)
|
79 |
+
assert abs(audio_norm.shape[1]-lmin * self.hop_length) < 3 * self.hop_length
|
80 |
+
spec, c, f0, uv = spec[:, :lmin], c[:, :lmin], f0[:lmin], uv[:lmin]
|
81 |
+
audio_norm = audio_norm[:, :lmin * self.hop_length]
|
82 |
+
|
83 |
+
return c, f0, spec, audio_norm, spk, uv
|
84 |
+
|
85 |
+
def random_slice(self, c, f0, spec, audio_norm, spk, uv):
|
86 |
+
# if spec.shape[1] < 30:
|
87 |
+
# print("skip too short audio:", filename)
|
88 |
+
# return None
|
89 |
+
if spec.shape[1] > 800:
|
90 |
+
start = random.randint(0, spec.shape[1]-800)
|
91 |
+
end = start + 790
|
92 |
+
spec, c, f0, uv = spec[:, start:end], c[:, start:end], f0[start:end], uv[start:end]
|
93 |
+
audio_norm = audio_norm[:, start * self.hop_length : end * self.hop_length]
|
94 |
+
|
95 |
+
return c, f0, spec, audio_norm, spk, uv
|
96 |
+
|
97 |
+
def __getitem__(self, index):
|
98 |
+
if self.all_in_mem:
|
99 |
+
return self.random_slice(*self.cache[index])
|
100 |
+
else:
|
101 |
+
return self.random_slice(*self.get_audio(self.audiopaths[index][0]))
|
102 |
+
|
103 |
+
def __len__(self):
|
104 |
+
return len(self.audiopaths)
|
105 |
+
|
106 |
+
|
107 |
+
class TextAudioCollate:
|
108 |
+
|
109 |
+
def __call__(self, batch):
|
110 |
+
batch = [b for b in batch if b is not None]
|
111 |
+
|
112 |
+
input_lengths, ids_sorted_decreasing = torch.sort(
|
113 |
+
torch.LongTensor([x[0].shape[1] for x in batch]),
|
114 |
+
dim=0, descending=True)
|
115 |
+
|
116 |
+
max_c_len = max([x[0].size(1) for x in batch])
|
117 |
+
max_wav_len = max([x[3].size(1) for x in batch])
|
118 |
+
|
119 |
+
lengths = torch.LongTensor(len(batch))
|
120 |
+
|
121 |
+
c_padded = torch.FloatTensor(len(batch), batch[0][0].shape[0], max_c_len)
|
122 |
+
f0_padded = torch.FloatTensor(len(batch), max_c_len)
|
123 |
+
spec_padded = torch.FloatTensor(len(batch), batch[0][2].shape[0], max_c_len)
|
124 |
+
wav_padded = torch.FloatTensor(len(batch), 1, max_wav_len)
|
125 |
+
spkids = torch.LongTensor(len(batch), 1)
|
126 |
+
uv_padded = torch.FloatTensor(len(batch), max_c_len)
|
127 |
+
|
128 |
+
c_padded.zero_()
|
129 |
+
spec_padded.zero_()
|
130 |
+
f0_padded.zero_()
|
131 |
+
wav_padded.zero_()
|
132 |
+
uv_padded.zero_()
|
133 |
+
|
134 |
+
for i in range(len(ids_sorted_decreasing)):
|
135 |
+
row = batch[ids_sorted_decreasing[i]]
|
136 |
+
|
137 |
+
c = row[0]
|
138 |
+
c_padded[i, :, :c.size(1)] = c
|
139 |
+
lengths[i] = c.size(1)
|
140 |
+
|
141 |
+
f0 = row[1]
|
142 |
+
f0_padded[i, :f0.size(0)] = f0
|
143 |
+
|
144 |
+
spec = row[2]
|
145 |
+
spec_padded[i, :, :spec.size(1)] = spec
|
146 |
+
|
147 |
+
wav = row[3]
|
148 |
+
wav_padded[i, :, :wav.size(1)] = wav
|
149 |
+
|
150 |
+
spkids[i, 0] = row[4]
|
151 |
+
|
152 |
+
uv = row[5]
|
153 |
+
uv_padded[i, :uv.size(0)] = uv
|
154 |
+
|
155 |
+
return c_padded, f0_padded, spec_padded, wav_padded, spkids, lengths, uv_padded
|
filelists/test.txt
ADDED
File without changes
|
filelists/train.txt
ADDED
@@ -0,0 +1,989 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
./dataset/44k/XT3.0/XT_103.wav
|
2 |
+
./dataset/44k/XT3.0/XT_875.wav
|
3 |
+
./dataset/44k/XT3.0/XT_114.wav
|
4 |
+
./dataset/44k/XT3.0/XT_237.wav
|
5 |
+
./dataset/44k/XT3.0/XT_337.wav
|
6 |
+
./dataset/44k/XT3.0/XT_642.wav
|
7 |
+
./dataset/44k/XT3.0/XT_896.wav
|
8 |
+
./dataset/44k/XT3.0/XT_980.wav
|
9 |
+
./dataset/44k/XT3.0/XT_8.wav
|
10 |
+
./dataset/44k/XT3.0/XT_963.wav
|
11 |
+
./dataset/44k/XT3.0/XT_545.wav
|
12 |
+
./dataset/44k/XT3.0/XT_401.wav
|
13 |
+
./dataset/44k/XT3.0/XT_129.wav
|
14 |
+
./dataset/44k/XT3.0/XT_291.wav
|
15 |
+
./dataset/44k/XT3.0/XT_431.wav
|
16 |
+
./dataset/44k/XT3.0/XT_89.wav
|
17 |
+
./dataset/44k/XT3.0/XT_494.wav
|
18 |
+
./dataset/44k/XT3.0/XT_234.wav
|
19 |
+
./dataset/44k/XT3.0/XT_598.wav
|
20 |
+
./dataset/44k/XT3.0/XT_124.wav
|
21 |
+
./dataset/44k/XT3.0/XT_555.wav
|
22 |
+
./dataset/44k/XT3.0/XT_469.wav
|
23 |
+
./dataset/44k/XT3.0/XT_589.wav
|
24 |
+
./dataset/44k/XT3.0/XT_195.wav
|
25 |
+
./dataset/44k/XT3.0/XT_988.wav
|
26 |
+
./dataset/44k/XT3.0/XT_745.wav
|
27 |
+
./dataset/44k/XT3.0/XT_968.wav
|
28 |
+
./dataset/44k/XT3.0/XT_668.wav
|
29 |
+
./dataset/44k/XT3.0/XT_953.wav
|
30 |
+
./dataset/44k/XT3.0/XT_723.wav
|
31 |
+
./dataset/44k/XT3.0/XT_772.wav
|
32 |
+
./dataset/44k/XT3.0/XT_897.wav
|
33 |
+
./dataset/44k/XT3.0/XT_767.wav
|
34 |
+
./dataset/44k/XT3.0/XT_476.wav
|
35 |
+
./dataset/44k/XT3.0/XT_721.wav
|
36 |
+
./dataset/44k/XT3.0/XT_843.wav
|
37 |
+
./dataset/44k/XT3.0/XT_274.wav
|
38 |
+
./dataset/44k/XT3.0/XT_305.wav
|
39 |
+
./dataset/44k/XT3.0/XT_850.wav
|
40 |
+
./dataset/44k/XT3.0/XT_282.wav
|
41 |
+
./dataset/44k/XT3.0/XT_439.wav
|
42 |
+
./dataset/44k/XT3.0/XT_240.wav
|
43 |
+
./dataset/44k/XT3.0/XT_30.wav
|
44 |
+
./dataset/44k/XT3.0/XT_438.wav
|
45 |
+
./dataset/44k/XT3.0/XT_455.wav
|
46 |
+
./dataset/44k/XT3.0/XT_207.wav
|
47 |
+
./dataset/44k/XT3.0/XT_659.wav
|
48 |
+
./dataset/44k/XT3.0/XT_541.wav
|
49 |
+
./dataset/44k/XT3.0/XT_191.wav
|
50 |
+
./dataset/44k/XT3.0/XT_354.wav
|
51 |
+
./dataset/44k/XT3.0/XT_911.wav
|
52 |
+
./dataset/44k/XT3.0/XT_167.wav
|
53 |
+
./dataset/44k/XT3.0/XT_966.wav
|
54 |
+
./dataset/44k/XT3.0/XT_101.wav
|
55 |
+
./dataset/44k/XT3.0/XT_112.wav
|
56 |
+
./dataset/44k/XT3.0/XT_923.wav
|
57 |
+
./dataset/44k/XT3.0/XT_977.wav
|
58 |
+
./dataset/44k/XT3.0/XT_205.wav
|
59 |
+
./dataset/44k/XT3.0/XT_83.wav
|
60 |
+
./dataset/44k/XT3.0/XT_388.wav
|
61 |
+
./dataset/44k/XT3.0/XT_430.wav
|
62 |
+
./dataset/44k/XT3.0/XT_665.wav
|
63 |
+
./dataset/44k/XT3.0/XT_10.wav
|
64 |
+
./dataset/44k/XT3.0/XT_952.wav
|
65 |
+
./dataset/44k/XT3.0/XT_25.wav
|
66 |
+
./dataset/44k/XT3.0/XT_352.wav
|
67 |
+
./dataset/44k/XT3.0/XT_976.wav
|
68 |
+
./dataset/44k/XT3.0/XT_357.wav
|
69 |
+
./dataset/44k/XT3.0/XT_648.wav
|
70 |
+
./dataset/44k/XT3.0/XT_832.wav
|
71 |
+
./dataset/44k/XT3.0/XT_846.wav
|
72 |
+
./dataset/44k/XT3.0/XT_387.wav
|
73 |
+
./dataset/44k/XT3.0/XT_643.wav
|
74 |
+
./dataset/44k/XT3.0/XT_323.wav
|
75 |
+
./dataset/44k/XT3.0/XT_532.wav
|
76 |
+
./dataset/44k/XT3.0/XT_512.wav
|
77 |
+
./dataset/44k/XT3.0/XT_553.wav
|
78 |
+
./dataset/44k/XT3.0/XT_790.wav
|
79 |
+
./dataset/44k/XT3.0/XT_540.wav
|
80 |
+
./dataset/44k/XT3.0/XT_162.wav
|
81 |
+
./dataset/44k/XT3.0/XT_300.wav
|
82 |
+
./dataset/44k/XT3.0/XT_941.wav
|
83 |
+
./dataset/44k/XT3.0/XT_681.wav
|
84 |
+
./dataset/44k/XT3.0/XT_244.wav
|
85 |
+
./dataset/44k/XT3.0/XT_621.wav
|
86 |
+
./dataset/44k/XT3.0/XT_797.wav
|
87 |
+
./dataset/44k/XT3.0/XT_428.wav
|
88 |
+
./dataset/44k/XT3.0/XT_295.wav
|
89 |
+
./dataset/44k/XT3.0/XT_466.wav
|
90 |
+
./dataset/44k/XT3.0/XT_777.wav
|
91 |
+
./dataset/44k/XT3.0/XT_987.wav
|
92 |
+
./dataset/44k/XT3.0/XT_872.wav
|
93 |
+
./dataset/44k/XT3.0/XT_335.wav
|
94 |
+
./dataset/44k/XT3.0/XT_754.wav
|
95 |
+
./dataset/44k/XT3.0/XT_264.wav
|
96 |
+
./dataset/44k/XT3.0/XT_153.wav
|
97 |
+
./dataset/44k/XT3.0/XT_285.wav
|
98 |
+
./dataset/44k/XT3.0/XT_917.wav
|
99 |
+
./dataset/44k/XT3.0/XT_262.wav
|
100 |
+
./dataset/44k/XT3.0/XT_379.wav
|
101 |
+
./dataset/44k/XT3.0/XT_652.wav
|
102 |
+
./dataset/44k/XT3.0/XT_666.wav
|
103 |
+
./dataset/44k/XT3.0/XT_249.wav
|
104 |
+
./dataset/44k/XT3.0/XT_537.wav
|
105 |
+
./dataset/44k/XT3.0/XT_67.wav
|
106 |
+
./dataset/44k/XT3.0/XT_138.wav
|
107 |
+
./dataset/44k/XT3.0/XT_11.wav
|
108 |
+
./dataset/44k/XT3.0/XT_585.wav
|
109 |
+
./dataset/44k/XT3.0/XT_46.wav
|
110 |
+
./dataset/44k/XT3.0/XT_346.wav
|
111 |
+
./dataset/44k/XT3.0/XT_307.wav
|
112 |
+
./dataset/44k/XT3.0/XT_569.wav
|
113 |
+
./dataset/44k/XT3.0/XT_426.wav
|
114 |
+
./dataset/44k/XT3.0/XT_169.wav
|
115 |
+
./dataset/44k/XT3.0/XT_383.wav
|
116 |
+
./dataset/44k/XT3.0/XT_92.wav
|
117 |
+
./dataset/44k/XT3.0/XT_188.wav
|
118 |
+
./dataset/44k/XT3.0/XT_901.wav
|
119 |
+
./dataset/44k/XT3.0/XT_758.wav
|
120 |
+
./dataset/44k/XT3.0/XT_220.wav
|
121 |
+
./dataset/44k/XT3.0/XT_835.wav
|
122 |
+
./dataset/44k/XT3.0/XT_839.wav
|
123 |
+
./dataset/44k/XT3.0/XT_373.wav
|
124 |
+
./dataset/44k/XT3.0/XT_266.wav
|
125 |
+
./dataset/44k/XT3.0/XT_746.wav
|
126 |
+
./dataset/44k/XT3.0/XT_546.wav
|
127 |
+
./dataset/44k/XT3.0/XT_280.wav
|
128 |
+
./dataset/44k/XT3.0/XT_399.wav
|
129 |
+
./dataset/44k/XT3.0/XT_658.wav
|
130 |
+
./dataset/44k/XT3.0/XT_59.wav
|
131 |
+
./dataset/44k/XT3.0/XT_922.wav
|
132 |
+
./dataset/44k/XT3.0/XT_676.wav
|
133 |
+
./dataset/44k/XT3.0/XT_682.wav
|
134 |
+
./dataset/44k/XT3.0/XT_919.wav
|
135 |
+
./dataset/44k/XT3.0/XT_725.wav
|
136 |
+
./dataset/44k/XT3.0/XT_247.wav
|
137 |
+
./dataset/44k/XT3.0/XT_317.wav
|
138 |
+
./dataset/44k/XT3.0/XT_869.wav
|
139 |
+
./dataset/44k/XT3.0/XT_618.wav
|
140 |
+
./dataset/44k/XT3.0/XT_424.wav
|
141 |
+
./dataset/44k/XT3.0/XT_502.wav
|
142 |
+
./dataset/44k/XT3.0/XT_940.wav
|
143 |
+
./dataset/44k/XT3.0/XT_828.wav
|
144 |
+
./dataset/44k/XT3.0/XT_518.wav
|
145 |
+
./dataset/44k/XT3.0/XT_628.wav
|
146 |
+
./dataset/44k/XT3.0/XT_802.wav
|
147 |
+
./dataset/44k/XT3.0/XT_485.wav
|
148 |
+
./dataset/44k/XT3.0/XT_728.wav
|
149 |
+
./dataset/44k/XT3.0/XT_874.wav
|
150 |
+
./dataset/44k/XT3.0/XT_96.wav
|
151 |
+
./dataset/44k/XT3.0/XT_830.wav
|
152 |
+
./dataset/44k/XT3.0/XT_904.wav
|
153 |
+
./dataset/44k/XT3.0/XT_443.wav
|
154 |
+
./dataset/44k/XT3.0/XT_813.wav
|
155 |
+
./dataset/44k/XT3.0/XT_128.wav
|
156 |
+
./dataset/44k/XT3.0/XT_798.wav
|
157 |
+
./dataset/44k/XT3.0/XT_773.wav
|
158 |
+
./dataset/44k/XT3.0/XT_294.wav
|
159 |
+
./dataset/44k/XT3.0/XT_340.wav
|
160 |
+
./dataset/44k/XT3.0/XT_242.wav
|
161 |
+
./dataset/44k/XT3.0/XT_525.wav
|
162 |
+
./dataset/44k/XT3.0/XT_735.wav
|
163 |
+
./dataset/44k/XT3.0/XT_165.wav
|
164 |
+
./dataset/44k/XT3.0/XT_43.wav
|
165 |
+
./dataset/44k/XT3.0/XT_174.wav
|
166 |
+
./dataset/44k/XT3.0/XT_702.wav
|
167 |
+
./dataset/44k/XT3.0/XT_984.wav
|
168 |
+
./dataset/44k/XT3.0/XT_159.wav
|
169 |
+
./dataset/44k/XT3.0/XT_856.wav
|
170 |
+
./dataset/44k/XT3.0/XT_575.wav
|
171 |
+
./dataset/44k/XT3.0/XT_200.wav
|
172 |
+
./dataset/44k/XT3.0/XT_63.wav
|
173 |
+
./dataset/44k/XT3.0/XT_842.wav
|
174 |
+
./dataset/44k/XT3.0/XT_496.wav
|
175 |
+
./dataset/44k/XT3.0/XT_760.wav
|
176 |
+
./dataset/44k/XT3.0/XT_176.wav
|
177 |
+
./dataset/44k/XT3.0/XT_927.wav
|
178 |
+
./dataset/44k/XT3.0/XT_794.wav
|
179 |
+
./dataset/44k/XT3.0/XT_194.wav
|
180 |
+
./dataset/44k/XT3.0/XT_57.wav
|
181 |
+
./dataset/44k/XT3.0/XT_825.wav
|
182 |
+
./dataset/44k/XT3.0/XT_590.wav
|
183 |
+
./dataset/44k/XT3.0/XT_417.wav
|
184 |
+
./dataset/44k/XT3.0/XT_51.wav
|
185 |
+
./dataset/44k/XT3.0/XT_509.wav
|
186 |
+
./dataset/44k/XT3.0/XT_891.wav
|
187 |
+
./dataset/44k/XT3.0/XT_410.wav
|
188 |
+
./dataset/44k/XT3.0/XT_577.wav
|
189 |
+
./dataset/44k/XT3.0/XT_738.wav
|
190 |
+
./dataset/44k/XT3.0/XT_2.wav
|
191 |
+
./dataset/44k/XT3.0/XT_523.wav
|
192 |
+
./dataset/44k/XT3.0/XT_32.wav
|
193 |
+
./dataset/44k/XT3.0/XT_454.wav
|
194 |
+
./dataset/44k/XT3.0/XT_503.wav
|
195 |
+
./dataset/44k/XT3.0/XT_218.wav
|
196 |
+
./dataset/44k/XT3.0/XT_774.wav
|
197 |
+
./dataset/44k/XT3.0/XT_347.wav
|
198 |
+
./dataset/44k/XT3.0/XT_824.wav
|
199 |
+
./dataset/44k/XT3.0/XT_362.wav
|
200 |
+
./dataset/44k/XT3.0/XT_766.wav
|
201 |
+
./dataset/44k/XT3.0/XT_243.wav
|
202 |
+
./dataset/44k/XT3.0/XT_209.wav
|
203 |
+
./dataset/44k/XT3.0/XT_660.wav
|
204 |
+
./dataset/44k/XT3.0/XT_117.wav
|
205 |
+
./dataset/44k/XT3.0/XT_697.wav
|
206 |
+
./dataset/44k/XT3.0/XT_749.wav
|
207 |
+
./dataset/44k/XT3.0/XT_561.wav
|
208 |
+
./dataset/44k/XT3.0/XT_198.wav
|
209 |
+
./dataset/44k/XT3.0/XT_434.wav
|
210 |
+
./dataset/44k/XT3.0/XT_636.wav
|
211 |
+
./dataset/44k/XT3.0/XT_299.wav
|
212 |
+
./dataset/44k/XT3.0/XT_880.wav
|
213 |
+
./dataset/44k/XT3.0/XT_93.wav
|
214 |
+
./dataset/44k/XT3.0/XT_818.wav
|
215 |
+
./dataset/44k/XT3.0/XT_71.wav
|
216 |
+
./dataset/44k/XT3.0/XT_371.wav
|
217 |
+
./dataset/44k/XT3.0/XT_470.wav
|
218 |
+
./dataset/44k/XT3.0/XT_302.wav
|
219 |
+
./dataset/44k/XT3.0/XT_931.wav
|
220 |
+
./dataset/44k/XT3.0/XT_792.wav
|
221 |
+
./dataset/44k/XT3.0/XT_958.wav
|
222 |
+
./dataset/44k/XT3.0/XT_907.wav
|
223 |
+
./dataset/44k/XT3.0/XT_562.wav
|
224 |
+
./dataset/44k/XT3.0/XT_791.wav
|
225 |
+
./dataset/44k/XT3.0/XT_691.wav
|
226 |
+
./dataset/44k/XT3.0/XT_484.wav
|
227 |
+
./dataset/44k/XT3.0/XT_511.wav
|
228 |
+
./dataset/44k/XT3.0/XT_607.wav
|
229 |
+
./dataset/44k/XT3.0/XT_744.wav
|
230 |
+
./dataset/44k/XT3.0/XT_34.wav
|
231 |
+
./dataset/44k/XT3.0/XT_127.wav
|
232 |
+
./dataset/44k/XT3.0/XT_493.wav
|
233 |
+
./dataset/44k/XT3.0/XT_395.wav
|
234 |
+
./dataset/44k/XT3.0/XT_24.wav
|
235 |
+
./dataset/44k/XT3.0/XT_48.wav
|
236 |
+
./dataset/44k/XT3.0/XT_771.wav
|
237 |
+
./dataset/44k/XT3.0/XT_779.wav
|
238 |
+
./dataset/44k/XT3.0/XT_938.wav
|
239 |
+
./dataset/44k/XT3.0/XT_680.wav
|
240 |
+
./dataset/44k/XT3.0/XT_787.wav
|
241 |
+
./dataset/44k/XT3.0/XT_62.wav
|
242 |
+
./dataset/44k/XT3.0/XT_440.wav
|
243 |
+
./dataset/44k/XT3.0/XT_29.wav
|
244 |
+
./dataset/44k/XT3.0/XT_827.wav
|
245 |
+
./dataset/44k/XT3.0/XT_173.wav
|
246 |
+
./dataset/44k/XT3.0/XT_992.wav
|
247 |
+
./dataset/44k/XT3.0/XT_121.wav
|
248 |
+
./dataset/44k/XT3.0/XT_867.wav
|
249 |
+
./dataset/44k/XT3.0/XT_670.wav
|
250 |
+
./dataset/44k/XT3.0/XT_157.wav
|
251 |
+
./dataset/44k/XT3.0/XT_795.wav
|
252 |
+
./dataset/44k/XT3.0/XT_4.wav
|
253 |
+
./dataset/44k/XT3.0/XT_930.wav
|
254 |
+
./dataset/44k/XT3.0/XT_570.wav
|
255 |
+
./dataset/44k/XT3.0/XT_743.wav
|
256 |
+
./dataset/44k/XT3.0/XT_343.wav
|
257 |
+
./dataset/44k/XT3.0/XT_604.wav
|
258 |
+
./dataset/44k/XT3.0/XT_672.wav
|
259 |
+
./dataset/44k/XT3.0/XT_68.wav
|
260 |
+
./dataset/44k/XT3.0/XT_437.wav
|
261 |
+
./dataset/44k/XT3.0/XT_225.wav
|
262 |
+
./dataset/44k/XT3.0/XT_849.wav
|
263 |
+
./dataset/44k/XT3.0/XT_732.wav
|
264 |
+
./dataset/44k/XT3.0/XT_707.wav
|
265 |
+
./dataset/44k/XT3.0/XT_951.wav
|
266 |
+
./dataset/44k/XT3.0/XT_276.wav
|
267 |
+
./dataset/44k/XT3.0/XT_360.wav
|
268 |
+
./dataset/44k/XT3.0/XT_58.wav
|
269 |
+
./dataset/44k/XT3.0/XT_640.wav
|
270 |
+
./dataset/44k/XT3.0/XT_425.wav
|
271 |
+
./dataset/44k/XT3.0/XT_631.wav
|
272 |
+
./dataset/44k/XT3.0/XT_85.wav
|
273 |
+
./dataset/44k/XT3.0/XT_689.wav
|
274 |
+
./dataset/44k/XT3.0/XT_759.wav
|
275 |
+
./dataset/44k/XT3.0/XT_731.wav
|
276 |
+
./dataset/44k/XT3.0/XT_404.wav
|
277 |
+
./dataset/44k/XT3.0/XT_704.wav
|
278 |
+
./dataset/44k/XT3.0/XT_451.wav
|
279 |
+
./dataset/44k/XT3.0/XT_960.wav
|
280 |
+
./dataset/44k/XT3.0/XT_394.wav
|
281 |
+
./dataset/44k/XT3.0/XT_556.wav
|
282 |
+
./dataset/44k/XT3.0/XT_551.wav
|
283 |
+
./dataset/44k/XT3.0/XT_886.wav
|
284 |
+
./dataset/44k/XT3.0/XT_472.wav
|
285 |
+
./dataset/44k/XT3.0/XT_104.wav
|
286 |
+
./dataset/44k/XT3.0/XT_685.wav
|
287 |
+
./dataset/44k/XT3.0/XT_812.wav
|
288 |
+
./dataset/44k/XT3.0/XT_973.wav
|
289 |
+
./dataset/44k/XT3.0/XT_959.wav
|
290 |
+
./dataset/44k/XT3.0/XT_549.wav
|
291 |
+
./dataset/44k/XT3.0/XT_765.wav
|
292 |
+
./dataset/44k/XT3.0/XT_804.wav
|
293 |
+
./dataset/44k/XT3.0/XT_436.wav
|
294 |
+
./dataset/44k/XT3.0/XT_823.wav
|
295 |
+
./dataset/44k/XT3.0/XT_879.wav
|
296 |
+
./dataset/44k/XT3.0/XT_206.wav
|
297 |
+
./dataset/44k/XT3.0/XT_288.wav
|
298 |
+
./dataset/44k/XT3.0/XT_474.wav
|
299 |
+
./dataset/44k/XT3.0/XT_197.wav
|
300 |
+
./dataset/44k/XT3.0/XT_227.wav
|
301 |
+
./dataset/44k/XT3.0/XT_289.wav
|
302 |
+
./dataset/44k/XT3.0/XT_594.wav
|
303 |
+
./dataset/44k/XT3.0/XT_497.wav
|
304 |
+
./dataset/44k/XT3.0/XT_319.wav
|
305 |
+
./dataset/44k/XT3.0/XT_714.wav
|
306 |
+
./dataset/44k/XT3.0/XT_747.wav
|
307 |
+
./dataset/44k/XT3.0/XT_602.wav
|
308 |
+
./dataset/44k/XT3.0/XT_946.wav
|
309 |
+
./dataset/44k/XT3.0/XT_739.wav
|
310 |
+
./dataset/44k/XT3.0/XT_624.wav
|
311 |
+
./dataset/44k/XT3.0/XT_324.wav
|
312 |
+
./dataset/44k/XT3.0/XT_514.wav
|
313 |
+
./dataset/44k/XT3.0/XT_724.wav
|
314 |
+
./dataset/44k/XT3.0/XT_756.wav
|
315 |
+
./dataset/44k/XT3.0/XT_706.wav
|
316 |
+
./dataset/44k/XT3.0/XT_90.wav
|
317 |
+
./dataset/44k/XT3.0/XT_290.wav
|
318 |
+
./dataset/44k/XT3.0/XT_559.wav
|
319 |
+
./dataset/44k/XT3.0/XT_79.wav
|
320 |
+
./dataset/44k/XT3.0/XT_757.wav
|
321 |
+
./dataset/44k/XT3.0/XT_381.wav
|
322 |
+
./dataset/44k/XT3.0/XT_172.wav
|
323 |
+
./dataset/44k/XT3.0/XT_192.wav
|
324 |
+
./dataset/44k/XT3.0/XT_637.wav
|
325 |
+
./dataset/44k/XT3.0/XT_816.wav
|
326 |
+
./dataset/44k/XT3.0/XT_993.wav
|
327 |
+
./dataset/44k/XT3.0/XT_870.wav
|
328 |
+
./dataset/44k/XT3.0/XT_632.wav
|
329 |
+
./dataset/44k/XT3.0/XT_385.wav
|
330 |
+
./dataset/44k/XT3.0/XT_156.wav
|
331 |
+
./dataset/44k/XT3.0/XT_42.wav
|
332 |
+
./dataset/44k/XT3.0/XT_444.wav
|
333 |
+
./dataset/44k/XT3.0/XT_912.wav
|
334 |
+
./dataset/44k/XT3.0/XT_393.wav
|
335 |
+
./dataset/44k/XT3.0/XT_692.wav
|
336 |
+
./dataset/44k/XT3.0/XT_351.wav
|
337 |
+
./dataset/44k/XT3.0/XT_258.wav
|
338 |
+
./dataset/44k/XT3.0/XT_620.wav
|
339 |
+
./dataset/44k/XT3.0/XT_718.wav
|
340 |
+
./dataset/44k/XT3.0/XT_283.wav
|
341 |
+
./dataset/44k/XT3.0/XT_601.wav
|
342 |
+
./dataset/44k/XT3.0/XT_661.wav
|
343 |
+
./dataset/44k/XT3.0/XT_13.wav
|
344 |
+
./dataset/44k/XT3.0/XT_855.wav
|
345 |
+
./dataset/44k/XT3.0/XT_703.wav
|
346 |
+
./dataset/44k/XT3.0/XT_860.wav
|
347 |
+
./dataset/44k/XT3.0/XT_957.wav
|
348 |
+
./dataset/44k/XT3.0/XT_139.wav
|
349 |
+
./dataset/44k/XT3.0/XT_519.wav
|
350 |
+
./dataset/44k/XT3.0/XT_524.wav
|
351 |
+
./dataset/44k/XT3.0/XT_279.wav
|
352 |
+
./dataset/44k/XT3.0/XT_712.wav
|
353 |
+
./dataset/44k/XT3.0/XT_515.wav
|
354 |
+
./dataset/44k/XT3.0/XT_181.wav
|
355 |
+
./dataset/44k/XT3.0/XT_527.wav
|
356 |
+
./dataset/44k/XT3.0/XT_201.wav
|
357 |
+
./dataset/44k/XT3.0/XT_582.wav
|
358 |
+
./dataset/44k/XT3.0/XT_338.wav
|
359 |
+
./dataset/44k/XT3.0/XT_232.wav
|
360 |
+
./dataset/44k/XT3.0/XT_478.wav
|
361 |
+
./dataset/44k/XT3.0/XT_94.wav
|
362 |
+
./dataset/44k/XT3.0/XT_308.wav
|
363 |
+
./dataset/44k/XT3.0/XT_377.wav
|
364 |
+
./dataset/44k/XT3.0/XT_608.wav
|
365 |
+
./dataset/44k/XT3.0/XT_663.wav
|
366 |
+
./dataset/44k/XT3.0/XT_734.wav
|
367 |
+
./dataset/44k/XT3.0/XT_588.wav
|
368 |
+
./dataset/44k/XT3.0/XT_655.wav
|
369 |
+
./dataset/44k/XT3.0/XT_36.wav
|
370 |
+
./dataset/44k/XT3.0/XT_265.wav
|
371 |
+
./dataset/44k/XT3.0/XT_445.wav
|
372 |
+
./dataset/44k/XT3.0/XT_429.wav
|
373 |
+
./dataset/44k/XT3.0/XT_710.wav
|
374 |
+
./dataset/44k/XT3.0/XT_254.wav
|
375 |
+
./dataset/44k/XT3.0/XT_457.wav
|
376 |
+
./dataset/44k/XT3.0/XT_858.wav
|
377 |
+
./dataset/44k/XT3.0/XT_367.wav
|
378 |
+
./dataset/44k/XT3.0/XT_166.wav
|
379 |
+
./dataset/44k/XT3.0/XT_462.wav
|
380 |
+
./dataset/44k/XT3.0/XT_202.wav
|
381 |
+
./dataset/44k/XT3.0/XT_446.wav
|
382 |
+
./dataset/44k/XT3.0/XT_768.wav
|
383 |
+
./dataset/44k/XT3.0/XT_591.wav
|
384 |
+
./dataset/44k/XT3.0/XT_420.wav
|
385 |
+
./dataset/44k/XT3.0/XT_495.wav
|
386 |
+
./dataset/44k/XT3.0/XT_460.wav
|
387 |
+
./dataset/44k/XT3.0/XT_269.wav
|
388 |
+
./dataset/44k/XT3.0/XT_219.wav
|
389 |
+
./dataset/44k/XT3.0/XT_675.wav
|
390 |
+
./dataset/44k/XT3.0/XT_499.wav
|
391 |
+
./dataset/44k/XT3.0/XT_715.wav
|
392 |
+
./dataset/44k/XT3.0/XT_544.wav
|
393 |
+
./dataset/44k/XT3.0/XT_412.wav
|
394 |
+
./dataset/44k/XT3.0/XT_433.wav
|
395 |
+
./dataset/44k/XT3.0/XT_284.wav
|
396 |
+
./dataset/44k/XT3.0/XT_175.wav
|
397 |
+
./dataset/44k/XT3.0/XT_956.wav
|
398 |
+
./dataset/44k/XT3.0/XT_483.wav
|
399 |
+
./dataset/44k/XT3.0/XT_136.wav
|
400 |
+
./dataset/44k/XT3.0/XT_99.wav
|
401 |
+
./dataset/44k/XT3.0/XT_55.wav
|
402 |
+
./dataset/44k/XT3.0/XT_45.wav
|
403 |
+
./dataset/44k/XT3.0/XT_184.wav
|
404 |
+
./dataset/44k/XT3.0/XT_1.wav
|
405 |
+
./dataset/44k/XT3.0/XT_217.wav
|
406 |
+
./dataset/44k/XT3.0/XT_223.wav
|
407 |
+
./dataset/44k/XT3.0/XT_599.wav
|
408 |
+
./dataset/44k/XT3.0/XT_677.wav
|
409 |
+
./dataset/44k/XT3.0/XT_170.wav
|
410 |
+
./dataset/44k/XT3.0/XT_505.wav
|
411 |
+
./dataset/44k/XT3.0/XT_885.wav
|
412 |
+
./dataset/44k/XT3.0/XT_775.wav
|
413 |
+
./dataset/44k/XT3.0/XT_76.wav
|
414 |
+
./dataset/44k/XT3.0/XT_230.wav
|
415 |
+
./dataset/44k/XT3.0/XT_741.wav
|
416 |
+
./dataset/44k/XT3.0/XT_819.wav
|
417 |
+
./dataset/44k/XT3.0/XT_574.wav
|
418 |
+
./dataset/44k/XT3.0/XT_35.wav
|
419 |
+
./dataset/44k/XT3.0/XT_596.wav
|
420 |
+
./dataset/44k/XT3.0/XT_688.wav
|
421 |
+
./dataset/44k/XT3.0/XT_56.wav
|
422 |
+
./dataset/44k/XT3.0/XT_906.wav
|
423 |
+
./dataset/44k/XT3.0/XT_222.wav
|
424 |
+
./dataset/44k/XT3.0/XT_432.wav
|
425 |
+
./dataset/44k/XT3.0/XT_945.wav
|
426 |
+
./dataset/44k/XT3.0/XT_873.wav
|
427 |
+
./dataset/44k/XT3.0/XT_150.wav
|
428 |
+
./dataset/44k/XT3.0/XT_204.wav
|
429 |
+
./dataset/44k/XT3.0/XT_318.wav
|
430 |
+
./dataset/44k/XT3.0/XT_964.wav
|
431 |
+
./dataset/44k/XT3.0/XT_981.wav
|
432 |
+
./dataset/44k/XT3.0/XT_54.wav
|
433 |
+
./dataset/44k/XT3.0/XT_581.wav
|
434 |
+
./dataset/44k/XT3.0/XT_986.wav
|
435 |
+
./dataset/44k/XT3.0/XT_612.wav
|
436 |
+
./dataset/44k/XT3.0/XT_391.wav
|
437 |
+
./dataset/44k/XT3.0/XT_122.wav
|
438 |
+
./dataset/44k/XT3.0/XT_78.wav
|
439 |
+
./dataset/44k/XT3.0/XT_208.wav
|
440 |
+
./dataset/44k/XT3.0/XT_69.wav
|
441 |
+
./dataset/44k/XT3.0/XT_807.wav
|
442 |
+
./dataset/44k/XT3.0/XT_521.wav
|
443 |
+
./dataset/44k/XT3.0/XT_70.wav
|
444 |
+
./dataset/44k/XT3.0/XT_116.wav
|
445 |
+
./dataset/44k/XT3.0/XT_186.wav
|
446 |
+
./dataset/44k/XT3.0/XT_115.wav
|
447 |
+
./dataset/44k/XT3.0/XT_657.wav
|
448 |
+
./dataset/44k/XT3.0/XT_961.wav
|
449 |
+
./dataset/44k/XT3.0/XT_293.wav
|
450 |
+
./dataset/44k/XT3.0/XT_108.wav
|
451 |
+
./dataset/44k/XT3.0/XT_408.wav
|
452 |
+
./dataset/44k/XT3.0/XT_751.wav
|
453 |
+
./dataset/44k/XT3.0/XT_95.wav
|
454 |
+
./dataset/44k/XT3.0/XT_566.wav
|
455 |
+
./dataset/44k/XT3.0/XT_838.wav
|
456 |
+
./dataset/44k/XT3.0/XT_164.wav
|
457 |
+
./dataset/44k/XT3.0/XT_87.wav
|
458 |
+
./dataset/44k/XT3.0/XT_613.wav
|
459 |
+
./dataset/44k/XT3.0/XT_292.wav
|
460 |
+
./dataset/44k/XT3.0/XT_161.wav
|
461 |
+
./dataset/44k/XT3.0/XT_344.wav
|
462 |
+
./dataset/44k/XT3.0/XT_782.wav
|
463 |
+
./dataset/44k/XT3.0/XT_528.wav
|
464 |
+
./dataset/44k/XT3.0/XT_936.wav
|
465 |
+
./dataset/44k/XT3.0/XT_151.wav
|
466 |
+
./dataset/44k/XT3.0/XT_788.wav
|
467 |
+
./dataset/44k/XT3.0/XT_534.wav
|
468 |
+
./dataset/44k/XT3.0/XT_853.wav
|
469 |
+
./dataset/44k/XT3.0/XT_419.wav
|
470 |
+
./dataset/44k/XT3.0/XT_131.wav
|
471 |
+
./dataset/44k/XT3.0/XT_821.wav
|
472 |
+
./dataset/44k/XT3.0/XT_259.wav
|
473 |
+
./dataset/44k/XT3.0/XT_679.wav
|
474 |
+
./dataset/44k/XT3.0/XT_884.wav
|
475 |
+
./dataset/44k/XT3.0/XT_726.wav
|
476 |
+
./dataset/44k/XT3.0/XT_320.wav
|
477 |
+
./dataset/44k/XT3.0/XT_592.wav
|
478 |
+
./dataset/44k/XT3.0/XT_614.wav
|
479 |
+
./dataset/44k/XT3.0/XT_834.wav
|
480 |
+
./dataset/44k/XT3.0/XT_531.wav
|
481 |
+
./dataset/44k/XT3.0/XT_698.wav
|
482 |
+
./dataset/44k/XT3.0/XT_985.wav
|
483 |
+
./dataset/44k/XT3.0/XT_991.wav
|
484 |
+
./dataset/44k/XT3.0/XT_160.wav
|
485 |
+
./dataset/44k/XT3.0/XT_106.wav
|
486 |
+
./dataset/44k/XT3.0/XT_801.wav
|
487 |
+
./dataset/44k/XT3.0/XT_107.wav
|
488 |
+
./dataset/44k/XT3.0/XT_416.wav
|
489 |
+
./dataset/44k/XT3.0/XT_81.wav
|
490 |
+
./dataset/44k/XT3.0/XT_44.wav
|
491 |
+
./dataset/44k/XT3.0/XT_578.wav
|
492 |
+
./dataset/44k/XT3.0/XT_854.wav
|
493 |
+
./dataset/44k/XT3.0/XT_203.wav
|
494 |
+
./dataset/44k/XT3.0/XT_647.wav
|
495 |
+
./dataset/44k/XT3.0/XT_761.wav
|
496 |
+
./dataset/44k/XT3.0/XT_826.wav
|
497 |
+
./dataset/44k/XT3.0/XT_287.wav
|
498 |
+
./dataset/44k/XT3.0/XT_333.wav
|
499 |
+
./dataset/44k/XT3.0/XT_943.wav
|
500 |
+
./dataset/44k/XT3.0/XT_369.wav
|
501 |
+
./dataset/44k/XT3.0/XT_753.wav
|
502 |
+
./dataset/44k/XT3.0/XT_304.wav
|
503 |
+
./dataset/44k/XT3.0/XT_740.wav
|
504 |
+
./dataset/44k/XT3.0/XT_84.wav
|
505 |
+
./dataset/44k/XT3.0/XT_363.wav
|
506 |
+
./dataset/44k/XT3.0/XT_189.wav
|
507 |
+
./dataset/44k/XT3.0/XT_154.wav
|
508 |
+
./dataset/44k/XT3.0/XT_118.wav
|
509 |
+
./dataset/44k/XT3.0/XT_19.wav
|
510 |
+
./dataset/44k/XT3.0/XT_708.wav
|
511 |
+
./dataset/44k/XT3.0/XT_177.wav
|
512 |
+
./dataset/44k/XT3.0/XT_171.wav
|
513 |
+
./dataset/44k/XT3.0/XT_565.wav
|
514 |
+
./dataset/44k/XT3.0/XT_359.wav
|
515 |
+
./dataset/44k/XT3.0/XT_309.wav
|
516 |
+
./dataset/44k/XT3.0/XT_971.wav
|
517 |
+
./dataset/44k/XT3.0/XT_507.wav
|
518 |
+
./dataset/44k/XT3.0/XT_547.wav
|
519 |
+
./dataset/44k/XT3.0/XT_397.wav
|
520 |
+
./dataset/44k/XT3.0/XT_358.wav
|
521 |
+
./dataset/44k/XT3.0/XT_113.wav
|
522 |
+
./dataset/44k/XT3.0/XT_252.wav
|
523 |
+
./dataset/44k/XT3.0/XT_560.wav
|
524 |
+
./dataset/44k/XT3.0/XT_3.wav
|
525 |
+
./dataset/44k/XT3.0/XT_769.wav
|
526 |
+
./dataset/44k/XT3.0/XT_634.wav
|
527 |
+
./dataset/44k/XT3.0/XT_12.wav
|
528 |
+
./dataset/44k/XT3.0/XT_350.wav
|
529 |
+
./dataset/44k/XT3.0/XT_539.wav
|
530 |
+
./dataset/44k/XT3.0/XT_421.wav
|
531 |
+
./dataset/44k/XT3.0/XT_935.wav
|
532 |
+
./dataset/44k/XT3.0/XT_881.wav
|
533 |
+
./dataset/44k/XT3.0/XT_882.wav
|
534 |
+
./dataset/44k/XT3.0/XT_822.wav
|
535 |
+
./dataset/44k/XT3.0/XT_736.wav
|
536 |
+
./dataset/44k/XT3.0/XT_883.wav
|
537 |
+
./dataset/44k/XT3.0/XT_33.wav
|
538 |
+
./dataset/44k/XT3.0/XT_277.wav
|
539 |
+
./dataset/44k/XT3.0/XT_970.wav
|
540 |
+
./dataset/44k/XT3.0/XT_297.wav
|
541 |
+
./dataset/44k/XT3.0/XT_890.wav
|
542 |
+
./dataset/44k/XT3.0/XT_763.wav
|
543 |
+
./dataset/44k/XT3.0/XT_876.wav
|
544 |
+
./dataset/44k/XT3.0/XT_948.wav
|
545 |
+
./dataset/44k/XT3.0/XT_491.wav
|
546 |
+
./dataset/44k/XT3.0/XT_722.wav
|
547 |
+
./dataset/44k/XT3.0/XT_212.wav
|
548 |
+
./dataset/44k/XT3.0/XT_331.wav
|
549 |
+
./dataset/44k/XT3.0/XT_40.wav
|
550 |
+
./dataset/44k/XT3.0/XT_126.wav
|
551 |
+
./dataset/44k/XT3.0/XT_840.wav
|
552 |
+
./dataset/44k/XT3.0/XT_405.wav
|
553 |
+
./dataset/44k/XT3.0/XT_140.wav
|
554 |
+
./dataset/44k/XT3.0/XT_815.wav
|
555 |
+
./dataset/44k/XT3.0/XT_72.wav
|
556 |
+
./dataset/44k/XT3.0/XT_374.wav
|
557 |
+
./dataset/44k/XT3.0/XT_311.wav
|
558 |
+
./dataset/44k/XT3.0/XT_448.wav
|
559 |
+
./dataset/44k/XT3.0/XT_236.wav
|
560 |
+
./dataset/44k/XT3.0/XT_711.wav
|
561 |
+
./dataset/44k/XT3.0/XT_669.wav
|
562 |
+
./dataset/44k/XT3.0/XT_268.wav
|
563 |
+
./dataset/44k/XT3.0/XT_817.wav
|
564 |
+
./dataset/44k/XT3.0/XT_877.wav
|
565 |
+
./dataset/44k/XT3.0/XT_586.wav
|
566 |
+
./dataset/44k/XT3.0/XT_489.wav
|
567 |
+
./dataset/44k/XT3.0/XT_256.wav
|
568 |
+
./dataset/44k/XT3.0/XT_332.wav
|
569 |
+
./dataset/44k/XT3.0/XT_459.wav
|
570 |
+
./dataset/44k/XT3.0/XT_793.wav
|
571 |
+
./dataset/44k/XT3.0/XT_449.wav
|
572 |
+
./dataset/44k/XT3.0/XT_473.wav
|
573 |
+
./dataset/44k/XT3.0/XT_310.wav
|
574 |
+
./dataset/44k/XT3.0/XT_950.wav
|
575 |
+
./dataset/44k/XT3.0/XT_651.wav
|
576 |
+
./dataset/44k/XT3.0/XT_625.wav
|
577 |
+
./dataset/44k/XT3.0/XT_389.wav
|
578 |
+
./dataset/44k/XT3.0/XT_786.wav
|
579 |
+
./dataset/44k/XT3.0/XT_102.wav
|
580 |
+
./dataset/44k/XT3.0/XT_458.wav
|
581 |
+
./dataset/44k/XT3.0/XT_386.wav
|
582 |
+
./dataset/44k/XT3.0/XT_622.wav
|
583 |
+
./dataset/44k/XT3.0/XT_933.wav
|
584 |
+
./dataset/44k/XT3.0/XT_450.wav
|
585 |
+
./dataset/44k/XT3.0/XT_17.wav
|
586 |
+
./dataset/44k/XT3.0/XT_800.wav
|
587 |
+
./dataset/44k/XT3.0/XT_695.wav
|
588 |
+
./dataset/44k/XT3.0/XT_155.wav
|
589 |
+
./dataset/44k/XT3.0/XT_144.wav
|
590 |
+
./dataset/44k/XT3.0/XT_14.wav
|
591 |
+
./dataset/44k/XT3.0/XT_568.wav
|
592 |
+
./dataset/44k/XT3.0/XT_727.wav
|
593 |
+
./dataset/44k/XT3.0/XT_334.wav
|
594 |
+
./dataset/44k/XT3.0/XT_615.wav
|
595 |
+
./dataset/44k/XT3.0/XT_88.wav
|
596 |
+
./dataset/44k/XT3.0/XT_693.wav
|
597 |
+
./dataset/44k/XT3.0/XT_306.wav
|
598 |
+
./dataset/44k/XT3.0/XT_275.wav
|
599 |
+
./dataset/44k/XT3.0/XT_37.wav
|
600 |
+
./dataset/44k/XT3.0/XT_878.wav
|
601 |
+
./dataset/44k/XT3.0/XT_349.wav
|
602 |
+
./dataset/44k/XT3.0/XT_196.wav
|
603 |
+
./dataset/44k/XT3.0/XT_380.wav
|
604 |
+
./dataset/44k/XT3.0/XT_921.wav
|
605 |
+
./dataset/44k/XT3.0/XT_684.wav
|
606 |
+
./dataset/44k/XT3.0/XT_303.wav
|
607 |
+
./dataset/44k/XT3.0/XT_646.wav
|
608 |
+
./dataset/44k/XT3.0/XT_336.wav
|
609 |
+
./dataset/44k/XT3.0/XT_967.wav
|
610 |
+
./dataset/44k/XT3.0/XT_929.wav
|
611 |
+
./dataset/44k/XT3.0/XT_382.wav
|
612 |
+
./dataset/44k/XT3.0/XT_427.wav
|
613 |
+
./dataset/44k/XT3.0/XT_480.wav
|
614 |
+
./dataset/44k/XT3.0/XT_686.wav
|
615 |
+
./dataset/44k/XT3.0/XT_719.wav
|
616 |
+
./dataset/44k/XT3.0/XT_805.wav
|
617 |
+
./dataset/44k/XT3.0/XT_74.wav
|
618 |
+
./dataset/44k/XT3.0/XT_273.wav
|
619 |
+
./dataset/44k/XT3.0/XT_378.wav
|
620 |
+
./dataset/44k/XT3.0/XT_899.wav
|
621 |
+
./dataset/44k/XT3.0/XT_717.wav
|
622 |
+
./dataset/44k/XT3.0/XT_829.wav
|
623 |
+
./dataset/44k/XT3.0/XT_905.wav
|
624 |
+
./dataset/44k/XT3.0/XT_477.wav
|
625 |
+
./dataset/44k/XT3.0/XT_488.wav
|
626 |
+
./dataset/44k/XT3.0/XT_149.wav
|
627 |
+
./dataset/44k/XT3.0/XT_944.wav
|
628 |
+
./dataset/44k/XT3.0/XT_864.wav
|
629 |
+
./dataset/44k/XT3.0/XT_400.wav
|
630 |
+
./dataset/44k/XT3.0/XT_402.wav
|
631 |
+
./dataset/44k/XT3.0/XT_0.wav
|
632 |
+
./dataset/44k/XT3.0/XT_390.wav
|
633 |
+
./dataset/44k/XT3.0/XT_348.wav
|
634 |
+
./dataset/44k/XT3.0/XT_638.wav
|
635 |
+
./dataset/44k/XT3.0/XT_245.wav
|
636 |
+
./dataset/44k/XT3.0/XT_593.wav
|
637 |
+
./dataset/44k/XT3.0/XT_550.wav
|
638 |
+
./dataset/44k/XT3.0/XT_435.wav
|
639 |
+
./dataset/44k/XT3.0/XT_542.wav
|
640 |
+
./dataset/44k/XT3.0/XT_423.wav
|
641 |
+
./dataset/44k/XT3.0/XT_649.wav
|
642 |
+
./dataset/44k/XT3.0/XT_38.wav
|
643 |
+
./dataset/44k/XT3.0/XT_533.wav
|
644 |
+
./dataset/44k/XT3.0/XT_504.wav
|
645 |
+
./dataset/44k/XT3.0/XT_530.wav
|
646 |
+
./dataset/44k/XT3.0/XT_20.wav
|
647 |
+
./dataset/44k/XT3.0/XT_925.wav
|
648 |
+
./dataset/44k/XT3.0/XT_39.wav
|
649 |
+
./dataset/44k/XT3.0/XT_915.wav
|
650 |
+
./dataset/44k/XT3.0/XT_316.wav
|
651 |
+
./dataset/44k/XT3.0/XT_214.wav
|
652 |
+
./dataset/44k/XT3.0/XT_178.wav
|
653 |
+
./dataset/44k/XT3.0/XT_221.wav
|
654 |
+
./dataset/44k/XT3.0/XT_501.wav
|
655 |
+
./dataset/44k/XT3.0/XT_932.wav
|
656 |
+
./dataset/44k/XT3.0/XT_513.wav
|
657 |
+
./dataset/44k/XT3.0/XT_250.wav
|
658 |
+
./dataset/44k/XT3.0/XT_619.wav
|
659 |
+
./dataset/44k/XT3.0/XT_580.wav
|
660 |
+
./dataset/44k/XT3.0/XT_516.wav
|
661 |
+
./dataset/44k/XT3.0/XT_65.wav
|
662 |
+
./dataset/44k/XT3.0/XT_529.wav
|
663 |
+
./dataset/44k/XT3.0/XT_785.wav
|
664 |
+
./dataset/44k/XT3.0/XT_579.wav
|
665 |
+
./dataset/44k/XT3.0/XT_866.wav
|
666 |
+
./dataset/44k/XT3.0/XT_481.wav
|
667 |
+
./dataset/44k/XT3.0/XT_281.wav
|
668 |
+
./dataset/44k/XT3.0/XT_635.wav
|
669 |
+
./dataset/44k/XT3.0/XT_716.wav
|
670 |
+
./dataset/44k/XT3.0/XT_135.wav
|
671 |
+
./dataset/44k/XT3.0/XT_15.wav
|
672 |
+
./dataset/44k/XT3.0/XT_571.wav
|
673 |
+
./dataset/44k/XT3.0/XT_9.wav
|
674 |
+
./dataset/44k/XT3.0/XT_924.wav
|
675 |
+
./dataset/44k/XT3.0/XT_510.wav
|
676 |
+
./dataset/44k/XT3.0/XT_729.wav
|
677 |
+
./dataset/44k/XT3.0/XT_261.wav
|
678 |
+
./dataset/44k/XT3.0/XT_5.wav
|
679 |
+
./dataset/44k/XT3.0/XT_629.wav
|
680 |
+
./dataset/44k/XT3.0/XT_148.wav
|
681 |
+
./dataset/44k/XT3.0/XT_120.wav
|
682 |
+
./dataset/44k/XT3.0/XT_809.wav
|
683 |
+
./dataset/44k/XT3.0/XT_538.wav
|
684 |
+
./dataset/44k/XT3.0/XT_949.wav
|
685 |
+
./dataset/44k/XT3.0/XT_887.wav
|
686 |
+
./dataset/44k/XT3.0/XT_441.wav
|
687 |
+
./dataset/44k/XT3.0/XT_861.wav
|
688 |
+
./dataset/44k/XT3.0/XT_152.wav
|
689 |
+
./dataset/44k/XT3.0/XT_969.wav
|
690 |
+
./dataset/44k/XT3.0/XT_49.wav
|
691 |
+
./dataset/44k/XT3.0/XT_606.wav
|
692 |
+
./dataset/44k/XT3.0/XT_272.wav
|
693 |
+
./dataset/44k/XT3.0/XT_355.wav
|
694 |
+
./dataset/44k/XT3.0/XT_908.wav
|
695 |
+
./dataset/44k/XT3.0/XT_847.wav
|
696 |
+
./dataset/44k/XT3.0/XT_238.wav
|
697 |
+
./dataset/44k/XT3.0/XT_520.wav
|
698 |
+
./dataset/44k/XT3.0/XT_934.wav
|
699 |
+
./dataset/44k/XT3.0/XT_366.wav
|
700 |
+
./dataset/44k/XT3.0/XT_748.wav
|
701 |
+
./dataset/44k/XT3.0/XT_442.wav
|
702 |
+
./dataset/44k/XT3.0/XT_465.wav
|
703 |
+
./dataset/44k/XT3.0/XT_372.wav
|
704 |
+
./dataset/44k/XT3.0/XT_701.wav
|
705 |
+
./dataset/44k/XT3.0/XT_50.wav
|
706 |
+
./dataset/44k/XT3.0/XT_134.wav
|
707 |
+
./dataset/44k/XT3.0/XT_342.wav
|
708 |
+
./dataset/44k/XT3.0/XT_989.wav
|
709 |
+
./dataset/44k/XT3.0/XT_21.wav
|
710 |
+
./dataset/44k/XT3.0/XT_584.wav
|
711 |
+
./dataset/44k/XT3.0/XT_145.wav
|
712 |
+
./dataset/44k/XT3.0/XT_345.wav
|
713 |
+
./dataset/44k/XT3.0/XT_583.wav
|
714 |
+
./dataset/44k/XT3.0/XT_844.wav
|
715 |
+
./dataset/44k/XT3.0/XT_730.wav
|
716 |
+
./dataset/44k/XT3.0/XT_211.wav
|
717 |
+
./dataset/44k/XT3.0/XT_508.wav
|
718 |
+
./dataset/44k/XT3.0/XT_895.wav
|
719 |
+
./dataset/44k/XT3.0/XT_66.wav
|
720 |
+
./dataset/44k/XT3.0/XT_674.wav
|
721 |
+
./dataset/44k/XT3.0/XT_764.wav
|
722 |
+
./dataset/44k/XT3.0/XT_600.wav
|
723 |
+
./dataset/44k/XT3.0/XT_733.wav
|
724 |
+
./dataset/44k/XT3.0/XT_26.wav
|
725 |
+
./dataset/44k/XT3.0/XT_77.wav
|
726 |
+
./dataset/44k/XT3.0/XT_972.wav
|
727 |
+
./dataset/44k/XT3.0/XT_158.wav
|
728 |
+
./dataset/44k/XT3.0/XT_837.wav
|
729 |
+
./dataset/44k/XT3.0/XT_461.wav
|
730 |
+
./dataset/44k/XT3.0/XT_974.wav
|
731 |
+
./dataset/44k/XT3.0/XT_563.wav
|
732 |
+
./dataset/44k/XT3.0/XT_616.wav
|
733 |
+
./dataset/44k/XT3.0/XT_241.wav
|
734 |
+
./dataset/44k/XT3.0/XT_326.wav
|
735 |
+
./dataset/44k/XT3.0/XT_361.wav
|
736 |
+
./dataset/44k/XT3.0/XT_75.wav
|
737 |
+
./dataset/44k/XT3.0/XT_536.wav
|
738 |
+
./dataset/44k/XT3.0/XT_656.wav
|
739 |
+
./dataset/44k/XT3.0/XT_955.wav
|
740 |
+
./dataset/44k/XT3.0/XT_447.wav
|
741 |
+
./dataset/44k/XT3.0/XT_626.wav
|
742 |
+
./dataset/44k/XT3.0/XT_633.wav
|
743 |
+
./dataset/44k/XT3.0/XT_979.wav
|
744 |
+
./dataset/44k/XT3.0/XT_595.wav
|
745 |
+
./dataset/44k/XT3.0/XT_865.wav
|
746 |
+
./dataset/44k/XT3.0/XT_965.wav
|
747 |
+
./dataset/44k/XT3.0/XT_762.wav
|
748 |
+
./dataset/44k/XT3.0/XT_982.wav
|
749 |
+
./dataset/44k/XT3.0/XT_784.wav
|
750 |
+
./dataset/44k/XT3.0/XT_552.wav
|
751 |
+
./dataset/44k/XT3.0/XT_557.wav
|
752 |
+
./dataset/44k/XT3.0/XT_587.wav
|
753 |
+
./dataset/44k/XT3.0/XT_109.wav
|
754 |
+
./dataset/44k/XT3.0/XT_6.wav
|
755 |
+
./dataset/44k/XT3.0/XT_627.wav
|
756 |
+
./dataset/44k/XT3.0/XT_146.wav
|
757 |
+
./dataset/44k/XT3.0/XT_871.wav
|
758 |
+
./dataset/44k/XT3.0/XT_422.wav
|
759 |
+
./dataset/44k/XT3.0/XT_260.wav
|
760 |
+
./dataset/44k/XT3.0/XT_789.wav
|
761 |
+
./dataset/44k/XT3.0/XT_271.wav
|
762 |
+
./dataset/44k/XT3.0/XT_498.wav
|
763 |
+
./dataset/44k/XT3.0/XT_962.wav
|
764 |
+
./dataset/44k/XT3.0/XT_918.wav
|
765 |
+
./dataset/44k/XT3.0/XT_687.wav
|
766 |
+
./dataset/44k/XT3.0/XT_696.wav
|
767 |
+
./dataset/44k/XT3.0/XT_80.wav
|
768 |
+
./dataset/44k/XT3.0/XT_248.wav
|
769 |
+
./dataset/44k/XT3.0/XT_132.wav
|
770 |
+
./dataset/44k/XT3.0/XT_119.wav
|
771 |
+
./dataset/44k/XT3.0/XT_142.wav
|
772 |
+
./dataset/44k/XT3.0/XT_667.wav
|
773 |
+
./dataset/44k/XT3.0/XT_133.wav
|
774 |
+
./dataset/44k/XT3.0/XT_403.wav
|
775 |
+
./dataset/44k/XT3.0/XT_396.wav
|
776 |
+
./dataset/44k/XT3.0/XT_190.wav
|
777 |
+
./dataset/44k/XT3.0/XT_978.wav
|
778 |
+
./dataset/44k/XT3.0/XT_47.wav
|
779 |
+
./dataset/44k/XT3.0/XT_902.wav
|
780 |
+
./dataset/44k/XT3.0/XT_452.wav
|
781 |
+
./dataset/44k/XT3.0/XT_664.wav
|
782 |
+
./dataset/44k/XT3.0/XT_199.wav
|
783 |
+
./dataset/44k/XT3.0/XT_814.wav
|
784 |
+
./dataset/44k/XT3.0/XT_370.wav
|
785 |
+
./dataset/44k/XT3.0/XT_914.wav
|
786 |
+
./dataset/44k/XT3.0/XT_567.wav
|
787 |
+
./dataset/44k/XT3.0/XT_246.wav
|
788 |
+
./dataset/44k/XT3.0/XT_780.wav
|
789 |
+
./dataset/44k/XT3.0/XT_286.wav
|
790 |
+
./dataset/44k/XT3.0/XT_868.wav
|
791 |
+
./dataset/44k/XT3.0/XT_60.wav
|
792 |
+
./dataset/44k/XT3.0/XT_548.wav
|
793 |
+
./dataset/44k/XT3.0/XT_330.wav
|
794 |
+
./dataset/44k/XT3.0/XT_263.wav
|
795 |
+
./dataset/44k/XT3.0/XT_468.wav
|
796 |
+
./dataset/44k/XT3.0/XT_16.wav
|
797 |
+
./dataset/44k/XT3.0/XT_750.wav
|
798 |
+
./dataset/44k/XT3.0/XT_314.wav
|
799 |
+
./dataset/44k/XT3.0/XT_368.wav
|
800 |
+
./dataset/44k/XT3.0/XT_662.wav
|
801 |
+
./dataset/44k/XT3.0/XT_251.wav
|
802 |
+
./dataset/44k/XT3.0/XT_298.wav
|
803 |
+
./dataset/44k/XT3.0/XT_315.wav
|
804 |
+
./dataset/44k/XT3.0/XT_543.wav
|
805 |
+
./dataset/44k/XT3.0/XT_576.wav
|
806 |
+
./dataset/44k/XT3.0/XT_467.wav
|
807 |
+
./dataset/44k/XT3.0/XT_215.wav
|
808 |
+
./dataset/44k/XT3.0/XT_535.wav
|
809 |
+
./dataset/44k/XT3.0/XT_28.wav
|
810 |
+
./dataset/44k/XT3.0/XT_947.wav
|
811 |
+
./dataset/44k/XT3.0/XT_913.wav
|
812 |
+
./dataset/44k/XT3.0/XT_100.wav
|
813 |
+
./dataset/44k/XT3.0/XT_486.wav
|
814 |
+
./dataset/44k/XT3.0/XT_889.wav
|
815 |
+
./dataset/44k/XT3.0/XT_41.wav
|
816 |
+
./dataset/44k/XT3.0/XT_52.wav
|
817 |
+
./dataset/44k/XT3.0/XT_97.wav
|
818 |
+
./dataset/44k/XT3.0/XT_61.wav
|
819 |
+
./dataset/44k/XT3.0/XT_406.wav
|
820 |
+
./dataset/44k/XT3.0/XT_994.wav
|
821 |
+
./dataset/44k/XT3.0/XT_91.wav
|
822 |
+
./dataset/44k/XT3.0/XT_841.wav
|
823 |
+
./dataset/44k/XT3.0/XT_859.wav
|
824 |
+
./dataset/44k/XT3.0/XT_653.wav
|
825 |
+
./dataset/44k/XT3.0/XT_453.wav
|
826 |
+
./dataset/44k/XT3.0/XT_806.wav
|
827 |
+
./dataset/44k/XT3.0/XT_937.wav
|
828 |
+
./dataset/44k/XT3.0/XT_356.wav
|
829 |
+
./dataset/44k/XT3.0/XT_353.wav
|
830 |
+
./dataset/44k/XT3.0/XT_73.wav
|
831 |
+
./dataset/44k/XT3.0/XT_888.wav
|
832 |
+
./dataset/44k/XT3.0/XT_193.wav
|
833 |
+
./dataset/44k/XT3.0/XT_611.wav
|
834 |
+
./dataset/44k/XT3.0/XT_893.wav
|
835 |
+
./dataset/44k/XT3.0/XT_27.wav
|
836 |
+
./dataset/44k/XT3.0/XT_690.wav
|
837 |
+
./dataset/44k/XT3.0/XT_852.wav
|
838 |
+
./dataset/44k/XT3.0/XT_228.wav
|
839 |
+
./dataset/44k/XT3.0/XT_639.wav
|
840 |
+
./dataset/44k/XT3.0/XT_975.wav
|
841 |
+
./dataset/44k/XT3.0/XT_564.wav
|
842 |
+
./dataset/44k/XT3.0/XT_673.wav
|
843 |
+
./dataset/44k/XT3.0/XT_700.wav
|
844 |
+
./dataset/44k/XT3.0/XT_487.wav
|
845 |
+
./dataset/44k/XT3.0/XT_321.wav
|
846 |
+
./dataset/44k/XT3.0/XT_709.wav
|
847 |
+
./dataset/44k/XT3.0/XT_776.wav
|
848 |
+
./dataset/44k/XT3.0/XT_185.wav
|
849 |
+
./dataset/44k/XT3.0/XT_796.wav
|
850 |
+
./dataset/44k/XT3.0/XT_327.wav
|
851 |
+
./dataset/44k/XT3.0/XT_781.wav
|
852 |
+
./dataset/44k/XT3.0/XT_130.wav
|
853 |
+
./dataset/44k/XT3.0/XT_18.wav
|
854 |
+
./dataset/44k/XT3.0/XT_407.wav
|
855 |
+
./dataset/44k/XT3.0/XT_851.wav
|
856 |
+
./dataset/44k/XT3.0/XT_857.wav
|
857 |
+
./dataset/44k/XT3.0/XT_522.wav
|
858 |
+
./dataset/44k/XT3.0/XT_328.wav
|
859 |
+
./dataset/44k/XT3.0/XT_415.wav
|
860 |
+
./dataset/44k/XT3.0/XT_226.wav
|
861 |
+
./dataset/44k/XT3.0/XT_833.wav
|
862 |
+
./dataset/44k/XT3.0/XT_831.wav
|
863 |
+
./dataset/44k/XT3.0/XT_920.wav
|
864 |
+
./dataset/44k/XT3.0/XT_267.wav
|
865 |
+
./dataset/44k/XT3.0/XT_312.wav
|
866 |
+
./dataset/44k/XT3.0/XT_365.wav
|
867 |
+
./dataset/44k/XT3.0/XT_301.wav
|
868 |
+
./dataset/44k/XT3.0/XT_341.wav
|
869 |
+
./dataset/44k/XT3.0/XT_845.wav
|
870 |
+
./dataset/44k/XT3.0/XT_141.wav
|
871 |
+
./dataset/44k/XT3.0/XT_322.wav
|
872 |
+
./dataset/44k/XT3.0/XT_820.wav
|
873 |
+
./dataset/44k/XT3.0/XT_231.wav
|
874 |
+
./dataset/44k/XT3.0/XT_182.wav
|
875 |
+
./dataset/44k/XT3.0/XT_257.wav
|
876 |
+
./dataset/44k/XT3.0/XT_364.wav
|
877 |
+
./dataset/44k/XT3.0/XT_909.wav
|
878 |
+
./dataset/44k/XT3.0/XT_409.wav
|
879 |
+
./dataset/44k/XT3.0/XT_554.wav
|
880 |
+
./dataset/44k/XT3.0/XT_654.wav
|
881 |
+
./dataset/44k/XT3.0/XT_147.wav
|
882 |
+
./dataset/44k/XT3.0/XT_143.wav
|
883 |
+
./dataset/44k/XT3.0/XT_253.wav
|
884 |
+
./dataset/44k/XT3.0/XT_573.wav
|
885 |
+
./dataset/44k/XT3.0/XT_464.wav
|
886 |
+
./dataset/44k/XT3.0/XT_916.wav
|
887 |
+
./dataset/44k/XT3.0/XT_137.wav
|
888 |
+
./dataset/44k/XT3.0/XT_482.wav
|
889 |
+
./dataset/44k/XT3.0/XT_339.wav
|
890 |
+
./dataset/44k/XT3.0/XT_506.wav
|
891 |
+
./dataset/44k/XT3.0/XT_392.wav
|
892 |
+
./dataset/44k/XT3.0/XT_720.wav
|
893 |
+
./dataset/44k/XT3.0/XT_645.wav
|
894 |
+
./dataset/44k/XT3.0/XT_213.wav
|
895 |
+
./dataset/44k/XT3.0/XT_898.wav
|
896 |
+
./dataset/44k/XT3.0/XT_183.wav
|
897 |
+
./dataset/44k/XT3.0/XT_778.wav
|
898 |
+
./dataset/44k/XT3.0/XT_471.wav
|
899 |
+
./dataset/44k/XT3.0/XT_463.wav
|
900 |
+
./dataset/44k/XT3.0/XT_799.wav
|
901 |
+
./dataset/44k/XT3.0/XT_110.wav
|
902 |
+
./dataset/44k/XT3.0/XT_411.wav
|
903 |
+
./dataset/44k/XT3.0/XT_398.wav
|
904 |
+
./dataset/44k/XT3.0/XT_742.wav
|
905 |
+
./dataset/44k/XT3.0/XT_7.wav
|
906 |
+
./dataset/44k/XT3.0/XT_22.wav
|
907 |
+
./dataset/44k/XT3.0/XT_187.wav
|
908 |
+
./dataset/44k/XT3.0/XT_123.wav
|
909 |
+
./dataset/44k/XT3.0/XT_848.wav
|
910 |
+
./dataset/44k/XT3.0/XT_413.wav
|
911 |
+
./dataset/44k/XT3.0/XT_490.wav
|
912 |
+
./dataset/44k/XT3.0/XT_644.wav
|
913 |
+
./dataset/44k/XT3.0/XT_808.wav
|
914 |
+
./dataset/44k/XT3.0/XT_125.wav
|
915 |
+
./dataset/44k/XT3.0/XT_572.wav
|
916 |
+
./dataset/44k/XT3.0/XT_623.wav
|
917 |
+
./dataset/44k/XT3.0/XT_384.wav
|
918 |
+
./dataset/44k/XT3.0/XT_705.wav
|
919 |
+
./dataset/44k/XT3.0/XT_836.wav
|
920 |
+
./dataset/44k/XT3.0/XT_270.wav
|
921 |
+
./dataset/44k/XT3.0/XT_671.wav
|
922 |
+
./dataset/44k/XT3.0/XT_168.wav
|
923 |
+
./dataset/44k/XT3.0/XT_641.wav
|
924 |
+
./dataset/44k/XT3.0/XT_105.wav
|
925 |
+
./dataset/44k/XT3.0/XT_605.wav
|
926 |
+
./dataset/44k/XT3.0/XT_53.wav
|
927 |
+
./dataset/44k/XT3.0/XT_376.wav
|
928 |
+
./dataset/44k/XT3.0/XT_863.wav
|
929 |
+
./dataset/44k/XT3.0/XT_418.wav
|
930 |
+
./dataset/44k/XT3.0/XT_239.wav
|
931 |
+
./dataset/44k/XT3.0/XT_990.wav
|
932 |
+
./dataset/44k/XT3.0/XT_526.wav
|
933 |
+
./dataset/44k/XT3.0/XT_597.wav
|
934 |
+
./dataset/44k/XT3.0/XT_900.wav
|
935 |
+
./dataset/44k/XT3.0/XT_64.wav
|
936 |
+
./dataset/44k/XT3.0/XT_86.wav
|
937 |
+
./dataset/44k/XT3.0/XT_325.wav
|
938 |
+
./dataset/44k/XT3.0/XT_910.wav
|
939 |
+
./dataset/44k/XT3.0/XT_617.wav
|
940 |
+
./dataset/44k/XT3.0/XT_803.wav
|
941 |
+
./dataset/44k/XT3.0/XT_630.wav
|
942 |
+
./dataset/44k/XT3.0/XT_500.wav
|
943 |
+
./dataset/44k/XT3.0/XT_558.wav
|
944 |
+
./dataset/44k/XT3.0/XT_475.wav
|
945 |
+
./dataset/44k/XT3.0/XT_31.wav
|
946 |
+
./dataset/44k/XT3.0/XT_479.wav
|
947 |
+
./dataset/44k/XT3.0/XT_82.wav
|
948 |
+
./dataset/44k/XT3.0/XT_942.wav
|
949 |
+
./dataset/44k/XT3.0/XT_111.wav
|
950 |
+
./dataset/44k/XT3.0/XT_699.wav
|
951 |
+
./dataset/44k/XT3.0/XT_903.wav
|
952 |
+
./dataset/44k/XT3.0/XT_296.wav
|
953 |
+
./dataset/44k/XT3.0/XT_610.wav
|
954 |
+
./dataset/44k/XT3.0/XT_694.wav
|
955 |
+
./dataset/44k/XT3.0/XT_329.wav
|
956 |
+
./dataset/44k/XT3.0/XT_983.wav
|
957 |
+
./dataset/44k/XT3.0/XT_603.wav
|
958 |
+
./dataset/44k/XT3.0/XT_23.wav
|
959 |
+
./dataset/44k/XT3.0/XT_456.wav
|
960 |
+
./dataset/44k/XT3.0/XT_216.wav
|
961 |
+
./dataset/44k/XT3.0/XT_313.wav
|
962 |
+
./dataset/44k/XT3.0/XT_224.wav
|
963 |
+
./dataset/44k/XT3.0/XT_810.wav
|
964 |
+
./dataset/44k/XT3.0/XT_894.wav
|
965 |
+
./dataset/44k/XT3.0/XT_755.wav
|
966 |
+
./dataset/44k/XT3.0/XT_180.wav
|
967 |
+
./dataset/44k/XT3.0/XT_517.wav
|
968 |
+
./dataset/44k/XT3.0/XT_414.wav
|
969 |
+
./dataset/44k/XT3.0/XT_954.wav
|
970 |
+
./dataset/44k/XT3.0/XT_713.wav
|
971 |
+
./dataset/44k/XT3.0/XT_926.wav
|
972 |
+
./dataset/44k/XT3.0/XT_375.wav
|
973 |
+
./dataset/44k/XT3.0/XT_862.wav
|
974 |
+
./dataset/44k/XT3.0/XT_492.wav
|
975 |
+
./dataset/44k/XT3.0/XT_233.wav
|
976 |
+
./dataset/44k/XT3.0/XT_650.wav
|
977 |
+
./dataset/44k/XT3.0/XT_892.wav
|
978 |
+
./dataset/44k/XT3.0/XT_770.wav
|
979 |
+
./dataset/44k/XT3.0/XT_737.wav
|
980 |
+
./dataset/44k/XT3.0/XT_811.wav
|
981 |
+
./dataset/44k/XT3.0/XT_752.wav
|
982 |
+
./dataset/44k/XT3.0/XT_235.wav
|
983 |
+
./dataset/44k/XT3.0/XT_210.wav
|
984 |
+
./dataset/44k/XT3.0/XT_229.wav
|
985 |
+
./dataset/44k/XT3.0/XT_939.wav
|
986 |
+
./dataset/44k/XT3.0/XT_98.wav
|
987 |
+
./dataset/44k/XT3.0/XT_678.wav
|
988 |
+
./dataset/44k/XT3.0/XT_278.wav
|
989 |
+
./dataset/44k/XT3.0/XT_683.wav
|
filelists/val.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
./dataset/44k/XT3.0/XT_928.wav
|
2 |
+
./dataset/44k/XT3.0/XT_783.wav
|
flask_api.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import io
|
2 |
+
import logging
|
3 |
+
|
4 |
+
import soundfile
|
5 |
+
import torch
|
6 |
+
import torchaudio
|
7 |
+
from flask import Flask, request, send_file
|
8 |
+
from flask_cors import CORS
|
9 |
+
|
10 |
+
from inference.infer_tool import Svc, RealTimeVC
|
11 |
+
|
12 |
+
app = Flask(__name__)
|
13 |
+
|
14 |
+
CORS(app)
|
15 |
+
|
16 |
+
logging.getLogger('numba').setLevel(logging.WARNING)
|
17 |
+
|
18 |
+
|
19 |
+
@app.route("/voiceChangeModel", methods=["POST"])
|
20 |
+
def voice_change_model():
|
21 |
+
request_form = request.form
|
22 |
+
wave_file = request.files.get("sample", None)
|
23 |
+
# 变调信息
|
24 |
+
f_pitch_change = float(request_form.get("fPitchChange", 0))
|
25 |
+
# DAW所需的采样率
|
26 |
+
daw_sample = int(float(request_form.get("sampleRate", 0)))
|
27 |
+
speaker_id = int(float(request_form.get("sSpeakId", 0)))
|
28 |
+
# http获得wav文件并转换
|
29 |
+
input_wav_path = io.BytesIO(wave_file.read())
|
30 |
+
|
31 |
+
# 模型推理
|
32 |
+
if raw_infer:
|
33 |
+
# out_audio, out_sr = svc_model.infer(speaker_id, f_pitch_change, input_wav_path)
|
34 |
+
out_audio, out_sr = svc_model.infer(speaker_id, f_pitch_change, input_wav_path, cluster_infer_ratio=0,
|
35 |
+
auto_predict_f0=False, noice_scale=0.4, f0_filter=False)
|
36 |
+
tar_audio = torchaudio.functional.resample(out_audio, svc_model.target_sample, daw_sample)
|
37 |
+
else:
|
38 |
+
out_audio = svc.process(svc_model, speaker_id, f_pitch_change, input_wav_path, cluster_infer_ratio=0,
|
39 |
+
auto_predict_f0=False, noice_scale=0.4, f0_filter=False)
|
40 |
+
tar_audio = torchaudio.functional.resample(torch.from_numpy(out_audio), svc_model.target_sample, daw_sample)
|
41 |
+
# 返回音频
|
42 |
+
out_wav_path = io.BytesIO()
|
43 |
+
soundfile.write(out_wav_path, tar_audio.cpu().numpy(), daw_sample, format="wav")
|
44 |
+
out_wav_path.seek(0)
|
45 |
+
return send_file(out_wav_path, download_name="temp.wav", as_attachment=True)
|
46 |
+
|
47 |
+
|
48 |
+
if __name__ == '__main__':
|
49 |
+
# 启用则为直接切片合成,False为交叉淡化方式
|
50 |
+
# vst插件调整0.3-0.5s切片时间可以降低延迟,直接切片方法会有连接处爆音、交叉淡化会有轻微重叠声音
|
51 |
+
# 自行选择能接受的方法,或将vst最大切片时间调整为1s,此处设为Ture,延迟大音质稳定一些
|
52 |
+
raw_infer = True
|
53 |
+
# 每个模型和config是唯一对应的
|
54 |
+
model_name = "logs/32k/G_174000-Copy1.pth"
|
55 |
+
config_name = "configs/config.json"
|
56 |
+
cluster_model_path = "logs/44k/kmeans_10000.pt"
|
57 |
+
svc_model = Svc(model_name, config_name, cluster_model_path=cluster_model_path)
|
58 |
+
svc = RealTimeVC()
|
59 |
+
# 此处与vst插件对应,不建议更改
|
60 |
+
app.run(port=6842, host="0.0.0.0", debug=False, threaded=False)
|
flask_api_full_song.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import io
|
2 |
+
import numpy as np
|
3 |
+
import soundfile
|
4 |
+
from flask import Flask, request, send_file
|
5 |
+
|
6 |
+
from inference import infer_tool
|
7 |
+
from inference import slicer
|
8 |
+
|
9 |
+
app = Flask(__name__)
|
10 |
+
|
11 |
+
|
12 |
+
@app.route("/wav2wav", methods=["POST"])
|
13 |
+
def wav2wav():
|
14 |
+
request_form = request.form
|
15 |
+
audio_path = request_form.get("audio_path", None) # wav文件地址
|
16 |
+
tran = int(float(request_form.get("tran", 0))) # 音调
|
17 |
+
spk = request_form.get("spk", 0) # 说话人(id或者name都可以,具体看你的config)
|
18 |
+
wav_format = request_form.get("wav_format", 'wav') # 范围文件格式
|
19 |
+
infer_tool.format_wav(audio_path)
|
20 |
+
chunks = slicer.cut(audio_path, db_thresh=-40)
|
21 |
+
audio_data, audio_sr = slicer.chunks2audio(audio_path, chunks)
|
22 |
+
|
23 |
+
audio = []
|
24 |
+
for (slice_tag, data) in audio_data:
|
25 |
+
print(f'#=====segment start, {round(len(data) / audio_sr, 3)}s======')
|
26 |
+
|
27 |
+
length = int(np.ceil(len(data) / audio_sr * svc_model.target_sample))
|
28 |
+
if slice_tag:
|
29 |
+
print('jump empty segment')
|
30 |
+
_audio = np.zeros(length)
|
31 |
+
else:
|
32 |
+
# padd
|
33 |
+
pad_len = int(audio_sr * 0.5)
|
34 |
+
data = np.concatenate([np.zeros([pad_len]), data, np.zeros([pad_len])])
|
35 |
+
raw_path = io.BytesIO()
|
36 |
+
soundfile.write(raw_path, data, audio_sr, format="wav")
|
37 |
+
raw_path.seek(0)
|
38 |
+
out_audio, out_sr = svc_model.infer(spk, tran, raw_path)
|
39 |
+
svc_model.clear_empty()
|
40 |
+
_audio = out_audio.cpu().numpy()
|
41 |
+
pad_len = int(svc_model.target_sample * 0.5)
|
42 |
+
_audio = _audio[pad_len:-pad_len]
|
43 |
+
|
44 |
+
audio.extend(list(infer_tool.pad_array(_audio, length)))
|
45 |
+
out_wav_path = io.BytesIO()
|
46 |
+
soundfile.write(out_wav_path, audio, svc_model.target_sample, format=wav_format)
|
47 |
+
out_wav_path.seek(0)
|
48 |
+
return send_file(out_wav_path, download_name=f"temp.{wav_format}", as_attachment=True)
|
49 |
+
|
50 |
+
|
51 |
+
if __name__ == '__main__':
|
52 |
+
model_name = "logs/44k/G_60000.pth" # 模型地址
|
53 |
+
config_name = "configs/config.json" # config地址
|
54 |
+
svc_model = infer_tool.Svc(model_name, config_name)
|
55 |
+
app.run(port=1145, host="0.0.0.0", debug=False, threaded=False)
|
hubert/__init__.py
ADDED
File without changes
|
hubert/__pycache__/__init__.cpython-38.pyc
ADDED
Binary file (124 Bytes). View file
|
|
hubert/__pycache__/hubert_model.cpython-38.pyc
ADDED
Binary file (7.57 kB). View file
|
|
hubert/checkpoint_best_legacy_500.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:60d936ec5a566776fc392e69ad8b630d14eb588111233fe313436e200a7b187b
|
3 |
+
size 1330114945
|
hubert/hubert_model.py
ADDED
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
import random
|
3 |
+
from typing import Optional, Tuple
|
4 |
+
|
5 |
+
import torch
|
6 |
+
import torch.nn as nn
|
7 |
+
import torch.nn.functional as t_func
|
8 |
+
from torch.nn.modules.utils import consume_prefix_in_state_dict_if_present
|
9 |
+
|
10 |
+
|
11 |
+
class Hubert(nn.Module):
|
12 |
+
def __init__(self, num_label_embeddings: int = 100, mask: bool = True):
|
13 |
+
super().__init__()
|
14 |
+
self._mask = mask
|
15 |
+
self.feature_extractor = FeatureExtractor()
|
16 |
+
self.feature_projection = FeatureProjection()
|
17 |
+
self.positional_embedding = PositionalConvEmbedding()
|
18 |
+
self.norm = nn.LayerNorm(768)
|
19 |
+
self.dropout = nn.Dropout(0.1)
|
20 |
+
self.encoder = TransformerEncoder(
|
21 |
+
nn.TransformerEncoderLayer(
|
22 |
+
768, 12, 3072, activation="gelu", batch_first=True
|
23 |
+
),
|
24 |
+
12,
|
25 |
+
)
|
26 |
+
self.proj = nn.Linear(768, 256)
|
27 |
+
|
28 |
+
self.masked_spec_embed = nn.Parameter(torch.FloatTensor(768).uniform_())
|
29 |
+
self.label_embedding = nn.Embedding(num_label_embeddings, 256)
|
30 |
+
|
31 |
+
def mask(self, x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
|
32 |
+
mask = None
|
33 |
+
if self.training and self._mask:
|
34 |
+
mask = _compute_mask((x.size(0), x.size(1)), 0.8, 10, x.device, 2)
|
35 |
+
x[mask] = self.masked_spec_embed.to(x.dtype)
|
36 |
+
return x, mask
|
37 |
+
|
38 |
+
def encode(
|
39 |
+
self, x: torch.Tensor, layer: Optional[int] = None
|
40 |
+
) -> Tuple[torch.Tensor, torch.Tensor]:
|
41 |
+
x = self.feature_extractor(x)
|
42 |
+
x = self.feature_projection(x.transpose(1, 2))
|
43 |
+
x, mask = self.mask(x)
|
44 |
+
x = x + self.positional_embedding(x)
|
45 |
+
x = self.dropout(self.norm(x))
|
46 |
+
x = self.encoder(x, output_layer=layer)
|
47 |
+
return x, mask
|
48 |
+
|
49 |
+
def logits(self, x: torch.Tensor) -> torch.Tensor:
|
50 |
+
logits = torch.cosine_similarity(
|
51 |
+
x.unsqueeze(2),
|
52 |
+
self.label_embedding.weight.unsqueeze(0).unsqueeze(0),
|
53 |
+
dim=-1,
|
54 |
+
)
|
55 |
+
return logits / 0.1
|
56 |
+
|
57 |
+
def forward(self, x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
|
58 |
+
x, mask = self.encode(x)
|
59 |
+
x = self.proj(x)
|
60 |
+
logits = self.logits(x)
|
61 |
+
return logits, mask
|
62 |
+
|
63 |
+
|
64 |
+
class HubertSoft(Hubert):
|
65 |
+
def __init__(self):
|
66 |
+
super().__init__()
|
67 |
+
|
68 |
+
@torch.inference_mode()
|
69 |
+
def units(self, wav: torch.Tensor) -> torch.Tensor:
|
70 |
+
wav = t_func.pad(wav, ((400 - 320) // 2, (400 - 320) // 2))
|
71 |
+
x, _ = self.encode(wav)
|
72 |
+
return self.proj(x)
|
73 |
+
|
74 |
+
|
75 |
+
class FeatureExtractor(nn.Module):
|
76 |
+
def __init__(self):
|
77 |
+
super().__init__()
|
78 |
+
self.conv0 = nn.Conv1d(1, 512, 10, 5, bias=False)
|
79 |
+
self.norm0 = nn.GroupNorm(512, 512)
|
80 |
+
self.conv1 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
81 |
+
self.conv2 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
82 |
+
self.conv3 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
83 |
+
self.conv4 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
84 |
+
self.conv5 = nn.Conv1d(512, 512, 2, 2, bias=False)
|
85 |
+
self.conv6 = nn.Conv1d(512, 512, 2, 2, bias=False)
|
86 |
+
|
87 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
88 |
+
x = t_func.gelu(self.norm0(self.conv0(x)))
|
89 |
+
x = t_func.gelu(self.conv1(x))
|
90 |
+
x = t_func.gelu(self.conv2(x))
|
91 |
+
x = t_func.gelu(self.conv3(x))
|
92 |
+
x = t_func.gelu(self.conv4(x))
|
93 |
+
x = t_func.gelu(self.conv5(x))
|
94 |
+
x = t_func.gelu(self.conv6(x))
|
95 |
+
return x
|
96 |
+
|
97 |
+
|
98 |
+
class FeatureProjection(nn.Module):
|
99 |
+
def __init__(self):
|
100 |
+
super().__init__()
|
101 |
+
self.norm = nn.LayerNorm(512)
|
102 |
+
self.projection = nn.Linear(512, 768)
|
103 |
+
self.dropout = nn.Dropout(0.1)
|
104 |
+
|
105 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
106 |
+
x = self.norm(x)
|
107 |
+
x = self.projection(x)
|
108 |
+
x = self.dropout(x)
|
109 |
+
return x
|
110 |
+
|
111 |
+
|
112 |
+
class PositionalConvEmbedding(nn.Module):
|
113 |
+
def __init__(self):
|
114 |
+
super().__init__()
|
115 |
+
self.conv = nn.Conv1d(
|
116 |
+
768,
|
117 |
+
768,
|
118 |
+
kernel_size=128,
|
119 |
+
padding=128 // 2,
|
120 |
+
groups=16,
|
121 |
+
)
|
122 |
+
self.conv = nn.utils.weight_norm(self.conv, name="weight", dim=2)
|
123 |
+
|
124 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
125 |
+
x = self.conv(x.transpose(1, 2))
|
126 |
+
x = t_func.gelu(x[:, :, :-1])
|
127 |
+
return x.transpose(1, 2)
|
128 |
+
|
129 |
+
|
130 |
+
class TransformerEncoder(nn.Module):
|
131 |
+
def __init__(
|
132 |
+
self, encoder_layer: nn.TransformerEncoderLayer, num_layers: int
|
133 |
+
) -> None:
|
134 |
+
super(TransformerEncoder, self).__init__()
|
135 |
+
self.layers = nn.ModuleList(
|
136 |
+
[copy.deepcopy(encoder_layer) for _ in range(num_layers)]
|
137 |
+
)
|
138 |
+
self.num_layers = num_layers
|
139 |
+
|
140 |
+
def forward(
|
141 |
+
self,
|
142 |
+
src: torch.Tensor,
|
143 |
+
mask: torch.Tensor = None,
|
144 |
+
src_key_padding_mask: torch.Tensor = None,
|
145 |
+
output_layer: Optional[int] = None,
|
146 |
+
) -> torch.Tensor:
|
147 |
+
output = src
|
148 |
+
for layer in self.layers[:output_layer]:
|
149 |
+
output = layer(
|
150 |
+
output, src_mask=mask, src_key_padding_mask=src_key_padding_mask
|
151 |
+
)
|
152 |
+
return output
|
153 |
+
|
154 |
+
|
155 |
+
def _compute_mask(
|
156 |
+
shape: Tuple[int, int],
|
157 |
+
mask_prob: float,
|
158 |
+
mask_length: int,
|
159 |
+
device: torch.device,
|
160 |
+
min_masks: int = 0,
|
161 |
+
) -> torch.Tensor:
|
162 |
+
batch_size, sequence_length = shape
|
163 |
+
|
164 |
+
if mask_length < 1:
|
165 |
+
raise ValueError("`mask_length` has to be bigger than 0.")
|
166 |
+
|
167 |
+
if mask_length > sequence_length:
|
168 |
+
raise ValueError(
|
169 |
+
f"`mask_length` has to be smaller than `sequence_length`, but got `mask_length`: {mask_length} and `sequence_length`: {sequence_length}`"
|
170 |
+
)
|
171 |
+
|
172 |
+
# compute number of masked spans in batch
|
173 |
+
num_masked_spans = int(mask_prob * sequence_length / mask_length + random.random())
|
174 |
+
num_masked_spans = max(num_masked_spans, min_masks)
|
175 |
+
|
176 |
+
# make sure num masked indices <= sequence_length
|
177 |
+
if num_masked_spans * mask_length > sequence_length:
|
178 |
+
num_masked_spans = sequence_length // mask_length
|
179 |
+
|
180 |
+
# SpecAugment mask to fill
|
181 |
+
mask = torch.zeros((batch_size, sequence_length), device=device, dtype=torch.bool)
|
182 |
+
|
183 |
+
# uniform distribution to sample from, make sure that offset samples are < sequence_length
|
184 |
+
uniform_dist = torch.ones(
|
185 |
+
(batch_size, sequence_length - (mask_length - 1)), device=device
|
186 |
+
)
|
187 |
+
|
188 |
+
# get random indices to mask
|
189 |
+
mask_indices = torch.multinomial(uniform_dist, num_masked_spans)
|
190 |
+
|
191 |
+
# expand masked indices to masked spans
|
192 |
+
mask_indices = (
|
193 |
+
mask_indices.unsqueeze(dim=-1)
|
194 |
+
.expand((batch_size, num_masked_spans, mask_length))
|
195 |
+
.reshape(batch_size, num_masked_spans * mask_length)
|
196 |
+
)
|
197 |
+
offsets = (
|
198 |
+
torch.arange(mask_length, device=device)[None, None, :]
|
199 |
+
.expand((batch_size, num_masked_spans, mask_length))
|
200 |
+
.reshape(batch_size, num_masked_spans * mask_length)
|
201 |
+
)
|
202 |
+
mask_idxs = mask_indices + offsets
|
203 |
+
|
204 |
+
# scatter indices to mask
|
205 |
+
mask = mask.scatter(1, mask_idxs, True)
|
206 |
+
|
207 |
+
return mask
|
208 |
+
|
209 |
+
|
210 |
+
def hubert_soft(
|
211 |
+
path: str,
|
212 |
+
) -> HubertSoft:
|
213 |
+
r"""HuBERT-Soft from `"A Comparison of Discrete and Soft Speech Units for Improved Voice Conversion"`.
|
214 |
+
Args:
|
215 |
+
path (str): path of a pretrained model
|
216 |
+
"""
|
217 |
+
hubert = HubertSoft()
|
218 |
+
checkpoint = torch.load(path)
|
219 |
+
consume_prefix_in_state_dict_if_present(checkpoint, "module.")
|
220 |
+
hubert.load_state_dict(checkpoint)
|
221 |
+
hubert.eval()
|
222 |
+
return hubert
|
hubert/hubert_model_onnx.py
ADDED
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
import random
|
3 |
+
from typing import Optional, Tuple
|
4 |
+
|
5 |
+
import torch
|
6 |
+
import torch.nn as nn
|
7 |
+
import torch.nn.functional as t_func
|
8 |
+
from torch.nn.modules.utils import consume_prefix_in_state_dict_if_present
|
9 |
+
|
10 |
+
|
11 |
+
class Hubert(nn.Module):
|
12 |
+
def __init__(self, num_label_embeddings: int = 100, mask: bool = True):
|
13 |
+
super().__init__()
|
14 |
+
self._mask = mask
|
15 |
+
self.feature_extractor = FeatureExtractor()
|
16 |
+
self.feature_projection = FeatureProjection()
|
17 |
+
self.positional_embedding = PositionalConvEmbedding()
|
18 |
+
self.norm = nn.LayerNorm(768)
|
19 |
+
self.dropout = nn.Dropout(0.1)
|
20 |
+
self.encoder = TransformerEncoder(
|
21 |
+
nn.TransformerEncoderLayer(
|
22 |
+
768, 12, 3072, activation="gelu", batch_first=True
|
23 |
+
),
|
24 |
+
12,
|
25 |
+
)
|
26 |
+
self.proj = nn.Linear(768, 256)
|
27 |
+
|
28 |
+
self.masked_spec_embed = nn.Parameter(torch.FloatTensor(768).uniform_())
|
29 |
+
self.label_embedding = nn.Embedding(num_label_embeddings, 256)
|
30 |
+
|
31 |
+
def mask(self, x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
|
32 |
+
mask = None
|
33 |
+
if self.training and self._mask:
|
34 |
+
mask = _compute_mask((x.size(0), x.size(1)), 0.8, 10, x.device, 2)
|
35 |
+
x[mask] = self.masked_spec_embed.to(x.dtype)
|
36 |
+
return x, mask
|
37 |
+
|
38 |
+
def encode(
|
39 |
+
self, x: torch.Tensor, layer: Optional[int] = None
|
40 |
+
) -> Tuple[torch.Tensor, torch.Tensor]:
|
41 |
+
x = self.feature_extractor(x)
|
42 |
+
x = self.feature_projection(x.transpose(1, 2))
|
43 |
+
x, mask = self.mask(x)
|
44 |
+
x = x + self.positional_embedding(x)
|
45 |
+
x = self.dropout(self.norm(x))
|
46 |
+
x = self.encoder(x, output_layer=layer)
|
47 |
+
return x, mask
|
48 |
+
|
49 |
+
def logits(self, x: torch.Tensor) -> torch.Tensor:
|
50 |
+
logits = torch.cosine_similarity(
|
51 |
+
x.unsqueeze(2),
|
52 |
+
self.label_embedding.weight.unsqueeze(0).unsqueeze(0),
|
53 |
+
dim=-1,
|
54 |
+
)
|
55 |
+
return logits / 0.1
|
56 |
+
|
57 |
+
|
58 |
+
class HubertSoft(Hubert):
|
59 |
+
def __init__(self):
|
60 |
+
super().__init__()
|
61 |
+
|
62 |
+
def units(self, wav: torch.Tensor) -> torch.Tensor:
|
63 |
+
wav = t_func.pad(wav, ((400 - 320) // 2, (400 - 320) // 2))
|
64 |
+
x, _ = self.encode(wav)
|
65 |
+
return self.proj(x)
|
66 |
+
|
67 |
+
def forward(self, x):
|
68 |
+
return self.units(x)
|
69 |
+
|
70 |
+
class FeatureExtractor(nn.Module):
|
71 |
+
def __init__(self):
|
72 |
+
super().__init__()
|
73 |
+
self.conv0 = nn.Conv1d(1, 512, 10, 5, bias=False)
|
74 |
+
self.norm0 = nn.GroupNorm(512, 512)
|
75 |
+
self.conv1 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
76 |
+
self.conv2 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
77 |
+
self.conv3 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
78 |
+
self.conv4 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
79 |
+
self.conv5 = nn.Conv1d(512, 512, 2, 2, bias=False)
|
80 |
+
self.conv6 = nn.Conv1d(512, 512, 2, 2, bias=False)
|
81 |
+
|
82 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
83 |
+
x = t_func.gelu(self.norm0(self.conv0(x)))
|
84 |
+
x = t_func.gelu(self.conv1(x))
|
85 |
+
x = t_func.gelu(self.conv2(x))
|
86 |
+
x = t_func.gelu(self.conv3(x))
|
87 |
+
x = t_func.gelu(self.conv4(x))
|
88 |
+
x = t_func.gelu(self.conv5(x))
|
89 |
+
x = t_func.gelu(self.conv6(x))
|
90 |
+
return x
|
91 |
+
|
92 |
+
|
93 |
+
class FeatureProjection(nn.Module):
|
94 |
+
def __init__(self):
|
95 |
+
super().__init__()
|
96 |
+
self.norm = nn.LayerNorm(512)
|
97 |
+
self.projection = nn.Linear(512, 768)
|
98 |
+
self.dropout = nn.Dropout(0.1)
|
99 |
+
|
100 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
101 |
+
x = self.norm(x)
|
102 |
+
x = self.projection(x)
|
103 |
+
x = self.dropout(x)
|
104 |
+
return x
|
105 |
+
|
106 |
+
|
107 |
+
class PositionalConvEmbedding(nn.Module):
|
108 |
+
def __init__(self):
|
109 |
+
super().__init__()
|
110 |
+
self.conv = nn.Conv1d(
|
111 |
+
768,
|
112 |
+
768,
|
113 |
+
kernel_size=128,
|
114 |
+
padding=128 // 2,
|
115 |
+
groups=16,
|
116 |
+
)
|
117 |
+
self.conv = nn.utils.weight_norm(self.conv, name="weight", dim=2)
|
118 |
+
|
119 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
120 |
+
x = self.conv(x.transpose(1, 2))
|
121 |
+
x = t_func.gelu(x[:, :, :-1])
|
122 |
+
return x.transpose(1, 2)
|
123 |
+
|
124 |
+
|
125 |
+
class TransformerEncoder(nn.Module):
|
126 |
+
def __init__(
|
127 |
+
self, encoder_layer: nn.TransformerEncoderLayer, num_layers: int
|
128 |
+
) -> None:
|
129 |
+
super(TransformerEncoder, self).__init__()
|
130 |
+
self.layers = nn.ModuleList(
|
131 |
+
[copy.deepcopy(encoder_layer) for _ in range(num_layers)]
|
132 |
+
)
|
133 |
+
self.num_layers = num_layers
|
134 |
+
|
135 |
+
def forward(
|
136 |
+
self,
|
137 |
+
src: torch.Tensor,
|
138 |
+
mask: torch.Tensor = None,
|
139 |
+
src_key_padding_mask: torch.Tensor = None,
|
140 |
+
output_layer: Optional[int] = None,
|
141 |
+
) -> torch.Tensor:
|
142 |
+
output = src
|
143 |
+
for layer in self.layers[:output_layer]:
|
144 |
+
output = layer(
|
145 |
+
output, src_mask=mask, src_key_padding_mask=src_key_padding_mask
|
146 |
+
)
|
147 |
+
return output
|
148 |
+
|
149 |
+
|
150 |
+
def _compute_mask(
|
151 |
+
shape: Tuple[int, int],
|
152 |
+
mask_prob: float,
|
153 |
+
mask_length: int,
|
154 |
+
device: torch.device,
|
155 |
+
min_masks: int = 0,
|
156 |
+
) -> torch.Tensor:
|
157 |
+
batch_size, sequence_length = shape
|
158 |
+
|
159 |
+
if mask_length < 1:
|
160 |
+
raise ValueError("`mask_length` has to be bigger than 0.")
|
161 |
+
|
162 |
+
if mask_length > sequence_length:
|
163 |
+
raise ValueError(
|
164 |
+
f"`mask_length` has to be smaller than `sequence_length`, but got `mask_length`: {mask_length} and `sequence_length`: {sequence_length}`"
|
165 |
+
)
|
166 |
+
|
167 |
+
# compute number of masked spans in batch
|
168 |
+
num_masked_spans = int(mask_prob * sequence_length / mask_length + random.random())
|
169 |
+
num_masked_spans = max(num_masked_spans, min_masks)
|
170 |
+
|
171 |
+
# make sure num masked indices <= sequence_length
|
172 |
+
if num_masked_spans * mask_length > sequence_length:
|
173 |
+
num_masked_spans = sequence_length // mask_length
|
174 |
+
|
175 |
+
# SpecAugment mask to fill
|
176 |
+
mask = torch.zeros((batch_size, sequence_length), device=device, dtype=torch.bool)
|
177 |
+
|
178 |
+
# uniform distribution to sample from, make sure that offset samples are < sequence_length
|
179 |
+
uniform_dist = torch.ones(
|
180 |
+
(batch_size, sequence_length - (mask_length - 1)), device=device
|
181 |
+
)
|
182 |
+
|
183 |
+
# get random indices to mask
|
184 |
+
mask_indices = torch.multinomial(uniform_dist, num_masked_spans)
|
185 |
+
|
186 |
+
# expand masked indices to masked spans
|
187 |
+
mask_indices = (
|
188 |
+
mask_indices.unsqueeze(dim=-1)
|
189 |
+
.expand((batch_size, num_masked_spans, mask_length))
|
190 |
+
.reshape(batch_size, num_masked_spans * mask_length)
|
191 |
+
)
|
192 |
+
offsets = (
|
193 |
+
torch.arange(mask_length, device=device)[None, None, :]
|
194 |
+
.expand((batch_size, num_masked_spans, mask_length))
|
195 |
+
.reshape(batch_size, num_masked_spans * mask_length)
|
196 |
+
)
|
197 |
+
mask_idxs = mask_indices + offsets
|
198 |
+
|
199 |
+
# scatter indices to mask
|
200 |
+
mask = mask.scatter(1, mask_idxs, True)
|
201 |
+
|
202 |
+
return mask
|
203 |
+
|
204 |
+
|
205 |
+
def hubert_soft(
|
206 |
+
path: str,
|
207 |
+
) -> HubertSoft:
|
208 |
+
r"""HuBERT-Soft from `"A Comparison of Discrete and Soft Speech Units for Improved Voice Conversion"`.
|
209 |
+
Args:
|
210 |
+
path (str): path of a pretrained model
|
211 |
+
"""
|
212 |
+
hubert = HubertSoft()
|
213 |
+
checkpoint = torch.load(path)
|
214 |
+
consume_prefix_in_state_dict_if_present(checkpoint, "module.")
|
215 |
+
hubert.load_state_dict(checkpoint)
|
216 |
+
hubert.eval()
|
217 |
+
return hubert
|
hubert/put_hubert_ckpt_here
ADDED
File without changes
|
inference/__init__.py
ADDED
File without changes
|
inference/__pycache__/__init__.cpython-38.pyc
ADDED
Binary file (127 Bytes). View file
|
|
inference/__pycache__/infer_tool.cpython-38.pyc
ADDED
Binary file (10.4 kB). View file
|
|
inference/__pycache__/slicer.cpython-38.pyc
ADDED
Binary file (3.83 kB). View file
|
|
inference/infer_tool.py
ADDED
@@ -0,0 +1,355 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import hashlib
|
2 |
+
import io
|
3 |
+
import json
|
4 |
+
import logging
|
5 |
+
import os
|
6 |
+
import time
|
7 |
+
from pathlib import Path
|
8 |
+
from inference import slicer
|
9 |
+
|
10 |
+
import librosa
|
11 |
+
import numpy as np
|
12 |
+
# import onnxruntime
|
13 |
+
import parselmouth
|
14 |
+
import soundfile
|
15 |
+
import torch
|
16 |
+
import hashlib
|
17 |
+
import io
|
18 |
+
import json
|
19 |
+
import logging
|
20 |
+
import os
|
21 |
+
import time
|
22 |
+
from pathlib import Path
|
23 |
+
from inference import slicer
|
24 |
+
|
25 |
+
import librosa
|
26 |
+
import numpy as np
|
27 |
+
# import onnxruntime
|
28 |
+
import parselmouth
|
29 |
+
import soundfile
|
30 |
+
import torch
|
31 |
+
import torchaudio
|
32 |
+
|
33 |
+
import cluster
|
34 |
+
from hubert import hubert_model
|
35 |
+
import utils
|
36 |
+
from models import SynthesizerTrn
|
37 |
+
|
38 |
+
logging.getLogger('matplotlib').setLevel(logging.WARNING)
|
39 |
+
|
40 |
+
|
41 |
+
def read_temp(file_name):
|
42 |
+
if not os.path.exists(file_name):
|
43 |
+
with open(file_name, "w") as f:
|
44 |
+
f.write(json.dumps({"info": "temp_dict"}))
|
45 |
+
return {}
|
46 |
+
else:
|
47 |
+
try:
|
48 |
+
with open(file_name, "r") as f:
|
49 |
+
data = f.read()
|
50 |
+
data_dict = json.loads(data)
|
51 |
+
if os.path.getsize(file_name) > 50 * 1024 * 1024:
|
52 |
+
f_name = file_name.replace("\\", "/").split("/")[-1]
|
53 |
+
print(f"clean {f_name}")
|
54 |
+
for wav_hash in list(data_dict.keys()):
|
55 |
+
if int(time.time()) - int(data_dict[wav_hash]["time"]) > 14 * 24 * 3600:
|
56 |
+
del data_dict[wav_hash]
|
57 |
+
except Exception as e:
|
58 |
+
print(e)
|
59 |
+
print(f"{file_name} error,auto rebuild file")
|
60 |
+
data_dict = {"info": "temp_dict"}
|
61 |
+
return data_dict
|
62 |
+
|
63 |
+
|
64 |
+
def write_temp(file_name, data):
|
65 |
+
with open(file_name, "w") as f:
|
66 |
+
f.write(json.dumps(data))
|
67 |
+
|
68 |
+
|
69 |
+
def timeit(func):
|
70 |
+
def run(*args, **kwargs):
|
71 |
+
t = time.time()
|
72 |
+
res = func(*args, **kwargs)
|
73 |
+
print('executing \'%s\' costed %.3fs' % (func.__name__, time.time() - t))
|
74 |
+
return res
|
75 |
+
|
76 |
+
return run
|
77 |
+
|
78 |
+
|
79 |
+
def format_wav(audio_path):
|
80 |
+
if Path(audio_path).suffix == '.wav':
|
81 |
+
return
|
82 |
+
raw_audio, raw_sample_rate = librosa.load(audio_path, mono=True, sr=None)
|
83 |
+
soundfile.write(Path(audio_path).with_suffix(".wav"), raw_audio, raw_sample_rate)
|
84 |
+
|
85 |
+
|
86 |
+
def get_end_file(dir_path, end):
|
87 |
+
file_lists = []
|
88 |
+
for root, dirs, files in os.walk(dir_path):
|
89 |
+
files = [f for f in files if f[0] != '.']
|
90 |
+
dirs[:] = [d for d in dirs if d[0] != '.']
|
91 |
+
for f_file in files:
|
92 |
+
if f_file.endswith(end):
|
93 |
+
file_lists.append(os.path.join(root, f_file).replace("\\", "/"))
|
94 |
+
return file_lists
|
95 |
+
|
96 |
+
|
97 |
+
def get_md5(content):
|
98 |
+
return hashlib.new("md5", content).hexdigest()
|
99 |
+
|
100 |
+
def fill_a_to_b(a, b):
|
101 |
+
if len(a) < len(b):
|
102 |
+
for _ in range(0, len(b) - len(a)):
|
103 |
+
a.append(a[0])
|
104 |
+
|
105 |
+
def mkdir(paths: list):
|
106 |
+
for path in paths:
|
107 |
+
if not os.path.exists(path):
|
108 |
+
os.mkdir(path)
|
109 |
+
|
110 |
+
def pad_array(arr, target_length):
|
111 |
+
current_length = arr.shape[0]
|
112 |
+
if current_length >= target_length:
|
113 |
+
return arr
|
114 |
+
else:
|
115 |
+
pad_width = target_length - current_length
|
116 |
+
pad_left = pad_width // 2
|
117 |
+
pad_right = pad_width - pad_left
|
118 |
+
padded_arr = np.pad(arr, (pad_left, pad_right), 'constant', constant_values=(0, 0))
|
119 |
+
return padded_arr
|
120 |
+
|
121 |
+
def split_list_by_n(list_collection, n, pre=0):
|
122 |
+
for i in range(0, len(list_collection), n):
|
123 |
+
yield list_collection[i-pre if i-pre>=0 else i: i + n]
|
124 |
+
|
125 |
+
|
126 |
+
class F0FilterException(Exception):
|
127 |
+
pass
|
128 |
+
|
129 |
+
class Svc(object):
|
130 |
+
def __init__(self, net_g_path, config_path,
|
131 |
+
device=None,
|
132 |
+
cluster_model_path="logs/44k/kmeans_10000.pt",
|
133 |
+
nsf_hifigan_enhance = False
|
134 |
+
):
|
135 |
+
self.net_g_path = net_g_path
|
136 |
+
if device is None:
|
137 |
+
self.dev = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
138 |
+
else:
|
139 |
+
self.dev = torch.device(device)
|
140 |
+
self.net_g_ms = None
|
141 |
+
self.hps_ms = utils.get_hparams_from_file(config_path)
|
142 |
+
self.target_sample = self.hps_ms.data.sampling_rate
|
143 |
+
self.hop_size = self.hps_ms.data.hop_length
|
144 |
+
self.spk2id = self.hps_ms.spk
|
145 |
+
self.nsf_hifigan_enhance = nsf_hifigan_enhance
|
146 |
+
# 加载hubert
|
147 |
+
self.hubert_model = utils.get_hubert_model().to(self.dev)
|
148 |
+
self.load_model()
|
149 |
+
if os.path.exists(cluster_model_path):
|
150 |
+
self.cluster_model = cluster.get_cluster_model(cluster_model_path)
|
151 |
+
if self.nsf_hifigan_enhance:
|
152 |
+
from modules.enhancer import Enhancer
|
153 |
+
self.enhancer = Enhancer('nsf-hifigan', 'pretrain/nsf_hifigan/model',device=self.dev)
|
154 |
+
|
155 |
+
def load_model(self):
|
156 |
+
# 获取模型配置
|
157 |
+
self.net_g_ms = SynthesizerTrn(
|
158 |
+
self.hps_ms.data.filter_length // 2 + 1,
|
159 |
+
self.hps_ms.train.segment_size // self.hps_ms.data.hop_length,
|
160 |
+
**self.hps_ms.model)
|
161 |
+
_ = utils.load_checkpoint(self.net_g_path, self.net_g_ms, None)
|
162 |
+
if "half" in self.net_g_path and torch.cuda.is_available():
|
163 |
+
_ = self.net_g_ms.half().eval().to(self.dev)
|
164 |
+
else:
|
165 |
+
_ = self.net_g_ms.eval().to(self.dev)
|
166 |
+
|
167 |
+
|
168 |
+
|
169 |
+
def get_unit_f0(self, in_path, tran, cluster_infer_ratio, speaker, f0_filter ,F0_mean_pooling):
|
170 |
+
|
171 |
+
wav, sr = librosa.load(in_path, sr=self.target_sample)
|
172 |
+
|
173 |
+
if F0_mean_pooling == True:
|
174 |
+
f0, uv = utils.compute_f0_uv_torchcrepe(torch.FloatTensor(wav), sampling_rate=self.target_sample, hop_length=self.hop_size,device=self.dev)
|
175 |
+
if f0_filter and sum(f0) == 0:
|
176 |
+
raise F0FilterException("未检测到人声")
|
177 |
+
f0 = torch.FloatTensor(list(f0))
|
178 |
+
uv = torch.FloatTensor(list(uv))
|
179 |
+
if F0_mean_pooling == False:
|
180 |
+
f0 = utils.compute_f0_parselmouth(wav, sampling_rate=self.target_sample, hop_length=self.hop_size)
|
181 |
+
if f0_filter and sum(f0) == 0:
|
182 |
+
raise F0FilterException("未检测到人声")
|
183 |
+
f0, uv = utils.interpolate_f0(f0)
|
184 |
+
f0 = torch.FloatTensor(f0)
|
185 |
+
uv = torch.FloatTensor(uv)
|
186 |
+
|
187 |
+
f0 = f0 * 2 ** (tran / 12)
|
188 |
+
f0 = f0.unsqueeze(0).to(self.dev)
|
189 |
+
uv = uv.unsqueeze(0).to(self.dev)
|
190 |
+
|
191 |
+
wav16k = librosa.resample(wav, orig_sr=self.target_sample, target_sr=16000)
|
192 |
+
wav16k = torch.from_numpy(wav16k).to(self.dev)
|
193 |
+
c = utils.get_hubert_content(self.hubert_model, wav_16k_tensor=wav16k)
|
194 |
+
c = utils.repeat_expand_2d(c.squeeze(0), f0.shape[1])
|
195 |
+
|
196 |
+
if cluster_infer_ratio !=0:
|
197 |
+
cluster_c = cluster.get_cluster_center_result(self.cluster_model, c.cpu().numpy().T, speaker).T
|
198 |
+
cluster_c = torch.FloatTensor(cluster_c).to(self.dev)
|
199 |
+
c = cluster_infer_ratio * cluster_c + (1 - cluster_infer_ratio) * c
|
200 |
+
|
201 |
+
c = c.unsqueeze(0)
|
202 |
+
return c, f0, uv
|
203 |
+
|
204 |
+
def infer(self, speaker, tran, raw_path,
|
205 |
+
cluster_infer_ratio=0,
|
206 |
+
auto_predict_f0=False,
|
207 |
+
noice_scale=0.4,
|
208 |
+
f0_filter=False,
|
209 |
+
F0_mean_pooling=False,
|
210 |
+
enhancer_adaptive_key = 0
|
211 |
+
):
|
212 |
+
|
213 |
+
speaker_id = self.spk2id.__dict__.get(speaker)
|
214 |
+
if not speaker_id and type(speaker) is int:
|
215 |
+
if len(self.spk2id.__dict__) >= speaker:
|
216 |
+
speaker_id = speaker
|
217 |
+
sid = torch.LongTensor([int(speaker_id)]).to(self.dev).unsqueeze(0)
|
218 |
+
c, f0, uv = self.get_unit_f0(raw_path, tran, cluster_infer_ratio, speaker, f0_filter,F0_mean_pooling)
|
219 |
+
if "half" in self.net_g_path and torch.cuda.is_available():
|
220 |
+
c = c.half()
|
221 |
+
with torch.no_grad():
|
222 |
+
start = time.time()
|
223 |
+
audio = self.net_g_ms.infer(c, f0=f0, g=sid, uv=uv, predict_f0=auto_predict_f0, noice_scale=noice_scale)[0,0].data.float()
|
224 |
+
if self.nsf_hifigan_enhance:
|
225 |
+
audio, _ = self.enhancer.enhance(
|
226 |
+
audio[None,:],
|
227 |
+
self.target_sample,
|
228 |
+
f0[:,:,None],
|
229 |
+
self.hps_ms.data.hop_length,
|
230 |
+
adaptive_key = enhancer_adaptive_key)
|
231 |
+
use_time = time.time() - start
|
232 |
+
print("vits use time:{}".format(use_time))
|
233 |
+
return audio, audio.shape[-1]
|
234 |
+
|
235 |
+
def clear_empty(self):
|
236 |
+
# 清理显存
|
237 |
+
torch.cuda.empty_cache()
|
238 |
+
|
239 |
+
def slice_inference(self,
|
240 |
+
raw_audio_path,
|
241 |
+
spk,
|
242 |
+
tran,
|
243 |
+
slice_db,
|
244 |
+
cluster_infer_ratio,
|
245 |
+
auto_predict_f0,
|
246 |
+
noice_scale,
|
247 |
+
pad_seconds=0.5,
|
248 |
+
clip_seconds=0,
|
249 |
+
lg_num=0,
|
250 |
+
lgr_num =0.75,
|
251 |
+
F0_mean_pooling = False,
|
252 |
+
enhancer_adaptive_key = 0
|
253 |
+
):
|
254 |
+
wav_path = raw_audio_path
|
255 |
+
chunks = slicer.cut(wav_path, db_thresh=slice_db)
|
256 |
+
audio_data, audio_sr = slicer.chunks2audio(wav_path, chunks)
|
257 |
+
per_size = int(clip_seconds*audio_sr)
|
258 |
+
lg_size = int(lg_num*audio_sr)
|
259 |
+
lg_size_r = int(lg_size*lgr_num)
|
260 |
+
lg_size_c_l = (lg_size-lg_size_r)//2
|
261 |
+
lg_size_c_r = lg_size-lg_size_r-lg_size_c_l
|
262 |
+
lg = np.linspace(0,1,lg_size_r) if lg_size!=0 else 0
|
263 |
+
|
264 |
+
audio = []
|
265 |
+
for (slice_tag, data) in audio_data:
|
266 |
+
print(f'#=====segment start, {round(len(data) / audio_sr, 3)}s======')
|
267 |
+
# padd
|
268 |
+
length = int(np.ceil(len(data) / audio_sr * self.target_sample))
|
269 |
+
if slice_tag:
|
270 |
+
print('jump empty segment')
|
271 |
+
_audio = np.zeros(length)
|
272 |
+
audio.extend(list(pad_array(_audio, length)))
|
273 |
+
continue
|
274 |
+
if per_size != 0:
|
275 |
+
datas = split_list_by_n(data, per_size,lg_size)
|
276 |
+
else:
|
277 |
+
datas = [data]
|
278 |
+
for k,dat in enumerate(datas):
|
279 |
+
per_length = int(np.ceil(len(dat) / audio_sr * self.target_sample)) if clip_seconds!=0 else length
|
280 |
+
if clip_seconds!=0: print(f'###=====segment clip start, {round(len(dat) / audio_sr, 3)}s======')
|
281 |
+
# padd
|
282 |
+
pad_len = int(audio_sr * pad_seconds)
|
283 |
+
dat = np.concatenate([np.zeros([pad_len]), dat, np.zeros([pad_len])])
|
284 |
+
raw_path = io.BytesIO()
|
285 |
+
soundfile.write(raw_path, dat, audio_sr, format="wav")
|
286 |
+
raw_path.seek(0)
|
287 |
+
out_audio, out_sr = self.infer(spk, tran, raw_path,
|
288 |
+
cluster_infer_ratio=cluster_infer_ratio,
|
289 |
+
auto_predict_f0=auto_predict_f0,
|
290 |
+
noice_scale=noice_scale,
|
291 |
+
F0_mean_pooling = F0_mean_pooling,
|
292 |
+
enhancer_adaptive_key = enhancer_adaptive_key
|
293 |
+
)
|
294 |
+
_audio = out_audio.cpu().numpy()
|
295 |
+
pad_len = int(self.target_sample * pad_seconds)
|
296 |
+
_audio = _audio[pad_len:-pad_len]
|
297 |
+
_audio = pad_array(_audio, per_length)
|
298 |
+
if lg_size!=0 and k!=0:
|
299 |
+
lg1 = audio[-(lg_size_r+lg_size_c_r):-lg_size_c_r] if lgr_num != 1 else audio[-lg_size:]
|
300 |
+
lg2 = _audio[lg_size_c_l:lg_size_c_l+lg_size_r] if lgr_num != 1 else _audio[0:lg_size]
|
301 |
+
lg_pre = lg1*(1-lg)+lg2*lg
|
302 |
+
audio = audio[0:-(lg_size_r+lg_size_c_r)] if lgr_num != 1 else audio[0:-lg_size]
|
303 |
+
audio.extend(lg_pre)
|
304 |
+
_audio = _audio[lg_size_c_l+lg_size_r:] if lgr_num != 1 else _audio[lg_size:]
|
305 |
+
audio.extend(list(_audio))
|
306 |
+
return np.array(audio)
|
307 |
+
|
308 |
+
class RealTimeVC:
|
309 |
+
def __init__(self):
|
310 |
+
self.last_chunk = None
|
311 |
+
self.last_o = None
|
312 |
+
self.chunk_len = 16000 # 区块长度
|
313 |
+
self.pre_len = 3840 # 交叉淡化长度,640的倍数
|
314 |
+
|
315 |
+
"""输入输出都是1维numpy 音频波形数组"""
|
316 |
+
|
317 |
+
def process(self, svc_model, speaker_id, f_pitch_change, input_wav_path,
|
318 |
+
cluster_infer_ratio=0,
|
319 |
+
auto_predict_f0=False,
|
320 |
+
noice_scale=0.4,
|
321 |
+
f0_filter=False):
|
322 |
+
|
323 |
+
import maad
|
324 |
+
audio, sr = torchaudio.load(input_wav_path)
|
325 |
+
audio = audio.cpu().numpy()[0]
|
326 |
+
temp_wav = io.BytesIO()
|
327 |
+
if self.last_chunk is None:
|
328 |
+
input_wav_path.seek(0)
|
329 |
+
|
330 |
+
audio, sr = svc_model.infer(speaker_id, f_pitch_change, input_wav_path,
|
331 |
+
cluster_infer_ratio=cluster_infer_ratio,
|
332 |
+
auto_predict_f0=auto_predict_f0,
|
333 |
+
noice_scale=noice_scale,
|
334 |
+
f0_filter=f0_filter)
|
335 |
+
|
336 |
+
audio = audio.cpu().numpy()
|
337 |
+
self.last_chunk = audio[-self.pre_len:]
|
338 |
+
self.last_o = audio
|
339 |
+
return audio[-self.chunk_len:]
|
340 |
+
else:
|
341 |
+
audio = np.concatenate([self.last_chunk, audio])
|
342 |
+
soundfile.write(temp_wav, audio, sr, format="wav")
|
343 |
+
temp_wav.seek(0)
|
344 |
+
|
345 |
+
audio, sr = svc_model.infer(speaker_id, f_pitch_change, temp_wav,
|
346 |
+
cluster_infer_ratio=cluster_infer_ratio,
|
347 |
+
auto_predict_f0=auto_predict_f0,
|
348 |
+
noice_scale=noice_scale,
|
349 |
+
f0_filter=f0_filter)
|
350 |
+
|
351 |
+
audio = audio.cpu().numpy()
|
352 |
+
ret = maad.util.crossfade(self.last_o, audio, self.pre_len)
|
353 |
+
self.last_chunk = audio[-self.pre_len:]
|
354 |
+
self.last_o = audio
|
355 |
+
return ret[self.chunk_len:2 * self.chunk_len]
|
inference/infer_tool_grad.py
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import hashlib
|
2 |
+
import json
|
3 |
+
import logging
|
4 |
+
import os
|
5 |
+
import time
|
6 |
+
from pathlib import Path
|
7 |
+
import io
|
8 |
+
import librosa
|
9 |
+
import maad
|
10 |
+
import numpy as np
|
11 |
+
from inference import slicer
|
12 |
+
import parselmouth
|
13 |
+
import soundfile
|
14 |
+
import torch
|
15 |
+
import torchaudio
|
16 |
+
|
17 |
+
from hubert import hubert_model
|
18 |
+
import utils
|
19 |
+
from models import SynthesizerTrn
|
20 |
+
logging.getLogger('numba').setLevel(logging.WARNING)
|
21 |
+
logging.getLogger('matplotlib').setLevel(logging.WARNING)
|
22 |
+
|
23 |
+
def resize2d_f0(x, target_len):
|
24 |
+
source = np.array(x)
|
25 |
+
source[source < 0.001] = np.nan
|
26 |
+
target = np.interp(np.arange(0, len(source) * target_len, len(source)) / target_len, np.arange(0, len(source)),
|
27 |
+
source)
|
28 |
+
res = np.nan_to_num(target)
|
29 |
+
return res
|
30 |
+
|
31 |
+
def get_f0(x, p_len,f0_up_key=0):
|
32 |
+
|
33 |
+
time_step = 160 / 16000 * 1000
|
34 |
+
f0_min = 50
|
35 |
+
f0_max = 1100
|
36 |
+
f0_mel_min = 1127 * np.log(1 + f0_min / 700)
|
37 |
+
f0_mel_max = 1127 * np.log(1 + f0_max / 700)
|
38 |
+
|
39 |
+
f0 = parselmouth.Sound(x, 16000).to_pitch_ac(
|
40 |
+
time_step=time_step / 1000, voicing_threshold=0.6,
|
41 |
+
pitch_floor=f0_min, pitch_ceiling=f0_max).selected_array['frequency']
|
42 |
+
|
43 |
+
pad_size=(p_len - len(f0) + 1) // 2
|
44 |
+
if(pad_size>0 or p_len - len(f0) - pad_size>0):
|
45 |
+
f0 = np.pad(f0,[[pad_size,p_len - len(f0) - pad_size]], mode='constant')
|
46 |
+
|
47 |
+
f0 *= pow(2, f0_up_key / 12)
|
48 |
+
f0_mel = 1127 * np.log(1 + f0 / 700)
|
49 |
+
f0_mel[f0_mel > 0] = (f0_mel[f0_mel > 0] - f0_mel_min) * 254 / (f0_mel_max - f0_mel_min) + 1
|
50 |
+
f0_mel[f0_mel <= 1] = 1
|
51 |
+
f0_mel[f0_mel > 255] = 255
|
52 |
+
f0_coarse = np.rint(f0_mel).astype(np.int)
|
53 |
+
return f0_coarse, f0
|
54 |
+
|
55 |
+
def clean_pitch(input_pitch):
|
56 |
+
num_nan = np.sum(input_pitch == 1)
|
57 |
+
if num_nan / len(input_pitch) > 0.9:
|
58 |
+
input_pitch[input_pitch != 1] = 1
|
59 |
+
return input_pitch
|
60 |
+
|
61 |
+
|
62 |
+
def plt_pitch(input_pitch):
|
63 |
+
input_pitch = input_pitch.astype(float)
|
64 |
+
input_pitch[input_pitch == 1] = np.nan
|
65 |
+
return input_pitch
|
66 |
+
|
67 |
+
|
68 |
+
def f0_to_pitch(ff):
|
69 |
+
f0_pitch = 69 + 12 * np.log2(ff / 440)
|
70 |
+
return f0_pitch
|
71 |
+
|
72 |
+
|
73 |
+
def fill_a_to_b(a, b):
|
74 |
+
if len(a) < len(b):
|
75 |
+
for _ in range(0, len(b) - len(a)):
|
76 |
+
a.append(a[0])
|
77 |
+
|
78 |
+
|
79 |
+
def mkdir(paths: list):
|
80 |
+
for path in paths:
|
81 |
+
if not os.path.exists(path):
|
82 |
+
os.mkdir(path)
|
83 |
+
|
84 |
+
|
85 |
+
class VitsSvc(object):
|
86 |
+
def __init__(self):
|
87 |
+
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
88 |
+
self.SVCVITS = None
|
89 |
+
self.hps = None
|
90 |
+
self.speakers = None
|
91 |
+
self.hubert_soft = utils.get_hubert_model()
|
92 |
+
|
93 |
+
def set_device(self, device):
|
94 |
+
self.device = torch.device(device)
|
95 |
+
self.hubert_soft.to(self.device)
|
96 |
+
if self.SVCVITS != None:
|
97 |
+
self.SVCVITS.to(self.device)
|
98 |
+
|
99 |
+
def loadCheckpoint(self, path):
|
100 |
+
self.hps = utils.get_hparams_from_file(f"checkpoints/{path}/config.json")
|
101 |
+
self.SVCVITS = SynthesizerTrn(
|
102 |
+
self.hps.data.filter_length // 2 + 1,
|
103 |
+
self.hps.train.segment_size // self.hps.data.hop_length,
|
104 |
+
**self.hps.model)
|
105 |
+
_ = utils.load_checkpoint(f"checkpoints/{path}/model.pth", self.SVCVITS, None)
|
106 |
+
_ = self.SVCVITS.eval().to(self.device)
|
107 |
+
self.speakers = self.hps.spk
|
108 |
+
|
109 |
+
def get_units(self, source, sr):
|
110 |
+
source = source.unsqueeze(0).to(self.device)
|
111 |
+
with torch.inference_mode():
|
112 |
+
units = self.hubert_soft.units(source)
|
113 |
+
return units
|
114 |
+
|
115 |
+
|
116 |
+
def get_unit_pitch(self, in_path, tran):
|
117 |
+
source, sr = torchaudio.load(in_path)
|
118 |
+
source = torchaudio.functional.resample(source, sr, 16000)
|
119 |
+
if len(source.shape) == 2 and source.shape[1] >= 2:
|
120 |
+
source = torch.mean(source, dim=0).unsqueeze(0)
|
121 |
+
soft = self.get_units(source, sr).squeeze(0).cpu().numpy()
|
122 |
+
f0_coarse, f0 = get_f0(source.cpu().numpy()[0], soft.shape[0]*2, tran)
|
123 |
+
return soft, f0
|
124 |
+
|
125 |
+
def infer(self, speaker_id, tran, raw_path):
|
126 |
+
speaker_id = self.speakers[speaker_id]
|
127 |
+
sid = torch.LongTensor([int(speaker_id)]).to(self.device).unsqueeze(0)
|
128 |
+
soft, pitch = self.get_unit_pitch(raw_path, tran)
|
129 |
+
f0 = torch.FloatTensor(clean_pitch(pitch)).unsqueeze(0).to(self.device)
|
130 |
+
stn_tst = torch.FloatTensor(soft)
|
131 |
+
with torch.no_grad():
|
132 |
+
x_tst = stn_tst.unsqueeze(0).to(self.device)
|
133 |
+
x_tst = torch.repeat_interleave(x_tst, repeats=2, dim=1).transpose(1, 2)
|
134 |
+
audio = self.SVCVITS.infer(x_tst, f0=f0, g=sid)[0,0].data.float()
|
135 |
+
return audio, audio.shape[-1]
|
136 |
+
|
137 |
+
def inference(self,srcaudio,chara,tran,slice_db):
|
138 |
+
sampling_rate, audio = srcaudio
|
139 |
+
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
|
140 |
+
if len(audio.shape) > 1:
|
141 |
+
audio = librosa.to_mono(audio.transpose(1, 0))
|
142 |
+
if sampling_rate != 16000:
|
143 |
+
audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)
|
144 |
+
soundfile.write("tmpwav.wav", audio, 16000, format="wav")
|
145 |
+
chunks = slicer.cut("tmpwav.wav", db_thresh=slice_db)
|
146 |
+
audio_data, audio_sr = slicer.chunks2audio("tmpwav.wav", chunks)
|
147 |
+
audio = []
|
148 |
+
for (slice_tag, data) in audio_data:
|
149 |
+
length = int(np.ceil(len(data) / audio_sr * self.hps.data.sampling_rate))
|
150 |
+
raw_path = io.BytesIO()
|
151 |
+
soundfile.write(raw_path, data, audio_sr, format="wav")
|
152 |
+
raw_path.seek(0)
|
153 |
+
if slice_tag:
|
154 |
+
_audio = np.zeros(length)
|
155 |
+
else:
|
156 |
+
out_audio, out_sr = self.infer(chara, tran, raw_path)
|
157 |
+
_audio = out_audio.cpu().numpy()
|
158 |
+
audio.extend(list(_audio))
|
159 |
+
audio = (np.array(audio) * 32768.0).astype('int16')
|
160 |
+
return (self.hps.data.sampling_rate,audio)
|
inference/slicer.py
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import librosa
|
2 |
+
import torch
|
3 |
+
import torchaudio
|
4 |
+
|
5 |
+
|
6 |
+
class Slicer:
|
7 |
+
def __init__(self,
|
8 |
+
sr: int,
|
9 |
+
threshold: float = -40.,
|
10 |
+
min_length: int = 5000,
|
11 |
+
min_interval: int = 300,
|
12 |
+
hop_size: int = 20,
|
13 |
+
max_sil_kept: int = 5000):
|
14 |
+
if not min_length >= min_interval >= hop_size:
|
15 |
+
raise ValueError('The following condition must be satisfied: min_length >= min_interval >= hop_size')
|
16 |
+
if not max_sil_kept >= hop_size:
|
17 |
+
raise ValueError('The following condition must be satisfied: max_sil_kept >= hop_size')
|
18 |
+
min_interval = sr * min_interval / 1000
|
19 |
+
self.threshold = 10 ** (threshold / 20.)
|
20 |
+
self.hop_size = round(sr * hop_size / 1000)
|
21 |
+
self.win_size = min(round(min_interval), 4 * self.hop_size)
|
22 |
+
self.min_length = round(sr * min_length / 1000 / self.hop_size)
|
23 |
+
self.min_interval = round(min_interval / self.hop_size)
|
24 |
+
self.max_sil_kept = round(sr * max_sil_kept / 1000 / self.hop_size)
|
25 |
+
|
26 |
+
def _apply_slice(self, waveform, begin, end):
|
27 |
+
if len(waveform.shape) > 1:
|
28 |
+
return waveform[:, begin * self.hop_size: min(waveform.shape[1], end * self.hop_size)]
|
29 |
+
else:
|
30 |
+
return waveform[begin * self.hop_size: min(waveform.shape[0], end * self.hop_size)]
|
31 |
+
|
32 |
+
# @timeit
|
33 |
+
def slice(self, waveform):
|
34 |
+
if len(waveform.shape) > 1:
|
35 |
+
samples = librosa.to_mono(waveform)
|
36 |
+
else:
|
37 |
+
samples = waveform
|
38 |
+
if samples.shape[0] <= self.min_length:
|
39 |
+
return {"0": {"slice": False, "split_time": f"0,{len(waveform)}"}}
|
40 |
+
rms_list = librosa.feature.rms(y=samples, frame_length=self.win_size, hop_length=self.hop_size).squeeze(0)
|
41 |
+
sil_tags = []
|
42 |
+
silence_start = None
|
43 |
+
clip_start = 0
|
44 |
+
for i, rms in enumerate(rms_list):
|
45 |
+
# Keep looping while frame is silent.
|
46 |
+
if rms < self.threshold:
|
47 |
+
# Record start of silent frames.
|
48 |
+
if silence_start is None:
|
49 |
+
silence_start = i
|
50 |
+
continue
|
51 |
+
# Keep looping while frame is not silent and silence start has not been recorded.
|
52 |
+
if silence_start is None:
|
53 |
+
continue
|
54 |
+
# Clear recorded silence start if interval is not enough or clip is too short
|
55 |
+
is_leading_silence = silence_start == 0 and i > self.max_sil_kept
|
56 |
+
need_slice_middle = i - silence_start >= self.min_interval and i - clip_start >= self.min_length
|
57 |
+
if not is_leading_silence and not need_slice_middle:
|
58 |
+
silence_start = None
|
59 |
+
continue
|
60 |
+
# Need slicing. Record the range of silent frames to be removed.
|
61 |
+
if i - silence_start <= self.max_sil_kept:
|
62 |
+
pos = rms_list[silence_start: i + 1].argmin() + silence_start
|
63 |
+
if silence_start == 0:
|
64 |
+
sil_tags.append((0, pos))
|
65 |
+
else:
|
66 |
+
sil_tags.append((pos, pos))
|
67 |
+
clip_start = pos
|
68 |
+
elif i - silence_start <= self.max_sil_kept * 2:
|
69 |
+
pos = rms_list[i - self.max_sil_kept: silence_start + self.max_sil_kept + 1].argmin()
|
70 |
+
pos += i - self.max_sil_kept
|
71 |
+
pos_l = rms_list[silence_start: silence_start + self.max_sil_kept + 1].argmin() + silence_start
|
72 |
+
pos_r = rms_list[i - self.max_sil_kept: i + 1].argmin() + i - self.max_sil_kept
|
73 |
+
if silence_start == 0:
|
74 |
+
sil_tags.append((0, pos_r))
|
75 |
+
clip_start = pos_r
|
76 |
+
else:
|
77 |
+
sil_tags.append((min(pos_l, pos), max(pos_r, pos)))
|
78 |
+
clip_start = max(pos_r, pos)
|
79 |
+
else:
|
80 |
+
pos_l = rms_list[silence_start: silence_start + self.max_sil_kept + 1].argmin() + silence_start
|
81 |
+
pos_r = rms_list[i - self.max_sil_kept: i + 1].argmin() + i - self.max_sil_kept
|
82 |
+
if silence_start == 0:
|
83 |
+
sil_tags.append((0, pos_r))
|
84 |
+
else:
|
85 |
+
sil_tags.append((pos_l, pos_r))
|
86 |
+
clip_start = pos_r
|
87 |
+
silence_start = None
|
88 |
+
# Deal with trailing silence.
|
89 |
+
total_frames = rms_list.shape[0]
|
90 |
+
if silence_start is not None and total_frames - silence_start >= self.min_interval:
|
91 |
+
silence_end = min(total_frames, silence_start + self.max_sil_kept)
|
92 |
+
pos = rms_list[silence_start: silence_end + 1].argmin() + silence_start
|
93 |
+
sil_tags.append((pos, total_frames + 1))
|
94 |
+
# Apply and return slices.
|
95 |
+
if len(sil_tags) == 0:
|
96 |
+
return {"0": {"slice": False, "split_time": f"0,{len(waveform)}"}}
|
97 |
+
else:
|
98 |
+
chunks = []
|
99 |
+
# 第一段静音并非从头开始,补上有声片段
|
100 |
+
if sil_tags[0][0]:
|
101 |
+
chunks.append(
|
102 |
+
{"slice": False, "split_time": f"0,{min(waveform.shape[0], sil_tags[0][0] * self.hop_size)}"})
|
103 |
+
for i in range(0, len(sil_tags)):
|
104 |
+
# 标识有声片段(跳过第一段)
|
105 |
+
if i:
|
106 |
+
chunks.append({"slice": False,
|
107 |
+
"split_time": f"{sil_tags[i - 1][1] * self.hop_size},{min(waveform.shape[0], sil_tags[i][0] * self.hop_size)}"})
|
108 |
+
# 标识所有静音片段
|
109 |
+
chunks.append({"slice": True,
|
110 |
+
"split_time": f"{sil_tags[i][0] * self.hop_size},{min(waveform.shape[0], sil_tags[i][1] * self.hop_size)}"})
|
111 |
+
# 最后一段静音并非结尾,补上结尾片段
|
112 |
+
if sil_tags[-1][1] * self.hop_size < len(waveform):
|
113 |
+
chunks.append({"slice": False, "split_time": f"{sil_tags[-1][1] * self.hop_size},{len(waveform)}"})
|
114 |
+
chunk_dict = {}
|
115 |
+
for i in range(len(chunks)):
|
116 |
+
chunk_dict[str(i)] = chunks[i]
|
117 |
+
return chunk_dict
|
118 |
+
|
119 |
+
|
120 |
+
def cut(audio_path, db_thresh=-30, min_len=5000):
|
121 |
+
audio, sr = librosa.load(audio_path, sr=None)
|
122 |
+
slicer = Slicer(
|
123 |
+
sr=sr,
|
124 |
+
threshold=db_thresh,
|
125 |
+
min_length=min_len
|
126 |
+
)
|
127 |
+
chunks = slicer.slice(audio)
|
128 |
+
return chunks
|
129 |
+
|
130 |
+
|
131 |
+
def chunks2audio(audio_path, chunks):
|
132 |
+
chunks = dict(chunks)
|
133 |
+
audio, sr = torchaudio.load(audio_path)
|
134 |
+
if len(audio.shape) == 2 and audio.shape[1] >= 2:
|
135 |
+
audio = torch.mean(audio, dim=0).unsqueeze(0)
|
136 |
+
audio = audio.cpu().numpy()[0]
|
137 |
+
result = []
|
138 |
+
for k, v in chunks.items():
|
139 |
+
tag = v["split_time"].split(",")
|
140 |
+
if tag[0] != tag[1]:
|
141 |
+
result.append((v["slice"], audio[int(tag[0]):int(tag[1])]))
|
142 |
+
return result, sr
|
inference_main.py
ADDED
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import io
|
2 |
+
import logging
|
3 |
+
import time
|
4 |
+
from pathlib import Path
|
5 |
+
|
6 |
+
import librosa
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
import numpy as np
|
9 |
+
import soundfile
|
10 |
+
|
11 |
+
from inference import infer_tool
|
12 |
+
from inference import slicer
|
13 |
+
from inference.infer_tool import Svc
|
14 |
+
|
15 |
+
logging.getLogger('numba').setLevel(logging.WARNING)
|
16 |
+
chunks_dict = infer_tool.read_temp("inference/chunks_temp.json")
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
def main():
|
21 |
+
import argparse
|
22 |
+
|
23 |
+
parser = argparse.ArgumentParser(description='sovits4 inference')
|
24 |
+
|
25 |
+
# 一定要设置的部分
|
26 |
+
parser.add_argument('-m', '--model_path', type=str, default="logs/44k/G_0.pth", help='模型路径')
|
27 |
+
parser.add_argument('-c', '--config_path', type=str, default="configs/config.json", help='配置文件路径')
|
28 |
+
parser.add_argument('-cl', '--clip', type=float, default=0, help='音频强制切片,默认0为自动切片,单位为秒/s')
|
29 |
+
parser.add_argument('-n', '--clean_names', type=str, nargs='+', default=["君の知らない物語-src.wav"], help='wav文件名列表,放在raw文件夹下')
|
30 |
+
parser.add_argument('-t', '--trans', type=int, nargs='+', default=[0], help='音高调整,支持正负(半音)')
|
31 |
+
parser.add_argument('-s', '--spk_list', type=str, nargs='+', default=['nen'], help='合成目标说话人名称')
|
32 |
+
|
33 |
+
# 可选项部分
|
34 |
+
parser.add_argument('-a', '--auto_predict_f0', action='store_true', default=False,help='语音转换自动预测音高,转换歌声时不要打开这个会严重跑调')
|
35 |
+
parser.add_argument('-cm', '--cluster_model_path', type=str, default="logs/44k/kmeans_10000.pt", help='聚类模型路径,如果没有训练聚类则随便填')
|
36 |
+
parser.add_argument('-cr', '--cluster_infer_ratio', type=float, default=0, help='聚类方案占比,范围0-1,若没有训练聚类模型则默认0即可')
|
37 |
+
parser.add_argument('-lg', '--linear_gradient', type=float, default=0, help='两段音频切片的交叉淡入长度,如果强制切片后出现人声不连贯可调整该数值,如果连贯建议采用默认值0,单位为秒')
|
38 |
+
parser.add_argument('-fmp', '--f0_mean_pooling', type=bool, default=False, help='是否对F0使用均值滤波器(池化),对部分哑音有改善。注意,启动该选项会导致推理速度下降,默认关闭')
|
39 |
+
parser.add_argument('-eh', '--enhance', type=bool, default=False, help='是否使用NSF_HIFIGAN增强器,该选项对部分训练集少的模型有一定的音质增强效果,但是对训练好的模型有反面效果,默认关闭')
|
40 |
+
|
41 |
+
# 不用动的部分
|
42 |
+
parser.add_argument('-sd', '--slice_db', type=int, default=-40, help='默认-40,嘈杂的音频可以-30,干声保留呼吸可以-50')
|
43 |
+
parser.add_argument('-d', '--device', type=str, default=None, help='推理设备,None则为自动选择cpu和gpu')
|
44 |
+
parser.add_argument('-ns', '--noice_scale', type=float, default=0.4, help='噪音级别,会影响咬字和音质,较为玄学')
|
45 |
+
parser.add_argument('-p', '--pad_seconds', type=float, default=0.5, help='推理音频pad秒数,由于未知原因开头结尾会有异响,pad一小段静音段后就不会出现')
|
46 |
+
parser.add_argument('-wf', '--wav_format', type=str, default='flac', help='音频输出格式')
|
47 |
+
parser.add_argument('-lgr', '--linear_gradient_retain', type=float, default=0.75, help='自动音频切片后,需要舍弃每段切片的头尾。该参数设置交叉长度保留的比例,范围0-1,左开右闭')
|
48 |
+
parser.add_argument('-eak', '--enhancer_adaptive_key', type=int, default=0, help='使增强器适应更高的音域(单位为半音数)|默认为0')
|
49 |
+
|
50 |
+
args = parser.parse_args()
|
51 |
+
|
52 |
+
clean_names = args.clean_names
|
53 |
+
trans = args.trans
|
54 |
+
spk_list = args.spk_list
|
55 |
+
slice_db = args.slice_db
|
56 |
+
wav_format = args.wav_format
|
57 |
+
auto_predict_f0 = args.auto_predict_f0
|
58 |
+
cluster_infer_ratio = args.cluster_infer_ratio
|
59 |
+
noice_scale = args.noice_scale
|
60 |
+
pad_seconds = args.pad_seconds
|
61 |
+
clip = args.clip
|
62 |
+
lg = args.linear_gradient
|
63 |
+
lgr = args.linear_gradient_retain
|
64 |
+
F0_mean_pooling = args.f0_mean_pooling
|
65 |
+
enhance = args.enhance
|
66 |
+
enhancer_adaptive_key = args.enhancer_adaptive_key
|
67 |
+
|
68 |
+
svc_model = Svc(args.model_path, args.config_path, args.device, args.cluster_model_path,enhance)
|
69 |
+
infer_tool.mkdir(["raw", "results"])
|
70 |
+
|
71 |
+
infer_tool.fill_a_to_b(trans, clean_names)
|
72 |
+
for clean_name, tran in zip(clean_names, trans):
|
73 |
+
raw_audio_path = f"raw/{clean_name}"
|
74 |
+
if "." not in raw_audio_path:
|
75 |
+
raw_audio_path += ".wav"
|
76 |
+
infer_tool.format_wav(raw_audio_path)
|
77 |
+
wav_path = Path(raw_audio_path).with_suffix('.wav')
|
78 |
+
chunks = slicer.cut(wav_path, db_thresh=slice_db)
|
79 |
+
audio_data, audio_sr = slicer.chunks2audio(wav_path, chunks)
|
80 |
+
per_size = int(clip*audio_sr)
|
81 |
+
lg_size = int(lg*audio_sr)
|
82 |
+
lg_size_r = int(lg_size*lgr)
|
83 |
+
lg_size_c_l = (lg_size-lg_size_r)//2
|
84 |
+
lg_size_c_r = lg_size-lg_size_r-lg_size_c_l
|
85 |
+
lg = np.linspace(0,1,lg_size_r) if lg_size!=0 else 0
|
86 |
+
|
87 |
+
for spk in spk_list:
|
88 |
+
audio = []
|
89 |
+
for (slice_tag, data) in audio_data:
|
90 |
+
print(f'#=====segment start, {round(len(data) / audio_sr, 3)}s======')
|
91 |
+
|
92 |
+
length = int(np.ceil(len(data) / audio_sr * svc_model.target_sample))
|
93 |
+
if slice_tag:
|
94 |
+
print('jump empty segment')
|
95 |
+
_audio = np.zeros(length)
|
96 |
+
audio.extend(list(infer_tool.pad_array(_audio, length)))
|
97 |
+
continue
|
98 |
+
if per_size != 0:
|
99 |
+
datas = infer_tool.split_list_by_n(data, per_size,lg_size)
|
100 |
+
else:
|
101 |
+
datas = [data]
|
102 |
+
for k,dat in enumerate(datas):
|
103 |
+
per_length = int(np.ceil(len(dat) / audio_sr * svc_model.target_sample)) if clip!=0 else length
|
104 |
+
if clip!=0: print(f'###=====segment clip start, {round(len(dat) / audio_sr, 3)}s======')
|
105 |
+
# padd
|
106 |
+
pad_len = int(audio_sr * pad_seconds)
|
107 |
+
dat = np.concatenate([np.zeros([pad_len]), dat, np.zeros([pad_len])])
|
108 |
+
raw_path = io.BytesIO()
|
109 |
+
soundfile.write(raw_path, dat, audio_sr, format="wav")
|
110 |
+
raw_path.seek(0)
|
111 |
+
out_audio, out_sr = svc_model.infer(spk, tran, raw_path,
|
112 |
+
cluster_infer_ratio=cluster_infer_ratio,
|
113 |
+
auto_predict_f0=auto_predict_f0,
|
114 |
+
noice_scale=noice_scale,
|
115 |
+
F0_mean_pooling = F0_mean_pooling,
|
116 |
+
enhancer_adaptive_key = enhancer_adaptive_key
|
117 |
+
)
|
118 |
+
_audio = out_audio.cpu().numpy()
|
119 |
+
pad_len = int(svc_model.target_sample * pad_seconds)
|
120 |
+
_audio = _audio[pad_len:-pad_len]
|
121 |
+
_audio = infer_tool.pad_array(_audio, per_length)
|
122 |
+
if lg_size!=0 and k!=0:
|
123 |
+
lg1 = audio[-(lg_size_r+lg_size_c_r):-lg_size_c_r] if lgr != 1 else audio[-lg_size:]
|
124 |
+
lg2 = _audio[lg_size_c_l:lg_size_c_l+lg_size_r] if lgr != 1 else _audio[0:lg_size]
|
125 |
+
lg_pre = lg1*(1-lg)+lg2*lg
|
126 |
+
audio = audio[0:-(lg_size_r+lg_size_c_r)] if lgr != 1 else audio[0:-lg_size]
|
127 |
+
audio.extend(lg_pre)
|
128 |
+
_audio = _audio[lg_size_c_l+lg_size_r:] if lgr != 1 else _audio[lg_size:]
|
129 |
+
audio.extend(list(_audio))
|
130 |
+
key = "auto" if auto_predict_f0 else f"{tran}key"
|
131 |
+
cluster_name = "" if cluster_infer_ratio == 0 else f"_{cluster_infer_ratio}"
|
132 |
+
res_path = f'./results/{clean_name}_{key}_{spk}{cluster_name}.{wav_format}'
|
133 |
+
soundfile.write(res_path, audio, svc_model.target_sample, format=wav_format)
|
134 |
+
svc_model.clear_empty()
|
135 |
+
|
136 |
+
if __name__ == '__main__':
|
137 |
+
main()
|
logs/44k/G_32000.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f0f19cbee4624c6ef0f4021f582f52bc33d5f03fda6f22d7d5ff2ff561bd6b3e
|
3 |
+
size 542178141
|
logs/44k/G_55000.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:968fcecab127bd0921b11bdacd746e2623dee9154a57ae943401128cfe40073c
|
3 |
+
size 542178141
|
logs/44k/G_62000.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1d664125574ef3277d7d72125c2cd1a07977eddac3aedc32e7dd64fe073c4b47
|
3 |
+
size 542178141
|
logs/44k/config.json
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 200,
|
4 |
+
"eval_interval": 1000,
|
5 |
+
"seed": 1234,
|
6 |
+
"epochs": 10000,
|
7 |
+
"learning_rate": 0.0002,
|
8 |
+
"betas": [
|
9 |
+
0.8,
|
10 |
+
0.99
|
11 |
+
],
|
12 |
+
"eps": 1e-09,
|
13 |
+
"batch_size": 12,
|
14 |
+
"fp16_run": false,
|
15 |
+
"lr_decay": 0.999875,
|
16 |
+
"segment_size": 10240,
|
17 |
+
"init_lr_ratio": 1,
|
18 |
+
"warmup_epochs": 0,
|
19 |
+
"c_mel": 45,
|
20 |
+
"c_kl": 1.0,
|
21 |
+
"use_sr": true,
|
22 |
+
"max_speclen": 512,
|
23 |
+
"port": "8001",
|
24 |
+
"keep_ckpts": 0,
|
25 |
+
"all_in_mem": false
|
26 |
+
},
|
27 |
+
"data": {
|
28 |
+
"training_files": "filelists/train.txt",
|
29 |
+
"validation_files": "filelists/val.txt",
|
30 |
+
"max_wav_value": 32768.0,
|
31 |
+
"sampling_rate": 44100,
|
32 |
+
"filter_length": 2048,
|
33 |
+
"hop_length": 512,
|
34 |
+
"win_length": 2048,
|
35 |
+
"n_mel_channels": 80,
|
36 |
+
"mel_fmin": 0.0,
|
37 |
+
"mel_fmax": 22050
|
38 |
+
},
|
39 |
+
"model": {
|
40 |
+
"inter_channels": 192,
|
41 |
+
"hidden_channels": 192,
|
42 |
+
"filter_channels": 768,
|
43 |
+
"n_heads": 2,
|
44 |
+
"n_layers": 6,
|
45 |
+
"kernel_size": 3,
|
46 |
+
"p_dropout": 0.1,
|
47 |
+
"resblock": "1",
|
48 |
+
"resblock_kernel_sizes": [
|
49 |
+
3,
|
50 |
+
7,
|
51 |
+
11
|
52 |
+
],
|
53 |
+
"resblock_dilation_sizes": [
|
54 |
+
[
|
55 |
+
1,
|
56 |
+
3,
|
57 |
+
5
|
58 |
+
],
|
59 |
+
[
|
60 |
+
1,
|
61 |
+
3,
|
62 |
+
5
|
63 |
+
],
|
64 |
+
[
|
65 |
+
1,
|
66 |
+
3,
|
67 |
+
5
|
68 |
+
]
|
69 |
+
],
|
70 |
+
"upsample_rates": [
|
71 |
+
8,
|
72 |
+
8,
|
73 |
+
2,
|
74 |
+
2,
|
75 |
+
2
|
76 |
+
],
|
77 |
+
"upsample_initial_channel": 512,
|
78 |
+
"upsample_kernel_sizes": [
|
79 |
+
16,
|
80 |
+
16,
|
81 |
+
4,
|
82 |
+
4,
|
83 |
+
4
|
84 |
+
],
|
85 |
+
"n_layers_q": 3,
|
86 |
+
"use_spectral_norm": false,
|
87 |
+
"gin_channels": 256,
|
88 |
+
"ssl_dim": 256,
|
89 |
+
"n_speakers": 1
|
90 |
+
},
|
91 |
+
"spk": {
|
92 |
+
"XT3.2": 0
|
93 |
+
}
|
94 |
+
}
|
logs/44k/kmeans_10000.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a3c52918842e4cc73e0d1d01627e8303ee103b059d93774a608ae5964a2df4f0
|
3 |
+
size 15432185
|
models.py
ADDED
@@ -0,0 +1,420 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
import math
|
3 |
+
import torch
|
4 |
+
from torch import nn
|
5 |
+
from torch.nn import functional as F
|
6 |
+
|
7 |
+
import modules.attentions as attentions
|
8 |
+
import modules.commons as commons
|
9 |
+
import modules.modules as modules
|
10 |
+
|
11 |
+
from torch.nn import Conv1d, ConvTranspose1d, AvgPool1d, Conv2d
|
12 |
+
from torch.nn.utils import weight_norm, remove_weight_norm, spectral_norm
|
13 |
+
|
14 |
+
import utils
|
15 |
+
from modules.commons import init_weights, get_padding
|
16 |
+
from vdecoder.hifigan.models import Generator
|
17 |
+
from utils import f0_to_coarse
|
18 |
+
|
19 |
+
class ResidualCouplingBlock(nn.Module):
|
20 |
+
def __init__(self,
|
21 |
+
channels,
|
22 |
+
hidden_channels,
|
23 |
+
kernel_size,
|
24 |
+
dilation_rate,
|
25 |
+
n_layers,
|
26 |
+
n_flows=4,
|
27 |
+
gin_channels=0):
|
28 |
+
super().__init__()
|
29 |
+
self.channels = channels
|
30 |
+
self.hidden_channels = hidden_channels
|
31 |
+
self.kernel_size = kernel_size
|
32 |
+
self.dilation_rate = dilation_rate
|
33 |
+
self.n_layers = n_layers
|
34 |
+
self.n_flows = n_flows
|
35 |
+
self.gin_channels = gin_channels
|
36 |
+
|
37 |
+
self.flows = nn.ModuleList()
|
38 |
+
for i in range(n_flows):
|
39 |
+
self.flows.append(modules.ResidualCouplingLayer(channels, hidden_channels, kernel_size, dilation_rate, n_layers, gin_channels=gin_channels, mean_only=True))
|
40 |
+
self.flows.append(modules.Flip())
|
41 |
+
|
42 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
43 |
+
if not reverse:
|
44 |
+
for flow in self.flows:
|
45 |
+
x, _ = flow(x, x_mask, g=g, reverse=reverse)
|
46 |
+
else:
|
47 |
+
for flow in reversed(self.flows):
|
48 |
+
x = flow(x, x_mask, g=g, reverse=reverse)
|
49 |
+
return x
|
50 |
+
|
51 |
+
|
52 |
+
class Encoder(nn.Module):
|
53 |
+
def __init__(self,
|
54 |
+
in_channels,
|
55 |
+
out_channels,
|
56 |
+
hidden_channels,
|
57 |
+
kernel_size,
|
58 |
+
dilation_rate,
|
59 |
+
n_layers,
|
60 |
+
gin_channels=0):
|
61 |
+
super().__init__()
|
62 |
+
self.in_channels = in_channels
|
63 |
+
self.out_channels = out_channels
|
64 |
+
self.hidden_channels = hidden_channels
|
65 |
+
self.kernel_size = kernel_size
|
66 |
+
self.dilation_rate = dilation_rate
|
67 |
+
self.n_layers = n_layers
|
68 |
+
self.gin_channels = gin_channels
|
69 |
+
|
70 |
+
self.pre = nn.Conv1d(in_channels, hidden_channels, 1)
|
71 |
+
self.enc = modules.WN(hidden_channels, kernel_size, dilation_rate, n_layers, gin_channels=gin_channels)
|
72 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels * 2, 1)
|
73 |
+
|
74 |
+
def forward(self, x, x_lengths, g=None):
|
75 |
+
# print(x.shape,x_lengths.shape)
|
76 |
+
x_mask = torch.unsqueeze(commons.sequence_mask(x_lengths, x.size(2)), 1).to(x.dtype)
|
77 |
+
x = self.pre(x) * x_mask
|
78 |
+
x = self.enc(x, x_mask, g=g)
|
79 |
+
stats = self.proj(x) * x_mask
|
80 |
+
m, logs = torch.split(stats, self.out_channels, dim=1)
|
81 |
+
z = (m + torch.randn_like(m) * torch.exp(logs)) * x_mask
|
82 |
+
return z, m, logs, x_mask
|
83 |
+
|
84 |
+
|
85 |
+
class TextEncoder(nn.Module):
|
86 |
+
def __init__(self,
|
87 |
+
out_channels,
|
88 |
+
hidden_channels,
|
89 |
+
kernel_size,
|
90 |
+
n_layers,
|
91 |
+
gin_channels=0,
|
92 |
+
filter_channels=None,
|
93 |
+
n_heads=None,
|
94 |
+
p_dropout=None):
|
95 |
+
super().__init__()
|
96 |
+
self.out_channels = out_channels
|
97 |
+
self.hidden_channels = hidden_channels
|
98 |
+
self.kernel_size = kernel_size
|
99 |
+
self.n_layers = n_layers
|
100 |
+
self.gin_channels = gin_channels
|
101 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels * 2, 1)
|
102 |
+
self.f0_emb = nn.Embedding(256, hidden_channels)
|
103 |
+
|
104 |
+
self.enc_ = attentions.Encoder(
|
105 |
+
hidden_channels,
|
106 |
+
filter_channels,
|
107 |
+
n_heads,
|
108 |
+
n_layers,
|
109 |
+
kernel_size,
|
110 |
+
p_dropout)
|
111 |
+
|
112 |
+
def forward(self, x, x_mask, f0=None, noice_scale=1):
|
113 |
+
x = x + self.f0_emb(f0).transpose(1,2)
|
114 |
+
x = self.enc_(x * x_mask, x_mask)
|
115 |
+
stats = self.proj(x) * x_mask
|
116 |
+
m, logs = torch.split(stats, self.out_channels, dim=1)
|
117 |
+
z = (m + torch.randn_like(m) * torch.exp(logs) * noice_scale) * x_mask
|
118 |
+
|
119 |
+
return z, m, logs, x_mask
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
+
class DiscriminatorP(torch.nn.Module):
|
124 |
+
def __init__(self, period, kernel_size=5, stride=3, use_spectral_norm=False):
|
125 |
+
super(DiscriminatorP, self).__init__()
|
126 |
+
self.period = period
|
127 |
+
self.use_spectral_norm = use_spectral_norm
|
128 |
+
norm_f = weight_norm if use_spectral_norm == False else spectral_norm
|
129 |
+
self.convs = nn.ModuleList([
|
130 |
+
norm_f(Conv2d(1, 32, (kernel_size, 1), (stride, 1), padding=(get_padding(kernel_size, 1), 0))),
|
131 |
+
norm_f(Conv2d(32, 128, (kernel_size, 1), (stride, 1), padding=(get_padding(kernel_size, 1), 0))),
|
132 |
+
norm_f(Conv2d(128, 512, (kernel_size, 1), (stride, 1), padding=(get_padding(kernel_size, 1), 0))),
|
133 |
+
norm_f(Conv2d(512, 1024, (kernel_size, 1), (stride, 1), padding=(get_padding(kernel_size, 1), 0))),
|
134 |
+
norm_f(Conv2d(1024, 1024, (kernel_size, 1), 1, padding=(get_padding(kernel_size, 1), 0))),
|
135 |
+
])
|
136 |
+
self.conv_post = norm_f(Conv2d(1024, 1, (3, 1), 1, padding=(1, 0)))
|
137 |
+
|
138 |
+
def forward(self, x):
|
139 |
+
fmap = []
|
140 |
+
|
141 |
+
# 1d to 2d
|
142 |
+
b, c, t = x.shape
|
143 |
+
if t % self.period != 0: # pad first
|
144 |
+
n_pad = self.period - (t % self.period)
|
145 |
+
x = F.pad(x, (0, n_pad), "reflect")
|
146 |
+
t = t + n_pad
|
147 |
+
x = x.view(b, c, t // self.period, self.period)
|
148 |
+
|
149 |
+
for l in self.convs:
|
150 |
+
x = l(x)
|
151 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
152 |
+
fmap.append(x)
|
153 |
+
x = self.conv_post(x)
|
154 |
+
fmap.append(x)
|
155 |
+
x = torch.flatten(x, 1, -1)
|
156 |
+
|
157 |
+
return x, fmap
|
158 |
+
|
159 |
+
|
160 |
+
class DiscriminatorS(torch.nn.Module):
|
161 |
+
def __init__(self, use_spectral_norm=False):
|
162 |
+
super(DiscriminatorS, self).__init__()
|
163 |
+
norm_f = weight_norm if use_spectral_norm == False else spectral_norm
|
164 |
+
self.convs = nn.ModuleList([
|
165 |
+
norm_f(Conv1d(1, 16, 15, 1, padding=7)),
|
166 |
+
norm_f(Conv1d(16, 64, 41, 4, groups=4, padding=20)),
|
167 |
+
norm_f(Conv1d(64, 256, 41, 4, groups=16, padding=20)),
|
168 |
+
norm_f(Conv1d(256, 1024, 41, 4, groups=64, padding=20)),
|
169 |
+
norm_f(Conv1d(1024, 1024, 41, 4, groups=256, padding=20)),
|
170 |
+
norm_f(Conv1d(1024, 1024, 5, 1, padding=2)),
|
171 |
+
])
|
172 |
+
self.conv_post = norm_f(Conv1d(1024, 1, 3, 1, padding=1))
|
173 |
+
|
174 |
+
def forward(self, x):
|
175 |
+
fmap = []
|
176 |
+
|
177 |
+
for l in self.convs:
|
178 |
+
x = l(x)
|
179 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
180 |
+
fmap.append(x)
|
181 |
+
x = self.conv_post(x)
|
182 |
+
fmap.append(x)
|
183 |
+
x = torch.flatten(x, 1, -1)
|
184 |
+
|
185 |
+
return x, fmap
|
186 |
+
|
187 |
+
|
188 |
+
class MultiPeriodDiscriminator(torch.nn.Module):
|
189 |
+
def __init__(self, use_spectral_norm=False):
|
190 |
+
super(MultiPeriodDiscriminator, self).__init__()
|
191 |
+
periods = [2,3,5,7,11]
|
192 |
+
|
193 |
+
discs = [DiscriminatorS(use_spectral_norm=use_spectral_norm)]
|
194 |
+
discs = discs + [DiscriminatorP(i, use_spectral_norm=use_spectral_norm) for i in periods]
|
195 |
+
self.discriminators = nn.ModuleList(discs)
|
196 |
+
|
197 |
+
def forward(self, y, y_hat):
|
198 |
+
y_d_rs = []
|
199 |
+
y_d_gs = []
|
200 |
+
fmap_rs = []
|
201 |
+
fmap_gs = []
|
202 |
+
for i, d in enumerate(self.discriminators):
|
203 |
+
y_d_r, fmap_r = d(y)
|
204 |
+
y_d_g, fmap_g = d(y_hat)
|
205 |
+
y_d_rs.append(y_d_r)
|
206 |
+
y_d_gs.append(y_d_g)
|
207 |
+
fmap_rs.append(fmap_r)
|
208 |
+
fmap_gs.append(fmap_g)
|
209 |
+
|
210 |
+
return y_d_rs, y_d_gs, fmap_rs, fmap_gs
|
211 |
+
|
212 |
+
|
213 |
+
class SpeakerEncoder(torch.nn.Module):
|
214 |
+
def __init__(self, mel_n_channels=80, model_num_layers=3, model_hidden_size=256, model_embedding_size=256):
|
215 |
+
super(SpeakerEncoder, self).__init__()
|
216 |
+
self.lstm = nn.LSTM(mel_n_channels, model_hidden_size, model_num_layers, batch_first=True)
|
217 |
+
self.linear = nn.Linear(model_hidden_size, model_embedding_size)
|
218 |
+
self.relu = nn.ReLU()
|
219 |
+
|
220 |
+
def forward(self, mels):
|
221 |
+
self.lstm.flatten_parameters()
|
222 |
+
_, (hidden, _) = self.lstm(mels)
|
223 |
+
embeds_raw = self.relu(self.linear(hidden[-1]))
|
224 |
+
return embeds_raw / torch.norm(embeds_raw, dim=1, keepdim=True)
|
225 |
+
|
226 |
+
def compute_partial_slices(self, total_frames, partial_frames, partial_hop):
|
227 |
+
mel_slices = []
|
228 |
+
for i in range(0, total_frames-partial_frames, partial_hop):
|
229 |
+
mel_range = torch.arange(i, i+partial_frames)
|
230 |
+
mel_slices.append(mel_range)
|
231 |
+
|
232 |
+
return mel_slices
|
233 |
+
|
234 |
+
def embed_utterance(self, mel, partial_frames=128, partial_hop=64):
|
235 |
+
mel_len = mel.size(1)
|
236 |
+
last_mel = mel[:,-partial_frames:]
|
237 |
+
|
238 |
+
if mel_len > partial_frames:
|
239 |
+
mel_slices = self.compute_partial_slices(mel_len, partial_frames, partial_hop)
|
240 |
+
mels = list(mel[:,s] for s in mel_slices)
|
241 |
+
mels.append(last_mel)
|
242 |
+
mels = torch.stack(tuple(mels), 0).squeeze(1)
|
243 |
+
|
244 |
+
with torch.no_grad():
|
245 |
+
partial_embeds = self(mels)
|
246 |
+
embed = torch.mean(partial_embeds, axis=0).unsqueeze(0)
|
247 |
+
#embed = embed / torch.linalg.norm(embed, 2)
|
248 |
+
else:
|
249 |
+
with torch.no_grad():
|
250 |
+
embed = self(last_mel)
|
251 |
+
|
252 |
+
return embed
|
253 |
+
|
254 |
+
class F0Decoder(nn.Module):
|
255 |
+
def __init__(self,
|
256 |
+
out_channels,
|
257 |
+
hidden_channels,
|
258 |
+
filter_channels,
|
259 |
+
n_heads,
|
260 |
+
n_layers,
|
261 |
+
kernel_size,
|
262 |
+
p_dropout,
|
263 |
+
spk_channels=0):
|
264 |
+
super().__init__()
|
265 |
+
self.out_channels = out_channels
|
266 |
+
self.hidden_channels = hidden_channels
|
267 |
+
self.filter_channels = filter_channels
|
268 |
+
self.n_heads = n_heads
|
269 |
+
self.n_layers = n_layers
|
270 |
+
self.kernel_size = kernel_size
|
271 |
+
self.p_dropout = p_dropout
|
272 |
+
self.spk_channels = spk_channels
|
273 |
+
|
274 |
+
self.prenet = nn.Conv1d(hidden_channels, hidden_channels, 3, padding=1)
|
275 |
+
self.decoder = attentions.FFT(
|
276 |
+
hidden_channels,
|
277 |
+
filter_channels,
|
278 |
+
n_heads,
|
279 |
+
n_layers,
|
280 |
+
kernel_size,
|
281 |
+
p_dropout)
|
282 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels, 1)
|
283 |
+
self.f0_prenet = nn.Conv1d(1, hidden_channels , 3, padding=1)
|
284 |
+
self.cond = nn.Conv1d(spk_channels, hidden_channels, 1)
|
285 |
+
|
286 |
+
def forward(self, x, norm_f0, x_mask, spk_emb=None):
|
287 |
+
x = torch.detach(x)
|
288 |
+
if (spk_emb is not None):
|
289 |
+
x = x + self.cond(spk_emb)
|
290 |
+
x += self.f0_prenet(norm_f0)
|
291 |
+
x = self.prenet(x) * x_mask
|
292 |
+
x = self.decoder(x * x_mask, x_mask)
|
293 |
+
x = self.proj(x) * x_mask
|
294 |
+
return x
|
295 |
+
|
296 |
+
|
297 |
+
class SynthesizerTrn(nn.Module):
|
298 |
+
"""
|
299 |
+
Synthesizer for Training
|
300 |
+
"""
|
301 |
+
|
302 |
+
def __init__(self,
|
303 |
+
spec_channels,
|
304 |
+
segment_size,
|
305 |
+
inter_channels,
|
306 |
+
hidden_channels,
|
307 |
+
filter_channels,
|
308 |
+
n_heads,
|
309 |
+
n_layers,
|
310 |
+
kernel_size,
|
311 |
+
p_dropout,
|
312 |
+
resblock,
|
313 |
+
resblock_kernel_sizes,
|
314 |
+
resblock_dilation_sizes,
|
315 |
+
upsample_rates,
|
316 |
+
upsample_initial_channel,
|
317 |
+
upsample_kernel_sizes,
|
318 |
+
gin_channels,
|
319 |
+
ssl_dim,
|
320 |
+
n_speakers,
|
321 |
+
sampling_rate=44100,
|
322 |
+
**kwargs):
|
323 |
+
|
324 |
+
super().__init__()
|
325 |
+
self.spec_channels = spec_channels
|
326 |
+
self.inter_channels = inter_channels
|
327 |
+
self.hidden_channels = hidden_channels
|
328 |
+
self.filter_channels = filter_channels
|
329 |
+
self.n_heads = n_heads
|
330 |
+
self.n_layers = n_layers
|
331 |
+
self.kernel_size = kernel_size
|
332 |
+
self.p_dropout = p_dropout
|
333 |
+
self.resblock = resblock
|
334 |
+
self.resblock_kernel_sizes = resblock_kernel_sizes
|
335 |
+
self.resblock_dilation_sizes = resblock_dilation_sizes
|
336 |
+
self.upsample_rates = upsample_rates
|
337 |
+
self.upsample_initial_channel = upsample_initial_channel
|
338 |
+
self.upsample_kernel_sizes = upsample_kernel_sizes
|
339 |
+
self.segment_size = segment_size
|
340 |
+
self.gin_channels = gin_channels
|
341 |
+
self.ssl_dim = ssl_dim
|
342 |
+
self.emb_g = nn.Embedding(n_speakers, gin_channels)
|
343 |
+
|
344 |
+
self.pre = nn.Conv1d(ssl_dim, hidden_channels, kernel_size=5, padding=2)
|
345 |
+
|
346 |
+
self.enc_p = TextEncoder(
|
347 |
+
inter_channels,
|
348 |
+
hidden_channels,
|
349 |
+
filter_channels=filter_channels,
|
350 |
+
n_heads=n_heads,
|
351 |
+
n_layers=n_layers,
|
352 |
+
kernel_size=kernel_size,
|
353 |
+
p_dropout=p_dropout
|
354 |
+
)
|
355 |
+
hps = {
|
356 |
+
"sampling_rate": sampling_rate,
|
357 |
+
"inter_channels": inter_channels,
|
358 |
+
"resblock": resblock,
|
359 |
+
"resblock_kernel_sizes": resblock_kernel_sizes,
|
360 |
+
"resblock_dilation_sizes": resblock_dilation_sizes,
|
361 |
+
"upsample_rates": upsample_rates,
|
362 |
+
"upsample_initial_channel": upsample_initial_channel,
|
363 |
+
"upsample_kernel_sizes": upsample_kernel_sizes,
|
364 |
+
"gin_channels": gin_channels,
|
365 |
+
}
|
366 |
+
self.dec = Generator(h=hps)
|
367 |
+
self.enc_q = Encoder(spec_channels, inter_channels, hidden_channels, 5, 1, 16, gin_channels=gin_channels)
|
368 |
+
self.flow = ResidualCouplingBlock(inter_channels, hidden_channels, 5, 1, 4, gin_channels=gin_channels)
|
369 |
+
self.f0_decoder = F0Decoder(
|
370 |
+
1,
|
371 |
+
hidden_channels,
|
372 |
+
filter_channels,
|
373 |
+
n_heads,
|
374 |
+
n_layers,
|
375 |
+
kernel_size,
|
376 |
+
p_dropout,
|
377 |
+
spk_channels=gin_channels
|
378 |
+
)
|
379 |
+
self.emb_uv = nn.Embedding(2, hidden_channels)
|
380 |
+
|
381 |
+
def forward(self, c, f0, uv, spec, g=None, c_lengths=None, spec_lengths=None):
|
382 |
+
g = self.emb_g(g).transpose(1,2)
|
383 |
+
# ssl prenet
|
384 |
+
x_mask = torch.unsqueeze(commons.sequence_mask(c_lengths, c.size(2)), 1).to(c.dtype)
|
385 |
+
x = self.pre(c) * x_mask + self.emb_uv(uv.long()).transpose(1,2)
|
386 |
+
|
387 |
+
# f0 predict
|
388 |
+
lf0 = 2595. * torch.log10(1. + f0.unsqueeze(1) / 700.) / 500
|
389 |
+
norm_lf0 = utils.normalize_f0(lf0, x_mask, uv)
|
390 |
+
pred_lf0 = self.f0_decoder(x, norm_lf0, x_mask, spk_emb=g)
|
391 |
+
|
392 |
+
# encoder
|
393 |
+
z_ptemp, m_p, logs_p, _ = self.enc_p(x, x_mask, f0=f0_to_coarse(f0))
|
394 |
+
z, m_q, logs_q, spec_mask = self.enc_q(spec, spec_lengths, g=g)
|
395 |
+
|
396 |
+
# flow
|
397 |
+
z_p = self.flow(z, spec_mask, g=g)
|
398 |
+
z_slice, pitch_slice, ids_slice = commons.rand_slice_segments_with_pitch(z, f0, spec_lengths, self.segment_size)
|
399 |
+
|
400 |
+
# nsf decoder
|
401 |
+
o = self.dec(z_slice, g=g, f0=pitch_slice)
|
402 |
+
|
403 |
+
return o, ids_slice, spec_mask, (z, z_p, m_p, logs_p, m_q, logs_q), pred_lf0, norm_lf0, lf0
|
404 |
+
|
405 |
+
def infer(self, c, f0, uv, g=None, noice_scale=0.35, predict_f0=False):
|
406 |
+
c_lengths = (torch.ones(c.size(0)) * c.size(-1)).to(c.device)
|
407 |
+
g = self.emb_g(g).transpose(1,2)
|
408 |
+
x_mask = torch.unsqueeze(commons.sequence_mask(c_lengths, c.size(2)), 1).to(c.dtype)
|
409 |
+
x = self.pre(c) * x_mask + self.emb_uv(uv.long()).transpose(1,2)
|
410 |
+
|
411 |
+
if predict_f0:
|
412 |
+
lf0 = 2595. * torch.log10(1. + f0.unsqueeze(1) / 700.) / 500
|
413 |
+
norm_lf0 = utils.normalize_f0(lf0, x_mask, uv, random_scale=False)
|
414 |
+
pred_lf0 = self.f0_decoder(x, norm_lf0, x_mask, spk_emb=g)
|
415 |
+
f0 = (700 * (torch.pow(10, pred_lf0 * 500 / 2595) - 1)).squeeze(1)
|
416 |
+
|
417 |
+
z_p, m_p, logs_p, c_mask = self.enc_p(x, x_mask, f0=f0_to_coarse(f0), noice_scale=noice_scale)
|
418 |
+
z = self.flow(z_p, c_mask, g=g, reverse=True)
|
419 |
+
o = self.dec(z * c_mask, g=g, f0=f0)
|
420 |
+
return o
|
models_backup/123.txt
ADDED
File without changes
|
modules/__init__.py
ADDED
File without changes
|
modules/__pycache__/__init__.cpython-38.pyc
ADDED
Binary file (125 Bytes). View file
|
|
modules/__pycache__/attentions.cpython-38.pyc
ADDED
Binary file (10.6 kB). View file
|
|
modules/__pycache__/commons.cpython-38.pyc
ADDED
Binary file (6.62 kB). View file
|
|
modules/__pycache__/crepe.cpython-38.pyc
ADDED
Binary file (8.7 kB). View file
|
|
modules/__pycache__/enhancer.cpython-38.pyc
ADDED
Binary file (3.34 kB). View file
|
|
modules/__pycache__/losses.cpython-38.pyc
ADDED
Binary file (1.53 kB). View file
|
|
modules/__pycache__/mel_processing.cpython-38.pyc
ADDED
Binary file (3.45 kB). View file
|
|
modules/__pycache__/modules.cpython-38.pyc
ADDED
Binary file (10.1 kB). View file
|
|
modules/attentions.py
ADDED
@@ -0,0 +1,349 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
import math
|
3 |
+
import numpy as np
|
4 |
+
import torch
|
5 |
+
from torch import nn
|
6 |
+
from torch.nn import functional as F
|
7 |
+
|
8 |
+
import modules.commons as commons
|
9 |
+
import modules.modules as modules
|
10 |
+
from modules.modules import LayerNorm
|
11 |
+
|
12 |
+
|
13 |
+
class FFT(nn.Module):
|
14 |
+
def __init__(self, hidden_channels, filter_channels, n_heads, n_layers=1, kernel_size=1, p_dropout=0.,
|
15 |
+
proximal_bias=False, proximal_init=True, **kwargs):
|
16 |
+
super().__init__()
|
17 |
+
self.hidden_channels = hidden_channels
|
18 |
+
self.filter_channels = filter_channels
|
19 |
+
self.n_heads = n_heads
|
20 |
+
self.n_layers = n_layers
|
21 |
+
self.kernel_size = kernel_size
|
22 |
+
self.p_dropout = p_dropout
|
23 |
+
self.proximal_bias = proximal_bias
|
24 |
+
self.proximal_init = proximal_init
|
25 |
+
|
26 |
+
self.drop = nn.Dropout(p_dropout)
|
27 |
+
self.self_attn_layers = nn.ModuleList()
|
28 |
+
self.norm_layers_0 = nn.ModuleList()
|
29 |
+
self.ffn_layers = nn.ModuleList()
|
30 |
+
self.norm_layers_1 = nn.ModuleList()
|
31 |
+
for i in range(self.n_layers):
|
32 |
+
self.self_attn_layers.append(
|
33 |
+
MultiHeadAttention(hidden_channels, hidden_channels, n_heads, p_dropout=p_dropout, proximal_bias=proximal_bias,
|
34 |
+
proximal_init=proximal_init))
|
35 |
+
self.norm_layers_0.append(LayerNorm(hidden_channels))
|
36 |
+
self.ffn_layers.append(
|
37 |
+
FFN(hidden_channels, hidden_channels, filter_channels, kernel_size, p_dropout=p_dropout, causal=True))
|
38 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
39 |
+
|
40 |
+
def forward(self, x, x_mask):
|
41 |
+
"""
|
42 |
+
x: decoder input
|
43 |
+
h: encoder output
|
44 |
+
"""
|
45 |
+
self_attn_mask = commons.subsequent_mask(x_mask.size(2)).to(device=x.device, dtype=x.dtype)
|
46 |
+
x = x * x_mask
|
47 |
+
for i in range(self.n_layers):
|
48 |
+
y = self.self_attn_layers[i](x, x, self_attn_mask)
|
49 |
+
y = self.drop(y)
|
50 |
+
x = self.norm_layers_0[i](x + y)
|
51 |
+
|
52 |
+
y = self.ffn_layers[i](x, x_mask)
|
53 |
+
y = self.drop(y)
|
54 |
+
x = self.norm_layers_1[i](x + y)
|
55 |
+
x = x * x_mask
|
56 |
+
return x
|
57 |
+
|
58 |
+
|
59 |
+
class Encoder(nn.Module):
|
60 |
+
def __init__(self, hidden_channels, filter_channels, n_heads, n_layers, kernel_size=1, p_dropout=0., window_size=4, **kwargs):
|
61 |
+
super().__init__()
|
62 |
+
self.hidden_channels = hidden_channels
|
63 |
+
self.filter_channels = filter_channels
|
64 |
+
self.n_heads = n_heads
|
65 |
+
self.n_layers = n_layers
|
66 |
+
self.kernel_size = kernel_size
|
67 |
+
self.p_dropout = p_dropout
|
68 |
+
self.window_size = window_size
|
69 |
+
|
70 |
+
self.drop = nn.Dropout(p_dropout)
|
71 |
+
self.attn_layers = nn.ModuleList()
|
72 |
+
self.norm_layers_1 = nn.ModuleList()
|
73 |
+
self.ffn_layers = nn.ModuleList()
|
74 |
+
self.norm_layers_2 = nn.ModuleList()
|
75 |
+
for i in range(self.n_layers):
|
76 |
+
self.attn_layers.append(MultiHeadAttention(hidden_channels, hidden_channels, n_heads, p_dropout=p_dropout, window_size=window_size))
|
77 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
78 |
+
self.ffn_layers.append(FFN(hidden_channels, hidden_channels, filter_channels, kernel_size, p_dropout=p_dropout))
|
79 |
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
80 |
+
|
81 |
+
def forward(self, x, x_mask):
|
82 |
+
attn_mask = x_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
83 |
+
x = x * x_mask
|
84 |
+
for i in range(self.n_layers):
|
85 |
+
y = self.attn_layers[i](x, x, attn_mask)
|
86 |
+
y = self.drop(y)
|
87 |
+
x = self.norm_layers_1[i](x + y)
|
88 |
+
|
89 |
+
y = self.ffn_layers[i](x, x_mask)
|
90 |
+
y = self.drop(y)
|
91 |
+
x = self.norm_layers_2[i](x + y)
|
92 |
+
x = x * x_mask
|
93 |
+
return x
|
94 |
+
|
95 |
+
|
96 |
+
class Decoder(nn.Module):
|
97 |
+
def __init__(self, hidden_channels, filter_channels, n_heads, n_layers, kernel_size=1, p_dropout=0., proximal_bias=False, proximal_init=True, **kwargs):
|
98 |
+
super().__init__()
|
99 |
+
self.hidden_channels = hidden_channels
|
100 |
+
self.filter_channels = filter_channels
|
101 |
+
self.n_heads = n_heads
|
102 |
+
self.n_layers = n_layers
|
103 |
+
self.kernel_size = kernel_size
|
104 |
+
self.p_dropout = p_dropout
|
105 |
+
self.proximal_bias = proximal_bias
|
106 |
+
self.proximal_init = proximal_init
|
107 |
+
|
108 |
+
self.drop = nn.Dropout(p_dropout)
|
109 |
+
self.self_attn_layers = nn.ModuleList()
|
110 |
+
self.norm_layers_0 = nn.ModuleList()
|
111 |
+
self.encdec_attn_layers = nn.ModuleList()
|
112 |
+
self.norm_layers_1 = nn.ModuleList()
|
113 |
+
self.ffn_layers = nn.ModuleList()
|
114 |
+
self.norm_layers_2 = nn.ModuleList()
|
115 |
+
for i in range(self.n_layers):
|
116 |
+
self.self_attn_layers.append(MultiHeadAttention(hidden_channels, hidden_channels, n_heads, p_dropout=p_dropout, proximal_bias=proximal_bias, proximal_init=proximal_init))
|
117 |
+
self.norm_layers_0.append(LayerNorm(hidden_channels))
|
118 |
+
self.encdec_attn_layers.append(MultiHeadAttention(hidden_channels, hidden_channels, n_heads, p_dropout=p_dropout))
|
119 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
120 |
+
self.ffn_layers.append(FFN(hidden_channels, hidden_channels, filter_channels, kernel_size, p_dropout=p_dropout, causal=True))
|
121 |
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
122 |
+
|
123 |
+
def forward(self, x, x_mask, h, h_mask):
|
124 |
+
"""
|
125 |
+
x: decoder input
|
126 |
+
h: encoder output
|
127 |
+
"""
|
128 |
+
self_attn_mask = commons.subsequent_mask(x_mask.size(2)).to(device=x.device, dtype=x.dtype)
|
129 |
+
encdec_attn_mask = h_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
130 |
+
x = x * x_mask
|
131 |
+
for i in range(self.n_layers):
|
132 |
+
y = self.self_attn_layers[i](x, x, self_attn_mask)
|
133 |
+
y = self.drop(y)
|
134 |
+
x = self.norm_layers_0[i](x + y)
|
135 |
+
|
136 |
+
y = self.encdec_attn_layers[i](x, h, encdec_attn_mask)
|
137 |
+
y = self.drop(y)
|
138 |
+
x = self.norm_layers_1[i](x + y)
|
139 |
+
|
140 |
+
y = self.ffn_layers[i](x, x_mask)
|
141 |
+
y = self.drop(y)
|
142 |
+
x = self.norm_layers_2[i](x + y)
|
143 |
+
x = x * x_mask
|
144 |
+
return x
|
145 |
+
|
146 |
+
|
147 |
+
class MultiHeadAttention(nn.Module):
|
148 |
+
def __init__(self, channels, out_channels, n_heads, p_dropout=0., window_size=None, heads_share=True, block_length=None, proximal_bias=False, proximal_init=False):
|
149 |
+
super().__init__()
|
150 |
+
assert channels % n_heads == 0
|
151 |
+
|
152 |
+
self.channels = channels
|
153 |
+
self.out_channels = out_channels
|
154 |
+
self.n_heads = n_heads
|
155 |
+
self.p_dropout = p_dropout
|
156 |
+
self.window_size = window_size
|
157 |
+
self.heads_share = heads_share
|
158 |
+
self.block_length = block_length
|
159 |
+
self.proximal_bias = proximal_bias
|
160 |
+
self.proximal_init = proximal_init
|
161 |
+
self.attn = None
|
162 |
+
|
163 |
+
self.k_channels = channels // n_heads
|
164 |
+
self.conv_q = nn.Conv1d(channels, channels, 1)
|
165 |
+
self.conv_k = nn.Conv1d(channels, channels, 1)
|
166 |
+
self.conv_v = nn.Conv1d(channels, channels, 1)
|
167 |
+
self.conv_o = nn.Conv1d(channels, out_channels, 1)
|
168 |
+
self.drop = nn.Dropout(p_dropout)
|
169 |
+
|
170 |
+
if window_size is not None:
|
171 |
+
n_heads_rel = 1 if heads_share else n_heads
|
172 |
+
rel_stddev = self.k_channels**-0.5
|
173 |
+
self.emb_rel_k = nn.Parameter(torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels) * rel_stddev)
|
174 |
+
self.emb_rel_v = nn.Parameter(torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels) * rel_stddev)
|
175 |
+
|
176 |
+
nn.init.xavier_uniform_(self.conv_q.weight)
|
177 |
+
nn.init.xavier_uniform_(self.conv_k.weight)
|
178 |
+
nn.init.xavier_uniform_(self.conv_v.weight)
|
179 |
+
if proximal_init:
|
180 |
+
with torch.no_grad():
|
181 |
+
self.conv_k.weight.copy_(self.conv_q.weight)
|
182 |
+
self.conv_k.bias.copy_(self.conv_q.bias)
|
183 |
+
|
184 |
+
def forward(self, x, c, attn_mask=None):
|
185 |
+
q = self.conv_q(x)
|
186 |
+
k = self.conv_k(c)
|
187 |
+
v = self.conv_v(c)
|
188 |
+
|
189 |
+
x, self.attn = self.attention(q, k, v, mask=attn_mask)
|
190 |
+
|
191 |
+
x = self.conv_o(x)
|
192 |
+
return x
|
193 |
+
|
194 |
+
def attention(self, query, key, value, mask=None):
|
195 |
+
# reshape [b, d, t] -> [b, n_h, t, d_k]
|
196 |
+
b, d, t_s, t_t = (*key.size(), query.size(2))
|
197 |
+
query = query.view(b, self.n_heads, self.k_channels, t_t).transpose(2, 3)
|
198 |
+
key = key.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
199 |
+
value = value.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
200 |
+
|
201 |
+
scores = torch.matmul(query / math.sqrt(self.k_channels), key.transpose(-2, -1))
|
202 |
+
if self.window_size is not None:
|
203 |
+
assert t_s == t_t, "Relative attention is only available for self-attention."
|
204 |
+
key_relative_embeddings = self._get_relative_embeddings(self.emb_rel_k, t_s)
|
205 |
+
rel_logits = self._matmul_with_relative_keys(query /math.sqrt(self.k_channels), key_relative_embeddings)
|
206 |
+
scores_local = self._relative_position_to_absolute_position(rel_logits)
|
207 |
+
scores = scores + scores_local
|
208 |
+
if self.proximal_bias:
|
209 |
+
assert t_s == t_t, "Proximal bias is only available for self-attention."
|
210 |
+
scores = scores + self._attention_bias_proximal(t_s).to(device=scores.device, dtype=scores.dtype)
|
211 |
+
if mask is not None:
|
212 |
+
scores = scores.masked_fill(mask == 0, -1e4)
|
213 |
+
if self.block_length is not None:
|
214 |
+
assert t_s == t_t, "Local attention is only available for self-attention."
|
215 |
+
block_mask = torch.ones_like(scores).triu(-self.block_length).tril(self.block_length)
|
216 |
+
scores = scores.masked_fill(block_mask == 0, -1e4)
|
217 |
+
p_attn = F.softmax(scores, dim=-1) # [b, n_h, t_t, t_s]
|
218 |
+
p_attn = self.drop(p_attn)
|
219 |
+
output = torch.matmul(p_attn, value)
|
220 |
+
if self.window_size is not None:
|
221 |
+
relative_weights = self._absolute_position_to_relative_position(p_attn)
|
222 |
+
value_relative_embeddings = self._get_relative_embeddings(self.emb_rel_v, t_s)
|
223 |
+
output = output + self._matmul_with_relative_values(relative_weights, value_relative_embeddings)
|
224 |
+
output = output.transpose(2, 3).contiguous().view(b, d, t_t) # [b, n_h, t_t, d_k] -> [b, d, t_t]
|
225 |
+
return output, p_attn
|
226 |
+
|
227 |
+
def _matmul_with_relative_values(self, x, y):
|
228 |
+
"""
|
229 |
+
x: [b, h, l, m]
|
230 |
+
y: [h or 1, m, d]
|
231 |
+
ret: [b, h, l, d]
|
232 |
+
"""
|
233 |
+
ret = torch.matmul(x, y.unsqueeze(0))
|
234 |
+
return ret
|
235 |
+
|
236 |
+
def _matmul_with_relative_keys(self, x, y):
|
237 |
+
"""
|
238 |
+
x: [b, h, l, d]
|
239 |
+
y: [h or 1, m, d]
|
240 |
+
ret: [b, h, l, m]
|
241 |
+
"""
|
242 |
+
ret = torch.matmul(x, y.unsqueeze(0).transpose(-2, -1))
|
243 |
+
return ret
|
244 |
+
|
245 |
+
def _get_relative_embeddings(self, relative_embeddings, length):
|
246 |
+
max_relative_position = 2 * self.window_size + 1
|
247 |
+
# Pad first before slice to avoid using cond ops.
|
248 |
+
pad_length = max(length - (self.window_size + 1), 0)
|
249 |
+
slice_start_position = max((self.window_size + 1) - length, 0)
|
250 |
+
slice_end_position = slice_start_position + 2 * length - 1
|
251 |
+
if pad_length > 0:
|
252 |
+
padded_relative_embeddings = F.pad(
|
253 |
+
relative_embeddings,
|
254 |
+
commons.convert_pad_shape([[0, 0], [pad_length, pad_length], [0, 0]]))
|
255 |
+
else:
|
256 |
+
padded_relative_embeddings = relative_embeddings
|
257 |
+
used_relative_embeddings = padded_relative_embeddings[:,slice_start_position:slice_end_position]
|
258 |
+
return used_relative_embeddings
|
259 |
+
|
260 |
+
def _relative_position_to_absolute_position(self, x):
|
261 |
+
"""
|
262 |
+
x: [b, h, l, 2*l-1]
|
263 |
+
ret: [b, h, l, l]
|
264 |
+
"""
|
265 |
+
batch, heads, length, _ = x.size()
|
266 |
+
# Concat columns of pad to shift from relative to absolute indexing.
|
267 |
+
x = F.pad(x, commons.convert_pad_shape([[0,0],[0,0],[0,0],[0,1]]))
|
268 |
+
|
269 |
+
# Concat extra elements so to add up to shape (len+1, 2*len-1).
|
270 |
+
x_flat = x.view([batch, heads, length * 2 * length])
|
271 |
+
x_flat = F.pad(x_flat, commons.convert_pad_shape([[0,0],[0,0],[0,length-1]]))
|
272 |
+
|
273 |
+
# Reshape and slice out the padded elements.
|
274 |
+
x_final = x_flat.view([batch, heads, length+1, 2*length-1])[:, :, :length, length-1:]
|
275 |
+
return x_final
|
276 |
+
|
277 |
+
def _absolute_position_to_relative_position(self, x):
|
278 |
+
"""
|
279 |
+
x: [b, h, l, l]
|
280 |
+
ret: [b, h, l, 2*l-1]
|
281 |
+
"""
|
282 |
+
batch, heads, length, _ = x.size()
|
283 |
+
# padd along column
|
284 |
+
x = F.pad(x, commons.convert_pad_shape([[0, 0], [0, 0], [0, 0], [0, length-1]]))
|
285 |
+
x_flat = x.view([batch, heads, length**2 + length*(length -1)])
|
286 |
+
# add 0's in the beginning that will skew the elements after reshape
|
287 |
+
x_flat = F.pad(x_flat, commons.convert_pad_shape([[0, 0], [0, 0], [length, 0]]))
|
288 |
+
x_final = x_flat.view([batch, heads, length, 2*length])[:,:,:,1:]
|
289 |
+
return x_final
|
290 |
+
|
291 |
+
def _attention_bias_proximal(self, length):
|
292 |
+
"""Bias for self-attention to encourage attention to close positions.
|
293 |
+
Args:
|
294 |
+
length: an integer scalar.
|
295 |
+
Returns:
|
296 |
+
a Tensor with shape [1, 1, length, length]
|
297 |
+
"""
|
298 |
+
r = torch.arange(length, dtype=torch.float32)
|
299 |
+
diff = torch.unsqueeze(r, 0) - torch.unsqueeze(r, 1)
|
300 |
+
return torch.unsqueeze(torch.unsqueeze(-torch.log1p(torch.abs(diff)), 0), 0)
|
301 |
+
|
302 |
+
|
303 |
+
class FFN(nn.Module):
|
304 |
+
def __init__(self, in_channels, out_channels, filter_channels, kernel_size, p_dropout=0., activation=None, causal=False):
|
305 |
+
super().__init__()
|
306 |
+
self.in_channels = in_channels
|
307 |
+
self.out_channels = out_channels
|
308 |
+
self.filter_channels = filter_channels
|
309 |
+
self.kernel_size = kernel_size
|
310 |
+
self.p_dropout = p_dropout
|
311 |
+
self.activation = activation
|
312 |
+
self.causal = causal
|
313 |
+
|
314 |
+
if causal:
|
315 |
+
self.padding = self._causal_padding
|
316 |
+
else:
|
317 |
+
self.padding = self._same_padding
|
318 |
+
|
319 |
+
self.conv_1 = nn.Conv1d(in_channels, filter_channels, kernel_size)
|
320 |
+
self.conv_2 = nn.Conv1d(filter_channels, out_channels, kernel_size)
|
321 |
+
self.drop = nn.Dropout(p_dropout)
|
322 |
+
|
323 |
+
def forward(self, x, x_mask):
|
324 |
+
x = self.conv_1(self.padding(x * x_mask))
|
325 |
+
if self.activation == "gelu":
|
326 |
+
x = x * torch.sigmoid(1.702 * x)
|
327 |
+
else:
|
328 |
+
x = torch.relu(x)
|
329 |
+
x = self.drop(x)
|
330 |
+
x = self.conv_2(self.padding(x * x_mask))
|
331 |
+
return x * x_mask
|
332 |
+
|
333 |
+
def _causal_padding(self, x):
|
334 |
+
if self.kernel_size == 1:
|
335 |
+
return x
|
336 |
+
pad_l = self.kernel_size - 1
|
337 |
+
pad_r = 0
|
338 |
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
339 |
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
340 |
+
return x
|
341 |
+
|
342 |
+
def _same_padding(self, x):
|
343 |
+
if self.kernel_size == 1:
|
344 |
+
return x
|
345 |
+
pad_l = (self.kernel_size - 1) // 2
|
346 |
+
pad_r = self.kernel_size // 2
|
347 |
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
348 |
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
349 |
+
return x
|
modules/commons.py
ADDED
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import numpy as np
|
3 |
+
import torch
|
4 |
+
from torch import nn
|
5 |
+
from torch.nn import functional as F
|
6 |
+
|
7 |
+
def slice_pitch_segments(x, ids_str, segment_size=4):
|
8 |
+
ret = torch.zeros_like(x[:, :segment_size])
|
9 |
+
for i in range(x.size(0)):
|
10 |
+
idx_str = ids_str[i]
|
11 |
+
idx_end = idx_str + segment_size
|
12 |
+
ret[i] = x[i, idx_str:idx_end]
|
13 |
+
return ret
|
14 |
+
|
15 |
+
def rand_slice_segments_with_pitch(x, pitch, x_lengths=None, segment_size=4):
|
16 |
+
b, d, t = x.size()
|
17 |
+
if x_lengths is None:
|
18 |
+
x_lengths = t
|
19 |
+
ids_str_max = x_lengths - segment_size + 1
|
20 |
+
ids_str = (torch.rand([b]).to(device=x.device) * ids_str_max).to(dtype=torch.long)
|
21 |
+
ret = slice_segments(x, ids_str, segment_size)
|
22 |
+
ret_pitch = slice_pitch_segments(pitch, ids_str, segment_size)
|
23 |
+
return ret, ret_pitch, ids_str
|
24 |
+
|
25 |
+
def init_weights(m, mean=0.0, std=0.01):
|
26 |
+
classname = m.__class__.__name__
|
27 |
+
if classname.find("Conv") != -1:
|
28 |
+
m.weight.data.normal_(mean, std)
|
29 |
+
|
30 |
+
|
31 |
+
def get_padding(kernel_size, dilation=1):
|
32 |
+
return int((kernel_size*dilation - dilation)/2)
|
33 |
+
|
34 |
+
|
35 |
+
def convert_pad_shape(pad_shape):
|
36 |
+
l = pad_shape[::-1]
|
37 |
+
pad_shape = [item for sublist in l for item in sublist]
|
38 |
+
return pad_shape
|
39 |
+
|
40 |
+
|
41 |
+
def intersperse(lst, item):
|
42 |
+
result = [item] * (len(lst) * 2 + 1)
|
43 |
+
result[1::2] = lst
|
44 |
+
return result
|
45 |
+
|
46 |
+
|
47 |
+
def kl_divergence(m_p, logs_p, m_q, logs_q):
|
48 |
+
"""KL(P||Q)"""
|
49 |
+
kl = (logs_q - logs_p) - 0.5
|
50 |
+
kl += 0.5 * (torch.exp(2. * logs_p) + ((m_p - m_q)**2)) * torch.exp(-2. * logs_q)
|
51 |
+
return kl
|
52 |
+
|
53 |
+
|
54 |
+
def rand_gumbel(shape):
|
55 |
+
"""Sample from the Gumbel distribution, protect from overflows."""
|
56 |
+
uniform_samples = torch.rand(shape) * 0.99998 + 0.00001
|
57 |
+
return -torch.log(-torch.log(uniform_samples))
|
58 |
+
|
59 |
+
|
60 |
+
def rand_gumbel_like(x):
|
61 |
+
g = rand_gumbel(x.size()).to(dtype=x.dtype, device=x.device)
|
62 |
+
return g
|
63 |
+
|
64 |
+
|
65 |
+
def slice_segments(x, ids_str, segment_size=4):
|
66 |
+
ret = torch.zeros_like(x[:, :, :segment_size])
|
67 |
+
for i in range(x.size(0)):
|
68 |
+
idx_str = ids_str[i]
|
69 |
+
idx_end = idx_str + segment_size
|
70 |
+
ret[i] = x[i, :, idx_str:idx_end]
|
71 |
+
return ret
|
72 |
+
|
73 |
+
|
74 |
+
def rand_slice_segments(x, x_lengths=None, segment_size=4):
|
75 |
+
b, d, t = x.size()
|
76 |
+
if x_lengths is None:
|
77 |
+
x_lengths = t
|
78 |
+
ids_str_max = x_lengths - segment_size + 1
|
79 |
+
ids_str = (torch.rand([b]).to(device=x.device) * ids_str_max).to(dtype=torch.long)
|
80 |
+
ret = slice_segments(x, ids_str, segment_size)
|
81 |
+
return ret, ids_str
|
82 |
+
|
83 |
+
|
84 |
+
def rand_spec_segments(x, x_lengths=None, segment_size=4):
|
85 |
+
b, d, t = x.size()
|
86 |
+
if x_lengths is None:
|
87 |
+
x_lengths = t
|
88 |
+
ids_str_max = x_lengths - segment_size
|
89 |
+
ids_str = (torch.rand([b]).to(device=x.device) * ids_str_max).to(dtype=torch.long)
|
90 |
+
ret = slice_segments(x, ids_str, segment_size)
|
91 |
+
return ret, ids_str
|
92 |
+
|
93 |
+
|
94 |
+
def get_timing_signal_1d(
|
95 |
+
length, channels, min_timescale=1.0, max_timescale=1.0e4):
|
96 |
+
position = torch.arange(length, dtype=torch.float)
|
97 |
+
num_timescales = channels // 2
|
98 |
+
log_timescale_increment = (
|
99 |
+
math.log(float(max_timescale) / float(min_timescale)) /
|
100 |
+
(num_timescales - 1))
|
101 |
+
inv_timescales = min_timescale * torch.exp(
|
102 |
+
torch.arange(num_timescales, dtype=torch.float) * -log_timescale_increment)
|
103 |
+
scaled_time = position.unsqueeze(0) * inv_timescales.unsqueeze(1)
|
104 |
+
signal = torch.cat([torch.sin(scaled_time), torch.cos(scaled_time)], 0)
|
105 |
+
signal = F.pad(signal, [0, 0, 0, channels % 2])
|
106 |
+
signal = signal.view(1, channels, length)
|
107 |
+
return signal
|
108 |
+
|
109 |
+
|
110 |
+
def add_timing_signal_1d(x, min_timescale=1.0, max_timescale=1.0e4):
|
111 |
+
b, channels, length = x.size()
|
112 |
+
signal = get_timing_signal_1d(length, channels, min_timescale, max_timescale)
|
113 |
+
return x + signal.to(dtype=x.dtype, device=x.device)
|
114 |
+
|
115 |
+
|
116 |
+
def cat_timing_signal_1d(x, min_timescale=1.0, max_timescale=1.0e4, axis=1):
|
117 |
+
b, channels, length = x.size()
|
118 |
+
signal = get_timing_signal_1d(length, channels, min_timescale, max_timescale)
|
119 |
+
return torch.cat([x, signal.to(dtype=x.dtype, device=x.device)], axis)
|
120 |
+
|
121 |
+
|
122 |
+
def subsequent_mask(length):
|
123 |
+
mask = torch.tril(torch.ones(length, length)).unsqueeze(0).unsqueeze(0)
|
124 |
+
return mask
|
125 |
+
|
126 |
+
|
127 |
+
@torch.jit.script
|
128 |
+
def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels):
|
129 |
+
n_channels_int = n_channels[0]
|
130 |
+
in_act = input_a + input_b
|
131 |
+
t_act = torch.tanh(in_act[:, :n_channels_int, :])
|
132 |
+
s_act = torch.sigmoid(in_act[:, n_channels_int:, :])
|
133 |
+
acts = t_act * s_act
|
134 |
+
return acts
|
135 |
+
|
136 |
+
|
137 |
+
def convert_pad_shape(pad_shape):
|
138 |
+
l = pad_shape[::-1]
|
139 |
+
pad_shape = [item for sublist in l for item in sublist]
|
140 |
+
return pad_shape
|
141 |
+
|
142 |
+
|
143 |
+
def shift_1d(x):
|
144 |
+
x = F.pad(x, convert_pad_shape([[0, 0], [0, 0], [1, 0]]))[:, :, :-1]
|
145 |
+
return x
|
146 |
+
|
147 |
+
|
148 |
+
def sequence_mask(length, max_length=None):
|
149 |
+
if max_length is None:
|
150 |
+
max_length = length.max()
|
151 |
+
x = torch.arange(max_length, dtype=length.dtype, device=length.device)
|
152 |
+
return x.unsqueeze(0) < length.unsqueeze(1)
|
153 |
+
|
154 |
+
|
155 |
+
def generate_path(duration, mask):
|
156 |
+
"""
|
157 |
+
duration: [b, 1, t_x]
|
158 |
+
mask: [b, 1, t_y, t_x]
|
159 |
+
"""
|
160 |
+
device = duration.device
|
161 |
+
|
162 |
+
b, _, t_y, t_x = mask.shape
|
163 |
+
cum_duration = torch.cumsum(duration, -1)
|
164 |
+
|
165 |
+
cum_duration_flat = cum_duration.view(b * t_x)
|
166 |
+
path = sequence_mask(cum_duration_flat, t_y).to(mask.dtype)
|
167 |
+
path = path.view(b, t_x, t_y)
|
168 |
+
path = path - F.pad(path, convert_pad_shape([[0, 0], [1, 0], [0, 0]]))[:, :-1]
|
169 |
+
path = path.unsqueeze(1).transpose(2,3) * mask
|
170 |
+
return path
|
171 |
+
|
172 |
+
|
173 |
+
def clip_grad_value_(parameters, clip_value, norm_type=2):
|
174 |
+
if isinstance(parameters, torch.Tensor):
|
175 |
+
parameters = [parameters]
|
176 |
+
parameters = list(filter(lambda p: p.grad is not None, parameters))
|
177 |
+
norm_type = float(norm_type)
|
178 |
+
if clip_value is not None:
|
179 |
+
clip_value = float(clip_value)
|
180 |
+
|
181 |
+
total_norm = 0
|
182 |
+
for p in parameters:
|
183 |
+
param_norm = p.grad.data.norm(norm_type)
|
184 |
+
total_norm += param_norm.item() ** norm_type
|
185 |
+
if clip_value is not None:
|
186 |
+
p.grad.data.clamp_(min=-clip_value, max=clip_value)
|
187 |
+
total_norm = total_norm ** (1. / norm_type)
|
188 |
+
return total_norm
|
modules/crepe.py
ADDED
@@ -0,0 +1,327 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Optional,Union
|
2 |
+
try:
|
3 |
+
from typing import Literal
|
4 |
+
except Exception as e:
|
5 |
+
from typing_extensions import Literal
|
6 |
+
import numpy as np
|
7 |
+
import torch
|
8 |
+
import torchcrepe
|
9 |
+
from torch import nn
|
10 |
+
from torch.nn import functional as F
|
11 |
+
import scipy
|
12 |
+
|
13 |
+
#from:https://github.com/fishaudio/fish-diffusion
|
14 |
+
|
15 |
+
def repeat_expand(
|
16 |
+
content: Union[torch.Tensor, np.ndarray], target_len: int, mode: str = "nearest"
|
17 |
+
):
|
18 |
+
"""Repeat content to target length.
|
19 |
+
This is a wrapper of torch.nn.functional.interpolate.
|
20 |
+
|
21 |
+
Args:
|
22 |
+
content (torch.Tensor): tensor
|
23 |
+
target_len (int): target length
|
24 |
+
mode (str, optional): interpolation mode. Defaults to "nearest".
|
25 |
+
|
26 |
+
Returns:
|
27 |
+
torch.Tensor: tensor
|
28 |
+
"""
|
29 |
+
|
30 |
+
ndim = content.ndim
|
31 |
+
|
32 |
+
if content.ndim == 1:
|
33 |
+
content = content[None, None]
|
34 |
+
elif content.ndim == 2:
|
35 |
+
content = content[None]
|
36 |
+
|
37 |
+
assert content.ndim == 3
|
38 |
+
|
39 |
+
is_np = isinstance(content, np.ndarray)
|
40 |
+
if is_np:
|
41 |
+
content = torch.from_numpy(content)
|
42 |
+
|
43 |
+
results = torch.nn.functional.interpolate(content, size=target_len, mode=mode)
|
44 |
+
|
45 |
+
if is_np:
|
46 |
+
results = results.numpy()
|
47 |
+
|
48 |
+
if ndim == 1:
|
49 |
+
return results[0, 0]
|
50 |
+
elif ndim == 2:
|
51 |
+
return results[0]
|
52 |
+
|
53 |
+
|
54 |
+
class BasePitchExtractor:
|
55 |
+
def __init__(
|
56 |
+
self,
|
57 |
+
hop_length: int = 512,
|
58 |
+
f0_min: float = 50.0,
|
59 |
+
f0_max: float = 1100.0,
|
60 |
+
keep_zeros: bool = True,
|
61 |
+
):
|
62 |
+
"""Base pitch extractor.
|
63 |
+
|
64 |
+
Args:
|
65 |
+
hop_length (int, optional): Hop length. Defaults to 512.
|
66 |
+
f0_min (float, optional): Minimum f0. Defaults to 50.0.
|
67 |
+
f0_max (float, optional): Maximum f0. Defaults to 1100.0.
|
68 |
+
keep_zeros (bool, optional): Whether keep zeros in pitch. Defaults to True.
|
69 |
+
"""
|
70 |
+
|
71 |
+
self.hop_length = hop_length
|
72 |
+
self.f0_min = f0_min
|
73 |
+
self.f0_max = f0_max
|
74 |
+
self.keep_zeros = keep_zeros
|
75 |
+
|
76 |
+
def __call__(self, x, sampling_rate=44100, pad_to=None):
|
77 |
+
raise NotImplementedError("BasePitchExtractor is not callable.")
|
78 |
+
|
79 |
+
def post_process(self, x, sampling_rate, f0, pad_to):
|
80 |
+
if isinstance(f0, np.ndarray):
|
81 |
+
f0 = torch.from_numpy(f0).float().to(x.device)
|
82 |
+
|
83 |
+
if pad_to is None:
|
84 |
+
return f0
|
85 |
+
|
86 |
+
f0 = repeat_expand(f0, pad_to)
|
87 |
+
|
88 |
+
if self.keep_zeros:
|
89 |
+
return f0
|
90 |
+
|
91 |
+
vuv_vector = torch.zeros_like(f0)
|
92 |
+
vuv_vector[f0 > 0.0] = 1.0
|
93 |
+
vuv_vector[f0 <= 0.0] = 0.0
|
94 |
+
|
95 |
+
# 去掉0频率, 并线性插值
|
96 |
+
nzindex = torch.nonzero(f0).squeeze()
|
97 |
+
f0 = torch.index_select(f0, dim=0, index=nzindex).cpu().numpy()
|
98 |
+
time_org = self.hop_length / sampling_rate * nzindex.cpu().numpy()
|
99 |
+
time_frame = np.arange(pad_to) * self.hop_length / sampling_rate
|
100 |
+
|
101 |
+
if f0.shape[0] <= 0:
|
102 |
+
return torch.zeros(pad_to, dtype=torch.float, device=x.device),torch.zeros(pad_to, dtype=torch.float, device=x.device)
|
103 |
+
|
104 |
+
if f0.shape[0] == 1:
|
105 |
+
return torch.ones(pad_to, dtype=torch.float, device=x.device) * f0[0],torch.ones(pad_to, dtype=torch.float, device=x.device)
|
106 |
+
|
107 |
+
# 大概可以用 torch 重写?
|
108 |
+
f0 = np.interp(time_frame, time_org, f0, left=f0[0], right=f0[-1])
|
109 |
+
vuv_vector = vuv_vector.cpu().numpy()
|
110 |
+
vuv_vector = np.ceil(scipy.ndimage.zoom(vuv_vector,pad_to/len(vuv_vector),order = 0))
|
111 |
+
|
112 |
+
return f0,vuv_vector
|
113 |
+
|
114 |
+
|
115 |
+
class MaskedAvgPool1d(nn.Module):
|
116 |
+
def __init__(
|
117 |
+
self, kernel_size: int, stride: Optional[int] = None, padding: Optional[int] = 0
|
118 |
+
):
|
119 |
+
"""An implementation of mean pooling that supports masked values.
|
120 |
+
|
121 |
+
Args:
|
122 |
+
kernel_size (int): The size of the median pooling window.
|
123 |
+
stride (int, optional): The stride of the median pooling window. Defaults to None.
|
124 |
+
padding (int, optional): The padding of the median pooling window. Defaults to 0.
|
125 |
+
"""
|
126 |
+
|
127 |
+
super(MaskedAvgPool1d, self).__init__()
|
128 |
+
self.kernel_size = kernel_size
|
129 |
+
self.stride = stride or kernel_size
|
130 |
+
self.padding = padding
|
131 |
+
|
132 |
+
def forward(self, x, mask=None):
|
133 |
+
ndim = x.dim()
|
134 |
+
if ndim == 2:
|
135 |
+
x = x.unsqueeze(1)
|
136 |
+
|
137 |
+
assert (
|
138 |
+
x.dim() == 3
|
139 |
+
), "Input tensor must have 2 or 3 dimensions (batch_size, channels, width)"
|
140 |
+
|
141 |
+
# Apply the mask by setting masked elements to zero, or make NaNs zero
|
142 |
+
if mask is None:
|
143 |
+
mask = ~torch.isnan(x)
|
144 |
+
|
145 |
+
# Ensure mask has the same shape as the input tensor
|
146 |
+
assert x.shape == mask.shape, "Input tensor and mask must have the same shape"
|
147 |
+
|
148 |
+
masked_x = torch.where(mask, x, torch.zeros_like(x))
|
149 |
+
# Create a ones kernel with the same number of channels as the input tensor
|
150 |
+
ones_kernel = torch.ones(x.size(1), 1, self.kernel_size, device=x.device)
|
151 |
+
|
152 |
+
# Perform sum pooling
|
153 |
+
sum_pooled = nn.functional.conv1d(
|
154 |
+
masked_x,
|
155 |
+
ones_kernel,
|
156 |
+
stride=self.stride,
|
157 |
+
padding=self.padding,
|
158 |
+
groups=x.size(1),
|
159 |
+
)
|
160 |
+
|
161 |
+
# Count the non-masked (valid) elements in each pooling window
|
162 |
+
valid_count = nn.functional.conv1d(
|
163 |
+
mask.float(),
|
164 |
+
ones_kernel,
|
165 |
+
stride=self.stride,
|
166 |
+
padding=self.padding,
|
167 |
+
groups=x.size(1),
|
168 |
+
)
|
169 |
+
valid_count = valid_count.clamp(min=1) # Avoid division by zero
|
170 |
+
|
171 |
+
# Perform masked average pooling
|
172 |
+
avg_pooled = sum_pooled / valid_count
|
173 |
+
|
174 |
+
# Fill zero values with NaNs
|
175 |
+
avg_pooled[avg_pooled == 0] = float("nan")
|
176 |
+
|
177 |
+
if ndim == 2:
|
178 |
+
return avg_pooled.squeeze(1)
|
179 |
+
|
180 |
+
return avg_pooled
|
181 |
+
|
182 |
+
|
183 |
+
class MaskedMedianPool1d(nn.Module):
|
184 |
+
def __init__(
|
185 |
+
self, kernel_size: int, stride: Optional[int] = None, padding: Optional[int] = 0
|
186 |
+
):
|
187 |
+
"""An implementation of median pooling that supports masked values.
|
188 |
+
|
189 |
+
This implementation is inspired by the median pooling implementation in
|
190 |
+
https://gist.github.com/rwightman/f2d3849281624be7c0f11c85c87c1598
|
191 |
+
|
192 |
+
Args:
|
193 |
+
kernel_size (int): The size of the median pooling window.
|
194 |
+
stride (int, optional): The stride of the median pooling window. Defaults to None.
|
195 |
+
padding (int, optional): The padding of the median pooling window. Defaults to 0.
|
196 |
+
"""
|
197 |
+
|
198 |
+
super(MaskedMedianPool1d, self).__init__()
|
199 |
+
self.kernel_size = kernel_size
|
200 |
+
self.stride = stride or kernel_size
|
201 |
+
self.padding = padding
|
202 |
+
|
203 |
+
def forward(self, x, mask=None):
|
204 |
+
ndim = x.dim()
|
205 |
+
if ndim == 2:
|
206 |
+
x = x.unsqueeze(1)
|
207 |
+
|
208 |
+
assert (
|
209 |
+
x.dim() == 3
|
210 |
+
), "Input tensor must have 2 or 3 dimensions (batch_size, channels, width)"
|
211 |
+
|
212 |
+
if mask is None:
|
213 |
+
mask = ~torch.isnan(x)
|
214 |
+
|
215 |
+
assert x.shape == mask.shape, "Input tensor and mask must have the same shape"
|
216 |
+
|
217 |
+
masked_x = torch.where(mask, x, torch.zeros_like(x))
|
218 |
+
|
219 |
+
x = F.pad(masked_x, (self.padding, self.padding), mode="reflect")
|
220 |
+
mask = F.pad(
|
221 |
+
mask.float(), (self.padding, self.padding), mode="constant", value=0
|
222 |
+
)
|
223 |
+
|
224 |
+
x = x.unfold(2, self.kernel_size, self.stride)
|
225 |
+
mask = mask.unfold(2, self.kernel_size, self.stride)
|
226 |
+
|
227 |
+
x = x.contiguous().view(x.size()[:3] + (-1,))
|
228 |
+
mask = mask.contiguous().view(mask.size()[:3] + (-1,)).to(x.device)
|
229 |
+
|
230 |
+
# Combine the mask with the input tensor
|
231 |
+
#x_masked = torch.where(mask.bool(), x, torch.fill_(torch.zeros_like(x),float("inf")))
|
232 |
+
x_masked = torch.where(mask.bool(), x, torch.FloatTensor([float("inf")]).to(x.device))
|
233 |
+
|
234 |
+
# Sort the masked tensor along the last dimension
|
235 |
+
x_sorted, _ = torch.sort(x_masked, dim=-1)
|
236 |
+
|
237 |
+
# Compute the count of non-masked (valid) values
|
238 |
+
valid_count = mask.sum(dim=-1)
|
239 |
+
|
240 |
+
# Calculate the index of the median value for each pooling window
|
241 |
+
median_idx = (torch.div((valid_count - 1), 2, rounding_mode='trunc')).clamp(min=0)
|
242 |
+
|
243 |
+
# Gather the median values using the calculated indices
|
244 |
+
median_pooled = x_sorted.gather(-1, median_idx.unsqueeze(-1).long()).squeeze(-1)
|
245 |
+
|
246 |
+
# Fill infinite values with NaNs
|
247 |
+
median_pooled[torch.isinf(median_pooled)] = float("nan")
|
248 |
+
|
249 |
+
if ndim == 2:
|
250 |
+
return median_pooled.squeeze(1)
|
251 |
+
|
252 |
+
return median_pooled
|
253 |
+
|
254 |
+
|
255 |
+
class CrepePitchExtractor(BasePitchExtractor):
|
256 |
+
def __init__(
|
257 |
+
self,
|
258 |
+
hop_length: int = 512,
|
259 |
+
f0_min: float = 50.0,
|
260 |
+
f0_max: float = 1100.0,
|
261 |
+
threshold: float = 0.05,
|
262 |
+
keep_zeros: bool = False,
|
263 |
+
device = None,
|
264 |
+
model: Literal["full", "tiny"] = "full",
|
265 |
+
use_fast_filters: bool = True,
|
266 |
+
):
|
267 |
+
super().__init__(hop_length, f0_min, f0_max, keep_zeros)
|
268 |
+
|
269 |
+
self.threshold = threshold
|
270 |
+
self.model = model
|
271 |
+
self.use_fast_filters = use_fast_filters
|
272 |
+
self.hop_length = hop_length
|
273 |
+
if device is None:
|
274 |
+
self.dev = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
275 |
+
else:
|
276 |
+
self.dev = torch.device(device)
|
277 |
+
if self.use_fast_filters:
|
278 |
+
self.median_filter = MaskedMedianPool1d(3, 1, 1).to(device)
|
279 |
+
self.mean_filter = MaskedAvgPool1d(3, 1, 1).to(device)
|
280 |
+
|
281 |
+
def __call__(self, x, sampling_rate=44100, pad_to=None):
|
282 |
+
"""Extract pitch using crepe.
|
283 |
+
|
284 |
+
|
285 |
+
Args:
|
286 |
+
x (torch.Tensor): Audio signal, shape (1, T).
|
287 |
+
sampling_rate (int, optional): Sampling rate. Defaults to 44100.
|
288 |
+
pad_to (int, optional): Pad to length. Defaults to None.
|
289 |
+
|
290 |
+
Returns:
|
291 |
+
torch.Tensor: Pitch, shape (T // hop_length,).
|
292 |
+
"""
|
293 |
+
|
294 |
+
assert x.ndim == 2, f"Expected 2D tensor, got {x.ndim}D tensor."
|
295 |
+
assert x.shape[0] == 1, f"Expected 1 channel, got {x.shape[0]} channels."
|
296 |
+
|
297 |
+
x = x.to(self.dev)
|
298 |
+
f0, pd = torchcrepe.predict(
|
299 |
+
x,
|
300 |
+
sampling_rate,
|
301 |
+
self.hop_length,
|
302 |
+
self.f0_min,
|
303 |
+
self.f0_max,
|
304 |
+
pad=True,
|
305 |
+
model=self.model,
|
306 |
+
batch_size=1024,
|
307 |
+
device=x.device,
|
308 |
+
return_periodicity=True,
|
309 |
+
)
|
310 |
+
|
311 |
+
# Filter, remove silence, set uv threshold, refer to the original warehouse readme
|
312 |
+
if self.use_fast_filters:
|
313 |
+
pd = self.median_filter(pd)
|
314 |
+
else:
|
315 |
+
pd = torchcrepe.filter.median(pd, 3)
|
316 |
+
|
317 |
+
pd = torchcrepe.threshold.Silence(-60.0)(pd, x, sampling_rate, 512)
|
318 |
+
f0 = torchcrepe.threshold.At(self.threshold)(f0, pd)
|
319 |
+
|
320 |
+
if self.use_fast_filters:
|
321 |
+
f0 = self.mean_filter(f0)
|
322 |
+
else:
|
323 |
+
f0 = torchcrepe.filter.mean(f0, 3)
|
324 |
+
|
325 |
+
f0 = torch.where(torch.isnan(f0), torch.full_like(f0, 0), f0)[0]
|
326 |
+
|
327 |
+
return self.post_process(x, sampling_rate, f0, pad_to)
|
modules/enhancer.py
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import torch
|
3 |
+
import torch.nn.functional as F
|
4 |
+
from vdecoder.nsf_hifigan.nvSTFT import STFT
|
5 |
+
from vdecoder.nsf_hifigan.models import load_model
|
6 |
+
from torchaudio.transforms import Resample
|
7 |
+
|
8 |
+
class Enhancer:
|
9 |
+
def __init__(self, enhancer_type, enhancer_ckpt, device=None):
|
10 |
+
if device is None:
|
11 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
12 |
+
self.device = device
|
13 |
+
|
14 |
+
if enhancer_type == 'nsf-hifigan':
|
15 |
+
self.enhancer = NsfHifiGAN(enhancer_ckpt, device=self.device)
|
16 |
+
else:
|
17 |
+
raise ValueError(f" [x] Unknown enhancer: {enhancer_type}")
|
18 |
+
|
19 |
+
self.resample_kernel = {}
|
20 |
+
self.enhancer_sample_rate = self.enhancer.sample_rate()
|
21 |
+
self.enhancer_hop_size = self.enhancer.hop_size()
|
22 |
+
|
23 |
+
def enhance(self,
|
24 |
+
audio, # 1, T
|
25 |
+
sample_rate,
|
26 |
+
f0, # 1, n_frames, 1
|
27 |
+
hop_size,
|
28 |
+
adaptive_key = 0,
|
29 |
+
silence_front = 0
|
30 |
+
):
|
31 |
+
# enhancer start time
|
32 |
+
start_frame = int(silence_front * sample_rate / hop_size)
|
33 |
+
real_silence_front = start_frame * hop_size / sample_rate
|
34 |
+
audio = audio[:, int(np.round(real_silence_front * sample_rate)) : ]
|
35 |
+
f0 = f0[: , start_frame :, :]
|
36 |
+
|
37 |
+
# adaptive parameters
|
38 |
+
adaptive_factor = 2 ** ( -adaptive_key / 12)
|
39 |
+
adaptive_sample_rate = 100 * int(np.round(self.enhancer_sample_rate / adaptive_factor / 100))
|
40 |
+
real_factor = self.enhancer_sample_rate / adaptive_sample_rate
|
41 |
+
|
42 |
+
# resample the ddsp output
|
43 |
+
if sample_rate == adaptive_sample_rate:
|
44 |
+
audio_res = audio
|
45 |
+
else:
|
46 |
+
key_str = str(sample_rate) + str(adaptive_sample_rate)
|
47 |
+
if key_str not in self.resample_kernel:
|
48 |
+
self.resample_kernel[key_str] = Resample(sample_rate, adaptive_sample_rate, lowpass_filter_width = 128).to(self.device)
|
49 |
+
audio_res = self.resample_kernel[key_str](audio)
|
50 |
+
|
51 |
+
n_frames = int(audio_res.size(-1) // self.enhancer_hop_size + 1)
|
52 |
+
|
53 |
+
# resample f0
|
54 |
+
f0_np = f0.squeeze(0).squeeze(-1).cpu().numpy()
|
55 |
+
f0_np *= real_factor
|
56 |
+
time_org = (hop_size / sample_rate) * np.arange(len(f0_np)) / real_factor
|
57 |
+
time_frame = (self.enhancer_hop_size / self.enhancer_sample_rate) * np.arange(n_frames)
|
58 |
+
f0_res = np.interp(time_frame, time_org, f0_np, left=f0_np[0], right=f0_np[-1])
|
59 |
+
f0_res = torch.from_numpy(f0_res).unsqueeze(0).float().to(self.device) # 1, n_frames
|
60 |
+
|
61 |
+
# enhance
|
62 |
+
enhanced_audio, enhancer_sample_rate = self.enhancer(audio_res, f0_res)
|
63 |
+
|
64 |
+
# resample the enhanced output
|
65 |
+
if adaptive_factor != 0:
|
66 |
+
key_str = str(adaptive_sample_rate) + str(enhancer_sample_rate)
|
67 |
+
if key_str not in self.resample_kernel:
|
68 |
+
self.resample_kernel[key_str] = Resample(adaptive_sample_rate, enhancer_sample_rate, lowpass_filter_width = 128).to(self.device)
|
69 |
+
enhanced_audio = self.resample_kernel[key_str](enhanced_audio)
|
70 |
+
|
71 |
+
# pad the silence frames
|
72 |
+
if start_frame > 0:
|
73 |
+
enhanced_audio = F.pad(enhanced_audio, (int(np.round(enhancer_sample_rate * real_silence_front)), 0))
|
74 |
+
|
75 |
+
return enhanced_audio, enhancer_sample_rate
|
76 |
+
|
77 |
+
|
78 |
+
class NsfHifiGAN(torch.nn.Module):
|
79 |
+
def __init__(self, model_path, device=None):
|
80 |
+
super().__init__()
|
81 |
+
if device is None:
|
82 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
83 |
+
self.device = device
|
84 |
+
print('| Load HifiGAN: ', model_path)
|
85 |
+
self.model, self.h = load_model(model_path, device=self.device)
|
86 |
+
|
87 |
+
def sample_rate(self):
|
88 |
+
return self.h.sampling_rate
|
89 |
+
|
90 |
+
def hop_size(self):
|
91 |
+
return self.h.hop_size
|
92 |
+
|
93 |
+
def forward(self, audio, f0):
|
94 |
+
stft = STFT(
|
95 |
+
self.h.sampling_rate,
|
96 |
+
self.h.num_mels,
|
97 |
+
self.h.n_fft,
|
98 |
+
self.h.win_size,
|
99 |
+
self.h.hop_size,
|
100 |
+
self.h.fmin,
|
101 |
+
self.h.fmax)
|
102 |
+
with torch.no_grad():
|
103 |
+
mel = stft.get_mel(audio)
|
104 |
+
enhanced_audio = self.model(mel, f0[:,:mel.size(-1)]).view(-1)
|
105 |
+
return enhanced_audio, self.h.sampling_rate
|