Spaces:
Running
Running
Upload 180 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .github/workflows/pull_format.yml +43 -0
- .github/workflows/push_format.yml +57 -0
- .gitignore +185 -0
- .gitmodules +0 -0
- .pre-commit-config.yaml +25 -0
- Data/sun/config.json +99 -0
- Data/sun/models/G_3500.pth +3 -0
- LICENSE +661 -0
- README.md +42 -13
- attentions.py +464 -0
- bert_gen.py +74 -0
- clap_gen.py +64 -0
- clap_wrapper.py +49 -0
- commons.py +158 -0
- compress_model.py +89 -0
- config.py +248 -0
- config.yml +177 -0
- configs/config.json +953 -0
- css/custom.css +18 -0
- data_utils.py +421 -0
- default_config.yml +177 -0
- emotional/clap-htsat-fused/.gitattributes +34 -0
- emotional/clap-htsat-fused/README.md +107 -0
- emotional/clap-htsat-fused/config.json +207 -0
- emotional/clap-htsat-fused/merges.txt +0 -0
- emotional/clap-htsat-fused/preprocessor_config.json +22 -0
- emotional/clap-htsat-fused/pytorch_model.bin +3 -0
- emotional/clap-htsat-fused/special_tokens_map.json +15 -0
- emotional/clap-htsat-fused/tokenizer.json +0 -0
- emotional/clap-htsat-fused/tokenizer_config.json +16 -0
- emotional/clap-htsat-fused/vocab.json +0 -0
- emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/.gitattributes +28 -0
- emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/LICENSE +437 -0
- emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/README.md +127 -0
- emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/config.json +122 -0
- emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/preprocessor_config.json +9 -0
- emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/pytorch_model.bin +3 -0
- emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/vocab.json +1 -0
- empty_emo.npy +3 -0
- export_onnx.py +12 -0
- filelists/sample.list +3 -0
- infer.py +381 -0
- losses.py +58 -0
- mel_processing.py +142 -0
- models.py +1075 -0
- modules.py +597 -0
- monotonic_align/__init__.py +16 -0
- monotonic_align/core.py +46 -0
- nltk_data/corpora/cmudict/README +76 -0
- nltk_data/corpora/cmudict/cmudict +0 -0
.github/workflows/pull_format.yml
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: pull format
|
2 |
+
|
3 |
+
on: [pull_request]
|
4 |
+
|
5 |
+
permissions:
|
6 |
+
contents: write
|
7 |
+
|
8 |
+
jobs:
|
9 |
+
pull_format:
|
10 |
+
runs-on: ${{ matrix.os }}
|
11 |
+
|
12 |
+
strategy:
|
13 |
+
matrix:
|
14 |
+
python-version: ["3.10"]
|
15 |
+
os: [ubuntu-latest]
|
16 |
+
fail-fast: false
|
17 |
+
|
18 |
+
continue-on-error: true
|
19 |
+
|
20 |
+
steps:
|
21 |
+
- name: checkout
|
22 |
+
continue-on-error: true
|
23 |
+
uses: actions/checkout@v3
|
24 |
+
with:
|
25 |
+
ref: ${{ github.head_ref }}
|
26 |
+
fetch-depth: 0
|
27 |
+
|
28 |
+
- name: Set up Python ${{ matrix.python-version }}
|
29 |
+
uses: actions/setup-python@v4
|
30 |
+
with:
|
31 |
+
python-version: ${{ matrix.python-version }}
|
32 |
+
|
33 |
+
- name: Install Black
|
34 |
+
run: pip install "black[jupyter]"
|
35 |
+
|
36 |
+
- name: Run Black
|
37 |
+
# run: black $(git ls-files '*.py')
|
38 |
+
run: black .
|
39 |
+
|
40 |
+
- name: Commit Back
|
41 |
+
uses: stefanzweifel/git-auto-commit-action@v4
|
42 |
+
with:
|
43 |
+
commit_message: Apply Code Formatter Change
|
.github/workflows/push_format.yml
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: push format
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- master
|
7 |
+
- dev
|
8 |
+
|
9 |
+
permissions:
|
10 |
+
contents: write
|
11 |
+
pull-requests: write
|
12 |
+
|
13 |
+
jobs:
|
14 |
+
push_format:
|
15 |
+
runs-on: ${{ matrix.os }}
|
16 |
+
|
17 |
+
strategy:
|
18 |
+
matrix:
|
19 |
+
python-version: ["3.10"]
|
20 |
+
os: [ubuntu-latest]
|
21 |
+
fail-fast: false
|
22 |
+
|
23 |
+
steps:
|
24 |
+
- uses: actions/checkout@v3
|
25 |
+
with:
|
26 |
+
ref: ${{github.ref_name}}
|
27 |
+
|
28 |
+
- name: Set up Python ${{ matrix.python-version }}
|
29 |
+
uses: actions/setup-python@v4
|
30 |
+
with:
|
31 |
+
python-version: ${{ matrix.python-version }}
|
32 |
+
|
33 |
+
- name: Install Black
|
34 |
+
run: pip install "black[jupyter]"
|
35 |
+
|
36 |
+
- name: Run Black
|
37 |
+
# run: black $(git ls-files '*.py')
|
38 |
+
run: black .
|
39 |
+
|
40 |
+
- name: Commit Back
|
41 |
+
continue-on-error: true
|
42 |
+
id: commitback
|
43 |
+
run: |
|
44 |
+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
45 |
+
git config --local user.name "github-actions[bot]"
|
46 |
+
git add --all
|
47 |
+
git commit -m "Format code"
|
48 |
+
|
49 |
+
- name: Create Pull Request
|
50 |
+
if: steps.commitback.outcome == 'success'
|
51 |
+
continue-on-error: true
|
52 |
+
uses: peter-evans/create-pull-request@v5
|
53 |
+
with:
|
54 |
+
delete-branch: true
|
55 |
+
body: Apply Code Formatter Change
|
56 |
+
title: Apply Code Formatter Change
|
57 |
+
commit-message: Automatic code format
|
.gitignore
ADDED
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
wheels/
|
23 |
+
share/python-wheels/
|
24 |
+
*.egg-info/
|
25 |
+
.installed.cfg
|
26 |
+
*.egg
|
27 |
+
MANIFEST
|
28 |
+
|
29 |
+
# PyInstaller
|
30 |
+
# Usually these files are written by a python script from a template
|
31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32 |
+
*.manifest
|
33 |
+
*.spec
|
34 |
+
|
35 |
+
# Installer logs
|
36 |
+
pip-log.txt
|
37 |
+
pip-delete-this-directory.txt
|
38 |
+
|
39 |
+
# Unit test / coverage reports
|
40 |
+
htmlcov/
|
41 |
+
.tox/
|
42 |
+
.nox/
|
43 |
+
.coverage
|
44 |
+
.coverage.*
|
45 |
+
.cache
|
46 |
+
nosetests.xml
|
47 |
+
coverage.xml
|
48 |
+
*.cover
|
49 |
+
*.py,cover
|
50 |
+
.hypothesis/
|
51 |
+
.pytest_cache/
|
52 |
+
cover/
|
53 |
+
|
54 |
+
# Translations
|
55 |
+
*.mo
|
56 |
+
*.pot
|
57 |
+
|
58 |
+
# Django stuff:
|
59 |
+
*.log
|
60 |
+
local_settings.py
|
61 |
+
db.sqlite3
|
62 |
+
db.sqlite3-journal
|
63 |
+
|
64 |
+
# Flask stuff:
|
65 |
+
instance/
|
66 |
+
.webassets-cache
|
67 |
+
|
68 |
+
# Scrapy stuff:
|
69 |
+
.scrapy
|
70 |
+
|
71 |
+
# Sphinx documentation
|
72 |
+
docs/_build/
|
73 |
+
|
74 |
+
# PyBuilder
|
75 |
+
.pybuilder/
|
76 |
+
target/
|
77 |
+
|
78 |
+
# Jupyter Notebook
|
79 |
+
.ipynb_checkpoints
|
80 |
+
|
81 |
+
# IPython
|
82 |
+
profile_default/
|
83 |
+
ipython_config.py
|
84 |
+
|
85 |
+
# pyenv
|
86 |
+
# For a library or package, you might want to ignore these files since the code is
|
87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
88 |
+
# .python-version
|
89 |
+
|
90 |
+
# pipenv
|
91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94 |
+
# install all needed dependencies.
|
95 |
+
#Pipfile.lock
|
96 |
+
|
97 |
+
# poetry
|
98 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100 |
+
# commonly ignored for libraries.
|
101 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
102 |
+
#poetry.lock
|
103 |
+
|
104 |
+
# pdm
|
105 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
106 |
+
#pdm.lock
|
107 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
108 |
+
# in version control.
|
109 |
+
# https://pdm.fming.dev/#use-with-ide
|
110 |
+
.pdm.toml
|
111 |
+
|
112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
113 |
+
__pypackages__/
|
114 |
+
|
115 |
+
# Celery stuff
|
116 |
+
celerybeat-schedule
|
117 |
+
celerybeat.pid
|
118 |
+
|
119 |
+
# SageMath parsed files
|
120 |
+
*.sage.py
|
121 |
+
|
122 |
+
# Environments
|
123 |
+
.env
|
124 |
+
.venv
|
125 |
+
env/
|
126 |
+
venv/
|
127 |
+
ENV/
|
128 |
+
env.bak/
|
129 |
+
venv.bak/
|
130 |
+
|
131 |
+
# Spyder project settings
|
132 |
+
.spyderproject
|
133 |
+
.spyproject
|
134 |
+
|
135 |
+
# Rope project settings
|
136 |
+
.ropeproject
|
137 |
+
|
138 |
+
# mkdocs documentation
|
139 |
+
/site
|
140 |
+
|
141 |
+
# mypy
|
142 |
+
.mypy_cache/
|
143 |
+
.dmypy.json
|
144 |
+
dmypy.json
|
145 |
+
|
146 |
+
# Pyre type checker
|
147 |
+
.pyre/
|
148 |
+
|
149 |
+
# pytype static type analyzer
|
150 |
+
.pytype/
|
151 |
+
|
152 |
+
# Cython debug symbols
|
153 |
+
cython_debug/
|
154 |
+
|
155 |
+
# PyCharm
|
156 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
157 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
158 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
+
#.idea/
|
161 |
+
|
162 |
+
.DS_Store
|
163 |
+
/models
|
164 |
+
/logs
|
165 |
+
|
166 |
+
filelists/*
|
167 |
+
!/filelists/esd.list
|
168 |
+
data/*
|
169 |
+
/*.yml
|
170 |
+
!/default_config.yml
|
171 |
+
/Web/
|
172 |
+
/emotional/*/*.bin
|
173 |
+
/bert/*/*.bin
|
174 |
+
/bert/*/*.h5
|
175 |
+
/bert/*/*.model
|
176 |
+
/bert/*/*.safetensors
|
177 |
+
/bert/*/*.msgpack
|
178 |
+
asr_transcript.py
|
179 |
+
extract_list.py
|
180 |
+
dataset
|
181 |
+
/Data
|
182 |
+
Model
|
183 |
+
raw/
|
184 |
+
logs/
|
185 |
+
Data/*
|
.gitmodules
ADDED
File without changes
|
.pre-commit-config.yaml
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
repos:
|
2 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
3 |
+
rev: v4.5.0
|
4 |
+
hooks:
|
5 |
+
- id: check-yaml
|
6 |
+
- id: end-of-file-fixer
|
7 |
+
- id: trailing-whitespace
|
8 |
+
|
9 |
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
10 |
+
rev: v0.1.7
|
11 |
+
hooks:
|
12 |
+
- id: ruff
|
13 |
+
args: [ --fix ]
|
14 |
+
|
15 |
+
- repo: https://github.com/psf/black
|
16 |
+
rev: 23.11.0
|
17 |
+
hooks:
|
18 |
+
- id: black
|
19 |
+
|
20 |
+
- repo: https://github.com/codespell-project/codespell
|
21 |
+
rev: v2.2.6
|
22 |
+
hooks:
|
23 |
+
- id: codespell
|
24 |
+
files: ^.*\.(py|md|rst|yml)$
|
25 |
+
args: [-L=fro]
|
Data/sun/config.json
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 100,
|
4 |
+
"eval_interval": 100,
|
5 |
+
"seed": 42,
|
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.99995,
|
16 |
+
"segment_size": 16384,
|
17 |
+
"init_lr_ratio": 1,
|
18 |
+
"warmup_epochs": 0,
|
19 |
+
"c_mel": 45,
|
20 |
+
"c_kl": 1.0,
|
21 |
+
"skip_optimizer": true,
|
22 |
+
"freeze_ZH_bert": false,
|
23 |
+
"freeze_JP_bert": false,
|
24 |
+
"freeze_EN_bert": false
|
25 |
+
},
|
26 |
+
"data": {
|
27 |
+
"training_files": "Data/sun/filelists/train.list",
|
28 |
+
"validation_files": "Data/sun/filelists/val.list",
|
29 |
+
"max_wav_value": 32768.0,
|
30 |
+
"sampling_rate": 44100,
|
31 |
+
"filter_length": 2048,
|
32 |
+
"hop_length": 512,
|
33 |
+
"win_length": 2048,
|
34 |
+
"n_mel_channels": 128,
|
35 |
+
"mel_fmin": 0.0,
|
36 |
+
"mel_fmax": null,
|
37 |
+
"add_blank": true,
|
38 |
+
"n_speakers": 1,
|
39 |
+
"cleaned_text": true,
|
40 |
+
"spk2id": {
|
41 |
+
"孙笑川": 0
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"model": {
|
45 |
+
"use_spk_conditioned_encoder": true,
|
46 |
+
"use_noise_scaled_mas": true,
|
47 |
+
"use_mel_posterior_encoder": false,
|
48 |
+
"use_duration_discriminator": true,
|
49 |
+
"inter_channels": 192,
|
50 |
+
"hidden_channels": 192,
|
51 |
+
"filter_channels": 768,
|
52 |
+
"n_heads": 2,
|
53 |
+
"n_layers": 6,
|
54 |
+
"kernel_size": 3,
|
55 |
+
"p_dropout": 0.1,
|
56 |
+
"resblock": "1",
|
57 |
+
"resblock_kernel_sizes": [
|
58 |
+
3,
|
59 |
+
7,
|
60 |
+
11
|
61 |
+
],
|
62 |
+
"resblock_dilation_sizes": [
|
63 |
+
[
|
64 |
+
1,
|
65 |
+
3,
|
66 |
+
5
|
67 |
+
],
|
68 |
+
[
|
69 |
+
1,
|
70 |
+
3,
|
71 |
+
5
|
72 |
+
],
|
73 |
+
[
|
74 |
+
1,
|
75 |
+
3,
|
76 |
+
5
|
77 |
+
]
|
78 |
+
],
|
79 |
+
"upsample_rates": [
|
80 |
+
8,
|
81 |
+
8,
|
82 |
+
2,
|
83 |
+
2,
|
84 |
+
2
|
85 |
+
],
|
86 |
+
"upsample_initial_channel": 512,
|
87 |
+
"upsample_kernel_sizes": [
|
88 |
+
16,
|
89 |
+
16,
|
90 |
+
8,
|
91 |
+
2,
|
92 |
+
2
|
93 |
+
],
|
94 |
+
"n_layers_q": 3,
|
95 |
+
"use_spectral_norm": false,
|
96 |
+
"gin_channels": 256
|
97 |
+
},
|
98 |
+
"version": "2.2"
|
99 |
+
}
|
Data/sun/models/G_3500.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7875e0df1038b3e971736ee0b8b963a3329d7114b5423875c52bfd158edc5a24
|
3 |
+
size 749755742
|
LICENSE
ADDED
@@ -0,0 +1,661 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU AFFERO GENERAL PUBLIC LICENSE
|
2 |
+
Version 3, 19 November 2007
|
3 |
+
|
4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
6 |
+
of this license document, but changing it is not allowed.
|
7 |
+
|
8 |
+
Preamble
|
9 |
+
|
10 |
+
The GNU Affero General Public License is a free, copyleft license for
|
11 |
+
software and other kinds of works, specifically designed to ensure
|
12 |
+
cooperation with the community in the case of network server software.
|
13 |
+
|
14 |
+
The licenses for most software and other practical works are designed
|
15 |
+
to take away your freedom to share and change the works. By contrast,
|
16 |
+
our General Public Licenses are intended to guarantee your freedom to
|
17 |
+
share and change all versions of a program--to make sure it remains free
|
18 |
+
software for all its users.
|
19 |
+
|
20 |
+
When we speak of free software, we are referring to freedom, not
|
21 |
+
price. Our General Public Licenses are designed to make sure that you
|
22 |
+
have the freedom to distribute copies of free software (and charge for
|
23 |
+
them if you wish), that you receive source code or can get it if you
|
24 |
+
want it, that you can change the software or use pieces of it in new
|
25 |
+
free programs, and that you know you can do these things.
|
26 |
+
|
27 |
+
Developers that use our General Public Licenses protect your rights
|
28 |
+
with two steps: (1) assert copyright on the software, and (2) offer
|
29 |
+
you this License which gives you legal permission to copy, distribute
|
30 |
+
and/or modify the software.
|
31 |
+
|
32 |
+
A secondary benefit of defending all users' freedom is that
|
33 |
+
improvements made in alternate versions of the program, if they
|
34 |
+
receive widespread use, become available for other developers to
|
35 |
+
incorporate. Many developers of free software are heartened and
|
36 |
+
encouraged by the resulting cooperation. However, in the case of
|
37 |
+
software used on network servers, this result may fail to come about.
|
38 |
+
The GNU General Public License permits making a modified version and
|
39 |
+
letting the public access it on a server without ever releasing its
|
40 |
+
source code to the public.
|
41 |
+
|
42 |
+
The GNU Affero General Public License is designed specifically to
|
43 |
+
ensure that, in such cases, the modified source code becomes available
|
44 |
+
to the community. It requires the operator of a network server to
|
45 |
+
provide the source code of the modified version running there to the
|
46 |
+
users of that server. Therefore, public use of a modified version, on
|
47 |
+
a publicly accessible server, gives the public access to the source
|
48 |
+
code of the modified version.
|
49 |
+
|
50 |
+
An older license, called the Affero General Public License and
|
51 |
+
published by Affero, was designed to accomplish similar goals. This is
|
52 |
+
a different license, not a version of the Affero GPL, but Affero has
|
53 |
+
released a new version of the Affero GPL which permits relicensing under
|
54 |
+
this license.
|
55 |
+
|
56 |
+
The precise terms and conditions for copying, distribution and
|
57 |
+
modification follow.
|
58 |
+
|
59 |
+
TERMS AND CONDITIONS
|
60 |
+
|
61 |
+
0. Definitions.
|
62 |
+
|
63 |
+
"This License" refers to version 3 of the GNU Affero General Public License.
|
64 |
+
|
65 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
66 |
+
works, such as semiconductor masks.
|
67 |
+
|
68 |
+
"The Program" refers to any copyrightable work licensed under this
|
69 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
70 |
+
"recipients" may be individuals or organizations.
|
71 |
+
|
72 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
73 |
+
in a fashion requiring copyright permission, other than the making of an
|
74 |
+
exact copy. The resulting work is called a "modified version" of the
|
75 |
+
earlier work or a work "based on" the earlier work.
|
76 |
+
|
77 |
+
A "covered work" means either the unmodified Program or a work based
|
78 |
+
on the Program.
|
79 |
+
|
80 |
+
To "propagate" a work means to do anything with it that, without
|
81 |
+
permission, would make you directly or secondarily liable for
|
82 |
+
infringement under applicable copyright law, except executing it on a
|
83 |
+
computer or modifying a private copy. Propagation includes copying,
|
84 |
+
distribution (with or without modification), making available to the
|
85 |
+
public, and in some countries other activities as well.
|
86 |
+
|
87 |
+
To "convey" a work means any kind of propagation that enables other
|
88 |
+
parties to make or receive copies. Mere interaction with a user through
|
89 |
+
a computer network, with no transfer of a copy, is not conveying.
|
90 |
+
|
91 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
92 |
+
to the extent that it includes a convenient and prominently visible
|
93 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
94 |
+
tells the user that there is no warranty for the work (except to the
|
95 |
+
extent that warranties are provided), that licensees may convey the
|
96 |
+
work under this License, and how to view a copy of this License. If
|
97 |
+
the interface presents a list of user commands or options, such as a
|
98 |
+
menu, a prominent item in the list meets this criterion.
|
99 |
+
|
100 |
+
1. Source Code.
|
101 |
+
|
102 |
+
The "source code" for a work means the preferred form of the work
|
103 |
+
for making modifications to it. "Object code" means any non-source
|
104 |
+
form of a work.
|
105 |
+
|
106 |
+
A "Standard Interface" means an interface that either is an official
|
107 |
+
standard defined by a recognized standards body, or, in the case of
|
108 |
+
interfaces specified for a particular programming language, one that
|
109 |
+
is widely used among developers working in that language.
|
110 |
+
|
111 |
+
The "System Libraries" of an executable work include anything, other
|
112 |
+
than the work as a whole, that (a) is included in the normal form of
|
113 |
+
packaging a Major Component, but which is not part of that Major
|
114 |
+
Component, and (b) serves only to enable use of the work with that
|
115 |
+
Major Component, or to implement a Standard Interface for which an
|
116 |
+
implementation is available to the public in source code form. A
|
117 |
+
"Major Component", in this context, means a major essential component
|
118 |
+
(kernel, window system, and so on) of the specific operating system
|
119 |
+
(if any) on which the executable work runs, or a compiler used to
|
120 |
+
produce the work, or an object code interpreter used to run it.
|
121 |
+
|
122 |
+
The "Corresponding Source" for a work in object code form means all
|
123 |
+
the source code needed to generate, install, and (for an executable
|
124 |
+
work) run the object code and to modify the work, including scripts to
|
125 |
+
control those activities. However, it does not include the work's
|
126 |
+
System Libraries, or general-purpose tools or generally available free
|
127 |
+
programs which are used unmodified in performing those activities but
|
128 |
+
which are not part of the work. For example, Corresponding Source
|
129 |
+
includes interface definition files associated with source files for
|
130 |
+
the work, and the source code for shared libraries and dynamically
|
131 |
+
linked subprograms that the work is specifically designed to require,
|
132 |
+
such as by intimate data communication or control flow between those
|
133 |
+
subprograms and other parts of the work.
|
134 |
+
|
135 |
+
The Corresponding Source need not include anything that users
|
136 |
+
can regenerate automatically from other parts of the Corresponding
|
137 |
+
Source.
|
138 |
+
|
139 |
+
The Corresponding Source for a work in source code form is that
|
140 |
+
same work.
|
141 |
+
|
142 |
+
2. Basic Permissions.
|
143 |
+
|
144 |
+
All rights granted under this License are granted for the term of
|
145 |
+
copyright on the Program, and are irrevocable provided the stated
|
146 |
+
conditions are met. This License explicitly affirms your unlimited
|
147 |
+
permission to run the unmodified Program. The output from running a
|
148 |
+
covered work is covered by this License only if the output, given its
|
149 |
+
content, constitutes a covered work. This License acknowledges your
|
150 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
151 |
+
|
152 |
+
You may make, run and propagate covered works that you do not
|
153 |
+
convey, without conditions so long as your license otherwise remains
|
154 |
+
in force. You may convey covered works to others for the sole purpose
|
155 |
+
of having them make modifications exclusively for you, or provide you
|
156 |
+
with facilities for running those works, provided that you comply with
|
157 |
+
the terms of this License in conveying all material for which you do
|
158 |
+
not control copyright. Those thus making or running the covered works
|
159 |
+
for you must do so exclusively on your behalf, under your direction
|
160 |
+
and control, on terms that prohibit them from making any copies of
|
161 |
+
your copyrighted material outside their relationship with you.
|
162 |
+
|
163 |
+
Conveying under any other circumstances is permitted solely under
|
164 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
165 |
+
makes it unnecessary.
|
166 |
+
|
167 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
168 |
+
|
169 |
+
No covered work shall be deemed part of an effective technological
|
170 |
+
measure under any applicable law fulfilling obligations under article
|
171 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
172 |
+
similar laws prohibiting or restricting circumvention of such
|
173 |
+
measures.
|
174 |
+
|
175 |
+
When you convey a covered work, you waive any legal power to forbid
|
176 |
+
circumvention of technological measures to the extent such circumvention
|
177 |
+
is effected by exercising rights under this License with respect to
|
178 |
+
the covered work, and you disclaim any intention to limit operation or
|
179 |
+
modification of the work as a means of enforcing, against the work's
|
180 |
+
users, your or third parties' legal rights to forbid circumvention of
|
181 |
+
technological measures.
|
182 |
+
|
183 |
+
4. Conveying Verbatim Copies.
|
184 |
+
|
185 |
+
You may convey verbatim copies of the Program's source code as you
|
186 |
+
receive it, in any medium, provided that you conspicuously and
|
187 |
+
appropriately publish on each copy an appropriate copyright notice;
|
188 |
+
keep intact all notices stating that this License and any
|
189 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
190 |
+
keep intact all notices of the absence of any warranty; and give all
|
191 |
+
recipients a copy of this License along with the Program.
|
192 |
+
|
193 |
+
You may charge any price or no price for each copy that you convey,
|
194 |
+
and you may offer support or warranty protection for a fee.
|
195 |
+
|
196 |
+
5. Conveying Modified Source Versions.
|
197 |
+
|
198 |
+
You may convey a work based on the Program, or the modifications to
|
199 |
+
produce it from the Program, in the form of source code under the
|
200 |
+
terms of section 4, provided that you also meet all of these conditions:
|
201 |
+
|
202 |
+
a) The work must carry prominent notices stating that you modified
|
203 |
+
it, and giving a relevant date.
|
204 |
+
|
205 |
+
b) The work must carry prominent notices stating that it is
|
206 |
+
released under this License and any conditions added under section
|
207 |
+
7. This requirement modifies the requirement in section 4 to
|
208 |
+
"keep intact all notices".
|
209 |
+
|
210 |
+
c) You must license the entire work, as a whole, under this
|
211 |
+
License to anyone who comes into possession of a copy. This
|
212 |
+
License will therefore apply, along with any applicable section 7
|
213 |
+
additional terms, to the whole of the work, and all its parts,
|
214 |
+
regardless of how they are packaged. This License gives no
|
215 |
+
permission to license the work in any other way, but it does not
|
216 |
+
invalidate such permission if you have separately received it.
|
217 |
+
|
218 |
+
d) If the work has interactive user interfaces, each must display
|
219 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
220 |
+
interfaces that do not display Appropriate Legal Notices, your
|
221 |
+
work need not make them do so.
|
222 |
+
|
223 |
+
A compilation of a covered work with other separate and independent
|
224 |
+
works, which are not by their nature extensions of the covered work,
|
225 |
+
and which are not combined with it such as to form a larger program,
|
226 |
+
in or on a volume of a storage or distribution medium, is called an
|
227 |
+
"aggregate" if the compilation and its resulting copyright are not
|
228 |
+
used to limit the access or legal rights of the compilation's users
|
229 |
+
beyond what the individual works permit. Inclusion of a covered work
|
230 |
+
in an aggregate does not cause this License to apply to the other
|
231 |
+
parts of the aggregate.
|
232 |
+
|
233 |
+
6. Conveying Non-Source Forms.
|
234 |
+
|
235 |
+
You may convey a covered work in object code form under the terms
|
236 |
+
of sections 4 and 5, provided that you also convey the
|
237 |
+
machine-readable Corresponding Source under the terms of this License,
|
238 |
+
in one of these ways:
|
239 |
+
|
240 |
+
a) Convey the object code in, or embodied in, a physical product
|
241 |
+
(including a physical distribution medium), accompanied by the
|
242 |
+
Corresponding Source fixed on a durable physical medium
|
243 |
+
customarily used for software interchange.
|
244 |
+
|
245 |
+
b) Convey the object code in, or embodied in, a physical product
|
246 |
+
(including a physical distribution medium), accompanied by a
|
247 |
+
written offer, valid for at least three years and valid for as
|
248 |
+
long as you offer spare parts or customer support for that product
|
249 |
+
model, to give anyone who possesses the object code either (1) a
|
250 |
+
copy of the Corresponding Source for all the software in the
|
251 |
+
product that is covered by this License, on a durable physical
|
252 |
+
medium customarily used for software interchange, for a price no
|
253 |
+
more than your reasonable cost of physically performing this
|
254 |
+
conveying of source, or (2) access to copy the
|
255 |
+
Corresponding Source from a network server at no charge.
|
256 |
+
|
257 |
+
c) Convey individual copies of the object code with a copy of the
|
258 |
+
written offer to provide the Corresponding Source. This
|
259 |
+
alternative is allowed only occasionally and noncommercially, and
|
260 |
+
only if you received the object code with such an offer, in accord
|
261 |
+
with subsection 6b.
|
262 |
+
|
263 |
+
d) Convey the object code by offering access from a designated
|
264 |
+
place (gratis or for a charge), and offer equivalent access to the
|
265 |
+
Corresponding Source in the same way through the same place at no
|
266 |
+
further charge. You need not require recipients to copy the
|
267 |
+
Corresponding Source along with the object code. If the place to
|
268 |
+
copy the object code is a network server, the Corresponding Source
|
269 |
+
may be on a different server (operated by you or a third party)
|
270 |
+
that supports equivalent copying facilities, provided you maintain
|
271 |
+
clear directions next to the object code saying where to find the
|
272 |
+
Corresponding Source. Regardless of what server hosts the
|
273 |
+
Corresponding Source, you remain obligated to ensure that it is
|
274 |
+
available for as long as needed to satisfy these requirements.
|
275 |
+
|
276 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
277 |
+
you inform other peers where the object code and Corresponding
|
278 |
+
Source of the work are being offered to the general public at no
|
279 |
+
charge under subsection 6d.
|
280 |
+
|
281 |
+
A separable portion of the object code, whose source code is excluded
|
282 |
+
from the Corresponding Source as a System Library, need not be
|
283 |
+
included in conveying the object code work.
|
284 |
+
|
285 |
+
A "User Product" is either (1) a "consumer product", which means any
|
286 |
+
tangible personal property which is normally used for personal, family,
|
287 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
288 |
+
into a dwelling. In determining whether a product is a consumer product,
|
289 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
290 |
+
product received by a particular user, "normally used" refers to a
|
291 |
+
typical or common use of that class of product, regardless of the status
|
292 |
+
of the particular user or of the way in which the particular user
|
293 |
+
actually uses, or expects or is expected to use, the product. A product
|
294 |
+
is a consumer product regardless of whether the product has substantial
|
295 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
296 |
+
the only significant mode of use of the product.
|
297 |
+
|
298 |
+
"Installation Information" for a User Product means any methods,
|
299 |
+
procedures, authorization keys, or other information required to install
|
300 |
+
and execute modified versions of a covered work in that User Product from
|
301 |
+
a modified version of its Corresponding Source. The information must
|
302 |
+
suffice to ensure that the continued functioning of the modified object
|
303 |
+
code is in no case prevented or interfered with solely because
|
304 |
+
modification has been made.
|
305 |
+
|
306 |
+
If you convey an object code work under this section in, or with, or
|
307 |
+
specifically for use in, a User Product, and the conveying occurs as
|
308 |
+
part of a transaction in which the right of possession and use of the
|
309 |
+
User Product is transferred to the recipient in perpetuity or for a
|
310 |
+
fixed term (regardless of how the transaction is characterized), the
|
311 |
+
Corresponding Source conveyed under this section must be accompanied
|
312 |
+
by the Installation Information. But this requirement does not apply
|
313 |
+
if neither you nor any third party retains the ability to install
|
314 |
+
modified object code on the User Product (for example, the work has
|
315 |
+
been installed in ROM).
|
316 |
+
|
317 |
+
The requirement to provide Installation Information does not include a
|
318 |
+
requirement to continue to provide support service, warranty, or updates
|
319 |
+
for a work that has been modified or installed by the recipient, or for
|
320 |
+
the User Product in which it has been modified or installed. Access to a
|
321 |
+
network may be denied when the modification itself materially and
|
322 |
+
adversely affects the operation of the network or violates the rules and
|
323 |
+
protocols for communication across the network.
|
324 |
+
|
325 |
+
Corresponding Source conveyed, and Installation Information provided,
|
326 |
+
in accord with this section must be in a format that is publicly
|
327 |
+
documented (and with an implementation available to the public in
|
328 |
+
source code form), and must require no special password or key for
|
329 |
+
unpacking, reading or copying.
|
330 |
+
|
331 |
+
7. Additional Terms.
|
332 |
+
|
333 |
+
"Additional permissions" are terms that supplement the terms of this
|
334 |
+
License by making exceptions from one or more of its conditions.
|
335 |
+
Additional permissions that are applicable to the entire Program shall
|
336 |
+
be treated as though they were included in this License, to the extent
|
337 |
+
that they are valid under applicable law. If additional permissions
|
338 |
+
apply only to part of the Program, that part may be used separately
|
339 |
+
under those permissions, but the entire Program remains governed by
|
340 |
+
this License without regard to the additional permissions.
|
341 |
+
|
342 |
+
When you convey a copy of a covered work, you may at your option
|
343 |
+
remove any additional permissions from that copy, or from any part of
|
344 |
+
it. (Additional permissions may be written to require their own
|
345 |
+
removal in certain cases when you modify the work.) You may place
|
346 |
+
additional permissions on material, added by you to a covered work,
|
347 |
+
for which you have or can give appropriate copyright permission.
|
348 |
+
|
349 |
+
Notwithstanding any other provision of this License, for material you
|
350 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
351 |
+
that material) supplement the terms of this License with terms:
|
352 |
+
|
353 |
+
a) Disclaiming warranty or limiting liability differently from the
|
354 |
+
terms of sections 15 and 16 of this License; or
|
355 |
+
|
356 |
+
b) Requiring preservation of specified reasonable legal notices or
|
357 |
+
author attributions in that material or in the Appropriate Legal
|
358 |
+
Notices displayed by works containing it; or
|
359 |
+
|
360 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
361 |
+
requiring that modified versions of such material be marked in
|
362 |
+
reasonable ways as different from the original version; or
|
363 |
+
|
364 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
365 |
+
authors of the material; or
|
366 |
+
|
367 |
+
e) Declining to grant rights under trademark law for use of some
|
368 |
+
trade names, trademarks, or service marks; or
|
369 |
+
|
370 |
+
f) Requiring indemnification of licensors and authors of that
|
371 |
+
material by anyone who conveys the material (or modified versions of
|
372 |
+
it) with contractual assumptions of liability to the recipient, for
|
373 |
+
any liability that these contractual assumptions directly impose on
|
374 |
+
those licensors and authors.
|
375 |
+
|
376 |
+
All other non-permissive additional terms are considered "further
|
377 |
+
restrictions" within the meaning of section 10. If the Program as you
|
378 |
+
received it, or any part of it, contains a notice stating that it is
|
379 |
+
governed by this License along with a term that is a further
|
380 |
+
restriction, you may remove that term. If a license document contains
|
381 |
+
a further restriction but permits relicensing or conveying under this
|
382 |
+
License, you may add to a covered work material governed by the terms
|
383 |
+
of that license document, provided that the further restriction does
|
384 |
+
not survive such relicensing or conveying.
|
385 |
+
|
386 |
+
If you add terms to a covered work in accord with this section, you
|
387 |
+
must place, in the relevant source files, a statement of the
|
388 |
+
additional terms that apply to those files, or a notice indicating
|
389 |
+
where to find the applicable terms.
|
390 |
+
|
391 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
392 |
+
form of a separately written license, or stated as exceptions;
|
393 |
+
the above requirements apply either way.
|
394 |
+
|
395 |
+
8. Termination.
|
396 |
+
|
397 |
+
You may not propagate or modify a covered work except as expressly
|
398 |
+
provided under this License. Any attempt otherwise to propagate or
|
399 |
+
modify it is void, and will automatically terminate your rights under
|
400 |
+
this License (including any patent licenses granted under the third
|
401 |
+
paragraph of section 11).
|
402 |
+
|
403 |
+
However, if you cease all violation of this License, then your
|
404 |
+
license from a particular copyright holder is reinstated (a)
|
405 |
+
provisionally, unless and until the copyright holder explicitly and
|
406 |
+
finally terminates your license, and (b) permanently, if the copyright
|
407 |
+
holder fails to notify you of the violation by some reasonable means
|
408 |
+
prior to 60 days after the cessation.
|
409 |
+
|
410 |
+
Moreover, your license from a particular copyright holder is
|
411 |
+
reinstated permanently if the copyright holder notifies you of the
|
412 |
+
violation by some reasonable means, this is the first time you have
|
413 |
+
received notice of violation of this License (for any work) from that
|
414 |
+
copyright holder, and you cure the violation prior to 30 days after
|
415 |
+
your receipt of the notice.
|
416 |
+
|
417 |
+
Termination of your rights under this section does not terminate the
|
418 |
+
licenses of parties who have received copies or rights from you under
|
419 |
+
this License. If your rights have been terminated and not permanently
|
420 |
+
reinstated, you do not qualify to receive new licenses for the same
|
421 |
+
material under section 10.
|
422 |
+
|
423 |
+
9. Acceptance Not Required for Having Copies.
|
424 |
+
|
425 |
+
You are not required to accept this License in order to receive or
|
426 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
427 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
428 |
+
to receive a copy likewise does not require acceptance. However,
|
429 |
+
nothing other than this License grants you permission to propagate or
|
430 |
+
modify any covered work. These actions infringe copyright if you do
|
431 |
+
not accept this License. Therefore, by modifying or propagating a
|
432 |
+
covered work, you indicate your acceptance of this License to do so.
|
433 |
+
|
434 |
+
10. Automatic Licensing of Downstream Recipients.
|
435 |
+
|
436 |
+
Each time you convey a covered work, the recipient automatically
|
437 |
+
receives a license from the original licensors, to run, modify and
|
438 |
+
propagate that work, subject to this License. You are not responsible
|
439 |
+
for enforcing compliance by third parties with this License.
|
440 |
+
|
441 |
+
An "entity transaction" is a transaction transferring control of an
|
442 |
+
organization, or substantially all assets of one, or subdividing an
|
443 |
+
organization, or merging organizations. If propagation of a covered
|
444 |
+
work results from an entity transaction, each party to that
|
445 |
+
transaction who receives a copy of the work also receives whatever
|
446 |
+
licenses to the work the party's predecessor in interest had or could
|
447 |
+
give under the previous paragraph, plus a right to possession of the
|
448 |
+
Corresponding Source of the work from the predecessor in interest, if
|
449 |
+
the predecessor has it or can get it with reasonable efforts.
|
450 |
+
|
451 |
+
You may not impose any further restrictions on the exercise of the
|
452 |
+
rights granted or affirmed under this License. For example, you may
|
453 |
+
not impose a license fee, royalty, or other charge for exercise of
|
454 |
+
rights granted under this License, and you may not initiate litigation
|
455 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
456 |
+
any patent claim is infringed by making, using, selling, offering for
|
457 |
+
sale, or importing the Program or any portion of it.
|
458 |
+
|
459 |
+
11. Patents.
|
460 |
+
|
461 |
+
A "contributor" is a copyright holder who authorizes use under this
|
462 |
+
License of the Program or a work on which the Program is based. The
|
463 |
+
work thus licensed is called the contributor's "contributor version".
|
464 |
+
|
465 |
+
A contributor's "essential patent claims" are all patent claims
|
466 |
+
owned or controlled by the contributor, whether already acquired or
|
467 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
468 |
+
by this License, of making, using, or selling its contributor version,
|
469 |
+
but do not include claims that would be infringed only as a
|
470 |
+
consequence of further modification of the contributor version. For
|
471 |
+
purposes of this definition, "control" includes the right to grant
|
472 |
+
patent sublicenses in a manner consistent with the requirements of
|
473 |
+
this License.
|
474 |
+
|
475 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
476 |
+
patent license under the contributor's essential patent claims, to
|
477 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
478 |
+
propagate the contents of its contributor version.
|
479 |
+
|
480 |
+
In the following three paragraphs, a "patent license" is any express
|
481 |
+
agreement or commitment, however denominated, not to enforce a patent
|
482 |
+
(such as an express permission to practice a patent or covenant not to
|
483 |
+
sue for patent infringement). To "grant" such a patent license to a
|
484 |
+
party means to make such an agreement or commitment not to enforce a
|
485 |
+
patent against the party.
|
486 |
+
|
487 |
+
If you convey a covered work, knowingly relying on a patent license,
|
488 |
+
and the Corresponding Source of the work is not available for anyone
|
489 |
+
to copy, free of charge and under the terms of this License, through a
|
490 |
+
publicly available network server or other readily accessible means,
|
491 |
+
then you must either (1) cause the Corresponding Source to be so
|
492 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
493 |
+
patent license for this particular work, or (3) arrange, in a manner
|
494 |
+
consistent with the requirements of this License, to extend the patent
|
495 |
+
license to downstream recipients. "Knowingly relying" means you have
|
496 |
+
actual knowledge that, but for the patent license, your conveying the
|
497 |
+
covered work in a country, or your recipient's use of the covered work
|
498 |
+
in a country, would infringe one or more identifiable patents in that
|
499 |
+
country that you have reason to believe are valid.
|
500 |
+
|
501 |
+
If, pursuant to or in connection with a single transaction or
|
502 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
503 |
+
covered work, and grant a patent license to some of the parties
|
504 |
+
receiving the covered work authorizing them to use, propagate, modify
|
505 |
+
or convey a specific copy of the covered work, then the patent license
|
506 |
+
you grant is automatically extended to all recipients of the covered
|
507 |
+
work and works based on it.
|
508 |
+
|
509 |
+
A patent license is "discriminatory" if it does not include within
|
510 |
+
the scope of its coverage, prohibits the exercise of, or is
|
511 |
+
conditioned on the non-exercise of one or more of the rights that are
|
512 |
+
specifically granted under this License. You may not convey a covered
|
513 |
+
work if you are a party to an arrangement with a third party that is
|
514 |
+
in the business of distributing software, under which you make payment
|
515 |
+
to the third party based on the extent of your activity of conveying
|
516 |
+
the work, and under which the third party grants, to any of the
|
517 |
+
parties who would receive the covered work from you, a discriminatory
|
518 |
+
patent license (a) in connection with copies of the covered work
|
519 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
520 |
+
for and in connection with specific products or compilations that
|
521 |
+
contain the covered work, unless you entered into that arrangement,
|
522 |
+
or that patent license was granted, prior to 28 March 2007.
|
523 |
+
|
524 |
+
Nothing in this License shall be construed as excluding or limiting
|
525 |
+
any implied license or other defenses to infringement that may
|
526 |
+
otherwise be available to you under applicable patent law.
|
527 |
+
|
528 |
+
12. No Surrender of Others' Freedom.
|
529 |
+
|
530 |
+
If conditions are imposed on you (whether by court order, agreement or
|
531 |
+
otherwise) that contradict the conditions of this License, they do not
|
532 |
+
excuse you from the conditions of this License. If you cannot convey a
|
533 |
+
covered work so as to satisfy simultaneously your obligations under this
|
534 |
+
License and any other pertinent obligations, then as a consequence you may
|
535 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
536 |
+
to collect a royalty for further conveying from those to whom you convey
|
537 |
+
the Program, the only way you could satisfy both those terms and this
|
538 |
+
License would be to refrain entirely from conveying the Program.
|
539 |
+
|
540 |
+
13. Remote Network Interaction; Use with the GNU General Public License.
|
541 |
+
|
542 |
+
Notwithstanding any other provision of this License, if you modify the
|
543 |
+
Program, your modified version must prominently offer all users
|
544 |
+
interacting with it remotely through a computer network (if your version
|
545 |
+
supports such interaction) an opportunity to receive the Corresponding
|
546 |
+
Source of your version by providing access to the Corresponding Source
|
547 |
+
from a network server at no charge, through some standard or customary
|
548 |
+
means of facilitating copying of software. This Corresponding Source
|
549 |
+
shall include the Corresponding Source for any work covered by version 3
|
550 |
+
of the GNU General Public License that is incorporated pursuant to the
|
551 |
+
following paragraph.
|
552 |
+
|
553 |
+
Notwithstanding any other provision of this License, you have
|
554 |
+
permission to link or combine any covered work with a work licensed
|
555 |
+
under version 3 of the GNU General Public License into a single
|
556 |
+
combined work, and to convey the resulting work. The terms of this
|
557 |
+
License will continue to apply to the part which is the covered work,
|
558 |
+
but the work with which it is combined will remain governed by version
|
559 |
+
3 of the GNU General Public License.
|
560 |
+
|
561 |
+
14. Revised Versions of this License.
|
562 |
+
|
563 |
+
The Free Software Foundation may publish revised and/or new versions of
|
564 |
+
the GNU Affero General Public License from time to time. Such new versions
|
565 |
+
will be similar in spirit to the present version, but may differ in detail to
|
566 |
+
address new problems or concerns.
|
567 |
+
|
568 |
+
Each version is given a distinguishing version number. If the
|
569 |
+
Program specifies that a certain numbered version of the GNU Affero General
|
570 |
+
Public License "or any later version" applies to it, you have the
|
571 |
+
option of following the terms and conditions either of that numbered
|
572 |
+
version or of any later version published by the Free Software
|
573 |
+
Foundation. If the Program does not specify a version number of the
|
574 |
+
GNU Affero General Public License, you may choose any version ever published
|
575 |
+
by the Free Software Foundation.
|
576 |
+
|
577 |
+
If the Program specifies that a proxy can decide which future
|
578 |
+
versions of the GNU Affero General Public License can be used, that proxy's
|
579 |
+
public statement of acceptance of a version permanently authorizes you
|
580 |
+
to choose that version for the Program.
|
581 |
+
|
582 |
+
Later license versions may give you additional or different
|
583 |
+
permissions. However, no additional obligations are imposed on any
|
584 |
+
author or copyright holder as a result of your choosing to follow a
|
585 |
+
later version.
|
586 |
+
|
587 |
+
15. Disclaimer of Warranty.
|
588 |
+
|
589 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
590 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
591 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
592 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
593 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
594 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
595 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
596 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
597 |
+
|
598 |
+
16. Limitation of Liability.
|
599 |
+
|
600 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
601 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
602 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
603 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
604 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
605 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
606 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
607 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
608 |
+
SUCH DAMAGES.
|
609 |
+
|
610 |
+
17. Interpretation of Sections 15 and 16.
|
611 |
+
|
612 |
+
If the disclaimer of warranty and limitation of liability provided
|
613 |
+
above cannot be given local legal effect according to their terms,
|
614 |
+
reviewing courts shall apply local law that most closely approximates
|
615 |
+
an absolute waiver of all civil liability in connection with the
|
616 |
+
Program, unless a warranty or assumption of liability accompanies a
|
617 |
+
copy of the Program in return for a fee.
|
618 |
+
|
619 |
+
END OF TERMS AND CONDITIONS
|
620 |
+
|
621 |
+
How to Apply These Terms to Your New Programs
|
622 |
+
|
623 |
+
If you develop a new program, and you want it to be of the greatest
|
624 |
+
possible use to the public, the best way to achieve this is to make it
|
625 |
+
free software which everyone can redistribute and change under these terms.
|
626 |
+
|
627 |
+
To do so, attach the following notices to the program. It is safest
|
628 |
+
to attach them to the start of each source file to most effectively
|
629 |
+
state the exclusion of warranty; and each file should have at least
|
630 |
+
the "copyright" line and a pointer to where the full notice is found.
|
631 |
+
|
632 |
+
<one line to give the program's name and a brief idea of what it does.>
|
633 |
+
Copyright (C) <year> <name of author>
|
634 |
+
|
635 |
+
This program is free software: you can redistribute it and/or modify
|
636 |
+
it under the terms of the GNU Affero General Public License as published
|
637 |
+
by the Free Software Foundation, either version 3 of the License, or
|
638 |
+
(at your option) any later version.
|
639 |
+
|
640 |
+
This program is distributed in the hope that it will be useful,
|
641 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
642 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
643 |
+
GNU Affero General Public License for more details.
|
644 |
+
|
645 |
+
You should have received a copy of the GNU Affero General Public License
|
646 |
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
647 |
+
|
648 |
+
Also add information on how to contact you by electronic and paper mail.
|
649 |
+
|
650 |
+
If your software can interact with users remotely through a computer
|
651 |
+
network, you should also make sure that it provides a way for users to
|
652 |
+
get its source. For example, if your program is a web application, its
|
653 |
+
interface could display a "Source" link that leads users to an archive
|
654 |
+
of the code. There are many ways you could offer source, and different
|
655 |
+
solutions will be better for different programs; see section 13 for the
|
656 |
+
specific requirements.
|
657 |
+
|
658 |
+
You should also get your employer (if you work as a programmer) or school,
|
659 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
660 |
+
For more information on this, and how to apply and follow the GNU AGPL, see
|
661 |
+
<https://www.gnu.org/licenses/>.
|
README.md
CHANGED
@@ -1,13 +1,42 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div align="center">
|
2 |
+
|
3 |
+
<img alt="LOGO" src="https://cdn.jsdelivr.net/gh/fishaudio/fish-diffusion@main/images/logo_512x512.png" width="256" height="256" />
|
4 |
+
|
5 |
+
# Bert-VITS2
|
6 |
+
|
7 |
+
VITS2 Backbone with multilingual bert
|
8 |
+
|
9 |
+
For quick guide, please refer to `webui_preprocess.py`.
|
10 |
+
|
11 |
+
简易教程请参见 `webui_preprocess.py`。
|
12 |
+
|
13 |
+
## 请注意,本项目核心思路来源于[anyvoiceai/MassTTS](https://github.com/anyvoiceai/MassTTS) 一个非常好的tts项目
|
14 |
+
## MassTTS的演示demo为[ai版峰哥锐评峰哥本人,并找回了在金三角失落的腰子](https://www.bilibili.com/video/BV1w24y1c7z9)
|
15 |
+
|
16 |
+
[//]: # (## 本项目与[PlayVoice/vits_chinese](https://github.com/PlayVoice/vits_chinese) 没有任何关系)
|
17 |
+
|
18 |
+
[//]: # ()
|
19 |
+
[//]: # (本仓库来源于之前朋友分享了ai峰哥的视频,本人被其中的效果惊艳,在自己尝试MassTTS以后发现fs在音质方面与vits有一定差距,并且training的pipeline比vits更复杂,因此按照其思路将bert)
|
20 |
+
|
21 |
+
## 成熟的旅行者/开拓者/舰长/博士/sensei/猎魔人/喵喵露/V应当参阅代码自己学习如何训练。
|
22 |
+
|
23 |
+
### 严禁将此项目用于一切违反《中华人民共和国宪法》,《中华人民共和国刑法》,《中华人民共和国治安管理处罚法》和《中华人民共和国民法典》之用途。
|
24 |
+
### 严禁用于任何政治相关用途。
|
25 |
+
#### Video:https://www.bilibili.com/video/BV1hp4y1K78E
|
26 |
+
#### Demo:https://www.bilibili.com/video/BV1TF411k78w
|
27 |
+
#### QQ Group:815818430
|
28 |
+
## References
|
29 |
+
+ [anyvoiceai/MassTTS](https://github.com/anyvoiceai/MassTTS)
|
30 |
+
+ [jaywalnut310/vits](https://github.com/jaywalnut310/vits)
|
31 |
+
+ [p0p4k/vits2_pytorch](https://github.com/p0p4k/vits2_pytorch)
|
32 |
+
+ [svc-develop-team/so-vits-svc](https://github.com/svc-develop-team/so-vits-svc)
|
33 |
+
+ [PaddlePaddle/PaddleSpeech](https://github.com/PaddlePaddle/PaddleSpeech)
|
34 |
+
+ [emotional-vits](https://github.com/innnky/emotional-vits)
|
35 |
+
+ [Bert-VITS2-en](https://github.com/xwan07017/Bert-VITS2-en)
|
36 |
+
+ [Bert-VITS2-UI](https://github.com/jiangyuxiaoxiao/Bert-VITS2-UI)
|
37 |
+
## 感谢所有贡献者作出的努力
|
38 |
+
<a href="https://github.com/fishaudio/Bert-VITS2/graphs/contributors" target="_blank">
|
39 |
+
<img src="https://contrib.rocks/image?repo=fishaudio/Bert-VITS2"/>
|
40 |
+
</a>
|
41 |
+
|
42 |
+
[//]: # (# 本项目所有代码引用均已写明,bert部分代码思路来源于[AI峰哥](https://www.bilibili.com/video/BV1w24y1c7z9),与[vits_chinese](https://github.com/PlayVoice/vits_chinese)无任何关系。欢迎各位查阅代码。同时,我们也对该开发者的[碰瓷,乃至开盒开发者的行为](https://www.bilibili.com/read/cv27101514/)表示强烈谴责。)
|
attentions.py
ADDED
@@ -0,0 +1,464 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch import nn
|
4 |
+
from torch.nn import functional as F
|
5 |
+
|
6 |
+
import commons
|
7 |
+
import logging
|
8 |
+
|
9 |
+
logger = logging.getLogger(__name__)
|
10 |
+
|
11 |
+
|
12 |
+
class LayerNorm(nn.Module):
|
13 |
+
def __init__(self, channels, eps=1e-5):
|
14 |
+
super().__init__()
|
15 |
+
self.channels = channels
|
16 |
+
self.eps = eps
|
17 |
+
|
18 |
+
self.gamma = nn.Parameter(torch.ones(channels))
|
19 |
+
self.beta = nn.Parameter(torch.zeros(channels))
|
20 |
+
|
21 |
+
def forward(self, x):
|
22 |
+
x = x.transpose(1, -1)
|
23 |
+
x = F.layer_norm(x, (self.channels,), self.gamma, self.beta, self.eps)
|
24 |
+
return x.transpose(1, -1)
|
25 |
+
|
26 |
+
|
27 |
+
@torch.jit.script
|
28 |
+
def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels):
|
29 |
+
n_channels_int = n_channels[0]
|
30 |
+
in_act = input_a + input_b
|
31 |
+
t_act = torch.tanh(in_act[:, :n_channels_int, :])
|
32 |
+
s_act = torch.sigmoid(in_act[:, n_channels_int:, :])
|
33 |
+
acts = t_act * s_act
|
34 |
+
return acts
|
35 |
+
|
36 |
+
|
37 |
+
class Encoder(nn.Module):
|
38 |
+
def __init__(
|
39 |
+
self,
|
40 |
+
hidden_channels,
|
41 |
+
filter_channels,
|
42 |
+
n_heads,
|
43 |
+
n_layers,
|
44 |
+
kernel_size=1,
|
45 |
+
p_dropout=0.0,
|
46 |
+
window_size=4,
|
47 |
+
isflow=True,
|
48 |
+
**kwargs
|
49 |
+
):
|
50 |
+
super().__init__()
|
51 |
+
self.hidden_channels = hidden_channels
|
52 |
+
self.filter_channels = filter_channels
|
53 |
+
self.n_heads = n_heads
|
54 |
+
self.n_layers = n_layers
|
55 |
+
self.kernel_size = kernel_size
|
56 |
+
self.p_dropout = p_dropout
|
57 |
+
self.window_size = window_size
|
58 |
+
# if isflow:
|
59 |
+
# cond_layer = torch.nn.Conv1d(256, 2*hidden_channels*n_layers, 1)
|
60 |
+
# self.cond_pre = torch.nn.Conv1d(hidden_channels, 2*hidden_channels, 1)
|
61 |
+
# self.cond_layer = weight_norm(cond_layer, name='weight')
|
62 |
+
# self.gin_channels = 256
|
63 |
+
self.cond_layer_idx = self.n_layers
|
64 |
+
if "gin_channels" in kwargs:
|
65 |
+
self.gin_channels = kwargs["gin_channels"]
|
66 |
+
if self.gin_channels != 0:
|
67 |
+
self.spk_emb_linear = nn.Linear(self.gin_channels, self.hidden_channels)
|
68 |
+
# vits2 says 3rd block, so idx is 2 by default
|
69 |
+
self.cond_layer_idx = (
|
70 |
+
kwargs["cond_layer_idx"] if "cond_layer_idx" in kwargs else 2
|
71 |
+
)
|
72 |
+
logging.debug(self.gin_channels, self.cond_layer_idx)
|
73 |
+
assert (
|
74 |
+
self.cond_layer_idx < self.n_layers
|
75 |
+
), "cond_layer_idx should be less than n_layers"
|
76 |
+
self.drop = nn.Dropout(p_dropout)
|
77 |
+
self.attn_layers = nn.ModuleList()
|
78 |
+
self.norm_layers_1 = nn.ModuleList()
|
79 |
+
self.ffn_layers = nn.ModuleList()
|
80 |
+
self.norm_layers_2 = nn.ModuleList()
|
81 |
+
for i in range(self.n_layers):
|
82 |
+
self.attn_layers.append(
|
83 |
+
MultiHeadAttention(
|
84 |
+
hidden_channels,
|
85 |
+
hidden_channels,
|
86 |
+
n_heads,
|
87 |
+
p_dropout=p_dropout,
|
88 |
+
window_size=window_size,
|
89 |
+
)
|
90 |
+
)
|
91 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
92 |
+
self.ffn_layers.append(
|
93 |
+
FFN(
|
94 |
+
hidden_channels,
|
95 |
+
hidden_channels,
|
96 |
+
filter_channels,
|
97 |
+
kernel_size,
|
98 |
+
p_dropout=p_dropout,
|
99 |
+
)
|
100 |
+
)
|
101 |
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
102 |
+
|
103 |
+
def forward(self, x, x_mask, g=None):
|
104 |
+
attn_mask = x_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
105 |
+
x = x * x_mask
|
106 |
+
for i in range(self.n_layers):
|
107 |
+
if i == self.cond_layer_idx and g is not None:
|
108 |
+
g = self.spk_emb_linear(g.transpose(1, 2))
|
109 |
+
g = g.transpose(1, 2)
|
110 |
+
x = x + g
|
111 |
+
x = x * x_mask
|
112 |
+
y = self.attn_layers[i](x, x, attn_mask)
|
113 |
+
y = self.drop(y)
|
114 |
+
x = self.norm_layers_1[i](x + y)
|
115 |
+
|
116 |
+
y = self.ffn_layers[i](x, x_mask)
|
117 |
+
y = self.drop(y)
|
118 |
+
x = self.norm_layers_2[i](x + y)
|
119 |
+
x = x * x_mask
|
120 |
+
return x
|
121 |
+
|
122 |
+
|
123 |
+
class Decoder(nn.Module):
|
124 |
+
def __init__(
|
125 |
+
self,
|
126 |
+
hidden_channels,
|
127 |
+
filter_channels,
|
128 |
+
n_heads,
|
129 |
+
n_layers,
|
130 |
+
kernel_size=1,
|
131 |
+
p_dropout=0.0,
|
132 |
+
proximal_bias=False,
|
133 |
+
proximal_init=True,
|
134 |
+
**kwargs
|
135 |
+
):
|
136 |
+
super().__init__()
|
137 |
+
self.hidden_channels = hidden_channels
|
138 |
+
self.filter_channels = filter_channels
|
139 |
+
self.n_heads = n_heads
|
140 |
+
self.n_layers = n_layers
|
141 |
+
self.kernel_size = kernel_size
|
142 |
+
self.p_dropout = p_dropout
|
143 |
+
self.proximal_bias = proximal_bias
|
144 |
+
self.proximal_init = proximal_init
|
145 |
+
|
146 |
+
self.drop = nn.Dropout(p_dropout)
|
147 |
+
self.self_attn_layers = nn.ModuleList()
|
148 |
+
self.norm_layers_0 = nn.ModuleList()
|
149 |
+
self.encdec_attn_layers = nn.ModuleList()
|
150 |
+
self.norm_layers_1 = nn.ModuleList()
|
151 |
+
self.ffn_layers = nn.ModuleList()
|
152 |
+
self.norm_layers_2 = nn.ModuleList()
|
153 |
+
for i in range(self.n_layers):
|
154 |
+
self.self_attn_layers.append(
|
155 |
+
MultiHeadAttention(
|
156 |
+
hidden_channels,
|
157 |
+
hidden_channels,
|
158 |
+
n_heads,
|
159 |
+
p_dropout=p_dropout,
|
160 |
+
proximal_bias=proximal_bias,
|
161 |
+
proximal_init=proximal_init,
|
162 |
+
)
|
163 |
+
)
|
164 |
+
self.norm_layers_0.append(LayerNorm(hidden_channels))
|
165 |
+
self.encdec_attn_layers.append(
|
166 |
+
MultiHeadAttention(
|
167 |
+
hidden_channels, hidden_channels, n_heads, p_dropout=p_dropout
|
168 |
+
)
|
169 |
+
)
|
170 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
171 |
+
self.ffn_layers.append(
|
172 |
+
FFN(
|
173 |
+
hidden_channels,
|
174 |
+
hidden_channels,
|
175 |
+
filter_channels,
|
176 |
+
kernel_size,
|
177 |
+
p_dropout=p_dropout,
|
178 |
+
causal=True,
|
179 |
+
)
|
180 |
+
)
|
181 |
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
182 |
+
|
183 |
+
def forward(self, x, x_mask, h, h_mask):
|
184 |
+
"""
|
185 |
+
x: decoder input
|
186 |
+
h: encoder output
|
187 |
+
"""
|
188 |
+
self_attn_mask = commons.subsequent_mask(x_mask.size(2)).to(
|
189 |
+
device=x.device, dtype=x.dtype
|
190 |
+
)
|
191 |
+
encdec_attn_mask = h_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
192 |
+
x = x * x_mask
|
193 |
+
for i in range(self.n_layers):
|
194 |
+
y = self.self_attn_layers[i](x, x, self_attn_mask)
|
195 |
+
y = self.drop(y)
|
196 |
+
x = self.norm_layers_0[i](x + y)
|
197 |
+
|
198 |
+
y = self.encdec_attn_layers[i](x, h, encdec_attn_mask)
|
199 |
+
y = self.drop(y)
|
200 |
+
x = self.norm_layers_1[i](x + y)
|
201 |
+
|
202 |
+
y = self.ffn_layers[i](x, x_mask)
|
203 |
+
y = self.drop(y)
|
204 |
+
x = self.norm_layers_2[i](x + y)
|
205 |
+
x = x * x_mask
|
206 |
+
return x
|
207 |
+
|
208 |
+
|
209 |
+
class MultiHeadAttention(nn.Module):
|
210 |
+
def __init__(
|
211 |
+
self,
|
212 |
+
channels,
|
213 |
+
out_channels,
|
214 |
+
n_heads,
|
215 |
+
p_dropout=0.0,
|
216 |
+
window_size=None,
|
217 |
+
heads_share=True,
|
218 |
+
block_length=None,
|
219 |
+
proximal_bias=False,
|
220 |
+
proximal_init=False,
|
221 |
+
):
|
222 |
+
super().__init__()
|
223 |
+
assert channels % n_heads == 0
|
224 |
+
|
225 |
+
self.channels = channels
|
226 |
+
self.out_channels = out_channels
|
227 |
+
self.n_heads = n_heads
|
228 |
+
self.p_dropout = p_dropout
|
229 |
+
self.window_size = window_size
|
230 |
+
self.heads_share = heads_share
|
231 |
+
self.block_length = block_length
|
232 |
+
self.proximal_bias = proximal_bias
|
233 |
+
self.proximal_init = proximal_init
|
234 |
+
self.attn = None
|
235 |
+
|
236 |
+
self.k_channels = channels // n_heads
|
237 |
+
self.conv_q = nn.Conv1d(channels, channels, 1)
|
238 |
+
self.conv_k = nn.Conv1d(channels, channels, 1)
|
239 |
+
self.conv_v = nn.Conv1d(channels, channels, 1)
|
240 |
+
self.conv_o = nn.Conv1d(channels, out_channels, 1)
|
241 |
+
self.drop = nn.Dropout(p_dropout)
|
242 |
+
|
243 |
+
if window_size is not None:
|
244 |
+
n_heads_rel = 1 if heads_share else n_heads
|
245 |
+
rel_stddev = self.k_channels**-0.5
|
246 |
+
self.emb_rel_k = nn.Parameter(
|
247 |
+
torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels)
|
248 |
+
* rel_stddev
|
249 |
+
)
|
250 |
+
self.emb_rel_v = nn.Parameter(
|
251 |
+
torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels)
|
252 |
+
* rel_stddev
|
253 |
+
)
|
254 |
+
|
255 |
+
nn.init.xavier_uniform_(self.conv_q.weight)
|
256 |
+
nn.init.xavier_uniform_(self.conv_k.weight)
|
257 |
+
nn.init.xavier_uniform_(self.conv_v.weight)
|
258 |
+
if proximal_init:
|
259 |
+
with torch.no_grad():
|
260 |
+
self.conv_k.weight.copy_(self.conv_q.weight)
|
261 |
+
self.conv_k.bias.copy_(self.conv_q.bias)
|
262 |
+
|
263 |
+
def forward(self, x, c, attn_mask=None):
|
264 |
+
q = self.conv_q(x)
|
265 |
+
k = self.conv_k(c)
|
266 |
+
v = self.conv_v(c)
|
267 |
+
|
268 |
+
x, self.attn = self.attention(q, k, v, mask=attn_mask)
|
269 |
+
|
270 |
+
x = self.conv_o(x)
|
271 |
+
return x
|
272 |
+
|
273 |
+
def attention(self, query, key, value, mask=None):
|
274 |
+
# reshape [b, d, t] -> [b, n_h, t, d_k]
|
275 |
+
b, d, t_s, t_t = (*key.size(), query.size(2))
|
276 |
+
query = query.view(b, self.n_heads, self.k_channels, t_t).transpose(2, 3)
|
277 |
+
key = key.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
278 |
+
value = value.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
279 |
+
|
280 |
+
scores = torch.matmul(query / math.sqrt(self.k_channels), key.transpose(-2, -1))
|
281 |
+
if self.window_size is not None:
|
282 |
+
assert (
|
283 |
+
t_s == t_t
|
284 |
+
), "Relative attention is only available for self-attention."
|
285 |
+
key_relative_embeddings = self._get_relative_embeddings(self.emb_rel_k, t_s)
|
286 |
+
rel_logits = self._matmul_with_relative_keys(
|
287 |
+
query / math.sqrt(self.k_channels), key_relative_embeddings
|
288 |
+
)
|
289 |
+
scores_local = self._relative_position_to_absolute_position(rel_logits)
|
290 |
+
scores = scores + scores_local
|
291 |
+
if self.proximal_bias:
|
292 |
+
assert t_s == t_t, "Proximal bias is only available for self-attention."
|
293 |
+
scores = scores + self._attention_bias_proximal(t_s).to(
|
294 |
+
device=scores.device, dtype=scores.dtype
|
295 |
+
)
|
296 |
+
if mask is not None:
|
297 |
+
scores = scores.masked_fill(mask == 0, -1e4)
|
298 |
+
if self.block_length is not None:
|
299 |
+
assert (
|
300 |
+
t_s == t_t
|
301 |
+
), "Local attention is only available for self-attention."
|
302 |
+
block_mask = (
|
303 |
+
torch.ones_like(scores)
|
304 |
+
.triu(-self.block_length)
|
305 |
+
.tril(self.block_length)
|
306 |
+
)
|
307 |
+
scores = scores.masked_fill(block_mask == 0, -1e4)
|
308 |
+
p_attn = F.softmax(scores, dim=-1) # [b, n_h, t_t, t_s]
|
309 |
+
p_attn = self.drop(p_attn)
|
310 |
+
output = torch.matmul(p_attn, value)
|
311 |
+
if self.window_size is not None:
|
312 |
+
relative_weights = self._absolute_position_to_relative_position(p_attn)
|
313 |
+
value_relative_embeddings = self._get_relative_embeddings(
|
314 |
+
self.emb_rel_v, t_s
|
315 |
+
)
|
316 |
+
output = output + self._matmul_with_relative_values(
|
317 |
+
relative_weights, value_relative_embeddings
|
318 |
+
)
|
319 |
+
output = (
|
320 |
+
output.transpose(2, 3).contiguous().view(b, d, t_t)
|
321 |
+
) # [b, n_h, t_t, d_k] -> [b, d, t_t]
|
322 |
+
return output, p_attn
|
323 |
+
|
324 |
+
def _matmul_with_relative_values(self, x, y):
|
325 |
+
"""
|
326 |
+
x: [b, h, l, m]
|
327 |
+
y: [h or 1, m, d]
|
328 |
+
ret: [b, h, l, d]
|
329 |
+
"""
|
330 |
+
ret = torch.matmul(x, y.unsqueeze(0))
|
331 |
+
return ret
|
332 |
+
|
333 |
+
def _matmul_with_relative_keys(self, x, y):
|
334 |
+
"""
|
335 |
+
x: [b, h, l, d]
|
336 |
+
y: [h or 1, m, d]
|
337 |
+
ret: [b, h, l, m]
|
338 |
+
"""
|
339 |
+
ret = torch.matmul(x, y.unsqueeze(0).transpose(-2, -1))
|
340 |
+
return ret
|
341 |
+
|
342 |
+
def _get_relative_embeddings(self, relative_embeddings, length):
|
343 |
+
2 * self.window_size + 1
|
344 |
+
# Pad first before slice to avoid using cond ops.
|
345 |
+
pad_length = max(length - (self.window_size + 1), 0)
|
346 |
+
slice_start_position = max((self.window_size + 1) - length, 0)
|
347 |
+
slice_end_position = slice_start_position + 2 * length - 1
|
348 |
+
if pad_length > 0:
|
349 |
+
padded_relative_embeddings = F.pad(
|
350 |
+
relative_embeddings,
|
351 |
+
commons.convert_pad_shape([[0, 0], [pad_length, pad_length], [0, 0]]),
|
352 |
+
)
|
353 |
+
else:
|
354 |
+
padded_relative_embeddings = relative_embeddings
|
355 |
+
used_relative_embeddings = padded_relative_embeddings[
|
356 |
+
:, slice_start_position:slice_end_position
|
357 |
+
]
|
358 |
+
return used_relative_embeddings
|
359 |
+
|
360 |
+
def _relative_position_to_absolute_position(self, x):
|
361 |
+
"""
|
362 |
+
x: [b, h, l, 2*l-1]
|
363 |
+
ret: [b, h, l, l]
|
364 |
+
"""
|
365 |
+
batch, heads, length, _ = x.size()
|
366 |
+
# Concat columns of pad to shift from relative to absolute indexing.
|
367 |
+
x = F.pad(x, commons.convert_pad_shape([[0, 0], [0, 0], [0, 0], [0, 1]]))
|
368 |
+
|
369 |
+
# Concat extra elements so to add up to shape (len+1, 2*len-1).
|
370 |
+
x_flat = x.view([batch, heads, length * 2 * length])
|
371 |
+
x_flat = F.pad(
|
372 |
+
x_flat, commons.convert_pad_shape([[0, 0], [0, 0], [0, length - 1]])
|
373 |
+
)
|
374 |
+
|
375 |
+
# Reshape and slice out the padded elements.
|
376 |
+
x_final = x_flat.view([batch, heads, length + 1, 2 * length - 1])[
|
377 |
+
:, :, :length, length - 1 :
|
378 |
+
]
|
379 |
+
return x_final
|
380 |
+
|
381 |
+
def _absolute_position_to_relative_position(self, x):
|
382 |
+
"""
|
383 |
+
x: [b, h, l, l]
|
384 |
+
ret: [b, h, l, 2*l-1]
|
385 |
+
"""
|
386 |
+
batch, heads, length, _ = x.size()
|
387 |
+
# pad along column
|
388 |
+
x = F.pad(
|
389 |
+
x, commons.convert_pad_shape([[0, 0], [0, 0], [0, 0], [0, length - 1]])
|
390 |
+
)
|
391 |
+
x_flat = x.view([batch, heads, length**2 + length * (length - 1)])
|
392 |
+
# add 0's in the beginning that will skew the elements after reshape
|
393 |
+
x_flat = F.pad(x_flat, commons.convert_pad_shape([[0, 0], [0, 0], [length, 0]]))
|
394 |
+
x_final = x_flat.view([batch, heads, length, 2 * length])[:, :, :, 1:]
|
395 |
+
return x_final
|
396 |
+
|
397 |
+
def _attention_bias_proximal(self, length):
|
398 |
+
"""Bias for self-attention to encourage attention to close positions.
|
399 |
+
Args:
|
400 |
+
length: an integer scalar.
|
401 |
+
Returns:
|
402 |
+
a Tensor with shape [1, 1, length, length]
|
403 |
+
"""
|
404 |
+
r = torch.arange(length, dtype=torch.float32)
|
405 |
+
diff = torch.unsqueeze(r, 0) - torch.unsqueeze(r, 1)
|
406 |
+
return torch.unsqueeze(torch.unsqueeze(-torch.log1p(torch.abs(diff)), 0), 0)
|
407 |
+
|
408 |
+
|
409 |
+
class FFN(nn.Module):
|
410 |
+
def __init__(
|
411 |
+
self,
|
412 |
+
in_channels,
|
413 |
+
out_channels,
|
414 |
+
filter_channels,
|
415 |
+
kernel_size,
|
416 |
+
p_dropout=0.0,
|
417 |
+
activation=None,
|
418 |
+
causal=False,
|
419 |
+
):
|
420 |
+
super().__init__()
|
421 |
+
self.in_channels = in_channels
|
422 |
+
self.out_channels = out_channels
|
423 |
+
self.filter_channels = filter_channels
|
424 |
+
self.kernel_size = kernel_size
|
425 |
+
self.p_dropout = p_dropout
|
426 |
+
self.activation = activation
|
427 |
+
self.causal = causal
|
428 |
+
|
429 |
+
if causal:
|
430 |
+
self.padding = self._causal_padding
|
431 |
+
else:
|
432 |
+
self.padding = self._same_padding
|
433 |
+
|
434 |
+
self.conv_1 = nn.Conv1d(in_channels, filter_channels, kernel_size)
|
435 |
+
self.conv_2 = nn.Conv1d(filter_channels, out_channels, kernel_size)
|
436 |
+
self.drop = nn.Dropout(p_dropout)
|
437 |
+
|
438 |
+
def forward(self, x, x_mask):
|
439 |
+
x = self.conv_1(self.padding(x * x_mask))
|
440 |
+
if self.activation == "gelu":
|
441 |
+
x = x * torch.sigmoid(1.702 * x)
|
442 |
+
else:
|
443 |
+
x = torch.relu(x)
|
444 |
+
x = self.drop(x)
|
445 |
+
x = self.conv_2(self.padding(x * x_mask))
|
446 |
+
return x * x_mask
|
447 |
+
|
448 |
+
def _causal_padding(self, x):
|
449 |
+
if self.kernel_size == 1:
|
450 |
+
return x
|
451 |
+
pad_l = self.kernel_size - 1
|
452 |
+
pad_r = 0
|
453 |
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
454 |
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
455 |
+
return x
|
456 |
+
|
457 |
+
def _same_padding(self, x):
|
458 |
+
if self.kernel_size == 1:
|
459 |
+
return x
|
460 |
+
pad_l = (self.kernel_size - 1) // 2
|
461 |
+
pad_r = self.kernel_size // 2
|
462 |
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
463 |
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
464 |
+
return x
|
bert_gen.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
from multiprocessing import Pool, cpu_count
|
3 |
+
|
4 |
+
import torch
|
5 |
+
import torch.multiprocessing as mp
|
6 |
+
from tqdm import tqdm
|
7 |
+
|
8 |
+
import commons
|
9 |
+
import utils
|
10 |
+
from config import config
|
11 |
+
from text import cleaned_text_to_sequence, get_bert
|
12 |
+
|
13 |
+
|
14 |
+
def process_line(line):
|
15 |
+
device = config.bert_gen_config.device
|
16 |
+
if config.bert_gen_config.use_multi_device:
|
17 |
+
rank = mp.current_process()._identity
|
18 |
+
rank = rank[0] if len(rank) > 0 else 0
|
19 |
+
if torch.cuda.is_available():
|
20 |
+
gpu_id = rank % torch.cuda.device_count()
|
21 |
+
device = torch.device(f"cuda:{gpu_id}")
|
22 |
+
else:
|
23 |
+
device = torch.device("cpu")
|
24 |
+
wav_path, _, language_str, text, phones, tone, word2ph = line.strip().split("|")
|
25 |
+
phone = phones.split(" ")
|
26 |
+
tone = [int(i) for i in tone.split(" ")]
|
27 |
+
word2ph = [int(i) for i in word2ph.split(" ")]
|
28 |
+
word2ph = [i for i in word2ph]
|
29 |
+
phone, tone, language = cleaned_text_to_sequence(phone, tone, language_str)
|
30 |
+
|
31 |
+
phone = commons.intersperse(phone, 0)
|
32 |
+
tone = commons.intersperse(tone, 0)
|
33 |
+
language = commons.intersperse(language, 0)
|
34 |
+
for i in range(len(word2ph)):
|
35 |
+
word2ph[i] = word2ph[i] * 2
|
36 |
+
word2ph[0] += 1
|
37 |
+
|
38 |
+
bert_path = wav_path.replace(".WAV", ".wav").replace(".wav", ".bert.pt")
|
39 |
+
|
40 |
+
try:
|
41 |
+
bert = torch.load(bert_path)
|
42 |
+
assert bert.shape[-1] == len(phone)
|
43 |
+
except Exception:
|
44 |
+
bert = get_bert(text, word2ph, language_str, device)
|
45 |
+
assert bert.shape[-1] == len(phone)
|
46 |
+
torch.save(bert, bert_path)
|
47 |
+
|
48 |
+
|
49 |
+
preprocess_text_config = config.preprocess_text_config
|
50 |
+
|
51 |
+
if __name__ == "__main__":
|
52 |
+
parser = argparse.ArgumentParser()
|
53 |
+
parser.add_argument(
|
54 |
+
"-c", "--config", type=str, default=config.bert_gen_config.config_path
|
55 |
+
)
|
56 |
+
parser.add_argument(
|
57 |
+
"--num_processes", type=int, default=config.bert_gen_config.num_processes
|
58 |
+
)
|
59 |
+
args, _ = parser.parse_known_args()
|
60 |
+
config_path = args.config
|
61 |
+
hps = utils.get_hparams_from_file(config_path)
|
62 |
+
lines = []
|
63 |
+
with open(hps.data.training_files, encoding="utf-8") as f:
|
64 |
+
lines.extend(f.readlines())
|
65 |
+
|
66 |
+
with open(hps.data.validation_files, encoding="utf-8") as f:
|
67 |
+
lines.extend(f.readlines())
|
68 |
+
if len(lines) != 0:
|
69 |
+
num_processes = min(args.num_processes, cpu_count())
|
70 |
+
with Pool(processes=num_processes) as pool:
|
71 |
+
for _ in tqdm(pool.imap_unordered(process_line, lines), total=len(lines)):
|
72 |
+
pass
|
73 |
+
|
74 |
+
print(f"bert生成完毕!, 共有{len(lines)}个bert.pt生成!")
|
clap_gen.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
from multiprocessing import Pool, cpu_count
|
3 |
+
|
4 |
+
import torch
|
5 |
+
import torch.multiprocessing as mp
|
6 |
+
from tqdm import tqdm
|
7 |
+
|
8 |
+
import utils
|
9 |
+
from config import config
|
10 |
+
from clap_wrapper import get_clap_audio_feature
|
11 |
+
import librosa
|
12 |
+
import os
|
13 |
+
|
14 |
+
os.environ["OMP_NUM_THREADS"] = "1"
|
15 |
+
os.environ["MKL_NUM_THREADS"] = "1"
|
16 |
+
|
17 |
+
|
18 |
+
def process_line(line):
|
19 |
+
device = config.emo_gen_config.device
|
20 |
+
if config.emo_gen_config.use_multi_device:
|
21 |
+
rank = mp.current_process()._identity
|
22 |
+
rank = rank[0] if len(rank) > 0 else 0
|
23 |
+
if torch.cuda.is_available():
|
24 |
+
gpu_id = rank % torch.cuda.device_count()
|
25 |
+
device = torch.device(f"cuda:{gpu_id}")
|
26 |
+
else:
|
27 |
+
device = torch.device("cpu")
|
28 |
+
wav_path, _, language_str, text, phones, tone, word2ph = line.strip().split("|")
|
29 |
+
|
30 |
+
clap_path = wav_path.replace(".WAV", ".wav").replace(".wav", ".emo.npy")
|
31 |
+
if os.path.isfile(clap_path):
|
32 |
+
return
|
33 |
+
|
34 |
+
audio = librosa.load(wav_path, 48000)[0]
|
35 |
+
# audio = librosa.resample(audio, 44100, 48000)
|
36 |
+
|
37 |
+
clap = get_clap_audio_feature(audio, device)
|
38 |
+
torch.save(clap, clap_path)
|
39 |
+
|
40 |
+
|
41 |
+
if __name__ == "__main__":
|
42 |
+
parser = argparse.ArgumentParser()
|
43 |
+
parser.add_argument(
|
44 |
+
"-c", "--config", type=str, default=config.emo_gen_config.config_path
|
45 |
+
)
|
46 |
+
parser.add_argument(
|
47 |
+
"--num_processes", type=int, default=config.emo_gen_config.num_processes
|
48 |
+
)
|
49 |
+
args, _ = parser.parse_known_args()
|
50 |
+
config_path = args.config
|
51 |
+
hps = utils.get_hparams_from_file(config_path)
|
52 |
+
lines = []
|
53 |
+
with open(hps.data.training_files, encoding="utf-8") as f:
|
54 |
+
lines.extend(f.readlines())
|
55 |
+
|
56 |
+
with open(hps.data.validation_files, encoding="utf-8") as f:
|
57 |
+
lines.extend(f.readlines())
|
58 |
+
if len(lines) != 0:
|
59 |
+
num_processes = min(args.num_processes, cpu_count())
|
60 |
+
with Pool(processes=num_processes) as pool:
|
61 |
+
for _ in tqdm(pool.imap_unordered(process_line, lines), total=len(lines)):
|
62 |
+
pass
|
63 |
+
|
64 |
+
print(f"clap生成完毕!, 共有{len(lines)}个emo.pt生成!")
|
clap_wrapper.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
|
3 |
+
import torch
|
4 |
+
from transformers import ClapModel, ClapProcessor
|
5 |
+
|
6 |
+
from config import config
|
7 |
+
|
8 |
+
models = dict()
|
9 |
+
processor = ClapProcessor.from_pretrained("./emotional/clap-htsat-fused")
|
10 |
+
|
11 |
+
|
12 |
+
def get_clap_audio_feature(audio_data, device=config.bert_gen_config.device):
|
13 |
+
if (
|
14 |
+
sys.platform == "darwin"
|
15 |
+
and torch.backends.mps.is_available()
|
16 |
+
and device == "cpu"
|
17 |
+
):
|
18 |
+
device = "mps"
|
19 |
+
if not device:
|
20 |
+
device = "cuda"
|
21 |
+
if device not in models.keys():
|
22 |
+
models[device] = ClapModel.from_pretrained("./emotional/clap-htsat-fused").to(
|
23 |
+
device
|
24 |
+
)
|
25 |
+
with torch.no_grad():
|
26 |
+
inputs = processor(
|
27 |
+
audios=audio_data, return_tensors="pt", sampling_rate=48000
|
28 |
+
).to(device)
|
29 |
+
emb = models[device].get_audio_features(**inputs)
|
30 |
+
return emb.T
|
31 |
+
|
32 |
+
|
33 |
+
def get_clap_text_feature(text, device=config.bert_gen_config.device):
|
34 |
+
if (
|
35 |
+
sys.platform == "darwin"
|
36 |
+
and torch.backends.mps.is_available()
|
37 |
+
and device == "cpu"
|
38 |
+
):
|
39 |
+
device = "mps"
|
40 |
+
if not device:
|
41 |
+
device = "cuda"
|
42 |
+
if device not in models.keys():
|
43 |
+
models[device] = ClapModel.from_pretrained("./emotional/clap-htsat-fused").to(
|
44 |
+
device
|
45 |
+
)
|
46 |
+
with torch.no_grad():
|
47 |
+
inputs = processor(text=text, return_tensors="pt").to(device)
|
48 |
+
emb = models[device].get_text_features(**inputs)
|
49 |
+
return emb.T
|
commons.py
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch.nn import functional as F
|
4 |
+
|
5 |
+
|
6 |
+
def init_weights(m, mean=0.0, std=0.01):
|
7 |
+
classname = m.__class__.__name__
|
8 |
+
if classname.find("Conv") != -1:
|
9 |
+
m.weight.data.normal_(mean, std)
|
10 |
+
|
11 |
+
|
12 |
+
def get_padding(kernel_size, dilation=1):
|
13 |
+
return int((kernel_size * dilation - dilation) / 2)
|
14 |
+
|
15 |
+
|
16 |
+
def convert_pad_shape(pad_shape):
|
17 |
+
layer = pad_shape[::-1]
|
18 |
+
pad_shape = [item for sublist in layer for item in sublist]
|
19 |
+
return pad_shape
|
20 |
+
|
21 |
+
|
22 |
+
def intersperse(lst, item):
|
23 |
+
result = [item] * (len(lst) * 2 + 1)
|
24 |
+
result[1::2] = lst
|
25 |
+
return result
|
26 |
+
|
27 |
+
|
28 |
+
def kl_divergence(m_p, logs_p, m_q, logs_q):
|
29 |
+
"""KL(P||Q)"""
|
30 |
+
kl = (logs_q - logs_p) - 0.5
|
31 |
+
kl += (
|
32 |
+
0.5 * (torch.exp(2.0 * logs_p) + ((m_p - m_q) ** 2)) * torch.exp(-2.0 * logs_q)
|
33 |
+
)
|
34 |
+
return kl
|
35 |
+
|
36 |
+
|
37 |
+
def rand_gumbel(shape):
|
38 |
+
"""Sample from the Gumbel distribution, protect from overflows."""
|
39 |
+
uniform_samples = torch.rand(shape) * 0.99998 + 0.00001
|
40 |
+
return -torch.log(-torch.log(uniform_samples))
|
41 |
+
|
42 |
+
|
43 |
+
def rand_gumbel_like(x):
|
44 |
+
g = rand_gumbel(x.size()).to(dtype=x.dtype, device=x.device)
|
45 |
+
return g
|
46 |
+
|
47 |
+
|
48 |
+
def slice_segments(x, ids_str, segment_size=4):
|
49 |
+
gather_indices = ids_str.view(x.size(0), 1, 1).repeat(
|
50 |
+
1, x.size(1), 1
|
51 |
+
) + torch.arange(segment_size, device=x.device)
|
52 |
+
return torch.gather(x, 2, gather_indices)
|
53 |
+
|
54 |
+
|
55 |
+
def rand_slice_segments(x, x_lengths=None, segment_size=4):
|
56 |
+
b, d, t = x.size()
|
57 |
+
if x_lengths is None:
|
58 |
+
x_lengths = t
|
59 |
+
ids_str_max = torch.clamp(x_lengths - segment_size + 1, min=0)
|
60 |
+
ids_str = (torch.rand([b], device=x.device) * ids_str_max).to(dtype=torch.long)
|
61 |
+
ret = slice_segments(x, ids_str, segment_size)
|
62 |
+
return ret, ids_str
|
63 |
+
|
64 |
+
|
65 |
+
def get_timing_signal_1d(length, channels, min_timescale=1.0, max_timescale=1.0e4):
|
66 |
+
position = torch.arange(length, dtype=torch.float)
|
67 |
+
num_timescales = channels // 2
|
68 |
+
log_timescale_increment = math.log(float(max_timescale) / float(min_timescale)) / (
|
69 |
+
num_timescales - 1
|
70 |
+
)
|
71 |
+
inv_timescales = min_timescale * torch.exp(
|
72 |
+
torch.arange(num_timescales, dtype=torch.float) * -log_timescale_increment
|
73 |
+
)
|
74 |
+
scaled_time = position.unsqueeze(0) * inv_timescales.unsqueeze(1)
|
75 |
+
signal = torch.cat([torch.sin(scaled_time), torch.cos(scaled_time)], 0)
|
76 |
+
signal = F.pad(signal, [0, 0, 0, channels % 2])
|
77 |
+
signal = signal.view(1, channels, length)
|
78 |
+
return signal
|
79 |
+
|
80 |
+
|
81 |
+
def add_timing_signal_1d(x, min_timescale=1.0, max_timescale=1.0e4):
|
82 |
+
b, channels, length = x.size()
|
83 |
+
signal = get_timing_signal_1d(length, channels, min_timescale, max_timescale)
|
84 |
+
return x + signal.to(dtype=x.dtype, device=x.device)
|
85 |
+
|
86 |
+
|
87 |
+
def cat_timing_signal_1d(x, min_timescale=1.0, max_timescale=1.0e4, axis=1):
|
88 |
+
b, channels, length = x.size()
|
89 |
+
signal = get_timing_signal_1d(length, channels, min_timescale, max_timescale)
|
90 |
+
return torch.cat([x, signal.to(dtype=x.dtype, device=x.device)], axis)
|
91 |
+
|
92 |
+
|
93 |
+
def subsequent_mask(length):
|
94 |
+
mask = torch.tril(torch.ones(length, length)).unsqueeze(0).unsqueeze(0)
|
95 |
+
return mask
|
96 |
+
|
97 |
+
|
98 |
+
@torch.jit.script
|
99 |
+
def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels):
|
100 |
+
n_channels_int = n_channels[0]
|
101 |
+
in_act = input_a + input_b
|
102 |
+
t_act = torch.tanh(in_act[:, :n_channels_int, :])
|
103 |
+
s_act = torch.sigmoid(in_act[:, n_channels_int:, :])
|
104 |
+
acts = t_act * s_act
|
105 |
+
return acts
|
106 |
+
|
107 |
+
|
108 |
+
def convert_pad_shape(pad_shape):
|
109 |
+
layer = pad_shape[::-1]
|
110 |
+
pad_shape = [item for sublist in layer for item in sublist]
|
111 |
+
return pad_shape
|
112 |
+
|
113 |
+
|
114 |
+
def shift_1d(x):
|
115 |
+
x = F.pad(x, convert_pad_shape([[0, 0], [0, 0], [1, 0]]))[:, :, :-1]
|
116 |
+
return x
|
117 |
+
|
118 |
+
|
119 |
+
def sequence_mask(length, max_length=None):
|
120 |
+
if max_length is None:
|
121 |
+
max_length = length.max()
|
122 |
+
x = torch.arange(max_length, dtype=length.dtype, device=length.device)
|
123 |
+
return x.unsqueeze(0) < length.unsqueeze(1)
|
124 |
+
|
125 |
+
|
126 |
+
def generate_path(duration, mask):
|
127 |
+
"""
|
128 |
+
duration: [b, 1, t_x]
|
129 |
+
mask: [b, 1, t_y, t_x]
|
130 |
+
"""
|
131 |
+
|
132 |
+
b, _, t_y, t_x = mask.shape
|
133 |
+
cum_duration = torch.cumsum(duration, -1)
|
134 |
+
|
135 |
+
cum_duration_flat = cum_duration.view(b * t_x)
|
136 |
+
path = sequence_mask(cum_duration_flat, t_y).to(mask.dtype)
|
137 |
+
path = path.view(b, t_x, t_y)
|
138 |
+
path = path - F.pad(path, convert_pad_shape([[0, 0], [1, 0], [0, 0]]))[:, :-1]
|
139 |
+
path = path.unsqueeze(1).transpose(2, 3) * mask
|
140 |
+
return path
|
141 |
+
|
142 |
+
|
143 |
+
def clip_grad_value_(parameters, clip_value, norm_type=2):
|
144 |
+
if isinstance(parameters, torch.Tensor):
|
145 |
+
parameters = [parameters]
|
146 |
+
parameters = list(filter(lambda p: p.grad is not None, parameters))
|
147 |
+
norm_type = float(norm_type)
|
148 |
+
if clip_value is not None:
|
149 |
+
clip_value = float(clip_value)
|
150 |
+
|
151 |
+
total_norm = 0
|
152 |
+
for p in parameters:
|
153 |
+
param_norm = p.grad.data.norm(norm_type)
|
154 |
+
total_norm += param_norm.item() ** norm_type
|
155 |
+
if clip_value is not None:
|
156 |
+
p.grad.data.clamp_(min=-clip_value, max=clip_value)
|
157 |
+
total_norm = total_norm ** (1.0 / norm_type)
|
158 |
+
return total_norm
|
compress_model.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from collections import OrderedDict
|
2 |
+
from text.symbols import symbols
|
3 |
+
import torch
|
4 |
+
|
5 |
+
from tools.log import logger
|
6 |
+
import utils
|
7 |
+
from models import SynthesizerTrn
|
8 |
+
import os
|
9 |
+
|
10 |
+
|
11 |
+
def copyStateDict(state_dict):
|
12 |
+
if list(state_dict.keys())[0].startswith("module"):
|
13 |
+
start_idx = 1
|
14 |
+
else:
|
15 |
+
start_idx = 0
|
16 |
+
new_state_dict = OrderedDict()
|
17 |
+
for k, v in state_dict.items():
|
18 |
+
name = ",".join(k.split(".")[start_idx:])
|
19 |
+
new_state_dict[name] = v
|
20 |
+
return new_state_dict
|
21 |
+
|
22 |
+
|
23 |
+
def removeOptimizer(config: str, input_model: str, ishalf: bool, output_model: str):
|
24 |
+
hps = utils.get_hparams_from_file(config)
|
25 |
+
|
26 |
+
net_g = SynthesizerTrn(
|
27 |
+
len(symbols),
|
28 |
+
hps.data.filter_length // 2 + 1,
|
29 |
+
hps.train.segment_size // hps.data.hop_length,
|
30 |
+
n_speakers=hps.data.n_speakers,
|
31 |
+
**hps.model,
|
32 |
+
)
|
33 |
+
|
34 |
+
optim_g = torch.optim.AdamW(
|
35 |
+
net_g.parameters(),
|
36 |
+
hps.train.learning_rate,
|
37 |
+
betas=hps.train.betas,
|
38 |
+
eps=hps.train.eps,
|
39 |
+
)
|
40 |
+
|
41 |
+
state_dict_g = torch.load(input_model, map_location="cpu")
|
42 |
+
new_dict_g = copyStateDict(state_dict_g)
|
43 |
+
keys = []
|
44 |
+
for k, v in new_dict_g["model"].items():
|
45 |
+
if "enc_q" in k:
|
46 |
+
continue # noqa: E701
|
47 |
+
keys.append(k)
|
48 |
+
|
49 |
+
new_dict_g = (
|
50 |
+
{k: new_dict_g["model"][k].half() for k in keys}
|
51 |
+
if ishalf
|
52 |
+
else {k: new_dict_g["model"][k] for k in keys}
|
53 |
+
)
|
54 |
+
|
55 |
+
torch.save(
|
56 |
+
{
|
57 |
+
"model": new_dict_g,
|
58 |
+
"iteration": 0,
|
59 |
+
"optimizer": optim_g.state_dict(),
|
60 |
+
"learning_rate": 0.0001,
|
61 |
+
},
|
62 |
+
output_model,
|
63 |
+
)
|
64 |
+
|
65 |
+
|
66 |
+
if __name__ == "__main__":
|
67 |
+
import argparse
|
68 |
+
|
69 |
+
parser = argparse.ArgumentParser()
|
70 |
+
parser.add_argument("-c", "--config", type=str, default="configs/config.json")
|
71 |
+
parser.add_argument("-i", "--input", type=str)
|
72 |
+
parser.add_argument("-o", "--output", type=str, default=None)
|
73 |
+
parser.add_argument(
|
74 |
+
"-hf", "--half", action="store_true", default=False, help="Save as FP16"
|
75 |
+
)
|
76 |
+
|
77 |
+
args = parser.parse_args()
|
78 |
+
|
79 |
+
output = args.output
|
80 |
+
|
81 |
+
if output is None:
|
82 |
+
import os.path
|
83 |
+
|
84 |
+
filename, ext = os.path.splitext(args.input)
|
85 |
+
half = "_half" if args.half else ""
|
86 |
+
output = filename + "_release" + half + ext
|
87 |
+
|
88 |
+
removeOptimizer(args.config, args.input, args.half, output)
|
89 |
+
logger.info(f"压缩模型成功, 输出模型: {os.path.abspath(output)}")
|
config.py
ADDED
@@ -0,0 +1,248 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
@Desc: 全局配置文件读取
|
3 |
+
"""
|
4 |
+
import argparse
|
5 |
+
import yaml
|
6 |
+
from typing import Dict, List
|
7 |
+
import os
|
8 |
+
import shutil
|
9 |
+
import sys
|
10 |
+
|
11 |
+
|
12 |
+
class Resample_config:
|
13 |
+
"""重采样配置"""
|
14 |
+
|
15 |
+
def __init__(self, in_dir: str, out_dir: str, sampling_rate: int = 44100):
|
16 |
+
self.sampling_rate: int = sampling_rate # 目标采样率
|
17 |
+
self.in_dir: str = in_dir # 待处理音频目录路径
|
18 |
+
self.out_dir: str = out_dir # 重采样输出路径
|
19 |
+
|
20 |
+
@classmethod
|
21 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
22 |
+
"""从字典中生成实例"""
|
23 |
+
|
24 |
+
# 不检查路径是否有效,此逻辑在resample.py中处理
|
25 |
+
data["in_dir"] = os.path.join(dataset_path, data["in_dir"])
|
26 |
+
data["out_dir"] = os.path.join(dataset_path, data["out_dir"])
|
27 |
+
|
28 |
+
return cls(**data)
|
29 |
+
|
30 |
+
|
31 |
+
class Preprocess_text_config:
|
32 |
+
"""数据预处理配置"""
|
33 |
+
|
34 |
+
def __init__(
|
35 |
+
self,
|
36 |
+
transcription_path: str,
|
37 |
+
cleaned_path: str,
|
38 |
+
train_path: str,
|
39 |
+
val_path: str,
|
40 |
+
config_path: str,
|
41 |
+
val_per_lang: int = 5,
|
42 |
+
max_val_total: int = 10000,
|
43 |
+
clean: bool = True,
|
44 |
+
):
|
45 |
+
self.transcription_path: str = transcription_path # 原始文本文件路径,文本格式应为{wav_path}|{speaker_name}|{language}|{text}。
|
46 |
+
self.cleaned_path: str = cleaned_path # 数据清洗后文本路径,可以不填。不填则将在原始文本目录生成
|
47 |
+
self.train_path: str = train_path # 训练集路径,可以不填。不填则将在原始文本目录生成
|
48 |
+
self.val_path: str = val_path # 验证集路径,可以不填。不填则将在原始文本目录生成
|
49 |
+
self.config_path: str = config_path # 配置文件路径
|
50 |
+
self.val_per_lang: int = val_per_lang # 每个speaker的验证集条数
|
51 |
+
self.max_val_total: int = max_val_total # 验证集最大条数,多于的会被截断并放到训练集中
|
52 |
+
self.clean: bool = clean # 是否进行数据清洗
|
53 |
+
|
54 |
+
@classmethod
|
55 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
56 |
+
"""从字典中生成实例"""
|
57 |
+
|
58 |
+
data["transcription_path"] = os.path.join(
|
59 |
+
dataset_path, data["transcription_path"]
|
60 |
+
)
|
61 |
+
if data["cleaned_path"] == "" or data["cleaned_path"] is None:
|
62 |
+
data["cleaned_path"] = None
|
63 |
+
else:
|
64 |
+
data["cleaned_path"] = os.path.join(dataset_path, data["cleaned_path"])
|
65 |
+
data["train_path"] = os.path.join(dataset_path, data["train_path"])
|
66 |
+
data["val_path"] = os.path.join(dataset_path, data["val_path"])
|
67 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
68 |
+
|
69 |
+
return cls(**data)
|
70 |
+
|
71 |
+
|
72 |
+
class Bert_gen_config:
|
73 |
+
"""bert_gen 配置"""
|
74 |
+
|
75 |
+
def __init__(
|
76 |
+
self,
|
77 |
+
config_path: str,
|
78 |
+
num_processes: int = 2,
|
79 |
+
device: str = "cuda",
|
80 |
+
use_multi_device: bool = False,
|
81 |
+
):
|
82 |
+
self.config_path = config_path
|
83 |
+
self.num_processes = num_processes
|
84 |
+
self.device = device
|
85 |
+
self.use_multi_device = use_multi_device
|
86 |
+
|
87 |
+
@classmethod
|
88 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
89 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
90 |
+
|
91 |
+
return cls(**data)
|
92 |
+
|
93 |
+
|
94 |
+
class Emo_gen_config:
|
95 |
+
"""emo_gen 配置"""
|
96 |
+
|
97 |
+
def __init__(
|
98 |
+
self,
|
99 |
+
config_path: str,
|
100 |
+
num_processes: int = 2,
|
101 |
+
device: str = "cuda",
|
102 |
+
use_multi_device: bool = False,
|
103 |
+
):
|
104 |
+
self.config_path = config_path
|
105 |
+
self.num_processes = num_processes
|
106 |
+
self.device = device
|
107 |
+
self.use_multi_device = use_multi_device
|
108 |
+
|
109 |
+
@classmethod
|
110 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
111 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
112 |
+
|
113 |
+
return cls(**data)
|
114 |
+
|
115 |
+
|
116 |
+
class Train_ms_config:
|
117 |
+
"""训练配置"""
|
118 |
+
|
119 |
+
def __init__(
|
120 |
+
self,
|
121 |
+
config_path: str,
|
122 |
+
env: Dict[str, any],
|
123 |
+
base: Dict[str, any],
|
124 |
+
model: str,
|
125 |
+
num_workers: int,
|
126 |
+
spec_cache: bool,
|
127 |
+
keep_ckpts: int,
|
128 |
+
):
|
129 |
+
self.env = env # 需要加载的环境变量
|
130 |
+
self.base = base # 底模配置
|
131 |
+
self.model = model # 训练模型存储目录,该路径为相对于dataset_path的路径,而非项目根目录
|
132 |
+
self.config_path = config_path # 配置文件路径
|
133 |
+
self.num_workers = num_workers # worker数量
|
134 |
+
self.spec_cache = spec_cache # 是否启用spec缓存
|
135 |
+
self.keep_ckpts = keep_ckpts # ckpt数量
|
136 |
+
|
137 |
+
@classmethod
|
138 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
139 |
+
# data["model"] = os.path.join(dataset_path, data["model"])
|
140 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
141 |
+
|
142 |
+
return cls(**data)
|
143 |
+
|
144 |
+
|
145 |
+
class Webui_config:
|
146 |
+
"""webui 配置"""
|
147 |
+
|
148 |
+
def __init__(
|
149 |
+
self,
|
150 |
+
device: str,
|
151 |
+
model: str,
|
152 |
+
config_path: str,
|
153 |
+
language_identification_library: str,
|
154 |
+
port: int = 7860,
|
155 |
+
share: bool = False,
|
156 |
+
debug: bool = False,
|
157 |
+
):
|
158 |
+
self.device: str = device
|
159 |
+
self.model: str = model # 端口号
|
160 |
+
self.config_path: str = config_path # 是否公开部署,对外网开放
|
161 |
+
self.port: int = port # 是否开启debug模式
|
162 |
+
self.share: bool = share # 模型路径
|
163 |
+
self.debug: bool = debug # 配置文件路径
|
164 |
+
self.language_identification_library: str = (
|
165 |
+
language_identification_library # 语种识别库
|
166 |
+
)
|
167 |
+
|
168 |
+
@classmethod
|
169 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
170 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
171 |
+
data["model"] = os.path.join(dataset_path, data["model"])
|
172 |
+
return cls(**data)
|
173 |
+
|
174 |
+
|
175 |
+
class Server_config:
|
176 |
+
def __init__(
|
177 |
+
self, models: List[Dict[str, any]], port: int = 5000, device: str = "cuda"
|
178 |
+
):
|
179 |
+
self.models: List[Dict[str, any]] = models # 需要加载的所有模型的配置
|
180 |
+
self.port: int = port # 端口号
|
181 |
+
self.device: str = device # 模型默认使用设备
|
182 |
+
|
183 |
+
@classmethod
|
184 |
+
def from_dict(cls, data: Dict[str, any]):
|
185 |
+
return cls(**data)
|
186 |
+
|
187 |
+
|
188 |
+
class Translate_config:
|
189 |
+
"""翻译api配置"""
|
190 |
+
|
191 |
+
def __init__(self, app_key: str, secret_key: str):
|
192 |
+
self.app_key = app_key
|
193 |
+
self.secret_key = secret_key
|
194 |
+
|
195 |
+
@classmethod
|
196 |
+
def from_dict(cls, data: Dict[str, any]):
|
197 |
+
return cls(**data)
|
198 |
+
|
199 |
+
|
200 |
+
class Config:
|
201 |
+
def __init__(self, config_path: str):
|
202 |
+
if not os.path.isfile(config_path) and os.path.isfile("default_config.yml"):
|
203 |
+
shutil.copy(src="default_config.yml", dst=config_path)
|
204 |
+
print(
|
205 |
+
f"已根据默认配置文件default_config.yml生成配置文件{config_path}。请按该配置文件的说明进行配置后重新运行。"
|
206 |
+
)
|
207 |
+
print("如无特殊需求,请勿修改default_config.yml或备份该文件。")
|
208 |
+
sys.exit(0)
|
209 |
+
with open(file=config_path, mode="r", encoding="utf-8") as file:
|
210 |
+
yaml_config: Dict[str, any] = yaml.safe_load(file.read())
|
211 |
+
dataset_path: str = yaml_config["dataset_path"]
|
212 |
+
openi_token: str = yaml_config["openi_token"]
|
213 |
+
self.dataset_path: str = dataset_path
|
214 |
+
self.mirror: str = yaml_config["mirror"]
|
215 |
+
self.openi_token: str = openi_token
|
216 |
+
self.resample_config: Resample_config = Resample_config.from_dict(
|
217 |
+
dataset_path, yaml_config["resample"]
|
218 |
+
)
|
219 |
+
self.preprocess_text_config: Preprocess_text_config = (
|
220 |
+
Preprocess_text_config.from_dict(
|
221 |
+
dataset_path, yaml_config["preprocess_text"]
|
222 |
+
)
|
223 |
+
)
|
224 |
+
self.bert_gen_config: Bert_gen_config = Bert_gen_config.from_dict(
|
225 |
+
dataset_path, yaml_config["bert_gen"]
|
226 |
+
)
|
227 |
+
self.emo_gen_config: Emo_gen_config = Emo_gen_config.from_dict(
|
228 |
+
dataset_path, yaml_config["emo_gen"]
|
229 |
+
)
|
230 |
+
self.train_ms_config: Train_ms_config = Train_ms_config.from_dict(
|
231 |
+
dataset_path, yaml_config["train_ms"]
|
232 |
+
)
|
233 |
+
self.webui_config: Webui_config = Webui_config.from_dict(
|
234 |
+
dataset_path, yaml_config["webui"]
|
235 |
+
)
|
236 |
+
self.server_config: Server_config = Server_config.from_dict(
|
237 |
+
yaml_config["server"]
|
238 |
+
)
|
239 |
+
self.translate_config: Translate_config = Translate_config.from_dict(
|
240 |
+
yaml_config["translate"]
|
241 |
+
)
|
242 |
+
|
243 |
+
|
244 |
+
parser = argparse.ArgumentParser()
|
245 |
+
# 为避免与以前的config.json起冲突,将其更名如下
|
246 |
+
parser.add_argument("-y", "--yml_config", type=str, default="config.yml")
|
247 |
+
args, _ = parser.parse_known_args()
|
248 |
+
config = Config(args.yml_config)
|
config.yml
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 全局配置
|
2 |
+
# 对于希望在同一时间使用多个配置文件的情况,例如两个GPU同时跑两个训练集:通过环境变量指定配置文件,不指定则默认为./config.yml
|
3 |
+
|
4 |
+
# 拟提供通用路径配置,统一存放数据,避免数据放得很乱
|
5 |
+
# 每个数据集与其对应的模型存放至统一路径下,后续所有的路径配置均为相对于datasetPath的路径
|
6 |
+
# 不填或者填空则路径为相对于项目根目录的路径
|
7 |
+
dataset_path: "Data/sun"
|
8 |
+
|
9 |
+
# 模型镜像源,默认huggingface,使用openi镜像源需指定openi_token
|
10 |
+
mirror: ""
|
11 |
+
openi_token: "" # openi token
|
12 |
+
|
13 |
+
# resample 音频重采样配置
|
14 |
+
# 注意, “:” 后需要加空格
|
15 |
+
resample:
|
16 |
+
# 目标重采样率
|
17 |
+
sampling_rate: 44100
|
18 |
+
# 音频文件输入路径,重采样会将该路径下所有.wav音频文件重采样
|
19 |
+
# 请填入相对于datasetPath的相对路径
|
20 |
+
in_dir: "audios/raw" # 相对于根目录的路径为 /datasetPath/in_dir
|
21 |
+
# 音频文件重采样后输出路径
|
22 |
+
out_dir: "audios/wavs"
|
23 |
+
|
24 |
+
|
25 |
+
# preprocess_text 数据集预处理相关配置
|
26 |
+
# 注意, “:” 后需要加空格
|
27 |
+
preprocess_text:
|
28 |
+
# 原始文本文件路径,文本格式应为{wav_path}|{speaker_name}|{language}|{text}。
|
29 |
+
transcription_path: ""
|
30 |
+
# 数据清洗后文本路径,可以不填。不填则将在原始文本目录生成
|
31 |
+
cleaned_path: ""
|
32 |
+
# 训练集路径
|
33 |
+
train_path: "filelists/train.list"
|
34 |
+
# 验证集路径
|
35 |
+
val_path: "filelists/val.list"
|
36 |
+
# 配置文件路径
|
37 |
+
config_path: "config.json"
|
38 |
+
# 每个语言的验证集条数
|
39 |
+
val_per_lang: 4
|
40 |
+
# 验证集最大条数,多于的会被截断并放到训练集中
|
41 |
+
max_val_total: 12
|
42 |
+
# 是否进行数据清洗
|
43 |
+
clean: true
|
44 |
+
|
45 |
+
|
46 |
+
# bert_gen 相关配置
|
47 |
+
# 注意, “:” 后需要加空格
|
48 |
+
bert_gen:
|
49 |
+
# 训练数据集配置文件路径
|
50 |
+
config_path: "config.json"
|
51 |
+
# 并行数
|
52 |
+
num_processes: 4
|
53 |
+
# 使用设备:可选项 "cuda" 显卡推理,"cpu" cpu推理
|
54 |
+
# 该选项同时决定了get_bert_feature的默认设备
|
55 |
+
device: "cuda"
|
56 |
+
# 使用多卡推理
|
57 |
+
use_multi_device: false
|
58 |
+
|
59 |
+
# emo_gen 相关配置
|
60 |
+
# 注意, “:” 后需要加空格
|
61 |
+
emo_gen:
|
62 |
+
# 训练数据集配置文件路径
|
63 |
+
config_path: "config.json"
|
64 |
+
# 并行数
|
65 |
+
num_processes: 4
|
66 |
+
# 使用设备:可选项 "cuda" 显卡推理,"cpu" cpu推理
|
67 |
+
device: "cuda"
|
68 |
+
# 使用多卡推理
|
69 |
+
use_multi_device: false
|
70 |
+
|
71 |
+
# train 训练配置
|
72 |
+
# 注意, “:” 后需要加空格
|
73 |
+
train_ms:
|
74 |
+
env:
|
75 |
+
MASTER_ADDR: "localhost"
|
76 |
+
MASTER_PORT: 10086
|
77 |
+
WORLD_SIZE: 1
|
78 |
+
LOCAL_RANK: 0
|
79 |
+
RANK: 0
|
80 |
+
# 可以填写任意名的环境变量
|
81 |
+
# THE_ENV_VAR_YOU_NEED_TO_USE: "1234567"
|
82 |
+
# 底模设置
|
83 |
+
base:
|
84 |
+
use_base_model: true
|
85 |
+
repo_id: "Stardust_minus/Bert-VITS2"
|
86 |
+
model_image: "Bert-VITS2_2.2-Clap底模" # openi网页的模型名
|
87 |
+
# 训练模型存储目录:与旧版本的区别,原先数据集是存放在logs/model_name下的,现在改为统一存放在Data/你的数据集/models下
|
88 |
+
model: "models"
|
89 |
+
# 配置文件路径
|
90 |
+
config_path: "config.json"
|
91 |
+
# 训练使用的worker,不建议超过CPU核心数
|
92 |
+
num_workers: 16
|
93 |
+
# 关闭此项可以节约接近50%的磁盘空间,但是可能导致实际训练速度变慢和更高的CPU使用率。
|
94 |
+
spec_cache: True
|
95 |
+
# 保存的检查点数量,多于此数目的权重会被删除来节省空间。
|
96 |
+
keep_ckpts: 38
|
97 |
+
|
98 |
+
|
99 |
+
# webui webui配置
|
100 |
+
# 注意, “:” 后需要加空格
|
101 |
+
webui:
|
102 |
+
# 推理设备
|
103 |
+
device: "cuda"
|
104 |
+
# 模型路径
|
105 |
+
model: "models/G_3500.pth"
|
106 |
+
# 配置文件路径
|
107 |
+
config_path: "config.json"
|
108 |
+
# 端口号
|
109 |
+
port: 6006
|
110 |
+
# 是否公开部署,对外网开放
|
111 |
+
share: false
|
112 |
+
# 是否开启debug模式
|
113 |
+
debug: false
|
114 |
+
# 语种识别库,可选langid, fastlid
|
115 |
+
language_identification_library: "langid"
|
116 |
+
|
117 |
+
|
118 |
+
# server-fastapi配置
|
119 |
+
# 注意, “:” 后需要加空格
|
120 |
+
# 注意,本配置下的所有配置均为相对于根目录的路径
|
121 |
+
server:
|
122 |
+
# 端口号
|
123 |
+
port: 5000
|
124 |
+
# 模型默认使用设备:但是当前并没有实现这个配置。
|
125 |
+
device: "cuda"
|
126 |
+
# 需要加载的所有模型的配置,可以填多个模型,也可以不填模型,等网页成功后手动加载模型
|
127 |
+
# 不加载模型的配置格式:删除默认给的两个模型配置,给models赋值 [ ],也就是空列表。参考模型2的speakers 即 models: [ ]
|
128 |
+
# 注意,所有模型都必须正确配置model与config的路径,空路径会导致加载错误。
|
129 |
+
# 也可以不填模型,等网页加载成功后手动填写models。
|
130 |
+
models:
|
131 |
+
- # 模型的路径
|
132 |
+
model: ""
|
133 |
+
# 模型config.json的路径
|
134 |
+
config: ""
|
135 |
+
# 模型使用设备,若填写则会覆盖默认配置
|
136 |
+
device: "cuda"
|
137 |
+
# 模型默认使用的语言
|
138 |
+
language: "ZH"
|
139 |
+
# 模型人物默认参数
|
140 |
+
# 不必填写所有人物,不填的使用默认值
|
141 |
+
# 暂时不用填写,当前尚未实现按人区分配置
|
142 |
+
speakers:
|
143 |
+
- speaker: "科比"
|
144 |
+
sdp_ratio: 0.2
|
145 |
+
noise_scale: 0.6
|
146 |
+
noise_scale_w: 0.8
|
147 |
+
length_scale: 1
|
148 |
+
- speaker: "五条悟"
|
149 |
+
sdp_ratio: 0.3
|
150 |
+
noise_scale: 0.7
|
151 |
+
noise_scale_w: 0.8
|
152 |
+
length_scale: 0.5
|
153 |
+
- speaker: "安倍晋三"
|
154 |
+
sdp_ratio: 0.2
|
155 |
+
noise_scale: 0.6
|
156 |
+
noise_scale_w: 0.8
|
157 |
+
length_scale: 1.2
|
158 |
+
- # 模型的路径
|
159 |
+
model: ""
|
160 |
+
# 模型config.json的路径
|
161 |
+
config: ""
|
162 |
+
# 模型使用设备,若填写则会覆盖默认配置
|
163 |
+
device: "cpu"
|
164 |
+
# 模型默认使用的语言
|
165 |
+
language: "JP"
|
166 |
+
# 模型人物默认参数
|
167 |
+
# 不必填写所有人物,不填的使用默认值
|
168 |
+
speakers: [ ] # 也可以不填
|
169 |
+
|
170 |
+
# 百度翻译开放平台 api配置
|
171 |
+
# api接入文档 https://api.fanyi.baidu.com/doc/21
|
172 |
+
# 请不要在github等网站公开分享你的app id 与 key
|
173 |
+
translate:
|
174 |
+
# 你的APPID
|
175 |
+
"app_key": ""
|
176 |
+
# 你的密钥
|
177 |
+
"secret_key": ""
|
configs/config.json
ADDED
@@ -0,0 +1,953 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 200,
|
4 |
+
"eval_interval": 1000,
|
5 |
+
"seed": 42,
|
6 |
+
"epochs": 1000,
|
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.99995,
|
16 |
+
"segment_size": 16384,
|
17 |
+
"init_lr_ratio": 1,
|
18 |
+
"warmup_epochs": 0,
|
19 |
+
"c_mel": 45,
|
20 |
+
"c_kl": 1.0,
|
21 |
+
"skip_optimizer": true,
|
22 |
+
"freeze_ZH_bert": false,
|
23 |
+
"freeze_JP_bert": false,
|
24 |
+
"freeze_EN_bert": false
|
25 |
+
},
|
26 |
+
"data": {
|
27 |
+
"training_files": "filelists/train.list",
|
28 |
+
"validation_files": "filelists/val.list",
|
29 |
+
"max_wav_value": 32768.0,
|
30 |
+
"sampling_rate": 44100,
|
31 |
+
"filter_length": 2048,
|
32 |
+
"hop_length": 512,
|
33 |
+
"win_length": 2048,
|
34 |
+
"n_mel_channels": 128,
|
35 |
+
"mel_fmin": 0.0,
|
36 |
+
"mel_fmax": null,
|
37 |
+
"add_blank": true,
|
38 |
+
"n_speakers": 896,
|
39 |
+
"cleaned_text": true,
|
40 |
+
"spk2id": {
|
41 |
+
"派蒙_ZH": 0,
|
42 |
+
"纳西妲_ZH": 1,
|
43 |
+
"凯亚_ZH": 2,
|
44 |
+
"阿贝多_ZH": 3,
|
45 |
+
"温迪_ZH": 4,
|
46 |
+
"枫原万叶_ZH": 5,
|
47 |
+
"钟离_ZH": 6,
|
48 |
+
"荒泷一斗_ZH": 7,
|
49 |
+
"八重神子_ZH": 8,
|
50 |
+
"艾尔海森_ZH": 9,
|
51 |
+
"提纳里_ZH": 10,
|
52 |
+
"迪希雅_ZH": 11,
|
53 |
+
"卡维_ZH": 12,
|
54 |
+
"宵宫_ZH": 13,
|
55 |
+
"那维莱特_ZH": 14,
|
56 |
+
"莱依拉_ZH": 15,
|
57 |
+
"赛诺_ZH": 16,
|
58 |
+
"莫娜_ZH": 17,
|
59 |
+
"诺艾尔_ZH": 18,
|
60 |
+
"托马_ZH": 19,
|
61 |
+
"凝光_ZH": 20,
|
62 |
+
"林尼_ZH": 21,
|
63 |
+
"北斗_ZH": 22,
|
64 |
+
"柯莱_ZH": 23,
|
65 |
+
"神里绫华_ZH": 24,
|
66 |
+
"可莉_ZH": 25,
|
67 |
+
"芭芭拉_ZH": 26,
|
68 |
+
"雷电将军_ZH": 27,
|
69 |
+
"娜维娅_ZH": 28,
|
70 |
+
"芙宁娜_ZH": 29,
|
71 |
+
"珊瑚宫心海_ZH": 30,
|
72 |
+
"鹿野院平藏_ZH": 31,
|
73 |
+
"迪奥娜_ZH": 32,
|
74 |
+
"琴_ZH": 33,
|
75 |
+
"五郎_ZH": 34,
|
76 |
+
"班尼特_ZH": 35,
|
77 |
+
"达达利亚_ZH": 36,
|
78 |
+
"安柏_ZH": 37,
|
79 |
+
"莱欧斯利_ZH": 38,
|
80 |
+
"夜兰_ZH": 39,
|
81 |
+
"妮露_ZH": 40,
|
82 |
+
"辛焱_ZH": 41,
|
83 |
+
"丽莎_ZH": 42,
|
84 |
+
"珐露珊_ZH": 43,
|
85 |
+
"魈_ZH": 44,
|
86 |
+
"香菱_ZH": 45,
|
87 |
+
"迪卢克_ZH": 46,
|
88 |
+
"砂糖_ZH": 47,
|
89 |
+
"烟绯_ZH": 48,
|
90 |
+
"早柚_ZH": 49,
|
91 |
+
"云堇_ZH": 50,
|
92 |
+
"刻晴_ZH": 51,
|
93 |
+
"重云_ZH": 52,
|
94 |
+
"优菈_ZH": 53,
|
95 |
+
"胡桃_ZH": 54,
|
96 |
+
"流浪者_ZH": 55,
|
97 |
+
"久岐忍_ZH": 56,
|
98 |
+
"神里绫人_ZH": 57,
|
99 |
+
"甘雨_ZH": 58,
|
100 |
+
"戴因斯雷布_ZH": 59,
|
101 |
+
"菲谢尔_ZH": 60,
|
102 |
+
"白术_ZH": 61,
|
103 |
+
"行秋_ZH": 62,
|
104 |
+
"九条裟罗_ZH": 63,
|
105 |
+
"夏洛蒂_ZH": 64,
|
106 |
+
"雷泽_ZH": 65,
|
107 |
+
"申鹤_ZH": 66,
|
108 |
+
"荧_ZH": 67,
|
109 |
+
"空_ZH": 68,
|
110 |
+
"迪娜泽黛_ZH": 69,
|
111 |
+
"凯瑟琳_ZH": 70,
|
112 |
+
"多莉_ZH": 71,
|
113 |
+
"坎蒂丝_ZH": 72,
|
114 |
+
"琳妮特_ZH": 73,
|
115 |
+
"萍姥姥_ZH": 74,
|
116 |
+
"罗莎莉亚_ZH": 75,
|
117 |
+
"埃德_ZH": 76,
|
118 |
+
"爱贝尔_ZH": 77,
|
119 |
+
"伊迪娅_ZH": 78,
|
120 |
+
"留云借风真君_ZH": 79,
|
121 |
+
"绮良良_ZH": 80,
|
122 |
+
"七七_ZH": 81,
|
123 |
+
"式大将_ZH": 82,
|
124 |
+
"瑶瑶_ZH": 83,
|
125 |
+
"奥兹_ZH": 84,
|
126 |
+
"菲米尼_ZH": 85,
|
127 |
+
"米卡_ZH": 86,
|
128 |
+
"哲平_ZH": 87,
|
129 |
+
"大肉丸_ZH": 88,
|
130 |
+
"托克_ZH": 89,
|
131 |
+
"蒂玛乌斯_ZH": 90,
|
132 |
+
"昆钧_ZH": 91,
|
133 |
+
"欧菲妮_ZH": 92,
|
134 |
+
"塞琉斯_ZH": 93,
|
135 |
+
"仆人_ZH": 94,
|
136 |
+
"迈勒斯_ZH": 95,
|
137 |
+
"希格雯_ZH": 96,
|
138 |
+
"阿守_ZH": 97,
|
139 |
+
"拉赫曼_ZH": 98,
|
140 |
+
"杜拉夫_ZH": 99,
|
141 |
+
"伊利亚斯_ZH": 100,
|
142 |
+
"阿晃_ZH": 101,
|
143 |
+
"旁白_ZH": 102,
|
144 |
+
"爱德琳_ZH": 103,
|
145 |
+
"埃洛伊_ZH": 104,
|
146 |
+
"德沃沙克_ZH": 105,
|
147 |
+
"玛乔丽_ZH": 106,
|
148 |
+
"塞塔蕾_ZH": 107,
|
149 |
+
"柊千里_ZH": 108,
|
150 |
+
"海芭夏_ZH": 109,
|
151 |
+
"九条镰治_ZH": 110,
|
152 |
+
"阿娜耶_ZH": 111,
|
153 |
+
"笼钓瓶一心_ZH": 112,
|
154 |
+
"回声海螺_ZH": 113,
|
155 |
+
"劳维克_ZH": 114,
|
156 |
+
"元太_ZH": 115,
|
157 |
+
"阿扎尔_ZH": 116,
|
158 |
+
"查尔斯_ZH": 117,
|
159 |
+
"阿洛瓦_ZH": 118,
|
160 |
+
"埃勒曼_ZH": 119,
|
161 |
+
"纳比尔_ZH": 120,
|
162 |
+
"莎拉_ZH": 121,
|
163 |
+
"康纳_ZH": 122,
|
164 |
+
"博来_ZH": 123,
|
165 |
+
"玛塞勒_ZH": 124,
|
166 |
+
"阿祇_ZH": 125,
|
167 |
+
"博士_ZH": 126,
|
168 |
+
"玛格丽特_ZH": 127,
|
169 |
+
"迪尔菲_ZH": 128,
|
170 |
+
"宛烟_ZH": 129,
|
171 |
+
"羽生田千鹤_ZH": 130,
|
172 |
+
"海妮耶_ZH": 131,
|
173 |
+
"旅行者_ZH": 132,
|
174 |
+
"霍夫曼_ZH": 133,
|
175 |
+
"佐西摩斯_ZH": 134,
|
176 |
+
"鹿野奈奈_ZH": 135,
|
177 |
+
"舒伯特_ZH": 136,
|
178 |
+
"天叔_ZH": 137,
|
179 |
+
"艾莉丝_ZH": 138,
|
180 |
+
"龙二_ZH": 139,
|
181 |
+
"莺儿_ZH": 140,
|
182 |
+
"嘉良_ZH": 141,
|
183 |
+
"一心传名刀_ZH": 142,
|
184 |
+
"费迪南德_ZH": 143,
|
185 |
+
"珊瑚_ZH": 144,
|
186 |
+
"言笑_ZH": 145,
|
187 |
+
"久利须_ZH": 146,
|
188 |
+
"嘉玛_ZH": 147,
|
189 |
+
"艾文_ZH": 148,
|
190 |
+
"克洛琳德_ZH": 149,
|
191 |
+
"丹吉尔_ZH": 150,
|
192 |
+
"女士_ZH": 151,
|
193 |
+
"白老先生_ZH": 152,
|
194 |
+
"天目十五_ZH": 153,
|
195 |
+
"老孟_ZH": 154,
|
196 |
+
"巴达维_ZH": 155,
|
197 |
+
"长生_ZH": 156,
|
198 |
+
"吴船长_ZH": 157,
|
199 |
+
"拉齐_ZH": 158,
|
200 |
+
"艾伯特_ZH": 159,
|
201 |
+
"松浦_ZH": 160,
|
202 |
+
"埃泽_ZH": 161,
|
203 |
+
"阿圆_ZH": 162,
|
204 |
+
"莫塞伊思_ZH": 163,
|
205 |
+
"阿拉夫_ZH": 164,
|
206 |
+
"杜吉耶_ZH": 165,
|
207 |
+
"石头_ZH": 166,
|
208 |
+
"百闻_ZH": 167,
|
209 |
+
"波洛_ZH": 168,
|
210 |
+
"斯坦利_ZH": 169,
|
211 |
+
"博易_ZH": 170,
|
212 |
+
"迈蒙_ZH": 171,
|
213 |
+
"掇星攫辰天君_ZH": 172,
|
214 |
+
"毗伽尔_ZH": 173,
|
215 |
+
"芙卡洛斯_ZH": 174,
|
216 |
+
"恶龙_ZH": 175,
|
217 |
+
"恕筠_ZH": 176,
|
218 |
+
"知易_ZH": 177,
|
219 |
+
"克列门特_ZH": 178,
|
220 |
+
"大慈树王_ZH": 179,
|
221 |
+
"西拉杰_ZH": 180,
|
222 |
+
"上杉_ZH": 181,
|
223 |
+
"阿尔卡米_ZH": 182,
|
224 |
+
"纯水精灵_ZH": 183,
|
225 |
+
"常九爷_ZH": 184,
|
226 |
+
"沙扎曼_ZH": 185,
|
227 |
+
"田铁嘴_ZH": 186,
|
228 |
+
"克罗索_ZH": 187,
|
229 |
+
"阿巴图伊_ZH": 188,
|
230 |
+
"悦_ZH": 189,
|
231 |
+
"阿佩普_ZH": 190,
|
232 |
+
"埃尔欣根_ZH": 191,
|
233 |
+
"萨赫哈蒂_ZH": 192,
|
234 |
+
"塔杰·拉德卡尼_ZH": 193,
|
235 |
+
"安西_ZH": 194,
|
236 |
+
"埃舍尔_ZH": 195,
|
237 |
+
"萨齐因_ZH": 196,
|
238 |
+
"派蒙_JP": 197,
|
239 |
+
"纳西妲_JP": 198,
|
240 |
+
"凯亚_JP": 199,
|
241 |
+
"阿贝多_JP": 200,
|
242 |
+
"温迪_JP": 201,
|
243 |
+
"枫原万叶_JP": 202,
|
244 |
+
"钟离_JP": 203,
|
245 |
+
"荒泷一斗_JP": 204,
|
246 |
+
"八重神子_JP": 205,
|
247 |
+
"艾尔海森_JP": 206,
|
248 |
+
"提纳里_JP": 207,
|
249 |
+
"迪希雅_JP": 208,
|
250 |
+
"卡维_JP": 209,
|
251 |
+
"宵宫_JP": 210,
|
252 |
+
"那维莱特_JP": 211,
|
253 |
+
"莱依拉_JP": 212,
|
254 |
+
"赛诺_JP": 213,
|
255 |
+
"莫娜_JP": 214,
|
256 |
+
"诺艾尔_JP": 215,
|
257 |
+
"托马_JP": 216,
|
258 |
+
"凝光_JP": 217,
|
259 |
+
"林尼_JP": 218,
|
260 |
+
"北斗_JP": 219,
|
261 |
+
"柯莱_JP": 220,
|
262 |
+
"神里绫华_JP": 221,
|
263 |
+
"可莉_JP": 222,
|
264 |
+
"芭芭拉_JP": 223,
|
265 |
+
"雷电将军_JP": 224,
|
266 |
+
"娜维娅_JP": 225,
|
267 |
+
"芙宁娜_JP": 226,
|
268 |
+
"珊瑚宫心海_JP": 227,
|
269 |
+
"鹿野院平藏_JP": 228,
|
270 |
+
"迪奥娜_JP": 229,
|
271 |
+
"琴_JP": 230,
|
272 |
+
"五郎_JP": 231,
|
273 |
+
"班尼特_JP": 232,
|
274 |
+
"达达利亚_JP": 233,
|
275 |
+
"安柏_JP": 234,
|
276 |
+
"莱欧斯利_JP": 235,
|
277 |
+
"夜兰_JP": 236,
|
278 |
+
"妮露_JP": 237,
|
279 |
+
"辛焱_JP": 238,
|
280 |
+
"丽莎_JP": 239,
|
281 |
+
"珐露珊_JP": 240,
|
282 |
+
"魈_JP": 241,
|
283 |
+
"香菱_JP": 242,
|
284 |
+
"迪卢克_JP": 243,
|
285 |
+
"砂糖_JP": 244,
|
286 |
+
"烟绯_JP": 245,
|
287 |
+
"早柚_JP": 246,
|
288 |
+
"云堇_JP": 247,
|
289 |
+
"刻晴_JP": 248,
|
290 |
+
"重云_JP": 249,
|
291 |
+
"优菈_JP": 250,
|
292 |
+
"胡桃_JP": 251,
|
293 |
+
"流浪者_JP": 252,
|
294 |
+
"久岐忍_JP": 253,
|
295 |
+
"神里绫人_JP": 254,
|
296 |
+
"甘雨_JP": 255,
|
297 |
+
"戴因斯雷布_JP": 256,
|
298 |
+
"菲谢尔_JP": 257,
|
299 |
+
"白术_JP": 258,
|
300 |
+
"行秋_JP": 259,
|
301 |
+
"九条裟罗_JP": 260,
|
302 |
+
"夏洛蒂_JP": 261,
|
303 |
+
"雷泽_JP": 262,
|
304 |
+
"申鹤_JP": 263,
|
305 |
+
"空_JP": 264,
|
306 |
+
"荧_JP": 265,
|
307 |
+
"迪娜泽黛_JP": 266,
|
308 |
+
"凯瑟琳_JP": 267,
|
309 |
+
"多莉_JP": 268,
|
310 |
+
"坎蒂丝_JP": 269,
|
311 |
+
"琳妮特_JP": 270,
|
312 |
+
"萍姥姥_JP": 271,
|
313 |
+
"罗莎莉亚_JP": 272,
|
314 |
+
"埃德_JP": 273,
|
315 |
+
"爱贝尔_JP": 274,
|
316 |
+
"伊迪娅_JP": 275,
|
317 |
+
"留云借风真君_JP": 276,
|
318 |
+
"绮良良_JP": 277,
|
319 |
+
"七七_JP": 278,
|
320 |
+
"式大将_JP": 279,
|
321 |
+
"瑶瑶_JP": 280,
|
322 |
+
"奥兹_JP": 281,
|
323 |
+
"菲米尼_JP": 282,
|
324 |
+
"米卡_JP": 283,
|
325 |
+
"哲平_JP": 284,
|
326 |
+
"大肉丸_JP": 285,
|
327 |
+
"托克_JP": 286,
|
328 |
+
"蒂玛乌斯_JP": 287,
|
329 |
+
"昆钧_JP": 288,
|
330 |
+
"欧菲妮_JP": 289,
|
331 |
+
"塞琉斯_JP": 290,
|
332 |
+
"仆人_JP": 291,
|
333 |
+
"迈勒斯_JP": 292,
|
334 |
+
"希格雯_JP": 293,
|
335 |
+
"阿守_JP": 294,
|
336 |
+
"拉赫曼_JP": 295,
|
337 |
+
"杜拉夫_JP": 296,
|
338 |
+
"伊利亚斯_JP": 297,
|
339 |
+
"阿晃_JP": 298,
|
340 |
+
"旁白_JP": 299,
|
341 |
+
"爱德琳_JP": 300,
|
342 |
+
"埃洛伊_JP": 301,
|
343 |
+
"德沃沙克_JP": 302,
|
344 |
+
"玛乔丽_JP": 303,
|
345 |
+
"塞塔蕾_JP": 304,
|
346 |
+
"柊千里_JP": 305,
|
347 |
+
"海芭夏_JP": 306,
|
348 |
+
"九条镰治_JP": 307,
|
349 |
+
"阿娜耶_JP": 308,
|
350 |
+
"笼钓瓶一心_JP": 309,
|
351 |
+
"回声海螺_JP": 310,
|
352 |
+
"劳维克_JP": 311,
|
353 |
+
"元太_JP": 312,
|
354 |
+
"阿扎尔_JP": 313,
|
355 |
+
"查尔斯_JP": 314,
|
356 |
+
"阿洛瓦_JP": 315,
|
357 |
+
"埃勒曼_JP": 316,
|
358 |
+
"纳比尔_JP": 317,
|
359 |
+
"莎拉_JP": 318,
|
360 |
+
"康纳_JP": 319,
|
361 |
+
"博来_JP": 320,
|
362 |
+
"玛塞勒_JP": 321,
|
363 |
+
"阿祇_JP": 322,
|
364 |
+
"博士_JP": 323,
|
365 |
+
"迪尔菲_JP": 324,
|
366 |
+
"玛格丽特_JP": 325,
|
367 |
+
"宛烟_JP": 326,
|
368 |
+
"羽生田千鹤_JP": 327,
|
369 |
+
"海妮耶_JP": 328,
|
370 |
+
"霍夫曼_JP": 329,
|
371 |
+
"旅行者_JP": 330,
|
372 |
+
"佐西摩斯_JP": 331,
|
373 |
+
"舒伯特_JP": 332,
|
374 |
+
"鹿野奈奈_JP": 333,
|
375 |
+
"天叔_JP": 334,
|
376 |
+
"龙二_JP": 335,
|
377 |
+
"艾莉丝_JP": 336,
|
378 |
+
"莺儿_JP": 337,
|
379 |
+
"嘉良_JP": 338,
|
380 |
+
"珊瑚_JP": 339,
|
381 |
+
"言笑_JP": 340,
|
382 |
+
"一心传名刀_JP": 341,
|
383 |
+
"费迪南德_JP": 342,
|
384 |
+
"久利须_JP": 343,
|
385 |
+
"嘉玛_JP": 344,
|
386 |
+
"艾文_JP": 345,
|
387 |
+
"克洛琳德_JP": 346,
|
388 |
+
"丹吉尔_JP": 347,
|
389 |
+
"天目十五_JP": 348,
|
390 |
+
"女士_JP": 349,
|
391 |
+
"老孟_JP": 350,
|
392 |
+
"白老先生_JP": 351,
|
393 |
+
"舍利夫_JP": 352,
|
394 |
+
"巴达维_JP": 353,
|
395 |
+
"拉齐_JP": 354,
|
396 |
+
"长生_JP": 355,
|
397 |
+
"吴船长_JP": 356,
|
398 |
+
"艾伯特_JP": 357,
|
399 |
+
"松浦_JP": 358,
|
400 |
+
"埃泽_JP": 359,
|
401 |
+
"阿圆_JP": 360,
|
402 |
+
"阿拉夫_JP": 361,
|
403 |
+
"莫塞伊思_JP": 362,
|
404 |
+
"石头_JP": 363,
|
405 |
+
"百闻_JP": 364,
|
406 |
+
"杜吉耶_JP": 365,
|
407 |
+
"波洛_JP": 366,
|
408 |
+
"掇星攫辰天君_JP": 367,
|
409 |
+
"迈蒙_JP": 368,
|
410 |
+
"博易_JP": 369,
|
411 |
+
"诗筠_JP": 370,
|
412 |
+
"斯坦利_JP": 371,
|
413 |
+
"毗伽尔_JP": 372,
|
414 |
+
"芙卡洛斯_JP": 373,
|
415 |
+
"恶龙_JP": 374,
|
416 |
+
"小仓澪_JP": 375,
|
417 |
+
"恕筠_JP": 376,
|
418 |
+
"知易_JP": 377,
|
419 |
+
"克列门特_JP": 378,
|
420 |
+
"大慈树王_JP": 379,
|
421 |
+
"望雅_JP": 380,
|
422 |
+
"黑田_JP": 381,
|
423 |
+
"卡莉娜_JP": 382,
|
424 |
+
"马姆杜_JP": 383,
|
425 |
+
"科林斯_JP": 384,
|
426 |
+
"上杉_JP": 385,
|
427 |
+
"西拉杰_JP": 386,
|
428 |
+
"菲尔戈黛特_JP": 387,
|
429 |
+
"一平_JP": 388,
|
430 |
+
"纯水精灵_JP": 389,
|
431 |
+
"阿尔卡米_JP": 390,
|
432 |
+
"老戴_JP": 391,
|
433 |
+
"谢赫祖拜尔_JP": 392,
|
434 |
+
"沙扎曼_JP": 393,
|
435 |
+
"田铁嘴_JP": 394,
|
436 |
+
"小野寺_JP": 395,
|
437 |
+
"百识_JP": 396,
|
438 |
+
"克罗索_JP": 397,
|
439 |
+
"莱斯格_JP": 398,
|
440 |
+
"芷巧_JP": 399,
|
441 |
+
"加藤洋平_JP": 400,
|
442 |
+
"阿巴图伊_JP": 401,
|
443 |
+
"埃尔欣根_JP": 402,
|
444 |
+
"斯嘉莉_JP": 403,
|
445 |
+
"阿佩普_JP": 404,
|
446 |
+
"巫女_JP": 405,
|
447 |
+
"卡布斯_JP": 406,
|
448 |
+
"洛伦佐_JP": 407,
|
449 |
+
"萨赫哈蒂_JP": 408,
|
450 |
+
"娜德瓦_JP": 409,
|
451 |
+
"塞德娜_JP": 410,
|
452 |
+
"塔杰·拉德卡尼_JP": 411,
|
453 |
+
"绘星_JP": 412,
|
454 |
+
"泽田_JP": 413,
|
455 |
+
"安西_JP": 414,
|
456 |
+
"拉伊德_JP": 415,
|
457 |
+
"亚卡巴_JP": 416,
|
458 |
+
"有乐斋_JP": 417,
|
459 |
+
"莱昂_JP": 418,
|
460 |
+
"尤苏波夫_JP": 419,
|
461 |
+
"夏妮_JP": 420,
|
462 |
+
"埃舍尔_JP": 421,
|
463 |
+
"萨齐因_JP": 422,
|
464 |
+
"古山_JP": 423,
|
465 |
+
"自称渊上之物_JP": 424,
|
466 |
+
"丹羽_JP": 425,
|
467 |
+
"塞萨尔的日记_JP": 426,
|
468 |
+
"派蒙_EN": 427,
|
469 |
+
"纳西妲_EN": 428,
|
470 |
+
"凯亚_EN": 429,
|
471 |
+
"阿贝多_EN": 430,
|
472 |
+
"温迪_EN": 431,
|
473 |
+
"枫原万叶_EN": 432,
|
474 |
+
"钟离_EN": 433,
|
475 |
+
"荒泷一斗_EN": 434,
|
476 |
+
"八重神子_EN": 435,
|
477 |
+
"艾尔海森_EN": 436,
|
478 |
+
"提纳里_EN": 437,
|
479 |
+
"迪希雅_EN": 438,
|
480 |
+
"卡维_EN": 439,
|
481 |
+
"宵宫_EN": 440,
|
482 |
+
"莱依拉_EN": 441,
|
483 |
+
"那维莱特_EN": 442,
|
484 |
+
"赛诺_EN": 443,
|
485 |
+
"莫娜_EN": 444,
|
486 |
+
"诺艾尔_EN": 445,
|
487 |
+
"托马_EN": 446,
|
488 |
+
"凝光_EN": 447,
|
489 |
+
"林尼_EN": 448,
|
490 |
+
"北斗_EN": 449,
|
491 |
+
"柯莱_EN": 450,
|
492 |
+
"神里绫华_EN": 451,
|
493 |
+
"可莉_EN": 452,
|
494 |
+
"芭芭拉_EN": 453,
|
495 |
+
"雷电将军_EN": 454,
|
496 |
+
"娜维娅_EN": 455,
|
497 |
+
"芙宁娜_EN": 456,
|
498 |
+
"珊瑚宫心海_EN": 457,
|
499 |
+
"鹿野院平藏_EN": 458,
|
500 |
+
"迪奥娜_EN": 459,
|
501 |
+
"五郎_EN": 460,
|
502 |
+
"琴_EN": 461,
|
503 |
+
"班尼特_EN": 462,
|
504 |
+
"达达利亚_EN": 463,
|
505 |
+
"安柏_EN": 464,
|
506 |
+
"莱欧斯利_EN": 465,
|
507 |
+
"夜兰_EN": 466,
|
508 |
+
"妮露_EN": 467,
|
509 |
+
"辛焱_EN": 468,
|
510 |
+
"珐露珊_EN": 469,
|
511 |
+
"丽莎_EN": 470,
|
512 |
+
"魈_EN": 471,
|
513 |
+
"香菱_EN": 472,
|
514 |
+
"迪卢克_EN": 473,
|
515 |
+
"砂糖_EN": 474,
|
516 |
+
"烟绯_EN": 475,
|
517 |
+
"早柚_EN": 476,
|
518 |
+
"云堇_EN": 477,
|
519 |
+
"刻晴_EN": 478,
|
520 |
+
"重云_EN": 479,
|
521 |
+
"优菈_EN": 480,
|
522 |
+
"胡桃_EN": 481,
|
523 |
+
"流浪者_EN": 482,
|
524 |
+
"久岐忍_EN": 483,
|
525 |
+
"神里绫人_EN": 484,
|
526 |
+
"甘雨_EN": 485,
|
527 |
+
"戴因斯雷布_EN": 486,
|
528 |
+
"菲谢尔_EN": 487,
|
529 |
+
"白术_EN": 488,
|
530 |
+
"行秋_EN": 489,
|
531 |
+
"九条裟罗_EN": 490,
|
532 |
+
"夏洛蒂_EN": 491,
|
533 |
+
"雷泽_EN": 492,
|
534 |
+
"申鹤_EN": 493,
|
535 |
+
"荧_EN": 494,
|
536 |
+
"空_EN": 495,
|
537 |
+
"迪娜泽黛_EN": 496,
|
538 |
+
"凯瑟琳_EN": 497,
|
539 |
+
"多莉_EN": 498,
|
540 |
+
"坎蒂丝_EN": 499,
|
541 |
+
"琳妮特_EN": 500,
|
542 |
+
"萍姥姥_EN": 501,
|
543 |
+
"罗莎莉亚_EN": 502,
|
544 |
+
"埃德_EN": 503,
|
545 |
+
"爱贝尔_EN": 504,
|
546 |
+
"伊迪娅_EN": 505,
|
547 |
+
"留云借风真君_EN": 506,
|
548 |
+
"绮良良_EN": 507,
|
549 |
+
"七七_EN": 508,
|
550 |
+
"式大将_EN": 509,
|
551 |
+
"瑶瑶_EN": 510,
|
552 |
+
"奥兹_EN": 511,
|
553 |
+
"菲米尼_EN": 512,
|
554 |
+
"米卡_EN": 513,
|
555 |
+
"哲平_EN": 514,
|
556 |
+
"大肉丸_EN": 515,
|
557 |
+
"托克_EN": 516,
|
558 |
+
"蒂玛乌斯_EN": 517,
|
559 |
+
"昆钧_EN": 518,
|
560 |
+
"欧菲妮_EN": 519,
|
561 |
+
"塞琉斯_EN": 520,
|
562 |
+
"仆人_EN": 521,
|
563 |
+
"迈勒斯_EN": 522,
|
564 |
+
"希格雯_EN": 523,
|
565 |
+
"阿守_EN": 524,
|
566 |
+
"拉赫曼_EN": 525,
|
567 |
+
"杜拉夫_EN": 526,
|
568 |
+
"伊利亚斯_EN": 527,
|
569 |
+
"阿晃_EN": 528,
|
570 |
+
"旁白_EN": 529,
|
571 |
+
"爱德琳_EN": 530,
|
572 |
+
"埃洛伊_EN": 531,
|
573 |
+
"德沃沙克_EN": 532,
|
574 |
+
"玛乔丽_EN": 533,
|
575 |
+
"塞塔蕾_EN": 534,
|
576 |
+
"柊千里_EN": 535,
|
577 |
+
"海芭夏_EN": 536,
|
578 |
+
"九条镰治_EN": 537,
|
579 |
+
"阿娜耶_EN": 538,
|
580 |
+
"笼钓瓶一心_EN": 539,
|
581 |
+
"回声海螺_EN": 540,
|
582 |
+
"劳维克_EN": 541,
|
583 |
+
"元太_EN": 542,
|
584 |
+
"阿扎尔_EN": 543,
|
585 |
+
"查尔斯_EN": 544,
|
586 |
+
"阿洛瓦_EN": 545,
|
587 |
+
"埃勒曼_EN": 546,
|
588 |
+
"纳比尔_EN": 547,
|
589 |
+
"莎拉_EN": 548,
|
590 |
+
"康纳_EN": 549,
|
591 |
+
"博来_EN": 550,
|
592 |
+
"玛塞勒_EN": 551,
|
593 |
+
"阿祇_EN": 552,
|
594 |
+
"博士_EN": 553,
|
595 |
+
"迪尔菲_EN": 554,
|
596 |
+
"宛烟_EN": 555,
|
597 |
+
"玛格丽特_EN": 556,
|
598 |
+
"羽生田千鹤_EN": 557,
|
599 |
+
"海妮耶_EN": 558,
|
600 |
+
"霍夫曼_EN": 559,
|
601 |
+
"旅行者_EN": 560,
|
602 |
+
"佐西摩斯_EN": 561,
|
603 |
+
"鹿野奈奈_EN": 562,
|
604 |
+
"舒伯特_EN": 563,
|
605 |
+
"天叔_EN": 564,
|
606 |
+
"艾莉丝_EN": 565,
|
607 |
+
"龙二_EN": 566,
|
608 |
+
"莺儿_EN": 567,
|
609 |
+
"嘉良_EN": 568,
|
610 |
+
"珊瑚_EN": 569,
|
611 |
+
"费迪南德_EN": 570,
|
612 |
+
"言笑_EN": 571,
|
613 |
+
"一心传名刀_EN": 572,
|
614 |
+
"久利须_EN": 573,
|
615 |
+
"嘉玛_EN": 574,
|
616 |
+
"艾文_EN": 575,
|
617 |
+
"克洛琳德_EN": 576,
|
618 |
+
"丹吉尔_EN": 577,
|
619 |
+
"女士_EN": 578,
|
620 |
+
"天目十五_EN": 579,
|
621 |
+
"老孟_EN": 580,
|
622 |
+
"白老先生_EN": 581,
|
623 |
+
"舍利夫_EN": 582,
|
624 |
+
"巴达维_EN": 583,
|
625 |
+
"拉齐_EN": 584,
|
626 |
+
"长生_EN": 585,
|
627 |
+
"吴船长_EN": 586,
|
628 |
+
"艾伯特_EN": 587,
|
629 |
+
"松浦_EN": 588,
|
630 |
+
"埃泽_EN": 589,
|
631 |
+
"阿圆_EN": 590,
|
632 |
+
"阿拉夫_EN": 591,
|
633 |
+
"莫塞伊思_EN": 592,
|
634 |
+
"石头_EN": 593,
|
635 |
+
"百闻_EN": 594,
|
636 |
+
"杜吉耶_EN": 595,
|
637 |
+
"波洛_EN": 596,
|
638 |
+
"斯坦利_EN": 597,
|
639 |
+
"掇星攫辰天君_EN": 598,
|
640 |
+
"迈蒙_EN": 599,
|
641 |
+
"博易_EN": 600,
|
642 |
+
"诗筠_EN": 601,
|
643 |
+
"毗伽尔_EN": 602,
|
644 |
+
"慧心_EN": 603,
|
645 |
+
"芙卡洛斯_EN": 604,
|
646 |
+
"恶龙_EN": 605,
|
647 |
+
"小仓澪_EN": 606,
|
648 |
+
"恕筠_EN": 607,
|
649 |
+
"知易_EN": 608,
|
650 |
+
"克列门特_EN": 609,
|
651 |
+
"大慈树王_EN": 610,
|
652 |
+
"维多利亚_EN": 611,
|
653 |
+
"黑田_EN": 612,
|
654 |
+
"马姆杜_EN": 613,
|
655 |
+
"科林斯_EN": 614,
|
656 |
+
"上杉_EN": 615,
|
657 |
+
"西拉杰_EN": 616,
|
658 |
+
"宁禄_EN": 617,
|
659 |
+
"纯水精灵_EN": 618,
|
660 |
+
"常九爷_EN": 619,
|
661 |
+
"阿尔卡米_EN": 620,
|
662 |
+
"沙扎曼_EN": 621,
|
663 |
+
"田铁嘴_EN": 622,
|
664 |
+
"加萨尼_EN": 623,
|
665 |
+
"克罗索_EN": 624,
|
666 |
+
"星稀_EN": 625,
|
667 |
+
"莱斯格_EN": 626,
|
668 |
+
"阿巴图伊_EN": 627,
|
669 |
+
"悦_EN": 628,
|
670 |
+
"德田_EN": 629,
|
671 |
+
"埃尔欣根_EN": 630,
|
672 |
+
"阿佩普_EN": 631,
|
673 |
+
"萨赫哈蒂_EN": 632,
|
674 |
+
"洛伦佐_EN": 633,
|
675 |
+
"塔杰·拉德卡尼_EN": 634,
|
676 |
+
"泽田_EN": 635,
|
677 |
+
"安西_EN": 636,
|
678 |
+
"理水叠山真君_EN": 637,
|
679 |
+
"埃舍尔_EN": 638,
|
680 |
+
"萨齐因_EN": 639,
|
681 |
+
"古田_EN": 640,
|
682 |
+
"三月七_ZH": 641,
|
683 |
+
"丹恒_ZH": 642,
|
684 |
+
"希儿_ZH": 643,
|
685 |
+
"娜塔莎_ZH": 644,
|
686 |
+
"希露瓦_ZH": 645,
|
687 |
+
"瓦尔特_ZH": 646,
|
688 |
+
"佩拉_ZH": 647,
|
689 |
+
"布洛妮娅_ZH": 648,
|
690 |
+
"虎克_ZH": 649,
|
691 |
+
"素裳_ZH": 650,
|
692 |
+
"克拉拉_ZH": 651,
|
693 |
+
"符玄_ZH": 652,
|
694 |
+
"白露_ZH": 653,
|
695 |
+
"杰帕德_ZH": 654,
|
696 |
+
"景元_ZH": 655,
|
697 |
+
"藿藿_ZH": 656,
|
698 |
+
"姬子_ZH": 657,
|
699 |
+
"穹_ZH": 658,
|
700 |
+
"星_ZH": 659,
|
701 |
+
"卡芙卡_ZH": 660,
|
702 |
+
"桂乃芬_ZH": 661,
|
703 |
+
"艾丝妲_ZH": 662,
|
704 |
+
"玲可_ZH": 663,
|
705 |
+
"彦卿_ZH": 664,
|
706 |
+
"托帕_ZH": 665,
|
707 |
+
"驭空_ZH": 666,
|
708 |
+
"浮烟_ZH": 667,
|
709 |
+
"停云_ZH": 668,
|
710 |
+
"镜流_ZH": 669,
|
711 |
+
"罗刹_ZH": 670,
|
712 |
+
"卢卡_ZH": 671,
|
713 |
+
"史瓦罗_ZH": 672,
|
714 |
+
"黑塔_ZH": 673,
|
715 |
+
"桑博_ZH": 674,
|
716 |
+
"伦纳德_ZH": 675,
|
717 |
+
"明曦_ZH": 676,
|
718 |
+
"银狼_ZH": 677,
|
719 |
+
"帕姆_ZH": 678,
|
720 |
+
"青雀_ZH": 679,
|
721 |
+
"乔瓦尼_ZH": 680,
|
722 |
+
"公输师傅_ZH": 681,
|
723 |
+
"晴霓_ZH": 682,
|
724 |
+
"螺丝咕姆_ZH": 683,
|
725 |
+
"阿兰_ZH": 684,
|
726 |
+
"奥列格_ZH": 685,
|
727 |
+
"丹枢_ZH": 686,
|
728 |
+
"尾巴_ZH": 687,
|
729 |
+
"寒鸦_ZH": 688,
|
730 |
+
"雪衣_ZH": 689,
|
731 |
+
"可可利亚_ZH": 690,
|
732 |
+
"青镞_ZH": 691,
|
733 |
+
"半夏_ZH": 692,
|
734 |
+
"银枝_ZH": 693,
|
735 |
+
"大毫_ZH": 694,
|
736 |
+
"霄翰_ZH": 695,
|
737 |
+
"信使_ZH": 696,
|
738 |
+
"费斯曼_ZH": 697,
|
739 |
+
"绿芙蓉_ZH": 698,
|
740 |
+
"dev_成男_ZH": 699,
|
741 |
+
"金人会长_ZH": 700,
|
742 |
+
"维利特_ZH": 701,
|
743 |
+
"维尔德_ZH": 702,
|
744 |
+
"斯科特_ZH": 703,
|
745 |
+
"卡波特_ZH": 704,
|
746 |
+
"刃_ZH": 705,
|
747 |
+
"岩明_ZH": 706,
|
748 |
+
"浣溪_ZH": 707,
|
749 |
+
"三月七_JP": 708,
|
750 |
+
"丹恒_JP": 709,
|
751 |
+
"希儿_JP": 710,
|
752 |
+
"娜塔莎_JP": 711,
|
753 |
+
"希露瓦_JP": 712,
|
754 |
+
"瓦尔特_JP": 713,
|
755 |
+
"佩拉_JP": 714,
|
756 |
+
"布洛妮娅_JP": 715,
|
757 |
+
"虎克_JP": 716,
|
758 |
+
"��裳_JP": 717,
|
759 |
+
"克拉拉_JP": 718,
|
760 |
+
"符玄_JP": 719,
|
761 |
+
"白露_JP": 720,
|
762 |
+
"杰帕德_JP": 721,
|
763 |
+
"景元_JP": 722,
|
764 |
+
"藿藿_JP": 723,
|
765 |
+
"姬子_JP": 724,
|
766 |
+
"卡芙卡_JP": 725,
|
767 |
+
"穹_JP": 726,
|
768 |
+
"星_JP": 727,
|
769 |
+
"桂乃芬_JP": 728,
|
770 |
+
"艾丝妲_JP": 729,
|
771 |
+
"彦卿_JP": 730,
|
772 |
+
"玲可_JP": 731,
|
773 |
+
"托帕_JP": 732,
|
774 |
+
"驭空_JP": 733,
|
775 |
+
"浮烟_JP": 734,
|
776 |
+
"停云_JP": 735,
|
777 |
+
"镜流_JP": 736,
|
778 |
+
"罗刹_JP": 737,
|
779 |
+
"卢卡_JP": 738,
|
780 |
+
"史瓦罗_JP": 739,
|
781 |
+
"黑塔_JP": 740,
|
782 |
+
"桑博_JP": 741,
|
783 |
+
"伦纳德_JP": 742,
|
784 |
+
"明曦_JP": 743,
|
785 |
+
"银狼_JP": 744,
|
786 |
+
"帕姆_JP": 745,
|
787 |
+
"青雀_JP": 746,
|
788 |
+
"乔瓦尼_JP": 747,
|
789 |
+
"公输师傅_JP": 748,
|
790 |
+
"晴霓_JP": 749,
|
791 |
+
"螺丝咕姆_JP": 750,
|
792 |
+
"阿兰_JP": 751,
|
793 |
+
"奥列格_JP": 752,
|
794 |
+
"丹枢_JP": 753,
|
795 |
+
"尾巴_JP": 754,
|
796 |
+
"寒鸦_JP": 755,
|
797 |
+
"雪衣_JP": 756,
|
798 |
+
"可可利亚_JP": 757,
|
799 |
+
"青镞_JP": 758,
|
800 |
+
"半夏_JP": 759,
|
801 |
+
"银枝_JP": 760,
|
802 |
+
"大毫_JP": 761,
|
803 |
+
"霄翰_JP": 762,
|
804 |
+
"信使_JP": 763,
|
805 |
+
"费斯曼_JP": 764,
|
806 |
+
"绿芙蓉_JP": 765,
|
807 |
+
"dev_成男_JP": 766,
|
808 |
+
"金人会长_JP": 767,
|
809 |
+
"维利特_JP": 768,
|
810 |
+
"维尔德_JP": 769,
|
811 |
+
"斯科特_JP": 770,
|
812 |
+
"刃_JP": 771,
|
813 |
+
"卡波特_JP": 772,
|
814 |
+
"岩明_JP": 773,
|
815 |
+
"浣溪_JP": 774,
|
816 |
+
"净砚_JP": 775,
|
817 |
+
"紫月季_JP": 776,
|
818 |
+
"歌蒂_JP": 777,
|
819 |
+
"奇怪的云骑_JP": 778,
|
820 |
+
"幻胧_JP": 779,
|
821 |
+
"斯薇塔_JP": 780,
|
822 |
+
"隐书_JP": 781,
|
823 |
+
"三月七_EN": 782,
|
824 |
+
"丹恒_EN": 783,
|
825 |
+
"希儿_EN": 784,
|
826 |
+
"娜塔莎_EN": 785,
|
827 |
+
"希露瓦_EN": 786,
|
828 |
+
"瓦尔特_EN": 787,
|
829 |
+
"佩拉_EN": 788,
|
830 |
+
"布洛妮娅_EN": 789,
|
831 |
+
"虎克_EN": 790,
|
832 |
+
"素裳_EN": 791,
|
833 |
+
"克拉拉_EN": 792,
|
834 |
+
"符玄_EN": 793,
|
835 |
+
"白露_EN": 794,
|
836 |
+
"杰帕德_EN": 795,
|
837 |
+
"景元_EN": 796,
|
838 |
+
"藿藿_EN": 797,
|
839 |
+
"姬子_EN": 798,
|
840 |
+
"卡芙卡_EN": 799,
|
841 |
+
"穹_EN": 800,
|
842 |
+
"星_EN": 801,
|
843 |
+
"桂乃芬_EN": 802,
|
844 |
+
"艾丝妲_EN": 803,
|
845 |
+
"彦卿_EN": 804,
|
846 |
+
"玲可_EN": 805,
|
847 |
+
"托帕_EN": 806,
|
848 |
+
"驭空_EN": 807,
|
849 |
+
"浮烟_EN": 808,
|
850 |
+
"停云_EN": 809,
|
851 |
+
"镜流_EN": 810,
|
852 |
+
"罗刹_EN": 811,
|
853 |
+
"卢卡_EN": 812,
|
854 |
+
"史瓦罗_EN": 813,
|
855 |
+
"黑塔_EN": 814,
|
856 |
+
"桑博_EN": 815,
|
857 |
+
"伦纳德_EN": 816,
|
858 |
+
"明曦_EN": 817,
|
859 |
+
"银狼_EN": 818,
|
860 |
+
"帕姆_EN": 819,
|
861 |
+
"青雀_EN": 820,
|
862 |
+
"乔瓦尼_EN": 821,
|
863 |
+
"公输师傅_EN": 822,
|
864 |
+
"晴霓_EN": 823,
|
865 |
+
"螺丝咕姆_EN": 824,
|
866 |
+
"阿兰_EN": 825,
|
867 |
+
"奥列格_EN": 826,
|
868 |
+
"丹枢_EN": 827,
|
869 |
+
"尾巴_EN": 828,
|
870 |
+
"寒鸦_EN": 829,
|
871 |
+
"雪衣_EN": 830,
|
872 |
+
"可可利亚_EN": 831,
|
873 |
+
"青镞_EN": 832,
|
874 |
+
"半夏_EN": 833,
|
875 |
+
"银枝_EN": 834,
|
876 |
+
"大毫_EN": 835,
|
877 |
+
"霄翰_EN": 836,
|
878 |
+
"信使_EN": 837,
|
879 |
+
"费斯曼_EN": 838,
|
880 |
+
"绿芙蓉_EN": 839,
|
881 |
+
"dev_成男_EN": 840,
|
882 |
+
"金人会长_EN": 841,
|
883 |
+
"维利特_EN": 842,
|
884 |
+
"维尔德_EN": 843,
|
885 |
+
"刃_EN": 844,
|
886 |
+
"卡波特_EN": 845,
|
887 |
+
"岩明_EN": 846,
|
888 |
+
"浣溪_EN": 847,
|
889 |
+
"紫月季_EN": 848,
|
890 |
+
"幻胧_EN": 849,
|
891 |
+
"女声_EN": 850,
|
892 |
+
"陆景和": 851,
|
893 |
+
"莫弈": 852,
|
894 |
+
"左然": 853,
|
895 |
+
"夏彦": 854
|
896 |
+
}
|
897 |
+
},
|
898 |
+
"model": {
|
899 |
+
"use_spk_conditioned_encoder": true,
|
900 |
+
"use_noise_scaled_mas": true,
|
901 |
+
"use_mel_posterior_encoder": false,
|
902 |
+
"use_duration_discriminator": true,
|
903 |
+
"inter_channels": 192,
|
904 |
+
"hidden_channels": 192,
|
905 |
+
"filter_channels": 768,
|
906 |
+
"n_heads": 2,
|
907 |
+
"n_layers": 6,
|
908 |
+
"kernel_size": 3,
|
909 |
+
"p_dropout": 0.1,
|
910 |
+
"resblock": "1",
|
911 |
+
"resblock_kernel_sizes": [
|
912 |
+
3,
|
913 |
+
7,
|
914 |
+
11
|
915 |
+
],
|
916 |
+
"resblock_dilation_sizes": [
|
917 |
+
[
|
918 |
+
1,
|
919 |
+
3,
|
920 |
+
5
|
921 |
+
],
|
922 |
+
[
|
923 |
+
1,
|
924 |
+
3,
|
925 |
+
5
|
926 |
+
],
|
927 |
+
[
|
928 |
+
1,
|
929 |
+
3,
|
930 |
+
5
|
931 |
+
]
|
932 |
+
],
|
933 |
+
"upsample_rates": [
|
934 |
+
8,
|
935 |
+
8,
|
936 |
+
2,
|
937 |
+
2,
|
938 |
+
2
|
939 |
+
],
|
940 |
+
"upsample_initial_channel": 512,
|
941 |
+
"upsample_kernel_sizes": [
|
942 |
+
16,
|
943 |
+
16,
|
944 |
+
8,
|
945 |
+
2,
|
946 |
+
2
|
947 |
+
],
|
948 |
+
"n_layers_q": 3,
|
949 |
+
"use_spectral_norm": false,
|
950 |
+
"gin_channels": 256
|
951 |
+
},
|
952 |
+
"version": "2.2"
|
953 |
+
}
|
css/custom.css
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
#yml_code {
|
3 |
+
height: 600px;
|
4 |
+
flex-grow: inherit;
|
5 |
+
overflow-y: auto;
|
6 |
+
}
|
7 |
+
|
8 |
+
#json_code {
|
9 |
+
height: 600px;
|
10 |
+
flex-grow: inherit;
|
11 |
+
overflow-y: auto;
|
12 |
+
}
|
13 |
+
|
14 |
+
#gpu_code {
|
15 |
+
height: 300px;
|
16 |
+
flex-grow: inherit;
|
17 |
+
overflow-y: auto;
|
18 |
+
}
|
data_utils.py
ADDED
@@ -0,0 +1,421 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import random
|
3 |
+
import torch
|
4 |
+
import torch.utils.data
|
5 |
+
from tqdm import tqdm
|
6 |
+
import numpy as np
|
7 |
+
from tools.log import logger
|
8 |
+
import commons
|
9 |
+
from mel_processing import spectrogram_torch, mel_spectrogram_torch
|
10 |
+
from utils import load_wav_to_torch, load_filepaths_and_text
|
11 |
+
from text import cleaned_text_to_sequence
|
12 |
+
from config import config
|
13 |
+
|
14 |
+
"""Multi speaker version"""
|
15 |
+
|
16 |
+
|
17 |
+
class TextAudioSpeakerLoader(torch.utils.data.Dataset):
|
18 |
+
"""
|
19 |
+
1) loads audio, speaker_id, text pairs
|
20 |
+
2) normalizes text and converts them to sequences of integers
|
21 |
+
3) computes spectrograms from audio files.
|
22 |
+
"""
|
23 |
+
|
24 |
+
def __init__(self, audiopaths_sid_text, hparams):
|
25 |
+
self.audiopaths_sid_text = load_filepaths_and_text(audiopaths_sid_text)
|
26 |
+
self.max_wav_value = hparams.max_wav_value
|
27 |
+
self.sampling_rate = hparams.sampling_rate
|
28 |
+
self.filter_length = hparams.filter_length
|
29 |
+
self.hop_length = hparams.hop_length
|
30 |
+
self.win_length = hparams.win_length
|
31 |
+
self.sampling_rate = hparams.sampling_rate
|
32 |
+
self.spk_map = hparams.spk2id
|
33 |
+
self.hparams = hparams
|
34 |
+
|
35 |
+
self.use_mel_spec_posterior = getattr(
|
36 |
+
hparams, "use_mel_posterior_encoder", False
|
37 |
+
)
|
38 |
+
if self.use_mel_spec_posterior:
|
39 |
+
self.n_mel_channels = getattr(hparams, "n_mel_channels", 80)
|
40 |
+
|
41 |
+
self.cleaned_text = getattr(hparams, "cleaned_text", False)
|
42 |
+
|
43 |
+
self.add_blank = hparams.add_blank
|
44 |
+
self.min_text_len = getattr(hparams, "min_text_len", 1)
|
45 |
+
self.max_text_len = getattr(hparams, "max_text_len", 384)
|
46 |
+
|
47 |
+
self.empty_emo = torch.squeeze(
|
48 |
+
torch.load("empty_emo.npy", map_location="cpu"), dim=1
|
49 |
+
)
|
50 |
+
|
51 |
+
random.seed(1234)
|
52 |
+
random.shuffle(self.audiopaths_sid_text)
|
53 |
+
self._filter()
|
54 |
+
|
55 |
+
def _filter(self):
|
56 |
+
"""
|
57 |
+
Filter text & store spec lengths
|
58 |
+
"""
|
59 |
+
# Store spectrogram lengths for Bucketing
|
60 |
+
# wav_length ~= file_size / (wav_channels * Bytes per dim) = file_size / (1 * 2)
|
61 |
+
# spec_length = wav_length // hop_length
|
62 |
+
|
63 |
+
audiopaths_sid_text_new = []
|
64 |
+
lengths = []
|
65 |
+
skipped = 0
|
66 |
+
logger.info("Init dataset...")
|
67 |
+
for _id, spk, language, text, phones, tone, word2ph in tqdm(
|
68 |
+
self.audiopaths_sid_text
|
69 |
+
):
|
70 |
+
audiopath = f"{_id}"
|
71 |
+
if self.min_text_len <= len(phones) and len(phones) <= self.max_text_len:
|
72 |
+
phones = phones.split(" ")
|
73 |
+
tone = [int(i) for i in tone.split(" ")]
|
74 |
+
word2ph = [int(i) for i in word2ph.split(" ")]
|
75 |
+
audiopaths_sid_text_new.append(
|
76 |
+
[audiopath, spk, language, text, phones, tone, word2ph]
|
77 |
+
)
|
78 |
+
lengths.append(os.path.getsize(audiopath) // (2 * self.hop_length))
|
79 |
+
else:
|
80 |
+
skipped += 1
|
81 |
+
logger.info(
|
82 |
+
"skipped: "
|
83 |
+
+ str(skipped)
|
84 |
+
+ ", total: "
|
85 |
+
+ str(len(self.audiopaths_sid_text))
|
86 |
+
)
|
87 |
+
self.audiopaths_sid_text = audiopaths_sid_text_new
|
88 |
+
self.lengths = lengths
|
89 |
+
|
90 |
+
def get_audio_text_speaker_pair(self, audiopath_sid_text):
|
91 |
+
# separate filename, speaker_id and text
|
92 |
+
audiopath, sid, language, text, phones, tone, word2ph = audiopath_sid_text
|
93 |
+
|
94 |
+
bert, ja_bert, en_bert, phones, tone, language = self.get_text(
|
95 |
+
text, word2ph, phones, tone, language, audiopath
|
96 |
+
)
|
97 |
+
|
98 |
+
spec, wav = self.get_audio(audiopath)
|
99 |
+
sid = torch.LongTensor([int(self.spk_map[sid])])
|
100 |
+
|
101 |
+
if np.random.rand() > 0.1:
|
102 |
+
emo = torch.squeeze(
|
103 |
+
torch.load(audiopath.replace(".wav", ".emo.npy"), map_location="cpu"),
|
104 |
+
dim=1,
|
105 |
+
)
|
106 |
+
else:
|
107 |
+
emo = self.empty_emo
|
108 |
+
return (phones, spec, wav, sid, tone, language, bert, ja_bert, en_bert, emo)
|
109 |
+
|
110 |
+
def get_audio(self, filename):
|
111 |
+
audio, sampling_rate = load_wav_to_torch(filename)
|
112 |
+
if sampling_rate != self.sampling_rate:
|
113 |
+
raise ValueError(
|
114 |
+
"{} {} SR doesn't match target {} SR".format(
|
115 |
+
filename, sampling_rate, self.sampling_rate
|
116 |
+
)
|
117 |
+
)
|
118 |
+
audio_norm = audio / self.max_wav_value
|
119 |
+
audio_norm = audio_norm.unsqueeze(0)
|
120 |
+
spec_filename = filename.replace(".wav", ".spec.pt")
|
121 |
+
if self.use_mel_spec_posterior:
|
122 |
+
spec_filename = spec_filename.replace(".spec.pt", ".mel.pt")
|
123 |
+
try:
|
124 |
+
spec = torch.load(spec_filename)
|
125 |
+
except:
|
126 |
+
if self.use_mel_spec_posterior:
|
127 |
+
spec = mel_spectrogram_torch(
|
128 |
+
audio_norm,
|
129 |
+
self.filter_length,
|
130 |
+
self.n_mel_channels,
|
131 |
+
self.sampling_rate,
|
132 |
+
self.hop_length,
|
133 |
+
self.win_length,
|
134 |
+
self.hparams.mel_fmin,
|
135 |
+
self.hparams.mel_fmax,
|
136 |
+
center=False,
|
137 |
+
)
|
138 |
+
else:
|
139 |
+
spec = spectrogram_torch(
|
140 |
+
audio_norm,
|
141 |
+
self.filter_length,
|
142 |
+
self.sampling_rate,
|
143 |
+
self.hop_length,
|
144 |
+
self.win_length,
|
145 |
+
center=False,
|
146 |
+
)
|
147 |
+
spec = torch.squeeze(spec, 0)
|
148 |
+
if config.train_ms_config.spec_cache:
|
149 |
+
torch.save(spec, spec_filename)
|
150 |
+
return spec, audio_norm
|
151 |
+
|
152 |
+
def get_text(self, text, word2ph, phone, tone, language_str, wav_path):
|
153 |
+
phone, tone, language = cleaned_text_to_sequence(phone, tone, language_str)
|
154 |
+
if self.add_blank:
|
155 |
+
phone = commons.intersperse(phone, 0)
|
156 |
+
tone = commons.intersperse(tone, 0)
|
157 |
+
language = commons.intersperse(language, 0)
|
158 |
+
for i in range(len(word2ph)):
|
159 |
+
word2ph[i] = word2ph[i] * 2
|
160 |
+
word2ph[0] += 1
|
161 |
+
bert_path = wav_path.replace(".wav", ".bert.pt")
|
162 |
+
try:
|
163 |
+
bert_ori = torch.load(bert_path)
|
164 |
+
assert bert_ori.shape[-1] == len(phone)
|
165 |
+
except Exception as e:
|
166 |
+
logger.warning("Bert load Failed")
|
167 |
+
logger.warning(e)
|
168 |
+
|
169 |
+
if language_str == "ZH":
|
170 |
+
bert = bert_ori
|
171 |
+
ja_bert = torch.rand(1024, len(phone))
|
172 |
+
en_bert = torch.rand(1024, len(phone))
|
173 |
+
elif language_str == "JP":
|
174 |
+
bert = torch.rand(1024, len(phone))
|
175 |
+
ja_bert = bert_ori
|
176 |
+
en_bert = torch.rand(1024, len(phone))
|
177 |
+
elif language_str == "EN":
|
178 |
+
bert = torch.rand(1024, len(phone))
|
179 |
+
ja_bert = torch.rand(1024, len(phone))
|
180 |
+
en_bert = bert_ori
|
181 |
+
phone = torch.LongTensor(phone)
|
182 |
+
tone = torch.LongTensor(tone)
|
183 |
+
language = torch.LongTensor(language)
|
184 |
+
return bert, ja_bert, en_bert, phone, tone, language
|
185 |
+
|
186 |
+
def get_sid(self, sid):
|
187 |
+
sid = torch.LongTensor([int(sid)])
|
188 |
+
return sid
|
189 |
+
|
190 |
+
def __getitem__(self, index):
|
191 |
+
return self.get_audio_text_speaker_pair(self.audiopaths_sid_text[index])
|
192 |
+
|
193 |
+
def __len__(self):
|
194 |
+
return len(self.audiopaths_sid_text)
|
195 |
+
|
196 |
+
|
197 |
+
class TextAudioSpeakerCollate:
|
198 |
+
"""Zero-pads model inputs and targets"""
|
199 |
+
|
200 |
+
def __init__(self, return_ids=False):
|
201 |
+
self.return_ids = return_ids
|
202 |
+
|
203 |
+
def __call__(self, batch):
|
204 |
+
"""Collate's training batch from normalized text, audio and speaker identities
|
205 |
+
PARAMS
|
206 |
+
------
|
207 |
+
batch: [text_normalized, spec_normalized, wav_normalized, sid]
|
208 |
+
"""
|
209 |
+
# Right zero-pad all one-hot text sequences to max input length
|
210 |
+
_, ids_sorted_decreasing = torch.sort(
|
211 |
+
torch.LongTensor([x[1].size(1) for x in batch]), dim=0, descending=True
|
212 |
+
)
|
213 |
+
|
214 |
+
max_text_len = max([len(x[0]) for x in batch])
|
215 |
+
max_spec_len = max([x[1].size(1) for x in batch])
|
216 |
+
max_wav_len = max([x[2].size(1) for x in batch])
|
217 |
+
|
218 |
+
text_lengths = torch.LongTensor(len(batch))
|
219 |
+
spec_lengths = torch.LongTensor(len(batch))
|
220 |
+
wav_lengths = torch.LongTensor(len(batch))
|
221 |
+
sid = torch.LongTensor(len(batch))
|
222 |
+
|
223 |
+
text_padded = torch.LongTensor(len(batch), max_text_len)
|
224 |
+
tone_padded = torch.LongTensor(len(batch), max_text_len)
|
225 |
+
language_padded = torch.LongTensor(len(batch), max_text_len)
|
226 |
+
bert_padded = torch.FloatTensor(len(batch), 1024, max_text_len)
|
227 |
+
ja_bert_padded = torch.FloatTensor(len(batch), 1024, max_text_len)
|
228 |
+
en_bert_padded = torch.FloatTensor(len(batch), 1024, max_text_len)
|
229 |
+
emo = torch.FloatTensor(len(batch), 512)
|
230 |
+
|
231 |
+
spec_padded = torch.FloatTensor(len(batch), batch[0][1].size(0), max_spec_len)
|
232 |
+
wav_padded = torch.FloatTensor(len(batch), 1, max_wav_len)
|
233 |
+
text_padded.zero_()
|
234 |
+
tone_padded.zero_()
|
235 |
+
language_padded.zero_()
|
236 |
+
spec_padded.zero_()
|
237 |
+
wav_padded.zero_()
|
238 |
+
bert_padded.zero_()
|
239 |
+
ja_bert_padded.zero_()
|
240 |
+
en_bert_padded.zero_()
|
241 |
+
emo.zero_()
|
242 |
+
|
243 |
+
for i in range(len(ids_sorted_decreasing)):
|
244 |
+
row = batch[ids_sorted_decreasing[i]]
|
245 |
+
|
246 |
+
text = row[0]
|
247 |
+
text_padded[i, : text.size(0)] = text
|
248 |
+
text_lengths[i] = text.size(0)
|
249 |
+
|
250 |
+
spec = row[1]
|
251 |
+
spec_padded[i, :, : spec.size(1)] = spec
|
252 |
+
spec_lengths[i] = spec.size(1)
|
253 |
+
|
254 |
+
wav = row[2]
|
255 |
+
wav_padded[i, :, : wav.size(1)] = wav
|
256 |
+
wav_lengths[i] = wav.size(1)
|
257 |
+
|
258 |
+
sid[i] = row[3]
|
259 |
+
|
260 |
+
tone = row[4]
|
261 |
+
tone_padded[i, : tone.size(0)] = tone
|
262 |
+
|
263 |
+
language = row[5]
|
264 |
+
language_padded[i, : language.size(0)] = language
|
265 |
+
|
266 |
+
bert = row[6]
|
267 |
+
bert_padded[i, :, : bert.size(1)] = bert
|
268 |
+
|
269 |
+
ja_bert = row[7]
|
270 |
+
ja_bert_padded[i, :, : ja_bert.size(1)] = ja_bert
|
271 |
+
|
272 |
+
en_bert = row[8]
|
273 |
+
en_bert_padded[i, :, : en_bert.size(1)] = en_bert
|
274 |
+
|
275 |
+
emo[i, :] = row[9]
|
276 |
+
|
277 |
+
return (
|
278 |
+
text_padded,
|
279 |
+
text_lengths,
|
280 |
+
spec_padded,
|
281 |
+
spec_lengths,
|
282 |
+
wav_padded,
|
283 |
+
wav_lengths,
|
284 |
+
sid,
|
285 |
+
tone_padded,
|
286 |
+
language_padded,
|
287 |
+
bert_padded,
|
288 |
+
ja_bert_padded,
|
289 |
+
en_bert_padded,
|
290 |
+
emo,
|
291 |
+
)
|
292 |
+
|
293 |
+
|
294 |
+
class DistributedBucketSampler(torch.utils.data.distributed.DistributedSampler):
|
295 |
+
"""
|
296 |
+
Maintain similar input lengths in a batch.
|
297 |
+
Length groups are specified by boundaries.
|
298 |
+
Ex) boundaries = [b1, b2, b3] -> any batch is included either {x | b1 < length(x) <=b2} or {x | b2 < length(x) <= b3}.
|
299 |
+
|
300 |
+
It removes samples which are not included in the boundaries.
|
301 |
+
Ex) boundaries = [b1, b2, b3] -> any x s.t. length(x) <= b1 or length(x) > b3 are discarded.
|
302 |
+
"""
|
303 |
+
|
304 |
+
def __init__(
|
305 |
+
self,
|
306 |
+
dataset,
|
307 |
+
batch_size,
|
308 |
+
boundaries,
|
309 |
+
num_replicas=None,
|
310 |
+
rank=None,
|
311 |
+
shuffle=True,
|
312 |
+
):
|
313 |
+
super().__init__(dataset, num_replicas=num_replicas, rank=rank, shuffle=shuffle)
|
314 |
+
self.lengths = dataset.lengths
|
315 |
+
self.batch_size = batch_size
|
316 |
+
self.boundaries = boundaries
|
317 |
+
|
318 |
+
self.buckets, self.num_samples_per_bucket = self._create_buckets()
|
319 |
+
self.total_size = sum(self.num_samples_per_bucket)
|
320 |
+
self.num_samples = self.total_size // self.num_replicas
|
321 |
+
|
322 |
+
def _create_buckets(self):
|
323 |
+
buckets = [[] for _ in range(len(self.boundaries) - 1)]
|
324 |
+
for i in range(len(self.lengths)):
|
325 |
+
length = self.lengths[i]
|
326 |
+
idx_bucket = self._bisect(length)
|
327 |
+
if idx_bucket != -1:
|
328 |
+
buckets[idx_bucket].append(i)
|
329 |
+
|
330 |
+
try:
|
331 |
+
for i in range(len(buckets) - 1, 0, -1):
|
332 |
+
if len(buckets[i]) == 0:
|
333 |
+
buckets.pop(i)
|
334 |
+
self.boundaries.pop(i + 1)
|
335 |
+
assert all(len(bucket) > 0 for bucket in buckets)
|
336 |
+
# When one bucket is not traversed
|
337 |
+
except Exception as e:
|
338 |
+
print("Bucket warning ", e)
|
339 |
+
for i in range(len(buckets) - 1, -1, -1):
|
340 |
+
if len(buckets[i]) == 0:
|
341 |
+
buckets.pop(i)
|
342 |
+
self.boundaries.pop(i + 1)
|
343 |
+
|
344 |
+
num_samples_per_bucket = []
|
345 |
+
for i in range(len(buckets)):
|
346 |
+
len_bucket = len(buckets[i])
|
347 |
+
total_batch_size = self.num_replicas * self.batch_size
|
348 |
+
rem = (
|
349 |
+
total_batch_size - (len_bucket % total_batch_size)
|
350 |
+
) % total_batch_size
|
351 |
+
num_samples_per_bucket.append(len_bucket + rem)
|
352 |
+
return buckets, num_samples_per_bucket
|
353 |
+
|
354 |
+
def __iter__(self):
|
355 |
+
# deterministically shuffle based on epoch
|
356 |
+
g = torch.Generator()
|
357 |
+
g.manual_seed(self.epoch)
|
358 |
+
|
359 |
+
indices = []
|
360 |
+
if self.shuffle:
|
361 |
+
for bucket in self.buckets:
|
362 |
+
indices.append(torch.randperm(len(bucket), generator=g).tolist())
|
363 |
+
else:
|
364 |
+
for bucket in self.buckets:
|
365 |
+
indices.append(list(range(len(bucket))))
|
366 |
+
|
367 |
+
batches = []
|
368 |
+
for i in range(len(self.buckets)):
|
369 |
+
bucket = self.buckets[i]
|
370 |
+
len_bucket = len(bucket)
|
371 |
+
if len_bucket == 0:
|
372 |
+
continue
|
373 |
+
ids_bucket = indices[i]
|
374 |
+
num_samples_bucket = self.num_samples_per_bucket[i]
|
375 |
+
|
376 |
+
# add extra samples to make it evenly divisible
|
377 |
+
rem = num_samples_bucket - len_bucket
|
378 |
+
ids_bucket = (
|
379 |
+
ids_bucket
|
380 |
+
+ ids_bucket * (rem // len_bucket)
|
381 |
+
+ ids_bucket[: (rem % len_bucket)]
|
382 |
+
)
|
383 |
+
|
384 |
+
# subsample
|
385 |
+
ids_bucket = ids_bucket[self.rank :: self.num_replicas]
|
386 |
+
|
387 |
+
# batching
|
388 |
+
for j in range(len(ids_bucket) // self.batch_size):
|
389 |
+
batch = [
|
390 |
+
bucket[idx]
|
391 |
+
for idx in ids_bucket[
|
392 |
+
j * self.batch_size : (j + 1) * self.batch_size
|
393 |
+
]
|
394 |
+
]
|
395 |
+
batches.append(batch)
|
396 |
+
|
397 |
+
if self.shuffle:
|
398 |
+
batch_ids = torch.randperm(len(batches), generator=g).tolist()
|
399 |
+
batches = [batches[i] for i in batch_ids]
|
400 |
+
self.batches = batches
|
401 |
+
|
402 |
+
assert len(self.batches) * self.batch_size == self.num_samples
|
403 |
+
return iter(self.batches)
|
404 |
+
|
405 |
+
def _bisect(self, x, lo=0, hi=None):
|
406 |
+
if hi is None:
|
407 |
+
hi = len(self.boundaries) - 1
|
408 |
+
|
409 |
+
if hi > lo:
|
410 |
+
mid = (hi + lo) // 2
|
411 |
+
if self.boundaries[mid] < x and x <= self.boundaries[mid + 1]:
|
412 |
+
return mid
|
413 |
+
elif x <= self.boundaries[mid]:
|
414 |
+
return self._bisect(x, lo, mid)
|
415 |
+
else:
|
416 |
+
return self._bisect(x, mid + 1, hi)
|
417 |
+
else:
|
418 |
+
return -1
|
419 |
+
|
420 |
+
def __len__(self):
|
421 |
+
return self.num_samples // self.batch_size
|
default_config.yml
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 全局配置
|
2 |
+
# 对于希望在同一时间使用多个配置文件的情况,例如两个GPU同时跑两个训练集:通过环境变量指定配置文件,不指定则默认为./config.yml
|
3 |
+
|
4 |
+
# 拟提供通用路径配置,统一存放数据,避免数据放得很乱
|
5 |
+
# 每个数据集与其对应的模型存放至统一路径下,后续所有的路径配置均为相对于datasetPath的路径
|
6 |
+
# 不填或者填空则路径为相对于项目根目录的路径
|
7 |
+
dataset_path: "Data/"
|
8 |
+
|
9 |
+
# 模型镜像源,默认huggingface,使用openi镜像源需指定openi_token
|
10 |
+
mirror: ""
|
11 |
+
openi_token: "" # openi token
|
12 |
+
|
13 |
+
# resample 音频重采样配置
|
14 |
+
# 注意, “:” 后需要加空格
|
15 |
+
resample:
|
16 |
+
# 目标重采样率
|
17 |
+
sampling_rate: 44100
|
18 |
+
# 音频文件输入路径,重采样会将该路径下所有.wav音频文件重采样
|
19 |
+
# 请填入相对于datasetPath的相对路径
|
20 |
+
in_dir: "audios/raw" # 相对于根目录的路径为 /datasetPath/in_dir
|
21 |
+
# 音频文件重采样后输出路径
|
22 |
+
out_dir: "audios/wavs"
|
23 |
+
|
24 |
+
|
25 |
+
# preprocess_text 数据集预处理相关配置
|
26 |
+
# 注意, “:” 后需要加空格
|
27 |
+
preprocess_text:
|
28 |
+
# 原始文本文件路径,文本格式应为{wav_path}|{speaker_name}|{language}|{text}。
|
29 |
+
transcription_path: "filelists/你的数据集文本.list"
|
30 |
+
# 数据清洗后文本路径,可以不填。不填则将在原始文本目录生成
|
31 |
+
cleaned_path: ""
|
32 |
+
# 训练集路径
|
33 |
+
train_path: "filelists/train.list"
|
34 |
+
# 验证集路径
|
35 |
+
val_path: "filelists/val.list"
|
36 |
+
# 配置文件路径
|
37 |
+
config_path: "config.json"
|
38 |
+
# 每个语言的验证集条数
|
39 |
+
val_per_lang: 4
|
40 |
+
# 验证集最大条数,多于的会被截断并放到训练集中
|
41 |
+
max_val_total: 12
|
42 |
+
# 是否进行数据清洗
|
43 |
+
clean: true
|
44 |
+
|
45 |
+
|
46 |
+
# bert_gen 相关配置
|
47 |
+
# 注意, “:” 后需要加空格
|
48 |
+
bert_gen:
|
49 |
+
# 训练数据集配置文件路径
|
50 |
+
config_path: "config.json"
|
51 |
+
# 并行数
|
52 |
+
num_processes: 4
|
53 |
+
# 使用设备:可选项 "cuda" 显卡推理,"cpu" cpu推理
|
54 |
+
# 该选项同时决定了get_bert_feature的默认设备
|
55 |
+
device: "cuda"
|
56 |
+
# 使用多卡推理
|
57 |
+
use_multi_device: false
|
58 |
+
|
59 |
+
# emo_gen 相关配置
|
60 |
+
# 注意, “:” 后需要加空格
|
61 |
+
emo_gen:
|
62 |
+
# 训练数据集配置文件路径
|
63 |
+
config_path: "config.json"
|
64 |
+
# 并行数
|
65 |
+
num_processes: 4
|
66 |
+
# 使用设备:可选项 "cuda" 显卡推理,"cpu" cpu推理
|
67 |
+
device: "cuda"
|
68 |
+
# 使用多卡推理
|
69 |
+
use_multi_device: false
|
70 |
+
|
71 |
+
# train 训练配置
|
72 |
+
# 注意, “:” 后需要加空格
|
73 |
+
train_ms:
|
74 |
+
env:
|
75 |
+
MASTER_ADDR: "localhost"
|
76 |
+
MASTER_PORT: 10086
|
77 |
+
WORLD_SIZE: 1
|
78 |
+
LOCAL_RANK: 0
|
79 |
+
RANK: 0
|
80 |
+
# 可以填写任意名的环境变量
|
81 |
+
# THE_ENV_VAR_YOU_NEED_TO_USE: "1234567"
|
82 |
+
# 底模设置
|
83 |
+
base:
|
84 |
+
use_base_model: false
|
85 |
+
repo_id: "Stardust_minus/Bert-VITS2"
|
86 |
+
model_image: "Bert-VITS2_2.1-Emo底模" # openi网页的模型名
|
87 |
+
# 训练模型存储目录:与旧版本的区别,原先数据集是存放在logs/model_name下的,现在改为统一存放在Data/你的数据集/models下
|
88 |
+
model: "models"
|
89 |
+
# 配置文件路径
|
90 |
+
config_path: "configs/config.json"
|
91 |
+
# 训练使用的worker,不建议超过CPU核心数
|
92 |
+
num_workers: 16
|
93 |
+
# 关闭此项可以节约接近50%的磁盘空间,但是可能导致实际训练速度变慢和更高的CPU使用率。
|
94 |
+
spec_cache: True
|
95 |
+
# 保存的检查点数量,多于此数目的权重会被删除来节省空间。
|
96 |
+
keep_ckpts: 8
|
97 |
+
|
98 |
+
|
99 |
+
# webui webui配置
|
100 |
+
# 注意, “:” 后需要加空格
|
101 |
+
webui:
|
102 |
+
# 推理设备
|
103 |
+
device: "cuda"
|
104 |
+
# 模型路径
|
105 |
+
model: "models/G_8000.pth"
|
106 |
+
# 配置文件路径
|
107 |
+
config_path: "configs/config.json"
|
108 |
+
# 端口号
|
109 |
+
port: 7860
|
110 |
+
# 是否公开部署,对外网开放
|
111 |
+
share: false
|
112 |
+
# 是否开启debug模式
|
113 |
+
debug: false
|
114 |
+
# 语种识别库,可选langid, fastlid
|
115 |
+
language_identification_library: "langid"
|
116 |
+
|
117 |
+
|
118 |
+
# server-fastapi配置
|
119 |
+
# 注意, “:” 后需要加空格
|
120 |
+
# 注意,本配置下的所有配置均为相对于根目录的路径
|
121 |
+
server:
|
122 |
+
# 端口号
|
123 |
+
port: 5000
|
124 |
+
# 模型默认使用设备:但是当前并没有实现这个配置。
|
125 |
+
device: "cuda"
|
126 |
+
# 需要加载的所有模型的配置,可以填多个模型,也可以不填模型,等网页成功后手动加载模型
|
127 |
+
# 不加载模型的配置格式:删除默认给的两个模型配置,给models赋值 [ ],也就是空列表。参考模型2的speakers 即 models: [ ]
|
128 |
+
# 注意,所有模型都必须正确配置model与config的路径,空路径会导致加载错误。
|
129 |
+
# 也可以不填模型,等网页加载成功后手动填写models。
|
130 |
+
models:
|
131 |
+
- # 模型的路径
|
132 |
+
model: ""
|
133 |
+
# 模型config.json的路径
|
134 |
+
config: ""
|
135 |
+
# 模型使用设备,若填写则会覆盖默认配置
|
136 |
+
device: "cuda"
|
137 |
+
# 模型默认使用的语言
|
138 |
+
language: "ZH"
|
139 |
+
# 模型人物默认参数
|
140 |
+
# 不必填写所有人物,不填的使用默认值
|
141 |
+
# 暂时不用填写,当前尚未实现按人区分配置
|
142 |
+
speakers:
|
143 |
+
- speaker: "科比"
|
144 |
+
sdp_ratio: 0.2
|
145 |
+
noise_scale: 0.6
|
146 |
+
noise_scale_w: 0.8
|
147 |
+
length_scale: 1
|
148 |
+
- speaker: "五条悟"
|
149 |
+
sdp_ratio: 0.3
|
150 |
+
noise_scale: 0.7
|
151 |
+
noise_scale_w: 0.8
|
152 |
+
length_scale: 0.5
|
153 |
+
- speaker: "安倍晋三"
|
154 |
+
sdp_ratio: 0.2
|
155 |
+
noise_scale: 0.6
|
156 |
+
noise_scale_w: 0.8
|
157 |
+
length_scale: 1.2
|
158 |
+
- # 模型的路径
|
159 |
+
model: ""
|
160 |
+
# 模型config.json的路径
|
161 |
+
config: ""
|
162 |
+
# 模型使用设备,若填写则会覆盖默认配置
|
163 |
+
device: "cpu"
|
164 |
+
# 模型默认使用的语言
|
165 |
+
language: "JP"
|
166 |
+
# 模型人物默认参数
|
167 |
+
# 不必填写所有人物,不填的使用默认值
|
168 |
+
speakers: [ ] # 也可以不填
|
169 |
+
|
170 |
+
# 百度翻译开放平台 api配置
|
171 |
+
# api接入文档 https://api.fanyi.baidu.com/doc/21
|
172 |
+
# 请不要在github等网站公开分享你的app id 与 key
|
173 |
+
translate:
|
174 |
+
# 你的APPID
|
175 |
+
"app_key": ""
|
176 |
+
# 你的密钥
|
177 |
+
"secret_key": ""
|
emotional/clap-htsat-fused/.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
|
emotional/clap-htsat-fused/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
---
|
4 |
+
# Model card for CLAP
|
5 |
+
|
6 |
+
Model card for CLAP: Contrastive Language-Audio Pretraining
|
7 |
+
|
8 |
+
![clap_image](https://s3.amazonaws.com/moonup/production/uploads/1678811100805-62441d1d9fdefb55a0b7d12c.png)
|
9 |
+
|
10 |
+
|
11 |
+
# Table of Contents
|
12 |
+
|
13 |
+
0. [TL;DR](#TL;DR)
|
14 |
+
1. [Model Details](#model-details)
|
15 |
+
2. [Usage](#usage)
|
16 |
+
3. [Uses](#uses)
|
17 |
+
4. [Citation](#citation)
|
18 |
+
|
19 |
+
# TL;DR
|
20 |
+
|
21 |
+
The abstract of the paper states that:
|
22 |
+
|
23 |
+
> Contrastive learning has shown remarkable success in the field of multimodal representation learning. In this paper, we propose a pipeline of contrastive language-audio pretraining to develop an audio representation by combining audio data with natural language descriptions. To accomplish this target, we first release LAION-Audio-630K, a large collection of 633,526 audio-text pairs from different data sources. Second, we construct a contrastive language-audio pretraining model by considering different audio encoders and text encoders. We incorporate the feature fusion mechanism and keyword-to-caption augmentation into the model design to further enable the model to process audio inputs of variable lengths and enhance the performance. Third, we perform comprehensive experiments to evaluate our model across three tasks: text-to-audio retrieval, zero-shot audio classification, and supervised audio classification. The results demonstrate that our model achieves superior performance in text-to-audio retrieval task. In audio classification tasks, the model achieves state-of-the-art performance in the zero-shot setting and is able to obtain performance comparable to models' results in the non-zero-shot setting. LAION-Audio-630K and the proposed model are both available to the public.
|
24 |
+
|
25 |
+
|
26 |
+
# Usage
|
27 |
+
|
28 |
+
You can use this model for zero shot audio classification or extracting audio and/or textual features.
|
29 |
+
|
30 |
+
# Uses
|
31 |
+
|
32 |
+
## Perform zero-shot audio classification
|
33 |
+
|
34 |
+
### Using `pipeline`
|
35 |
+
|
36 |
+
```python
|
37 |
+
from datasets import load_dataset
|
38 |
+
from transformers import pipeline
|
39 |
+
|
40 |
+
dataset = load_dataset("ashraq/esc50")
|
41 |
+
audio = dataset["train"]["audio"][-1]["array"]
|
42 |
+
|
43 |
+
audio_classifier = pipeline(task="zero-shot-audio-classification", model="laion/clap-htsat-fused")
|
44 |
+
output = audio_classifier(audio, candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"])
|
45 |
+
print(output)
|
46 |
+
>>> [{"score": 0.999, "label": "Sound of a dog"}, {"score": 0.001, "label": "Sound of vaccum cleaner"}]
|
47 |
+
```
|
48 |
+
|
49 |
+
## Run the model:
|
50 |
+
|
51 |
+
You can also get the audio and text embeddings using `ClapModel`
|
52 |
+
|
53 |
+
### Run the model on CPU:
|
54 |
+
|
55 |
+
```python
|
56 |
+
from datasets import load_dataset
|
57 |
+
from transformers import ClapModel, ClapProcessor
|
58 |
+
|
59 |
+
librispeech_dummy = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
60 |
+
audio_sample = librispeech_dummy[0]
|
61 |
+
|
62 |
+
model = ClapModel.from_pretrained("laion/clap-htsat-fused")
|
63 |
+
processor = ClapProcessor.from_pretrained("laion/clap-htsat-fused")
|
64 |
+
|
65 |
+
inputs = processor(audios=audio_sample["audio"]["array"], return_tensors="pt")
|
66 |
+
audio_embed = model.get_audio_features(**inputs)
|
67 |
+
```
|
68 |
+
|
69 |
+
### Run the model on GPU:
|
70 |
+
|
71 |
+
```python
|
72 |
+
from datasets import load_dataset
|
73 |
+
from transformers import ClapModel, ClapProcessor
|
74 |
+
|
75 |
+
librispeech_dummy = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
76 |
+
audio_sample = librispeech_dummy[0]
|
77 |
+
|
78 |
+
model = ClapModel.from_pretrained("laion/clap-htsat-fused").to(0)
|
79 |
+
processor = ClapProcessor.from_pretrained("laion/clap-htsat-fused")
|
80 |
+
|
81 |
+
inputs = processor(audios=audio_sample["audio"]["array"], return_tensors="pt").to(0)
|
82 |
+
audio_embed = model.get_audio_features(**inputs)
|
83 |
+
```
|
84 |
+
|
85 |
+
|
86 |
+
# Citation
|
87 |
+
|
88 |
+
If you are using this model for your work, please consider citing the original paper:
|
89 |
+
```
|
90 |
+
@misc{https://doi.org/10.48550/arxiv.2211.06687,
|
91 |
+
doi = {10.48550/ARXIV.2211.06687},
|
92 |
+
|
93 |
+
url = {https://arxiv.org/abs/2211.06687},
|
94 |
+
|
95 |
+
author = {Wu, Yusong and Chen, Ke and Zhang, Tianyu and Hui, Yuchen and Berg-Kirkpatrick, Taylor and Dubnov, Shlomo},
|
96 |
+
|
97 |
+
keywords = {Sound (cs.SD), Audio and Speech Processing (eess.AS), FOS: Computer and information sciences, FOS: Computer and information sciences, FOS: Electrical engineering, electronic engineering, information engineering, FOS: Electrical engineering, electronic engineering, information engineering},
|
98 |
+
|
99 |
+
title = {Large-scale Contrastive Language-Audio Pretraining with Feature Fusion and Keyword-to-Caption Augmentation},
|
100 |
+
|
101 |
+
publisher = {arXiv},
|
102 |
+
|
103 |
+
year = {2022},
|
104 |
+
|
105 |
+
copyright = {Creative Commons Attribution 4.0 International}
|
106 |
+
}
|
107 |
+
```
|
emotional/clap-htsat-fused/config.json
ADDED
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_commit_hash": null,
|
3 |
+
"architectures": [
|
4 |
+
"ClapModel"
|
5 |
+
],
|
6 |
+
"audio_config": {
|
7 |
+
"_name_or_path": "",
|
8 |
+
"add_cross_attention": false,
|
9 |
+
"aff_block_r": 4,
|
10 |
+
"architectures": null,
|
11 |
+
"attention_probs_dropout_prob": 0.0,
|
12 |
+
"bad_words_ids": null,
|
13 |
+
"begin_suppress_tokens": null,
|
14 |
+
"bos_token_id": null,
|
15 |
+
"chunk_size_feed_forward": 0,
|
16 |
+
"cross_attention_hidden_size": null,
|
17 |
+
"decoder_start_token_id": null,
|
18 |
+
"depths": [
|
19 |
+
2,
|
20 |
+
2,
|
21 |
+
6,
|
22 |
+
2
|
23 |
+
],
|
24 |
+
"diversity_penalty": 0.0,
|
25 |
+
"do_sample": false,
|
26 |
+
"drop_path_rate": 0.0,
|
27 |
+
"early_stopping": false,
|
28 |
+
"enable_fusion": true,
|
29 |
+
"enable_patch_fusion": true,
|
30 |
+
"enable_patch_layer_norm": true,
|
31 |
+
"encoder_no_repeat_ngram_size": 0,
|
32 |
+
"eos_token_id": null,
|
33 |
+
"exponential_decay_length_penalty": null,
|
34 |
+
"finetuning_task": null,
|
35 |
+
"flatten_patch_embeds": true,
|
36 |
+
"forced_bos_token_id": null,
|
37 |
+
"forced_eos_token_id": null,
|
38 |
+
"fusion_num_hidden_layers": 2,
|
39 |
+
"fusion_type": null,
|
40 |
+
"hidden_act": "gelu",
|
41 |
+
"hidden_dropout_prob": 0.1,
|
42 |
+
"hidden_size": 768,
|
43 |
+
"id2label": {
|
44 |
+
"0": "LABEL_0",
|
45 |
+
"1": "LABEL_1"
|
46 |
+
},
|
47 |
+
"initializer_factor": 1.0,
|
48 |
+
"is_decoder": false,
|
49 |
+
"is_encoder_decoder": false,
|
50 |
+
"label2id": {
|
51 |
+
"LABEL_0": 0,
|
52 |
+
"LABEL_1": 1
|
53 |
+
},
|
54 |
+
"layer_norm_eps": 1e-05,
|
55 |
+
"length_penalty": 1.0,
|
56 |
+
"max_length": 20,
|
57 |
+
"min_length": 0,
|
58 |
+
"mlp_ratio": 4.0,
|
59 |
+
"model_type": "clap_audio_model",
|
60 |
+
"no_repeat_ngram_size": 0,
|
61 |
+
"num_attention_heads": [
|
62 |
+
4,
|
63 |
+
8,
|
64 |
+
16,
|
65 |
+
32
|
66 |
+
],
|
67 |
+
"num_beam_groups": 1,
|
68 |
+
"num_beams": 1,
|
69 |
+
"num_classes": 527,
|
70 |
+
"num_hidden_layers": 4,
|
71 |
+
"num_mel_bins": 64,
|
72 |
+
"num_return_sequences": 1,
|
73 |
+
"output_attentions": false,
|
74 |
+
"output_hidden_states": false,
|
75 |
+
"output_scores": false,
|
76 |
+
"pad_token_id": null,
|
77 |
+
"patch_embed_input_channels": 1,
|
78 |
+
"patch_embeds_hidden_size": 96,
|
79 |
+
"patch_size": 4,
|
80 |
+
"patch_stride": [
|
81 |
+
4,
|
82 |
+
4
|
83 |
+
],
|
84 |
+
"prefix": null,
|
85 |
+
"problem_type": null,
|
86 |
+
"projection_dim": 512,
|
87 |
+
"projection_hidden_act": "relu",
|
88 |
+
"projection_hidden_size": 768,
|
89 |
+
"pruned_heads": {},
|
90 |
+
"qkv_bias": true,
|
91 |
+
"remove_invalid_values": false,
|
92 |
+
"repetition_penalty": 1.0,
|
93 |
+
"return_dict": true,
|
94 |
+
"return_dict_in_generate": false,
|
95 |
+
"sep_token_id": null,
|
96 |
+
"spec_size": 256,
|
97 |
+
"suppress_tokens": null,
|
98 |
+
"task_specific_params": null,
|
99 |
+
"temperature": 1.0,
|
100 |
+
"tf_legacy_loss": false,
|
101 |
+
"tie_encoder_decoder": false,
|
102 |
+
"tie_word_embeddings": true,
|
103 |
+
"tokenizer_class": null,
|
104 |
+
"top_k": 50,
|
105 |
+
"top_p": 1.0,
|
106 |
+
"torch_dtype": null,
|
107 |
+
"torchscript": false,
|
108 |
+
"transformers_version": "4.27.0.dev0",
|
109 |
+
"typical_p": 1.0,
|
110 |
+
"use_bfloat16": false,
|
111 |
+
"window_size": 8
|
112 |
+
},
|
113 |
+
"hidden_size": 768,
|
114 |
+
"initializer_factor": 1.0,
|
115 |
+
"logit_scale_init_value": 14.285714285714285,
|
116 |
+
"model_type": "clap",
|
117 |
+
"num_hidden_layers": 16,
|
118 |
+
"projection_dim": 512,
|
119 |
+
"projection_hidden_act": "relu",
|
120 |
+
"text_config": {
|
121 |
+
"_name_or_path": "",
|
122 |
+
"add_cross_attention": false,
|
123 |
+
"architectures": null,
|
124 |
+
"attention_probs_dropout_prob": 0.1,
|
125 |
+
"bad_words_ids": null,
|
126 |
+
"begin_suppress_tokens": null,
|
127 |
+
"bos_token_id": 0,
|
128 |
+
"chunk_size_feed_forward": 0,
|
129 |
+
"classifier_dropout": null,
|
130 |
+
"cross_attention_hidden_size": null,
|
131 |
+
"decoder_start_token_id": null,
|
132 |
+
"diversity_penalty": 0.0,
|
133 |
+
"do_sample": false,
|
134 |
+
"early_stopping": false,
|
135 |
+
"encoder_no_repeat_ngram_size": 0,
|
136 |
+
"eos_token_id": 2,
|
137 |
+
"exponential_decay_length_penalty": null,
|
138 |
+
"finetuning_task": null,
|
139 |
+
"forced_bos_token_id": null,
|
140 |
+
"forced_eos_token_id": null,
|
141 |
+
"fusion_hidden_size": 768,
|
142 |
+
"fusion_num_hidden_layers": 2,
|
143 |
+
"hidden_act": "gelu",
|
144 |
+
"hidden_dropout_prob": 0.1,
|
145 |
+
"hidden_size": 768,
|
146 |
+
"id2label": {
|
147 |
+
"0": "LABEL_0",
|
148 |
+
"1": "LABEL_1"
|
149 |
+
},
|
150 |
+
"initializer_factor": 1.0,
|
151 |
+
"initializer_range": 0.02,
|
152 |
+
"intermediate_size": 3072,
|
153 |
+
"is_decoder": false,
|
154 |
+
"is_encoder_decoder": false,
|
155 |
+
"label2id": {
|
156 |
+
"LABEL_0": 0,
|
157 |
+
"LABEL_1": 1
|
158 |
+
},
|
159 |
+
"layer_norm_eps": 1e-12,
|
160 |
+
"length_penalty": 1.0,
|
161 |
+
"max_length": 20,
|
162 |
+
"max_position_embeddings": 514,
|
163 |
+
"min_length": 0,
|
164 |
+
"model_type": "clap_text_model",
|
165 |
+
"no_repeat_ngram_size": 0,
|
166 |
+
"num_attention_heads": 12,
|
167 |
+
"num_beam_groups": 1,
|
168 |
+
"num_beams": 1,
|
169 |
+
"num_hidden_layers": 12,
|
170 |
+
"num_return_sequences": 1,
|
171 |
+
"output_attentions": false,
|
172 |
+
"output_hidden_states": false,
|
173 |
+
"output_scores": false,
|
174 |
+
"pad_token_id": 1,
|
175 |
+
"position_embedding_type": "absolute",
|
176 |
+
"prefix": null,
|
177 |
+
"problem_type": null,
|
178 |
+
"projection_dim": 512,
|
179 |
+
"projection_hidden_act": "relu",
|
180 |
+
"projection_hidden_size": 768,
|
181 |
+
"pruned_heads": {},
|
182 |
+
"remove_invalid_values": false,
|
183 |
+
"repetition_penalty": 1.0,
|
184 |
+
"return_dict": true,
|
185 |
+
"return_dict_in_generate": false,
|
186 |
+
"sep_token_id": null,
|
187 |
+
"suppress_tokens": null,
|
188 |
+
"task_specific_params": null,
|
189 |
+
"temperature": 1.0,
|
190 |
+
"tf_legacy_loss": false,
|
191 |
+
"tie_encoder_decoder": false,
|
192 |
+
"tie_word_embeddings": true,
|
193 |
+
"tokenizer_class": null,
|
194 |
+
"top_k": 50,
|
195 |
+
"top_p": 1.0,
|
196 |
+
"torch_dtype": null,
|
197 |
+
"torchscript": false,
|
198 |
+
"transformers_version": "4.27.0.dev0",
|
199 |
+
"type_vocab_size": 1,
|
200 |
+
"typical_p": 1.0,
|
201 |
+
"use_bfloat16": false,
|
202 |
+
"use_cache": true,
|
203 |
+
"vocab_size": 50265
|
204 |
+
},
|
205 |
+
"torch_dtype": "float32",
|
206 |
+
"transformers_version": null
|
207 |
+
}
|
emotional/clap-htsat-fused/merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
emotional/clap-htsat-fused/preprocessor_config.json
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"chunk_length_s": 10,
|
3 |
+
"feature_extractor_type": "ClapFeatureExtractor",
|
4 |
+
"feature_size": 64,
|
5 |
+
"fft_window_size": 1024,
|
6 |
+
"frequency_max": 14000,
|
7 |
+
"frequency_min": 50,
|
8 |
+
"hop_length": 480,
|
9 |
+
"max_length_s": 10,
|
10 |
+
"n_fft": 1024,
|
11 |
+
"nb_frequency_bins": 513,
|
12 |
+
"nb_max_frames": 1000,
|
13 |
+
"nb_max_samples": 480000,
|
14 |
+
"padding": "repeatpad",
|
15 |
+
"padding_side": "right",
|
16 |
+
"padding_value": 0.0,
|
17 |
+
"processor_class": "ClapProcessor",
|
18 |
+
"return_attention_mask": false,
|
19 |
+
"sampling_rate": 48000,
|
20 |
+
"top_db": null,
|
21 |
+
"truncation": "fusion"
|
22 |
+
}
|
emotional/clap-htsat-fused/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1ed5d0215d887551ddd0a49ce7311b21429ebdf1e6a129d4e68f743357225253
|
3 |
+
size 614596545
|
emotional/clap-htsat-fused/special_tokens_map.json
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": "<s>",
|
3 |
+
"cls_token": "<s>",
|
4 |
+
"eos_token": "</s>",
|
5 |
+
"mask_token": {
|
6 |
+
"content": "<mask>",
|
7 |
+
"lstrip": true,
|
8 |
+
"normalized": false,
|
9 |
+
"rstrip": false,
|
10 |
+
"single_word": false
|
11 |
+
},
|
12 |
+
"pad_token": "<pad>",
|
13 |
+
"sep_token": "</s>",
|
14 |
+
"unk_token": "<unk>"
|
15 |
+
}
|
emotional/clap-htsat-fused/tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
emotional/clap-htsat-fused/tokenizer_config.json
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_prefix_space": false,
|
3 |
+
"bos_token": "<s>",
|
4 |
+
"cls_token": "<s>",
|
5 |
+
"eos_token": "</s>",
|
6 |
+
"errors": "replace",
|
7 |
+
"mask_token": "<mask>",
|
8 |
+
"model_max_length": 512,
|
9 |
+
"pad_token": "<pad>",
|
10 |
+
"processor_class": "ClapProcessor",
|
11 |
+
"sep_token": "</s>",
|
12 |
+
"special_tokens_map_file": null,
|
13 |
+
"tokenizer_class": "RobertaTokenizer",
|
14 |
+
"trim_offsets": true,
|
15 |
+
"unk_token": "<unk>"
|
16 |
+
}
|
emotional/clap-htsat-fused/vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/.gitattributes
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.bz2 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 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
20 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/LICENSE
ADDED
@@ -0,0 +1,437 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Attribution-NonCommercial-ShareAlike 4.0 International
|
2 |
+
|
3 |
+
=======================================================================
|
4 |
+
|
5 |
+
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
6 |
+
does not provide legal services or legal advice. Distribution of
|
7 |
+
Creative Commons public licenses does not create a lawyer-client or
|
8 |
+
other relationship. Creative Commons makes its licenses and related
|
9 |
+
information available on an "as-is" basis. Creative Commons gives no
|
10 |
+
warranties regarding its licenses, any material licensed under their
|
11 |
+
terms and conditions, or any related information. Creative Commons
|
12 |
+
disclaims all liability for damages resulting from their use to the
|
13 |
+
fullest extent possible.
|
14 |
+
|
15 |
+
Using Creative Commons Public Licenses
|
16 |
+
|
17 |
+
Creative Commons public licenses provide a standard set of terms and
|
18 |
+
conditions that creators and other rights holders may use to share
|
19 |
+
original works of authorship and other material subject to copyright
|
20 |
+
and certain other rights specified in the public license below. The
|
21 |
+
following considerations are for informational purposes only, are not
|
22 |
+
exhaustive, and do not form part of our licenses.
|
23 |
+
|
24 |
+
Considerations for licensors: Our public licenses are
|
25 |
+
intended for use by those authorized to give the public
|
26 |
+
permission to use material in ways otherwise restricted by
|
27 |
+
copyright and certain other rights. Our licenses are
|
28 |
+
irrevocable. Licensors should read and understand the terms
|
29 |
+
and conditions of the license they choose before applying it.
|
30 |
+
Licensors should also secure all rights necessary before
|
31 |
+
applying our licenses so that the public can reuse the
|
32 |
+
material as expected. Licensors should clearly mark any
|
33 |
+
material not subject to the license. This includes other CC-
|
34 |
+
licensed material, or material used under an exception or
|
35 |
+
limitation to copyright. More considerations for licensors:
|
36 |
+
wiki.creativecommons.org/Considerations_for_licensors
|
37 |
+
|
38 |
+
Considerations for the public: By using one of our public
|
39 |
+
licenses, a licensor grants the public permission to use the
|
40 |
+
licensed material under specified terms and conditions. If
|
41 |
+
the licensor's permission is not necessary for any reason--for
|
42 |
+
example, because of any applicable exception or limitation to
|
43 |
+
copyright--then that use is not regulated by the license. Our
|
44 |
+
licenses grant only permissions under copyright and certain
|
45 |
+
other rights that a licensor has authority to grant. Use of
|
46 |
+
the licensed material may still be restricted for other
|
47 |
+
reasons, including because others have copyright or other
|
48 |
+
rights in the material. A licensor may make special requests,
|
49 |
+
such as asking that all changes be marked or described.
|
50 |
+
Although not required by our licenses, you are encouraged to
|
51 |
+
respect those requests where reasonable. More considerations
|
52 |
+
for the public:
|
53 |
+
wiki.creativecommons.org/Considerations_for_licensees
|
54 |
+
|
55 |
+
=======================================================================
|
56 |
+
|
57 |
+
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
|
58 |
+
Public License
|
59 |
+
|
60 |
+
By exercising the Licensed Rights (defined below), You accept and agree
|
61 |
+
to be bound by the terms and conditions of this Creative Commons
|
62 |
+
Attribution-NonCommercial-ShareAlike 4.0 International Public License
|
63 |
+
("Public License"). To the extent this Public License may be
|
64 |
+
interpreted as a contract, You are granted the Licensed Rights in
|
65 |
+
consideration of Your acceptance of these terms and conditions, and the
|
66 |
+
Licensor grants You such rights in consideration of benefits the
|
67 |
+
Licensor receives from making the Licensed Material available under
|
68 |
+
these terms and conditions.
|
69 |
+
|
70 |
+
|
71 |
+
Section 1 -- Definitions.
|
72 |
+
|
73 |
+
a. Adapted Material means material subject to Copyright and Similar
|
74 |
+
Rights that is derived from or based upon the Licensed Material
|
75 |
+
and in which the Licensed Material is translated, altered,
|
76 |
+
arranged, transformed, or otherwise modified in a manner requiring
|
77 |
+
permission under the Copyright and Similar Rights held by the
|
78 |
+
Licensor. For purposes of this Public License, where the Licensed
|
79 |
+
Material is a musical work, performance, or sound recording,
|
80 |
+
Adapted Material is always produced where the Licensed Material is
|
81 |
+
synched in timed relation with a moving image.
|
82 |
+
|
83 |
+
b. Adapter's License means the license You apply to Your Copyright
|
84 |
+
and Similar Rights in Your contributions to Adapted Material in
|
85 |
+
accordance with the terms and conditions of this Public License.
|
86 |
+
|
87 |
+
c. BY-NC-SA Compatible License means a license listed at
|
88 |
+
creativecommons.org/compatiblelicenses, approved by Creative
|
89 |
+
Commons as essentially the equivalent of this Public License.
|
90 |
+
|
91 |
+
d. Copyright and Similar Rights means copyright and/or similar rights
|
92 |
+
closely related to copyright including, without limitation,
|
93 |
+
performance, broadcast, sound recording, and Sui Generis Database
|
94 |
+
Rights, without regard to how the rights are labeled or
|
95 |
+
categorized. For purposes of this Public License, the rights
|
96 |
+
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
97 |
+
Rights.
|
98 |
+
|
99 |
+
e. Effective Technological Measures means those measures that, in the
|
100 |
+
absence of proper authority, may not be circumvented under laws
|
101 |
+
fulfilling obligations under Article 11 of the WIPO Copyright
|
102 |
+
Treaty adopted on December 20, 1996, and/or similar international
|
103 |
+
agreements.
|
104 |
+
|
105 |
+
f. Exceptions and Limitations means fair use, fair dealing, and/or
|
106 |
+
any other exception or limitation to Copyright and Similar Rights
|
107 |
+
that applies to Your use of the Licensed Material.
|
108 |
+
|
109 |
+
g. License Elements means the license attributes listed in the name
|
110 |
+
of a Creative Commons Public License. The License Elements of this
|
111 |
+
Public License are Attribution, NonCommercial, and ShareAlike.
|
112 |
+
|
113 |
+
h. Licensed Material means the artistic or literary work, database,
|
114 |
+
or other material to which the Licensor applied this Public
|
115 |
+
License.
|
116 |
+
|
117 |
+
i. Licensed Rights means the rights granted to You subject to the
|
118 |
+
terms and conditions of this Public License, which are limited to
|
119 |
+
all Copyright and Similar Rights that apply to Your use of the
|
120 |
+
Licensed Material and that the Licensor has authority to license.
|
121 |
+
|
122 |
+
j. Licensor means the individual(s) or entity(ies) granting rights
|
123 |
+
under this Public License.
|
124 |
+
|
125 |
+
k. NonCommercial means not primarily intended for or directed towards
|
126 |
+
commercial advantage or monetary compensation. For purposes of
|
127 |
+
this Public License, the exchange of the Licensed Material for
|
128 |
+
other material subject to Copyright and Similar Rights by digital
|
129 |
+
file-sharing or similar means is NonCommercial provided there is
|
130 |
+
no payment of monetary compensation in connection with the
|
131 |
+
exchange.
|
132 |
+
|
133 |
+
l. Share means to provide material to the public by any means or
|
134 |
+
process that requires permission under the Licensed Rights, such
|
135 |
+
as reproduction, public display, public performance, distribution,
|
136 |
+
dissemination, communication, or importation, and to make material
|
137 |
+
available to the public including in ways that members of the
|
138 |
+
public may access the material from a place and at a time
|
139 |
+
individually chosen by them.
|
140 |
+
|
141 |
+
m. Sui Generis Database Rights means rights other than copyright
|
142 |
+
resulting from Directive 96/9/EC of the European Parliament and of
|
143 |
+
the Council of 11 March 1996 on the legal protection of databases,
|
144 |
+
as amended and/or succeeded, as well as other essentially
|
145 |
+
equivalent rights anywhere in the world.
|
146 |
+
|
147 |
+
n. You means the individual or entity exercising the Licensed Rights
|
148 |
+
under this Public License. Your has a corresponding meaning.
|
149 |
+
|
150 |
+
|
151 |
+
Section 2 -- Scope.
|
152 |
+
|
153 |
+
a. License grant.
|
154 |
+
|
155 |
+
1. Subject to the terms and conditions of this Public License,
|
156 |
+
the Licensor hereby grants You a worldwide, royalty-free,
|
157 |
+
non-sublicensable, non-exclusive, irrevocable license to
|
158 |
+
exercise the Licensed Rights in the Licensed Material to:
|
159 |
+
|
160 |
+
a. reproduce and Share the Licensed Material, in whole or
|
161 |
+
in part, for NonCommercial purposes only; and
|
162 |
+
|
163 |
+
b. produce, reproduce, and Share Adapted Material for
|
164 |
+
NonCommercial purposes only.
|
165 |
+
|
166 |
+
2. Exceptions and Limitations. For the avoidance of doubt, where
|
167 |
+
Exceptions and Limitations apply to Your use, this Public
|
168 |
+
License does not apply, and You do not need to comply with
|
169 |
+
its terms and conditions.
|
170 |
+
|
171 |
+
3. Term. The term of this Public License is specified in Section
|
172 |
+
6(a).
|
173 |
+
|
174 |
+
4. Media and formats; technical modifications allowed. The
|
175 |
+
Licensor authorizes You to exercise the Licensed Rights in
|
176 |
+
all media and formats whether now known or hereafter created,
|
177 |
+
and to make technical modifications necessary to do so. The
|
178 |
+
Licensor waives and/or agrees not to assert any right or
|
179 |
+
authority to forbid You from making technical modifications
|
180 |
+
necessary to exercise the Licensed Rights, including
|
181 |
+
technical modifications necessary to circumvent Effective
|
182 |
+
Technological Measures. For purposes of this Public License,
|
183 |
+
simply making modifications authorized by this Section 2(a)
|
184 |
+
(4) never produces Adapted Material.
|
185 |
+
|
186 |
+
5. Downstream recipients.
|
187 |
+
|
188 |
+
a. Offer from the Licensor -- Licensed Material. Every
|
189 |
+
recipient of the Licensed Material automatically
|
190 |
+
receives an offer from the Licensor to exercise the
|
191 |
+
Licensed Rights under the terms and conditions of this
|
192 |
+
Public License.
|
193 |
+
|
194 |
+
b. Additional offer from the Licensor -- Adapted Material.
|
195 |
+
Every recipient of Adapted Material from You
|
196 |
+
automatically receives an offer from the Licensor to
|
197 |
+
exercise the Licensed Rights in the Adapted Material
|
198 |
+
under the conditions of the Adapter's License You apply.
|
199 |
+
|
200 |
+
c. No downstream restrictions. You may not offer or impose
|
201 |
+
any additional or different terms or conditions on, or
|
202 |
+
apply any Effective Technological Measures to, the
|
203 |
+
Licensed Material if doing so restricts exercise of the
|
204 |
+
Licensed Rights by any recipient of the Licensed
|
205 |
+
Material.
|
206 |
+
|
207 |
+
6. No endorsement. Nothing in this Public License constitutes or
|
208 |
+
may be construed as permission to assert or imply that You
|
209 |
+
are, or that Your use of the Licensed Material is, connected
|
210 |
+
with, or sponsored, endorsed, or granted official status by,
|
211 |
+
the Licensor or others designated to receive attribution as
|
212 |
+
provided in Section 3(a)(1)(A)(i).
|
213 |
+
|
214 |
+
b. Other rights.
|
215 |
+
|
216 |
+
1. Moral rights, such as the right of integrity, are not
|
217 |
+
licensed under this Public License, nor are publicity,
|
218 |
+
privacy, and/or other similar personality rights; however, to
|
219 |
+
the extent possible, the Licensor waives and/or agrees not to
|
220 |
+
assert any such rights held by the Licensor to the limited
|
221 |
+
extent necessary to allow You to exercise the Licensed
|
222 |
+
Rights, but not otherwise.
|
223 |
+
|
224 |
+
2. Patent and trademark rights are not licensed under this
|
225 |
+
Public License.
|
226 |
+
|
227 |
+
3. To the extent possible, the Licensor waives any right to
|
228 |
+
collect royalties from You for the exercise of the Licensed
|
229 |
+
Rights, whether directly or through a collecting society
|
230 |
+
under any voluntary or waivable statutory or compulsory
|
231 |
+
licensing scheme. In all other cases the Licensor expressly
|
232 |
+
reserves any right to collect such royalties, including when
|
233 |
+
the Licensed Material is used other than for NonCommercial
|
234 |
+
purposes.
|
235 |
+
|
236 |
+
|
237 |
+
Section 3 -- License Conditions.
|
238 |
+
|
239 |
+
Your exercise of the Licensed Rights is expressly made subject to the
|
240 |
+
following conditions.
|
241 |
+
|
242 |
+
a. Attribution.
|
243 |
+
|
244 |
+
1. If You Share the Licensed Material (including in modified
|
245 |
+
form), You must:
|
246 |
+
|
247 |
+
a. retain the following if it is supplied by the Licensor
|
248 |
+
with the Licensed Material:
|
249 |
+
|
250 |
+
i. identification of the creator(s) of the Licensed
|
251 |
+
Material and any others designated to receive
|
252 |
+
attribution, in any reasonable manner requested by
|
253 |
+
the Licensor (including by pseudonym if
|
254 |
+
designated);
|
255 |
+
|
256 |
+
ii. a copyright notice;
|
257 |
+
|
258 |
+
iii. a notice that refers to this Public License;
|
259 |
+
|
260 |
+
iv. a notice that refers to the disclaimer of
|
261 |
+
warranties;
|
262 |
+
|
263 |
+
v. a URI or hyperlink to the Licensed Material to the
|
264 |
+
extent reasonably practicable;
|
265 |
+
|
266 |
+
b. indicate if You modified the Licensed Material and
|
267 |
+
retain an indication of any previous modifications; and
|
268 |
+
|
269 |
+
c. indicate the Licensed Material is licensed under this
|
270 |
+
Public License, and include the text of, or the URI or
|
271 |
+
hyperlink to, this Public License.
|
272 |
+
|
273 |
+
2. You may satisfy the conditions in Section 3(a)(1) in any
|
274 |
+
reasonable manner based on the medium, means, and context in
|
275 |
+
which You Share the Licensed Material. For example, it may be
|
276 |
+
reasonable to satisfy the conditions by providing a URI or
|
277 |
+
hyperlink to a resource that includes the required
|
278 |
+
information.
|
279 |
+
3. If requested by the Licensor, You must remove any of the
|
280 |
+
information required by Section 3(a)(1)(A) to the extent
|
281 |
+
reasonably practicable.
|
282 |
+
|
283 |
+
b. ShareAlike.
|
284 |
+
|
285 |
+
In addition to the conditions in Section 3(a), if You Share
|
286 |
+
Adapted Material You produce, the following conditions also apply.
|
287 |
+
|
288 |
+
1. The Adapter's License You apply must be a Creative Commons
|
289 |
+
license with the same License Elements, this version or
|
290 |
+
later, or a BY-NC-SA Compatible License.
|
291 |
+
|
292 |
+
2. You must include the text of, or the URI or hyperlink to, the
|
293 |
+
Adapter's License You apply. You may satisfy this condition
|
294 |
+
in any reasonable manner based on the medium, means, and
|
295 |
+
context in which You Share Adapted Material.
|
296 |
+
|
297 |
+
3. You may not offer or impose any additional or different terms
|
298 |
+
or conditions on, or apply any Effective Technological
|
299 |
+
Measures to, Adapted Material that restrict exercise of the
|
300 |
+
rights granted under the Adapter's License You apply.
|
301 |
+
|
302 |
+
|
303 |
+
Section 4 -- Sui Generis Database Rights.
|
304 |
+
|
305 |
+
Where the Licensed Rights include Sui Generis Database Rights that
|
306 |
+
apply to Your use of the Licensed Material:
|
307 |
+
|
308 |
+
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
309 |
+
to extract, reuse, reproduce, and Share all or a substantial
|
310 |
+
portion of the contents of the database for NonCommercial purposes
|
311 |
+
only;
|
312 |
+
|
313 |
+
b. if You include all or a substantial portion of the database
|
314 |
+
contents in a database in which You have Sui Generis Database
|
315 |
+
Rights, then the database in which You have Sui Generis Database
|
316 |
+
Rights (but not its individual contents) is Adapted Material,
|
317 |
+
including for purposes of Section 3(b); and
|
318 |
+
|
319 |
+
c. You must comply with the conditions in Section 3(a) if You Share
|
320 |
+
all or a substantial portion of the contents of the database.
|
321 |
+
|
322 |
+
For the avoidance of doubt, this Section 4 supplements and does not
|
323 |
+
replace Your obligations under this Public License where the Licensed
|
324 |
+
Rights include other Copyright and Similar Rights.
|
325 |
+
|
326 |
+
|
327 |
+
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
328 |
+
|
329 |
+
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
330 |
+
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
331 |
+
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
332 |
+
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
333 |
+
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
334 |
+
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
335 |
+
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
336 |
+
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
337 |
+
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
338 |
+
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
339 |
+
|
340 |
+
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
341 |
+
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
342 |
+
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
343 |
+
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
344 |
+
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
345 |
+
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
346 |
+
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
347 |
+
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
348 |
+
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
349 |
+
|
350 |
+
c. The disclaimer of warranties and limitation of liability provided
|
351 |
+
above shall be interpreted in a manner that, to the extent
|
352 |
+
possible, most closely approximates an absolute disclaimer and
|
353 |
+
waiver of all liability.
|
354 |
+
|
355 |
+
|
356 |
+
Section 6 -- Term and Termination.
|
357 |
+
|
358 |
+
a. This Public License applies for the term of the Copyright and
|
359 |
+
Similar Rights licensed here. However, if You fail to comply with
|
360 |
+
this Public License, then Your rights under this Public License
|
361 |
+
terminate automatically.
|
362 |
+
|
363 |
+
b. Where Your right to use the Licensed Material has terminated under
|
364 |
+
Section 6(a), it reinstates:
|
365 |
+
|
366 |
+
1. automatically as of the date the violation is cured, provided
|
367 |
+
it is cured within 30 days of Your discovery of the
|
368 |
+
violation; or
|
369 |
+
|
370 |
+
2. upon express reinstatement by the Licensor.
|
371 |
+
|
372 |
+
For the avoidance of doubt, this Section 6(b) does not affect any
|
373 |
+
right the Licensor may have to seek remedies for Your violations
|
374 |
+
of this Public License.
|
375 |
+
|
376 |
+
c. For the avoidance of doubt, the Licensor may also offer the
|
377 |
+
Licensed Material under separate terms or conditions or stop
|
378 |
+
distributing the Licensed Material at any time; however, doing so
|
379 |
+
will not terminate this Public License.
|
380 |
+
|
381 |
+
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
382 |
+
License.
|
383 |
+
|
384 |
+
|
385 |
+
Section 7 -- Other Terms and Conditions.
|
386 |
+
|
387 |
+
a. The Licensor shall not be bound by any additional or different
|
388 |
+
terms or conditions communicated by You unless expressly agreed.
|
389 |
+
|
390 |
+
b. Any arrangements, understandings, or agreements regarding the
|
391 |
+
Licensed Material not stated herein are separate from and
|
392 |
+
independent of the terms and conditions of this Public License.
|
393 |
+
|
394 |
+
|
395 |
+
Section 8 -- Interpretation.
|
396 |
+
|
397 |
+
a. For the avoidance of doubt, this Public License does not, and
|
398 |
+
shall not be interpreted to, reduce, limit, restrict, or impose
|
399 |
+
conditions on any use of the Licensed Material that could lawfully
|
400 |
+
be made without permission under this Public License.
|
401 |
+
|
402 |
+
b. To the extent possible, if any provision of this Public License is
|
403 |
+
deemed unenforceable, it shall be automatically reformed to the
|
404 |
+
minimum extent necessary to make it enforceable. If the provision
|
405 |
+
cannot be reformed, it shall be severed from this Public License
|
406 |
+
without affecting the enforceability of the remaining terms and
|
407 |
+
conditions.
|
408 |
+
|
409 |
+
c. No term or condition of this Public License will be waived and no
|
410 |
+
failure to comply consented to unless expressly agreed to by the
|
411 |
+
Licensor.
|
412 |
+
|
413 |
+
d. Nothing in this Public License constitutes or may be interpreted
|
414 |
+
as a limitation upon, or waiver of, any privileges and immunities
|
415 |
+
that apply to the Licensor or You, including from the legal
|
416 |
+
processes of any jurisdiction or authority.
|
417 |
+
|
418 |
+
=======================================================================
|
419 |
+
|
420 |
+
Creative Commons is not a party to its public
|
421 |
+
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
422 |
+
its public licenses to material it publishes and in those instances
|
423 |
+
will be considered the “Licensor.” The text of the Creative Commons
|
424 |
+
public licenses is dedicated to the public domain under the CC0 Public
|
425 |
+
Domain Dedication. Except for the limited purpose of indicating that
|
426 |
+
material is shared under a Creative Commons public license or as
|
427 |
+
otherwise permitted by the Creative Commons policies published at
|
428 |
+
creativecommons.org/policies, Creative Commons does not authorize the
|
429 |
+
use of the trademark "Creative Commons" or any other trademark or logo
|
430 |
+
of Creative Commons without its prior written consent including,
|
431 |
+
without limitation, in connection with any unauthorized modifications
|
432 |
+
to any of its public licenses or any other arrangements,
|
433 |
+
understandings, or agreements concerning use of licensed material. For
|
434 |
+
the avoidance of doubt, this paragraph does not form part of the
|
435 |
+
public licenses.
|
436 |
+
|
437 |
+
Creative Commons may be contacted at creativecommons.org.
|
emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/README.md
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: en
|
3 |
+
datasets:
|
4 |
+
- msp-podcast
|
5 |
+
inference: true
|
6 |
+
tags:
|
7 |
+
- speech
|
8 |
+
- audio
|
9 |
+
- wav2vec2
|
10 |
+
- audio-classification
|
11 |
+
- emotion-recognition
|
12 |
+
license: cc-by-nc-sa-4.0
|
13 |
+
pipeline_tag: audio-classification
|
14 |
+
---
|
15 |
+
|
16 |
+
# Model for Dimensional Speech Emotion Recognition based on Wav2vec 2.0
|
17 |
+
|
18 |
+
The model expects a raw audio signal as input and outputs predictions for arousal, dominance and valence in a range of approximately 0...1. In addition, it also provides the pooled states of the last transformer layer. The model was created by fine-tuning [
|
19 |
+
Wav2Vec2-Large-Robust](https://huggingface.co/facebook/wav2vec2-large-robust) on [MSP-Podcast](https://ecs.utdallas.edu/research/researchlabs/msp-lab/MSP-Podcast.html) (v1.7). The model was pruned from 24 to 12 transformer layers before fine-tuning. An [ONNX](https://onnx.ai/") export of the model is available from [doi:10.5281/zenodo.6221127](https://zenodo.org/record/6221127). Further details are given in the associated [paper](https://arxiv.org/abs/2203.07378) and [tutorial](https://github.com/audeering/w2v2-how-to).
|
20 |
+
|
21 |
+
# Usage
|
22 |
+
|
23 |
+
```python
|
24 |
+
import numpy as np
|
25 |
+
import torch
|
26 |
+
import torch.nn as nn
|
27 |
+
from transformers import Wav2Vec2Processor
|
28 |
+
from transformers.models.wav2vec2.modeling_wav2vec2 import (
|
29 |
+
Wav2Vec2Model,
|
30 |
+
Wav2Vec2PreTrainedModel,
|
31 |
+
)
|
32 |
+
|
33 |
+
|
34 |
+
class RegressionHead(nn.Module):
|
35 |
+
r"""Classification head."""
|
36 |
+
|
37 |
+
def __init__(self, config):
|
38 |
+
|
39 |
+
super().__init__()
|
40 |
+
|
41 |
+
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
|
42 |
+
self.dropout = nn.Dropout(config.final_dropout)
|
43 |
+
self.out_proj = nn.Linear(config.hidden_size, config.num_labels)
|
44 |
+
|
45 |
+
def forward(self, features, **kwargs):
|
46 |
+
|
47 |
+
x = features
|
48 |
+
x = self.dropout(x)
|
49 |
+
x = self.dense(x)
|
50 |
+
x = torch.tanh(x)
|
51 |
+
x = self.dropout(x)
|
52 |
+
x = self.out_proj(x)
|
53 |
+
|
54 |
+
return x
|
55 |
+
|
56 |
+
|
57 |
+
class EmotionModel(Wav2Vec2PreTrainedModel):
|
58 |
+
r"""Speech emotion classifier."""
|
59 |
+
|
60 |
+
def __init__(self, config):
|
61 |
+
|
62 |
+
super().__init__(config)
|
63 |
+
|
64 |
+
self.config = config
|
65 |
+
self.wav2vec2 = Wav2Vec2Model(config)
|
66 |
+
self.classifier = RegressionHead(config)
|
67 |
+
self.init_weights()
|
68 |
+
|
69 |
+
def forward(
|
70 |
+
self,
|
71 |
+
input_values,
|
72 |
+
):
|
73 |
+
|
74 |
+
outputs = self.wav2vec2(input_values)
|
75 |
+
hidden_states = outputs[0]
|
76 |
+
hidden_states = torch.mean(hidden_states, dim=1)
|
77 |
+
logits = self.classifier(hidden_states)
|
78 |
+
|
79 |
+
return hidden_states, logits
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
# load model from hub
|
84 |
+
device = 'cpu'
|
85 |
+
model_name = 'audeering/wav2vec2-large-robust-12-ft-emotion-msp-dim'
|
86 |
+
processor = Wav2Vec2Processor.from_pretrained(model_name)
|
87 |
+
model = EmotionModel.from_pretrained(model_name)
|
88 |
+
|
89 |
+
# dummy signal
|
90 |
+
sampling_rate = 16000
|
91 |
+
signal = np.zeros((1, sampling_rate), dtype=np.float32)
|
92 |
+
|
93 |
+
|
94 |
+
def process_func(
|
95 |
+
x: np.ndarray,
|
96 |
+
sampling_rate: int,
|
97 |
+
embeddings: bool = False,
|
98 |
+
) -> np.ndarray:
|
99 |
+
r"""Predict emotions or extract embeddings from raw audio signal."""
|
100 |
+
|
101 |
+
# run through processor to normalize signal
|
102 |
+
# always returns a batch, so we just get the first entry
|
103 |
+
# then we put it on the device
|
104 |
+
y = processor(x, sampling_rate=sampling_rate)
|
105 |
+
y = y['input_values'][0]
|
106 |
+
y = y.reshape(1, -1)
|
107 |
+
y = torch.from_numpy(y).to(device)
|
108 |
+
|
109 |
+
# run through model
|
110 |
+
with torch.no_grad():
|
111 |
+
y = model(y)[0 if embeddings else 1]
|
112 |
+
|
113 |
+
# convert to numpy
|
114 |
+
y = y.detach().cpu().numpy()
|
115 |
+
|
116 |
+
return y
|
117 |
+
|
118 |
+
|
119 |
+
print(process_func(signal, sampling_rate))
|
120 |
+
# Arousal dominance valence
|
121 |
+
# [[0.5460754 0.6062266 0.40431657]]
|
122 |
+
|
123 |
+
print(process_func(signal, sampling_rate, embeddings=True))
|
124 |
+
# Pooled hidden states of last transformer layer
|
125 |
+
# [[-0.00752167 0.0065819 -0.00746342 ... 0.00663632 0.00848748
|
126 |
+
# 0.00599211]]
|
127 |
+
```
|
emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/config.json
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "torch",
|
3 |
+
"activation_dropout": 0.1,
|
4 |
+
"adapter_kernel_size": 3,
|
5 |
+
"adapter_stride": 2,
|
6 |
+
"add_adapter": false,
|
7 |
+
"apply_spec_augment": true,
|
8 |
+
"architectures": [
|
9 |
+
"Wav2Vec2ForSpeechClassification"
|
10 |
+
],
|
11 |
+
"attention_dropout": 0.1,
|
12 |
+
"bos_token_id": 1,
|
13 |
+
"classifier_proj_size": 256,
|
14 |
+
"codevector_dim": 768,
|
15 |
+
"contrastive_logits_temperature": 0.1,
|
16 |
+
"conv_bias": true,
|
17 |
+
"conv_dim": [
|
18 |
+
512,
|
19 |
+
512,
|
20 |
+
512,
|
21 |
+
512,
|
22 |
+
512,
|
23 |
+
512,
|
24 |
+
512
|
25 |
+
],
|
26 |
+
"conv_kernel": [
|
27 |
+
10,
|
28 |
+
3,
|
29 |
+
3,
|
30 |
+
3,
|
31 |
+
3,
|
32 |
+
2,
|
33 |
+
2
|
34 |
+
],
|
35 |
+
"conv_stride": [
|
36 |
+
5,
|
37 |
+
2,
|
38 |
+
2,
|
39 |
+
2,
|
40 |
+
2,
|
41 |
+
2,
|
42 |
+
2
|
43 |
+
],
|
44 |
+
"ctc_loss_reduction": "sum",
|
45 |
+
"ctc_zero_infinity": false,
|
46 |
+
"diversity_loss_weight": 0.1,
|
47 |
+
"do_stable_layer_norm": true,
|
48 |
+
"eos_token_id": 2,
|
49 |
+
"feat_extract_activation": "gelu",
|
50 |
+
"feat_extract_dropout": 0.0,
|
51 |
+
"feat_extract_norm": "layer",
|
52 |
+
"feat_proj_dropout": 0.1,
|
53 |
+
"feat_quantizer_dropout": 0.0,
|
54 |
+
"final_dropout": 0.1,
|
55 |
+
"finetuning_task": "wav2vec2_reg",
|
56 |
+
"gradient_checkpointing": false,
|
57 |
+
"hidden_act": "gelu",
|
58 |
+
"hidden_dropout": 0.1,
|
59 |
+
"hidden_dropout_prob": 0.1,
|
60 |
+
"hidden_size": 1024,
|
61 |
+
"id2label": {
|
62 |
+
"0": "arousal",
|
63 |
+
"1": "dominance",
|
64 |
+
"2": "valence"
|
65 |
+
},
|
66 |
+
"initializer_range": 0.02,
|
67 |
+
"intermediate_size": 4096,
|
68 |
+
"label2id": {
|
69 |
+
"arousal": 0,
|
70 |
+
"dominance": 1,
|
71 |
+
"valence": 2
|
72 |
+
},
|
73 |
+
"layer_norm_eps": 1e-05,
|
74 |
+
"layerdrop": 0.1,
|
75 |
+
"mask_feature_length": 10,
|
76 |
+
"mask_feature_min_masks": 0,
|
77 |
+
"mask_feature_prob": 0.0,
|
78 |
+
"mask_time_length": 10,
|
79 |
+
"mask_time_min_masks": 2,
|
80 |
+
"mask_time_prob": 0.05,
|
81 |
+
"model_type": "wav2vec2",
|
82 |
+
"num_adapter_layers": 3,
|
83 |
+
"num_attention_heads": 16,
|
84 |
+
"num_codevector_groups": 2,
|
85 |
+
"num_codevectors_per_group": 320,
|
86 |
+
"num_conv_pos_embedding_groups": 16,
|
87 |
+
"num_conv_pos_embeddings": 128,
|
88 |
+
"num_feat_extract_layers": 7,
|
89 |
+
"num_hidden_layers": 12,
|
90 |
+
"num_negatives": 100,
|
91 |
+
"output_hidden_size": 1024,
|
92 |
+
"pad_token_id": 0,
|
93 |
+
"pooling_mode": "mean",
|
94 |
+
"problem_type": "regression",
|
95 |
+
"proj_codevector_dim": 768,
|
96 |
+
"tdnn_dilation": [
|
97 |
+
1,
|
98 |
+
2,
|
99 |
+
3,
|
100 |
+
1,
|
101 |
+
1
|
102 |
+
],
|
103 |
+
"tdnn_dim": [
|
104 |
+
512,
|
105 |
+
512,
|
106 |
+
512,
|
107 |
+
512,
|
108 |
+
1500
|
109 |
+
],
|
110 |
+
"tdnn_kernel": [
|
111 |
+
5,
|
112 |
+
3,
|
113 |
+
3,
|
114 |
+
1,
|
115 |
+
1
|
116 |
+
],
|
117 |
+
"torch_dtype": "float32",
|
118 |
+
"transformers_version": "4.17.0.dev0",
|
119 |
+
"use_weighted_layer_sum": false,
|
120 |
+
"vocab_size": null,
|
121 |
+
"xvector_output_dim": 512
|
122 |
+
}
|
emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/preprocessor_config.json
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"do_normalize": true,
|
3 |
+
"feature_extractor_type": "Wav2Vec2FeatureExtractor",
|
4 |
+
"feature_size": 1,
|
5 |
+
"padding_side": "right",
|
6 |
+
"padding_value": 0.0,
|
7 |
+
"return_attention_mask": true,
|
8 |
+
"sampling_rate": 16000
|
9 |
+
}
|
emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:176d9d1ce29a8bddbab44068b9c1c194c51624c7f1812905e01355da58b18816
|
3 |
+
size 661436013
|
emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/vocab.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{}
|
empty_emo.npy
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:07063411ab7d6e7aacfc73c582616c3fbc8fdf518b20d42d8be77bc9caf6fab9
|
3 |
+
size 3238
|
export_onnx.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from onnx_modules import export_onnx
|
2 |
+
import os
|
3 |
+
|
4 |
+
if __name__ == "__main__":
|
5 |
+
export_path = "MyModel"
|
6 |
+
model_path = "S:\\VSGIT\\bert-vits2\\G_178000.pth"
|
7 |
+
config_path = "S:\\VSGIT\\bert-vits2\\config.json"
|
8 |
+
if not os.path.exists("onnx"):
|
9 |
+
os.makedirs("onnx")
|
10 |
+
if not os.path.exists(f"onnx/{export_path}"):
|
11 |
+
os.makedirs(f"onnx/{export_path}")
|
12 |
+
export_onnx(export_path, model_path, config_path)
|
filelists/sample.list
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
Example:
|
2 |
+
{wav_path}|{speaker_name}|{language}|{text}
|
3 |
+
派蒙_1.wav|派蒙|ZH|前面的区域,以后再来探索吧!
|
infer.py
ADDED
@@ -0,0 +1,381 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
版本管理、兼容推理及模型加载实现。
|
3 |
+
版本说明:
|
4 |
+
1. 版本号与github的release版本号对应,使用哪个release版本训练的模型即对应其版本号
|
5 |
+
2. 请在模型的config.json中显示声明版本号,添加一个字段"version" : "你的版本号"
|
6 |
+
特殊版本说明:
|
7 |
+
1.1.1-fix: 1.1.1版本训练的模型,但是在推理时使用dev的日语修复
|
8 |
+
2.2:当前版本
|
9 |
+
"""
|
10 |
+
import torch
|
11 |
+
import commons
|
12 |
+
from text import cleaned_text_to_sequence, get_bert
|
13 |
+
from clap_wrapper import get_clap_audio_feature, get_clap_text_feature
|
14 |
+
from text.cleaner import clean_text
|
15 |
+
import utils
|
16 |
+
import numpy as np
|
17 |
+
|
18 |
+
from models import SynthesizerTrn
|
19 |
+
from text.symbols import symbols
|
20 |
+
|
21 |
+
from oldVersion.V210.models import SynthesizerTrn as V210SynthesizerTrn
|
22 |
+
from oldVersion.V210.text import symbols as V210symbols
|
23 |
+
from oldVersion.V200.models import SynthesizerTrn as V200SynthesizerTrn
|
24 |
+
from oldVersion.V200.text import symbols as V200symbols
|
25 |
+
from oldVersion.V111.models import SynthesizerTrn as V111SynthesizerTrn
|
26 |
+
from oldVersion.V111.text import symbols as V111symbols
|
27 |
+
from oldVersion.V110.models import SynthesizerTrn as V110SynthesizerTrn
|
28 |
+
from oldVersion.V110.text import symbols as V110symbols
|
29 |
+
from oldVersion.V101.models import SynthesizerTrn as V101SynthesizerTrn
|
30 |
+
from oldVersion.V101.text import symbols as V101symbols
|
31 |
+
|
32 |
+
from oldVersion import V111, V110, V101, V200
|
33 |
+
|
34 |
+
# 当前版本信息
|
35 |
+
latest_version = "2.2"
|
36 |
+
|
37 |
+
# 版本兼容
|
38 |
+
SynthesizerTrnMap = {
|
39 |
+
"2.1": V210SynthesizerTrn,
|
40 |
+
"2.0.2-fix": V200SynthesizerTrn,
|
41 |
+
"2.0.1": V200SynthesizerTrn,
|
42 |
+
"2.0": V200SynthesizerTrn,
|
43 |
+
"1.1.1-fix": V111SynthesizerTrn,
|
44 |
+
"1.1.1": V111SynthesizerTrn,
|
45 |
+
"1.1": V110SynthesizerTrn,
|
46 |
+
"1.1.0": V110SynthesizerTrn,
|
47 |
+
"1.0.1": V101SynthesizerTrn,
|
48 |
+
"1.0": V101SynthesizerTrn,
|
49 |
+
"1.0.0": V101SynthesizerTrn,
|
50 |
+
}
|
51 |
+
|
52 |
+
symbolsMap = {
|
53 |
+
"2.1": V210symbols,
|
54 |
+
"2.0.2-fix": V200symbols,
|
55 |
+
"2.0.1": V200symbols,
|
56 |
+
"2.0": V200symbols,
|
57 |
+
"1.1.1-fix": V111symbols,
|
58 |
+
"1.1.1": V111symbols,
|
59 |
+
"1.1": V110symbols,
|
60 |
+
"1.1.0": V110symbols,
|
61 |
+
"1.0.1": V101symbols,
|
62 |
+
"1.0": V101symbols,
|
63 |
+
"1.0.0": V101symbols,
|
64 |
+
}
|
65 |
+
|
66 |
+
|
67 |
+
# def get_emo_(reference_audio, emotion, sid):
|
68 |
+
# emo = (
|
69 |
+
# torch.from_numpy(get_emo(reference_audio))
|
70 |
+
# if reference_audio and emotion == -1
|
71 |
+
# else torch.FloatTensor(
|
72 |
+
# np.load(f"emo_clustering/{sid}/cluster_center_{emotion}.npy")
|
73 |
+
# )
|
74 |
+
# )
|
75 |
+
# return emo
|
76 |
+
|
77 |
+
|
78 |
+
def get_net_g(model_path: str, version: str, device: str, hps):
|
79 |
+
if version != latest_version:
|
80 |
+
net_g = SynthesizerTrnMap[version](
|
81 |
+
len(symbolsMap[version]),
|
82 |
+
hps.data.filter_length // 2 + 1,
|
83 |
+
hps.train.segment_size // hps.data.hop_length,
|
84 |
+
n_speakers=hps.data.n_speakers,
|
85 |
+
**hps.model,
|
86 |
+
).to(device)
|
87 |
+
else:
|
88 |
+
# 当前版本模型 net_g
|
89 |
+
net_g = SynthesizerTrn(
|
90 |
+
len(symbols),
|
91 |
+
hps.data.filter_length // 2 + 1,
|
92 |
+
hps.train.segment_size // hps.data.hop_length,
|
93 |
+
n_speakers=hps.data.n_speakers,
|
94 |
+
**hps.model,
|
95 |
+
).to(device)
|
96 |
+
_ = net_g.eval()
|
97 |
+
_ = utils.load_checkpoint(model_path, net_g, None, skip_optimizer=True)
|
98 |
+
return net_g
|
99 |
+
|
100 |
+
|
101 |
+
def get_text(text, language_str, hps, device):
|
102 |
+
# 在此处实现当前版本的get_text
|
103 |
+
norm_text, phone, tone, word2ph = clean_text(text, language_str)
|
104 |
+
phone, tone, language = cleaned_text_to_sequence(phone, tone, language_str)
|
105 |
+
|
106 |
+
if hps.data.add_blank:
|
107 |
+
phone = commons.intersperse(phone, 0)
|
108 |
+
tone = commons.intersperse(tone, 0)
|
109 |
+
language = commons.intersperse(language, 0)
|
110 |
+
for i in range(len(word2ph)):
|
111 |
+
word2ph[i] = word2ph[i] * 2
|
112 |
+
word2ph[0] += 1
|
113 |
+
bert_ori = get_bert(norm_text, word2ph, language_str, device)
|
114 |
+
del word2ph
|
115 |
+
assert bert_ori.shape[-1] == len(phone), phone
|
116 |
+
|
117 |
+
if language_str == "ZH":
|
118 |
+
bert = bert_ori
|
119 |
+
ja_bert = torch.rand(1024, len(phone))
|
120 |
+
en_bert = torch.rand(1024, len(phone))
|
121 |
+
elif language_str == "JP":
|
122 |
+
bert = torch.rand(1024, len(phone))
|
123 |
+
ja_bert = bert_ori
|
124 |
+
en_bert = torch.rand(1024, len(phone))
|
125 |
+
elif language_str == "EN":
|
126 |
+
bert = torch.rand(1024, len(phone))
|
127 |
+
ja_bert = torch.rand(1024, len(phone))
|
128 |
+
en_bert = bert_ori
|
129 |
+
else:
|
130 |
+
raise ValueError("language_str should be ZH, JP or EN")
|
131 |
+
|
132 |
+
assert bert.shape[-1] == len(
|
133 |
+
phone
|
134 |
+
), f"Bert seq len {bert.shape[-1]} != {len(phone)}"
|
135 |
+
|
136 |
+
phone = torch.LongTensor(phone)
|
137 |
+
tone = torch.LongTensor(tone)
|
138 |
+
language = torch.LongTensor(language)
|
139 |
+
return bert, ja_bert, en_bert, phone, tone, language
|
140 |
+
|
141 |
+
|
142 |
+
def infer(
|
143 |
+
text,
|
144 |
+
emotion,
|
145 |
+
sdp_ratio,
|
146 |
+
noise_scale,
|
147 |
+
noise_scale_w,
|
148 |
+
length_scale,
|
149 |
+
sid,
|
150 |
+
language,
|
151 |
+
hps,
|
152 |
+
net_g,
|
153 |
+
device,
|
154 |
+
reference_audio=None,
|
155 |
+
skip_start=False,
|
156 |
+
skip_end=False,
|
157 |
+
):
|
158 |
+
# 2.2版���参数位置变了
|
159 |
+
# 2.1 参数新增 emotion reference_audio skip_start skip_end
|
160 |
+
# inferMap_V3 = {
|
161 |
+
# "2.1": V210.infer,
|
162 |
+
# }
|
163 |
+
# 支持中日英三语版本
|
164 |
+
inferMap_V2 = {
|
165 |
+
"2.0.2-fix": V200.infer,
|
166 |
+
"2.0.1": V200.infer,
|
167 |
+
"2.0": V200.infer,
|
168 |
+
"1.1.1-fix": V111.infer_fix,
|
169 |
+
"1.1.1": V111.infer,
|
170 |
+
"1.1": V110.infer,
|
171 |
+
"1.1.0": V110.infer,
|
172 |
+
}
|
173 |
+
# 仅支持中文版本
|
174 |
+
# 在测试中,并未发现两个版本的模型不能互相通用
|
175 |
+
inferMap_V1 = {
|
176 |
+
"1.0.1": V101.infer,
|
177 |
+
"1.0": V101.infer,
|
178 |
+
"1.0.0": V101.infer,
|
179 |
+
}
|
180 |
+
version = hps.version if hasattr(hps, "version") else latest_version
|
181 |
+
# 非当前版本,根据版本号选择合适的infer
|
182 |
+
if version != latest_version:
|
183 |
+
# if version in inferMap_V3.keys():
|
184 |
+
# return inferMap_V3[version](
|
185 |
+
# text,
|
186 |
+
# sdp_ratio,
|
187 |
+
# noise_scale,
|
188 |
+
# noise_scale_w,
|
189 |
+
# length_scale,
|
190 |
+
# sid,
|
191 |
+
# language,
|
192 |
+
# hps,
|
193 |
+
# net_g,
|
194 |
+
# device,
|
195 |
+
# reference_audio,
|
196 |
+
# emotion,
|
197 |
+
# skip_start,
|
198 |
+
# skip_end,
|
199 |
+
# )
|
200 |
+
if version in inferMap_V2.keys():
|
201 |
+
return inferMap_V2[version](
|
202 |
+
text,
|
203 |
+
sdp_ratio,
|
204 |
+
noise_scale,
|
205 |
+
noise_scale_w,
|
206 |
+
length_scale,
|
207 |
+
sid,
|
208 |
+
language,
|
209 |
+
hps,
|
210 |
+
net_g,
|
211 |
+
device,
|
212 |
+
)
|
213 |
+
if version in inferMap_V1.keys():
|
214 |
+
return inferMap_V1[version](
|
215 |
+
text,
|
216 |
+
sdp_ratio,
|
217 |
+
noise_scale,
|
218 |
+
noise_scale_w,
|
219 |
+
length_scale,
|
220 |
+
sid,
|
221 |
+
hps,
|
222 |
+
net_g,
|
223 |
+
device,
|
224 |
+
)
|
225 |
+
# 在此处实现当前版本的推理
|
226 |
+
# emo = get_emo_(reference_audio, emotion, sid)
|
227 |
+
if isinstance(reference_audio, np.ndarray):
|
228 |
+
emo = get_clap_audio_feature(reference_audio, device)
|
229 |
+
else:
|
230 |
+
emo = get_clap_text_feature(emotion, device)
|
231 |
+
emo = torch.squeeze(emo, dim=1)
|
232 |
+
|
233 |
+
bert, ja_bert, en_bert, phones, tones, lang_ids = get_text(
|
234 |
+
text, language, hps, device
|
235 |
+
)
|
236 |
+
if skip_start:
|
237 |
+
phones = phones[3:]
|
238 |
+
tones = tones[3:]
|
239 |
+
lang_ids = lang_ids[3:]
|
240 |
+
bert = bert[:, 3:]
|
241 |
+
ja_bert = ja_bert[:, 3:]
|
242 |
+
en_bert = en_bert[:, 3:]
|
243 |
+
if skip_end:
|
244 |
+
phones = phones[:-2]
|
245 |
+
tones = tones[:-2]
|
246 |
+
lang_ids = lang_ids[:-2]
|
247 |
+
bert = bert[:, :-2]
|
248 |
+
ja_bert = ja_bert[:, :-2]
|
249 |
+
en_bert = en_bert[:, :-2]
|
250 |
+
with torch.no_grad():
|
251 |
+
x_tst = phones.to(device).unsqueeze(0)
|
252 |
+
tones = tones.to(device).unsqueeze(0)
|
253 |
+
lang_ids = lang_ids.to(device).unsqueeze(0)
|
254 |
+
bert = bert.to(device).unsqueeze(0)
|
255 |
+
ja_bert = ja_bert.to(device).unsqueeze(0)
|
256 |
+
en_bert = en_bert.to(device).unsqueeze(0)
|
257 |
+
x_tst_lengths = torch.LongTensor([phones.size(0)]).to(device)
|
258 |
+
emo = emo.to(device).unsqueeze(0)
|
259 |
+
del phones
|
260 |
+
speakers = torch.LongTensor([hps.data.spk2id[sid]]).to(device)
|
261 |
+
audio = (
|
262 |
+
net_g.infer(
|
263 |
+
x_tst,
|
264 |
+
x_tst_lengths,
|
265 |
+
speakers,
|
266 |
+
tones,
|
267 |
+
lang_ids,
|
268 |
+
bert,
|
269 |
+
ja_bert,
|
270 |
+
en_bert,
|
271 |
+
emo,
|
272 |
+
sdp_ratio=sdp_ratio,
|
273 |
+
noise_scale=noise_scale,
|
274 |
+
noise_scale_w=noise_scale_w,
|
275 |
+
length_scale=length_scale,
|
276 |
+
)[0][0, 0]
|
277 |
+
.data.cpu()
|
278 |
+
.float()
|
279 |
+
.numpy()
|
280 |
+
)
|
281 |
+
del x_tst, tones, lang_ids, bert, x_tst_lengths, speakers, ja_bert, en_bert, emo
|
282 |
+
if torch.cuda.is_available():
|
283 |
+
torch.cuda.empty_cache()
|
284 |
+
return audio
|
285 |
+
|
286 |
+
|
287 |
+
def infer_multilang(
|
288 |
+
text,
|
289 |
+
sdp_ratio,
|
290 |
+
noise_scale,
|
291 |
+
noise_scale_w,
|
292 |
+
length_scale,
|
293 |
+
sid,
|
294 |
+
language,
|
295 |
+
hps,
|
296 |
+
net_g,
|
297 |
+
device,
|
298 |
+
reference_audio=None,
|
299 |
+
emotion=None,
|
300 |
+
skip_start=False,
|
301 |
+
skip_end=False,
|
302 |
+
):
|
303 |
+
bert, ja_bert, en_bert, phones, tones, lang_ids = [], [], [], [], [], []
|
304 |
+
# emo = get_emo_(reference_audio, emotion, sid)
|
305 |
+
if isinstance(reference_audio, np.ndarray):
|
306 |
+
emo = get_clap_audio_feature(reference_audio, device)
|
307 |
+
else:
|
308 |
+
emo = get_clap_text_feature(emotion, device)
|
309 |
+
emo = torch.squeeze(emo, dim=1)
|
310 |
+
for idx, (txt, lang) in enumerate(zip(text, language)):
|
311 |
+
skip_start = (idx != 0) or (skip_start and idx == 0)
|
312 |
+
skip_end = (idx != len(text) - 1) or (skip_end and idx == len(text) - 1)
|
313 |
+
(
|
314 |
+
temp_bert,
|
315 |
+
temp_ja_bert,
|
316 |
+
temp_en_bert,
|
317 |
+
temp_phones,
|
318 |
+
temp_tones,
|
319 |
+
temp_lang_ids,
|
320 |
+
) = get_text(txt, lang, hps, device)
|
321 |
+
if skip_start:
|
322 |
+
temp_bert = temp_bert[:, 3:]
|
323 |
+
temp_ja_bert = temp_ja_bert[:, 3:]
|
324 |
+
temp_en_bert = temp_en_bert[:, 3:]
|
325 |
+
temp_phones = temp_phones[3:]
|
326 |
+
temp_tones = temp_tones[3:]
|
327 |
+
temp_lang_ids = temp_lang_ids[3:]
|
328 |
+
if skip_end:
|
329 |
+
temp_bert = temp_bert[:, :-2]
|
330 |
+
temp_ja_bert = temp_ja_bert[:, :-2]
|
331 |
+
temp_en_bert = temp_en_bert[:, :-2]
|
332 |
+
temp_phones = temp_phones[:-2]
|
333 |
+
temp_tones = temp_tones[:-2]
|
334 |
+
temp_lang_ids = temp_lang_ids[:-2]
|
335 |
+
bert.append(temp_bert)
|
336 |
+
ja_bert.append(temp_ja_bert)
|
337 |
+
en_bert.append(temp_en_bert)
|
338 |
+
phones.append(temp_phones)
|
339 |
+
tones.append(temp_tones)
|
340 |
+
lang_ids.append(temp_lang_ids)
|
341 |
+
bert = torch.concatenate(bert, dim=1)
|
342 |
+
ja_bert = torch.concatenate(ja_bert, dim=1)
|
343 |
+
en_bert = torch.concatenate(en_bert, dim=1)
|
344 |
+
phones = torch.concatenate(phones, dim=0)
|
345 |
+
tones = torch.concatenate(tones, dim=0)
|
346 |
+
lang_ids = torch.concatenate(lang_ids, dim=0)
|
347 |
+
with torch.no_grad():
|
348 |
+
x_tst = phones.to(device).unsqueeze(0)
|
349 |
+
tones = tones.to(device).unsqueeze(0)
|
350 |
+
lang_ids = lang_ids.to(device).unsqueeze(0)
|
351 |
+
bert = bert.to(device).unsqueeze(0)
|
352 |
+
ja_bert = ja_bert.to(device).unsqueeze(0)
|
353 |
+
en_bert = en_bert.to(device).unsqueeze(0)
|
354 |
+
emo = emo.to(device).unsqueeze(0)
|
355 |
+
x_tst_lengths = torch.LongTensor([phones.size(0)]).to(device)
|
356 |
+
del phones
|
357 |
+
speakers = torch.LongTensor([hps.data.spk2id[sid]]).to(device)
|
358 |
+
audio = (
|
359 |
+
net_g.infer(
|
360 |
+
x_tst,
|
361 |
+
x_tst_lengths,
|
362 |
+
speakers,
|
363 |
+
tones,
|
364 |
+
lang_ids,
|
365 |
+
bert,
|
366 |
+
ja_bert,
|
367 |
+
en_bert,
|
368 |
+
emo,
|
369 |
+
sdp_ratio=sdp_ratio,
|
370 |
+
noise_scale=noise_scale,
|
371 |
+
noise_scale_w=noise_scale_w,
|
372 |
+
length_scale=length_scale,
|
373 |
+
)[0][0, 0]
|
374 |
+
.data.cpu()
|
375 |
+
.float()
|
376 |
+
.numpy()
|
377 |
+
)
|
378 |
+
del x_tst, tones, lang_ids, bert, x_tst_lengths, speakers, ja_bert, en_bert, emo
|
379 |
+
if torch.cuda.is_available():
|
380 |
+
torch.cuda.empty_cache()
|
381 |
+
return audio
|
losses.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
|
3 |
+
|
4 |
+
def feature_loss(fmap_r, fmap_g):
|
5 |
+
loss = 0
|
6 |
+
for dr, dg in zip(fmap_r, fmap_g):
|
7 |
+
for rl, gl in zip(dr, dg):
|
8 |
+
rl = rl.float().detach()
|
9 |
+
gl = gl.float()
|
10 |
+
loss += torch.mean(torch.abs(rl - gl))
|
11 |
+
|
12 |
+
return loss * 2
|
13 |
+
|
14 |
+
|
15 |
+
def discriminator_loss(disc_real_outputs, disc_generated_outputs):
|
16 |
+
loss = 0
|
17 |
+
r_losses = []
|
18 |
+
g_losses = []
|
19 |
+
for dr, dg in zip(disc_real_outputs, disc_generated_outputs):
|
20 |
+
dr = dr.float()
|
21 |
+
dg = dg.float()
|
22 |
+
r_loss = torch.mean((1 - dr) ** 2)
|
23 |
+
g_loss = torch.mean(dg**2)
|
24 |
+
loss += r_loss + g_loss
|
25 |
+
r_losses.append(r_loss.item())
|
26 |
+
g_losses.append(g_loss.item())
|
27 |
+
|
28 |
+
return loss, r_losses, g_losses
|
29 |
+
|
30 |
+
|
31 |
+
def generator_loss(disc_outputs):
|
32 |
+
loss = 0
|
33 |
+
gen_losses = []
|
34 |
+
for dg in disc_outputs:
|
35 |
+
dg = dg.float()
|
36 |
+
l = torch.mean((1 - dg) ** 2)
|
37 |
+
gen_losses.append(l)
|
38 |
+
loss += l
|
39 |
+
|
40 |
+
return loss, gen_losses
|
41 |
+
|
42 |
+
|
43 |
+
def kl_loss(z_p, logs_q, m_p, logs_p, z_mask):
|
44 |
+
"""
|
45 |
+
z_p, logs_q: [b, h, t_t]
|
46 |
+
m_p, logs_p: [b, h, t_t]
|
47 |
+
"""
|
48 |
+
z_p = z_p.float()
|
49 |
+
logs_q = logs_q.float()
|
50 |
+
m_p = m_p.float()
|
51 |
+
logs_p = logs_p.float()
|
52 |
+
z_mask = z_mask.float()
|
53 |
+
|
54 |
+
kl = logs_p - logs_q - 0.5
|
55 |
+
kl += 0.5 * ((z_p - m_p) ** 2) * torch.exp(-2.0 * logs_p)
|
56 |
+
kl = torch.sum(kl * z_mask)
|
57 |
+
l = kl / torch.sum(z_mask)
|
58 |
+
return l
|
mel_processing.py
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.utils.data
|
3 |
+
from librosa.filters import mel as librosa_mel_fn
|
4 |
+
import warnings
|
5 |
+
|
6 |
+
# warnings.simplefilter(action='ignore', category=FutureWarning)
|
7 |
+
warnings.filterwarnings(action="ignore")
|
8 |
+
MAX_WAV_VALUE = 32768.0
|
9 |
+
|
10 |
+
|
11 |
+
def dynamic_range_compression_torch(x, C=1, clip_val=1e-5):
|
12 |
+
"""
|
13 |
+
PARAMS
|
14 |
+
------
|
15 |
+
C: compression factor
|
16 |
+
"""
|
17 |
+
return torch.log(torch.clamp(x, min=clip_val) * C)
|
18 |
+
|
19 |
+
|
20 |
+
def dynamic_range_decompression_torch(x, C=1):
|
21 |
+
"""
|
22 |
+
PARAMS
|
23 |
+
------
|
24 |
+
C: compression factor used to compress
|
25 |
+
"""
|
26 |
+
return torch.exp(x) / C
|
27 |
+
|
28 |
+
|
29 |
+
def spectral_normalize_torch(magnitudes):
|
30 |
+
output = dynamic_range_compression_torch(magnitudes)
|
31 |
+
return output
|
32 |
+
|
33 |
+
|
34 |
+
def spectral_de_normalize_torch(magnitudes):
|
35 |
+
output = dynamic_range_decompression_torch(magnitudes)
|
36 |
+
return output
|
37 |
+
|
38 |
+
|
39 |
+
mel_basis = {}
|
40 |
+
hann_window = {}
|
41 |
+
|
42 |
+
|
43 |
+
def spectrogram_torch(y, n_fft, sampling_rate, hop_size, win_size, center=False):
|
44 |
+
if torch.min(y) < -1.0:
|
45 |
+
print("min value is ", torch.min(y))
|
46 |
+
if torch.max(y) > 1.0:
|
47 |
+
print("max value is ", torch.max(y))
|
48 |
+
|
49 |
+
global hann_window
|
50 |
+
dtype_device = str(y.dtype) + "_" + str(y.device)
|
51 |
+
wnsize_dtype_device = str(win_size) + "_" + dtype_device
|
52 |
+
if wnsize_dtype_device not in hann_window:
|
53 |
+
hann_window[wnsize_dtype_device] = torch.hann_window(win_size).to(
|
54 |
+
dtype=y.dtype, device=y.device
|
55 |
+
)
|
56 |
+
|
57 |
+
y = torch.nn.functional.pad(
|
58 |
+
y.unsqueeze(1),
|
59 |
+
(int((n_fft - hop_size) / 2), int((n_fft - hop_size) / 2)),
|
60 |
+
mode="reflect",
|
61 |
+
)
|
62 |
+
y = y.squeeze(1)
|
63 |
+
|
64 |
+
spec = torch.stft(
|
65 |
+
y,
|
66 |
+
n_fft,
|
67 |
+
hop_length=hop_size,
|
68 |
+
win_length=win_size,
|
69 |
+
window=hann_window[wnsize_dtype_device],
|
70 |
+
center=center,
|
71 |
+
pad_mode="reflect",
|
72 |
+
normalized=False,
|
73 |
+
onesided=True,
|
74 |
+
return_complex=False,
|
75 |
+
)
|
76 |
+
|
77 |
+
spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6)
|
78 |
+
return spec
|
79 |
+
|
80 |
+
|
81 |
+
def spec_to_mel_torch(spec, n_fft, num_mels, sampling_rate, fmin, fmax):
|
82 |
+
global mel_basis
|
83 |
+
dtype_device = str(spec.dtype) + "_" + str(spec.device)
|
84 |
+
fmax_dtype_device = str(fmax) + "_" + dtype_device
|
85 |
+
if fmax_dtype_device not in mel_basis:
|
86 |
+
mel = librosa_mel_fn(sampling_rate, n_fft, num_mels, fmin, fmax)
|
87 |
+
mel_basis[fmax_dtype_device] = torch.from_numpy(mel).to(
|
88 |
+
dtype=spec.dtype, device=spec.device
|
89 |
+
)
|
90 |
+
spec = torch.matmul(mel_basis[fmax_dtype_device], spec)
|
91 |
+
spec = spectral_normalize_torch(spec)
|
92 |
+
return spec
|
93 |
+
|
94 |
+
|
95 |
+
def mel_spectrogram_torch(
|
96 |
+
y, n_fft, num_mels, sampling_rate, hop_size, win_size, fmin, fmax, center=False
|
97 |
+
):
|
98 |
+
if torch.min(y) < -1.0:
|
99 |
+
print("min value is ", torch.min(y))
|
100 |
+
if torch.max(y) > 1.0:
|
101 |
+
print("max value is ", torch.max(y))
|
102 |
+
|
103 |
+
global mel_basis, hann_window
|
104 |
+
dtype_device = str(y.dtype) + "_" + str(y.device)
|
105 |
+
fmax_dtype_device = str(fmax) + "_" + dtype_device
|
106 |
+
wnsize_dtype_device = str(win_size) + "_" + dtype_device
|
107 |
+
if fmax_dtype_device not in mel_basis:
|
108 |
+
mel = librosa_mel_fn(sampling_rate, n_fft, num_mels, fmin, fmax)
|
109 |
+
mel_basis[fmax_dtype_device] = torch.from_numpy(mel).to(
|
110 |
+
dtype=y.dtype, device=y.device
|
111 |
+
)
|
112 |
+
if wnsize_dtype_device not in hann_window:
|
113 |
+
hann_window[wnsize_dtype_device] = torch.hann_window(win_size).to(
|
114 |
+
dtype=y.dtype, device=y.device
|
115 |
+
)
|
116 |
+
|
117 |
+
y = torch.nn.functional.pad(
|
118 |
+
y.unsqueeze(1),
|
119 |
+
(int((n_fft - hop_size) / 2), int((n_fft - hop_size) / 2)),
|
120 |
+
mode="reflect",
|
121 |
+
)
|
122 |
+
y = y.squeeze(1)
|
123 |
+
|
124 |
+
spec = torch.stft(
|
125 |
+
y,
|
126 |
+
n_fft,
|
127 |
+
hop_length=hop_size,
|
128 |
+
win_length=win_size,
|
129 |
+
window=hann_window[wnsize_dtype_device],
|
130 |
+
center=center,
|
131 |
+
pad_mode="reflect",
|
132 |
+
normalized=False,
|
133 |
+
onesided=True,
|
134 |
+
return_complex=False,
|
135 |
+
)
|
136 |
+
|
137 |
+
spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6)
|
138 |
+
|
139 |
+
spec = torch.matmul(mel_basis[fmax_dtype_device], spec)
|
140 |
+
spec = spectral_normalize_torch(spec)
|
141 |
+
|
142 |
+
return spec
|
models.py
ADDED
@@ -0,0 +1,1075 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch import nn
|
4 |
+
from torch.nn import functional as F
|
5 |
+
|
6 |
+
import commons
|
7 |
+
import modules
|
8 |
+
import attentions
|
9 |
+
import monotonic_align
|
10 |
+
|
11 |
+
from torch.nn import Conv1d, ConvTranspose1d, Conv2d
|
12 |
+
from torch.nn.utils import weight_norm, remove_weight_norm, spectral_norm
|
13 |
+
|
14 |
+
from commons import init_weights, get_padding
|
15 |
+
from text import symbols, num_tones, num_languages
|
16 |
+
|
17 |
+
from vector_quantize_pytorch import VectorQuantize
|
18 |
+
|
19 |
+
|
20 |
+
class DurationDiscriminator(nn.Module): # vits2
|
21 |
+
def __init__(
|
22 |
+
self, in_channels, filter_channels, kernel_size, p_dropout, gin_channels=0
|
23 |
+
):
|
24 |
+
super().__init__()
|
25 |
+
|
26 |
+
self.in_channels = in_channels
|
27 |
+
self.filter_channels = filter_channels
|
28 |
+
self.kernel_size = kernel_size
|
29 |
+
self.p_dropout = p_dropout
|
30 |
+
self.gin_channels = gin_channels
|
31 |
+
|
32 |
+
self.drop = nn.Dropout(p_dropout)
|
33 |
+
self.conv_1 = nn.Conv1d(
|
34 |
+
in_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
35 |
+
)
|
36 |
+
self.norm_1 = modules.LayerNorm(filter_channels)
|
37 |
+
self.conv_2 = nn.Conv1d(
|
38 |
+
filter_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
39 |
+
)
|
40 |
+
self.norm_2 = modules.LayerNorm(filter_channels)
|
41 |
+
self.dur_proj = nn.Conv1d(1, filter_channels, 1)
|
42 |
+
|
43 |
+
self.pre_out_conv_1 = nn.Conv1d(
|
44 |
+
2 * filter_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
45 |
+
)
|
46 |
+
self.pre_out_norm_1 = modules.LayerNorm(filter_channels)
|
47 |
+
self.pre_out_conv_2 = nn.Conv1d(
|
48 |
+
filter_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
49 |
+
)
|
50 |
+
self.pre_out_norm_2 = modules.LayerNorm(filter_channels)
|
51 |
+
|
52 |
+
if gin_channels != 0:
|
53 |
+
self.cond = nn.Conv1d(gin_channels, in_channels, 1)
|
54 |
+
|
55 |
+
self.output_layer = nn.Sequential(nn.Linear(filter_channels, 1), nn.Sigmoid())
|
56 |
+
|
57 |
+
def forward_probability(self, x, x_mask, dur, g=None):
|
58 |
+
dur = self.dur_proj(dur)
|
59 |
+
x = torch.cat([x, dur], dim=1)
|
60 |
+
x = self.pre_out_conv_1(x * x_mask)
|
61 |
+
x = torch.relu(x)
|
62 |
+
x = self.pre_out_norm_1(x)
|
63 |
+
x = self.drop(x)
|
64 |
+
x = self.pre_out_conv_2(x * x_mask)
|
65 |
+
x = torch.relu(x)
|
66 |
+
x = self.pre_out_norm_2(x)
|
67 |
+
x = self.drop(x)
|
68 |
+
x = x * x_mask
|
69 |
+
x = x.transpose(1, 2)
|
70 |
+
output_prob = self.output_layer(x)
|
71 |
+
return output_prob
|
72 |
+
|
73 |
+
def forward(self, x, x_mask, dur_r, dur_hat, g=None):
|
74 |
+
x = torch.detach(x)
|
75 |
+
if g is not None:
|
76 |
+
g = torch.detach(g)
|
77 |
+
x = x + self.cond(g)
|
78 |
+
x = self.conv_1(x * x_mask)
|
79 |
+
x = torch.relu(x)
|
80 |
+
x = self.norm_1(x)
|
81 |
+
x = self.drop(x)
|
82 |
+
x = self.conv_2(x * x_mask)
|
83 |
+
x = torch.relu(x)
|
84 |
+
x = self.norm_2(x)
|
85 |
+
x = self.drop(x)
|
86 |
+
|
87 |
+
output_probs = []
|
88 |
+
for dur in [dur_r, dur_hat]:
|
89 |
+
output_prob = self.forward_probability(x, x_mask, dur, g)
|
90 |
+
output_probs.append(output_prob)
|
91 |
+
|
92 |
+
return output_probs
|
93 |
+
|
94 |
+
|
95 |
+
class TransformerCouplingBlock(nn.Module):
|
96 |
+
def __init__(
|
97 |
+
self,
|
98 |
+
channels,
|
99 |
+
hidden_channels,
|
100 |
+
filter_channels,
|
101 |
+
n_heads,
|
102 |
+
n_layers,
|
103 |
+
kernel_size,
|
104 |
+
p_dropout,
|
105 |
+
n_flows=4,
|
106 |
+
gin_channels=0,
|
107 |
+
share_parameter=False,
|
108 |
+
):
|
109 |
+
super().__init__()
|
110 |
+
self.channels = channels
|
111 |
+
self.hidden_channels = hidden_channels
|
112 |
+
self.kernel_size = kernel_size
|
113 |
+
self.n_layers = n_layers
|
114 |
+
self.n_flows = n_flows
|
115 |
+
self.gin_channels = gin_channels
|
116 |
+
|
117 |
+
self.flows = nn.ModuleList()
|
118 |
+
|
119 |
+
self.wn = (
|
120 |
+
attentions.FFT(
|
121 |
+
hidden_channels,
|
122 |
+
filter_channels,
|
123 |
+
n_heads,
|
124 |
+
n_layers,
|
125 |
+
kernel_size,
|
126 |
+
p_dropout,
|
127 |
+
isflow=True,
|
128 |
+
gin_channels=self.gin_channels,
|
129 |
+
)
|
130 |
+
if share_parameter
|
131 |
+
else None
|
132 |
+
)
|
133 |
+
|
134 |
+
for i in range(n_flows):
|
135 |
+
self.flows.append(
|
136 |
+
modules.TransformerCouplingLayer(
|
137 |
+
channels,
|
138 |
+
hidden_channels,
|
139 |
+
kernel_size,
|
140 |
+
n_layers,
|
141 |
+
n_heads,
|
142 |
+
p_dropout,
|
143 |
+
filter_channels,
|
144 |
+
mean_only=True,
|
145 |
+
wn_sharing_parameter=self.wn,
|
146 |
+
gin_channels=self.gin_channels,
|
147 |
+
)
|
148 |
+
)
|
149 |
+
self.flows.append(modules.Flip())
|
150 |
+
|
151 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
152 |
+
if not reverse:
|
153 |
+
for flow in self.flows:
|
154 |
+
x, _ = flow(x, x_mask, g=g, reverse=reverse)
|
155 |
+
else:
|
156 |
+
for flow in reversed(self.flows):
|
157 |
+
x = flow(x, x_mask, g=g, reverse=reverse)
|
158 |
+
return x
|
159 |
+
|
160 |
+
|
161 |
+
class StochasticDurationPredictor(nn.Module):
|
162 |
+
def __init__(
|
163 |
+
self,
|
164 |
+
in_channels,
|
165 |
+
filter_channels,
|
166 |
+
kernel_size,
|
167 |
+
p_dropout,
|
168 |
+
n_flows=4,
|
169 |
+
gin_channels=0,
|
170 |
+
):
|
171 |
+
super().__init__()
|
172 |
+
filter_channels = in_channels # it needs to be removed from future version.
|
173 |
+
self.in_channels = in_channels
|
174 |
+
self.filter_channels = filter_channels
|
175 |
+
self.kernel_size = kernel_size
|
176 |
+
self.p_dropout = p_dropout
|
177 |
+
self.n_flows = n_flows
|
178 |
+
self.gin_channels = gin_channels
|
179 |
+
|
180 |
+
self.log_flow = modules.Log()
|
181 |
+
self.flows = nn.ModuleList()
|
182 |
+
self.flows.append(modules.ElementwiseAffine(2))
|
183 |
+
for i in range(n_flows):
|
184 |
+
self.flows.append(
|
185 |
+
modules.ConvFlow(2, filter_channels, kernel_size, n_layers=3)
|
186 |
+
)
|
187 |
+
self.flows.append(modules.Flip())
|
188 |
+
|
189 |
+
self.post_pre = nn.Conv1d(1, filter_channels, 1)
|
190 |
+
self.post_proj = nn.Conv1d(filter_channels, filter_channels, 1)
|
191 |
+
self.post_convs = modules.DDSConv(
|
192 |
+
filter_channels, kernel_size, n_layers=3, p_dropout=p_dropout
|
193 |
+
)
|
194 |
+
self.post_flows = nn.ModuleList()
|
195 |
+
self.post_flows.append(modules.ElementwiseAffine(2))
|
196 |
+
for i in range(4):
|
197 |
+
self.post_flows.append(
|
198 |
+
modules.ConvFlow(2, filter_channels, kernel_size, n_layers=3)
|
199 |
+
)
|
200 |
+
self.post_flows.append(modules.Flip())
|
201 |
+
|
202 |
+
self.pre = nn.Conv1d(in_channels, filter_channels, 1)
|
203 |
+
self.proj = nn.Conv1d(filter_channels, filter_channels, 1)
|
204 |
+
self.convs = modules.DDSConv(
|
205 |
+
filter_channels, kernel_size, n_layers=3, p_dropout=p_dropout
|
206 |
+
)
|
207 |
+
if gin_channels != 0:
|
208 |
+
self.cond = nn.Conv1d(gin_channels, filter_channels, 1)
|
209 |
+
|
210 |
+
def forward(self, x, x_mask, w=None, g=None, reverse=False, noise_scale=1.0):
|
211 |
+
x = torch.detach(x)
|
212 |
+
x = self.pre(x)
|
213 |
+
if g is not None:
|
214 |
+
g = torch.detach(g)
|
215 |
+
x = x + self.cond(g)
|
216 |
+
x = self.convs(x, x_mask)
|
217 |
+
x = self.proj(x) * x_mask
|
218 |
+
|
219 |
+
if not reverse:
|
220 |
+
flows = self.flows
|
221 |
+
assert w is not None
|
222 |
+
|
223 |
+
logdet_tot_q = 0
|
224 |
+
h_w = self.post_pre(w)
|
225 |
+
h_w = self.post_convs(h_w, x_mask)
|
226 |
+
h_w = self.post_proj(h_w) * x_mask
|
227 |
+
e_q = (
|
228 |
+
torch.randn(w.size(0), 2, w.size(2)).to(device=x.device, dtype=x.dtype)
|
229 |
+
* x_mask
|
230 |
+
)
|
231 |
+
z_q = e_q
|
232 |
+
for flow in self.post_flows:
|
233 |
+
z_q, logdet_q = flow(z_q, x_mask, g=(x + h_w))
|
234 |
+
logdet_tot_q += logdet_q
|
235 |
+
z_u, z1 = torch.split(z_q, [1, 1], 1)
|
236 |
+
u = torch.sigmoid(z_u) * x_mask
|
237 |
+
z0 = (w - u) * x_mask
|
238 |
+
logdet_tot_q += torch.sum(
|
239 |
+
(F.logsigmoid(z_u) + F.logsigmoid(-z_u)) * x_mask, [1, 2]
|
240 |
+
)
|
241 |
+
logq = (
|
242 |
+
torch.sum(-0.5 * (math.log(2 * math.pi) + (e_q**2)) * x_mask, [1, 2])
|
243 |
+
- logdet_tot_q
|
244 |
+
)
|
245 |
+
|
246 |
+
logdet_tot = 0
|
247 |
+
z0, logdet = self.log_flow(z0, x_mask)
|
248 |
+
logdet_tot += logdet
|
249 |
+
z = torch.cat([z0, z1], 1)
|
250 |
+
for flow in flows:
|
251 |
+
z, logdet = flow(z, x_mask, g=x, reverse=reverse)
|
252 |
+
logdet_tot = logdet_tot + logdet
|
253 |
+
nll = (
|
254 |
+
torch.sum(0.5 * (math.log(2 * math.pi) + (z**2)) * x_mask, [1, 2])
|
255 |
+
- logdet_tot
|
256 |
+
)
|
257 |
+
return nll + logq # [b]
|
258 |
+
else:
|
259 |
+
flows = list(reversed(self.flows))
|
260 |
+
flows = flows[:-2] + [flows[-1]] # remove a useless vflow
|
261 |
+
z = (
|
262 |
+
torch.randn(x.size(0), 2, x.size(2)).to(device=x.device, dtype=x.dtype)
|
263 |
+
* noise_scale
|
264 |
+
)
|
265 |
+
for flow in flows:
|
266 |
+
z = flow(z, x_mask, g=x, reverse=reverse)
|
267 |
+
z0, z1 = torch.split(z, [1, 1], 1)
|
268 |
+
logw = z0
|
269 |
+
return logw
|
270 |
+
|
271 |
+
|
272 |
+
class DurationPredictor(nn.Module):
|
273 |
+
def __init__(
|
274 |
+
self, in_channels, filter_channels, kernel_size, p_dropout, gin_channels=0
|
275 |
+
):
|
276 |
+
super().__init__()
|
277 |
+
|
278 |
+
self.in_channels = in_channels
|
279 |
+
self.filter_channels = filter_channels
|
280 |
+
self.kernel_size = kernel_size
|
281 |
+
self.p_dropout = p_dropout
|
282 |
+
self.gin_channels = gin_channels
|
283 |
+
|
284 |
+
self.drop = nn.Dropout(p_dropout)
|
285 |
+
self.conv_1 = nn.Conv1d(
|
286 |
+
in_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
287 |
+
)
|
288 |
+
self.norm_1 = modules.LayerNorm(filter_channels)
|
289 |
+
self.conv_2 = nn.Conv1d(
|
290 |
+
filter_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
291 |
+
)
|
292 |
+
self.norm_2 = modules.LayerNorm(filter_channels)
|
293 |
+
self.proj = nn.Conv1d(filter_channels, 1, 1)
|
294 |
+
|
295 |
+
if gin_channels != 0:
|
296 |
+
self.cond = nn.Conv1d(gin_channels, in_channels, 1)
|
297 |
+
|
298 |
+
def forward(self, x, x_mask, g=None):
|
299 |
+
x = torch.detach(x)
|
300 |
+
if g is not None:
|
301 |
+
g = torch.detach(g)
|
302 |
+
x = x + self.cond(g)
|
303 |
+
x = self.conv_1(x * x_mask)
|
304 |
+
x = torch.relu(x)
|
305 |
+
x = self.norm_1(x)
|
306 |
+
x = self.drop(x)
|
307 |
+
x = self.conv_2(x * x_mask)
|
308 |
+
x = torch.relu(x)
|
309 |
+
x = self.norm_2(x)
|
310 |
+
x = self.drop(x)
|
311 |
+
x = self.proj(x * x_mask)
|
312 |
+
return x * x_mask
|
313 |
+
|
314 |
+
|
315 |
+
class Bottleneck(nn.Sequential):
|
316 |
+
def __init__(self, in_dim, hidden_dim):
|
317 |
+
c_fc1 = nn.Linear(in_dim, hidden_dim, bias=False)
|
318 |
+
c_fc2 = nn.Linear(in_dim, hidden_dim, bias=False)
|
319 |
+
super().__init__(*[c_fc1, c_fc2])
|
320 |
+
|
321 |
+
|
322 |
+
class Block(nn.Module):
|
323 |
+
def __init__(self, in_dim, hidden_dim) -> None:
|
324 |
+
super().__init__()
|
325 |
+
self.norm = nn.LayerNorm(in_dim)
|
326 |
+
self.mlp = MLP(in_dim, hidden_dim)
|
327 |
+
|
328 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
329 |
+
x = x + self.mlp(self.norm(x))
|
330 |
+
return x
|
331 |
+
|
332 |
+
|
333 |
+
class MLP(nn.Module):
|
334 |
+
def __init__(self, in_dim, hidden_dim):
|
335 |
+
super().__init__()
|
336 |
+
self.c_fc1 = nn.Linear(in_dim, hidden_dim, bias=False)
|
337 |
+
self.c_fc2 = nn.Linear(in_dim, hidden_dim, bias=False)
|
338 |
+
self.c_proj = nn.Linear(hidden_dim, in_dim, bias=False)
|
339 |
+
|
340 |
+
def forward(self, x: torch.Tensor):
|
341 |
+
x = F.silu(self.c_fc1(x)) * self.c_fc2(x)
|
342 |
+
x = self.c_proj(x)
|
343 |
+
return x
|
344 |
+
|
345 |
+
|
346 |
+
class TextEncoder(nn.Module):
|
347 |
+
def __init__(
|
348 |
+
self,
|
349 |
+
n_vocab,
|
350 |
+
out_channels,
|
351 |
+
hidden_channels,
|
352 |
+
filter_channels,
|
353 |
+
n_heads,
|
354 |
+
n_layers,
|
355 |
+
kernel_size,
|
356 |
+
p_dropout,
|
357 |
+
n_speakers,
|
358 |
+
gin_channels=0,
|
359 |
+
):
|
360 |
+
super().__init__()
|
361 |
+
self.n_vocab = n_vocab
|
362 |
+
self.out_channels = out_channels
|
363 |
+
self.hidden_channels = hidden_channels
|
364 |
+
self.filter_channels = filter_channels
|
365 |
+
self.n_heads = n_heads
|
366 |
+
self.n_layers = n_layers
|
367 |
+
self.kernel_size = kernel_size
|
368 |
+
self.p_dropout = p_dropout
|
369 |
+
self.gin_channels = gin_channels
|
370 |
+
self.emb = nn.Embedding(len(symbols), hidden_channels)
|
371 |
+
nn.init.normal_(self.emb.weight, 0.0, hidden_channels**-0.5)
|
372 |
+
self.tone_emb = nn.Embedding(num_tones, hidden_channels)
|
373 |
+
nn.init.normal_(self.tone_emb.weight, 0.0, hidden_channels**-0.5)
|
374 |
+
self.language_emb = nn.Embedding(num_languages, hidden_channels)
|
375 |
+
nn.init.normal_(self.language_emb.weight, 0.0, hidden_channels**-0.5)
|
376 |
+
self.bert_proj = nn.Conv1d(1024, hidden_channels, 1)
|
377 |
+
self.ja_bert_proj = nn.Conv1d(1024, hidden_channels, 1)
|
378 |
+
self.en_bert_proj = nn.Conv1d(1024, hidden_channels, 1)
|
379 |
+
# self.emo_proj = nn.Linear(512, hidden_channels)
|
380 |
+
self.in_feature_net = nn.Sequential(
|
381 |
+
# input is assumed to an already normalized embedding
|
382 |
+
nn.Linear(512, 1028, bias=False),
|
383 |
+
nn.GELU(),
|
384 |
+
nn.LayerNorm(1028),
|
385 |
+
*[Block(1028, 512) for _ in range(1)],
|
386 |
+
nn.Linear(1028, 512, bias=False),
|
387 |
+
# normalize before passing to VQ?
|
388 |
+
# nn.GELU(),
|
389 |
+
# nn.LayerNorm(512),
|
390 |
+
)
|
391 |
+
self.emo_vq = VectorQuantize(
|
392 |
+
dim=512,
|
393 |
+
codebook_size=64,
|
394 |
+
codebook_dim=32,
|
395 |
+
commitment_weight=0.1,
|
396 |
+
decay=0.85,
|
397 |
+
heads=32,
|
398 |
+
kmeans_iters=20,
|
399 |
+
separate_codebook_per_head=True,
|
400 |
+
stochastic_sample_codes=True,
|
401 |
+
threshold_ema_dead_code=2,
|
402 |
+
)
|
403 |
+
self.out_feature_net = nn.Linear(512, hidden_channels)
|
404 |
+
|
405 |
+
self.encoder = attentions.Encoder(
|
406 |
+
hidden_channels,
|
407 |
+
filter_channels,
|
408 |
+
n_heads,
|
409 |
+
n_layers,
|
410 |
+
kernel_size,
|
411 |
+
p_dropout,
|
412 |
+
gin_channels=self.gin_channels,
|
413 |
+
)
|
414 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels * 2, 1)
|
415 |
+
|
416 |
+
def forward(
|
417 |
+
self, x, x_lengths, tone, language, bert, ja_bert, en_bert, emo, sid, g=None
|
418 |
+
):
|
419 |
+
sid = sid.cpu()
|
420 |
+
bert_emb = self.bert_proj(bert).transpose(1, 2)
|
421 |
+
ja_bert_emb = self.ja_bert_proj(ja_bert).transpose(1, 2)
|
422 |
+
en_bert_emb = self.en_bert_proj(en_bert).transpose(1, 2)
|
423 |
+
emo_emb = self.in_feature_net(emo)
|
424 |
+
emo_emb, _, loss_commit = self.emo_vq(emo_emb.unsqueeze(1))
|
425 |
+
loss_commit = loss_commit.mean()
|
426 |
+
emo_emb = self.out_feature_net(emo_emb)
|
427 |
+
# emo_emb = self.emo_proj(emo.unsqueeze(1))
|
428 |
+
x = (
|
429 |
+
self.emb(x)
|
430 |
+
+ self.tone_emb(tone)
|
431 |
+
+ self.language_emb(language)
|
432 |
+
+ bert_emb
|
433 |
+
+ ja_bert_emb
|
434 |
+
+ en_bert_emb
|
435 |
+
+ emo_emb
|
436 |
+
) * math.sqrt(
|
437 |
+
self.hidden_channels
|
438 |
+
) # [b, t, h]
|
439 |
+
x = torch.transpose(x, 1, -1) # [b, h, t]
|
440 |
+
x_mask = torch.unsqueeze(commons.sequence_mask(x_lengths, x.size(2)), 1).to(
|
441 |
+
x.dtype
|
442 |
+
)
|
443 |
+
|
444 |
+
x = self.encoder(x * x_mask, x_mask, g=g)
|
445 |
+
stats = self.proj(x) * x_mask
|
446 |
+
|
447 |
+
m, logs = torch.split(stats, self.out_channels, dim=1)
|
448 |
+
return x, m, logs, x_mask, loss_commit
|
449 |
+
|
450 |
+
|
451 |
+
class ResidualCouplingBlock(nn.Module):
|
452 |
+
def __init__(
|
453 |
+
self,
|
454 |
+
channels,
|
455 |
+
hidden_channels,
|
456 |
+
kernel_size,
|
457 |
+
dilation_rate,
|
458 |
+
n_layers,
|
459 |
+
n_flows=4,
|
460 |
+
gin_channels=0,
|
461 |
+
):
|
462 |
+
super().__init__()
|
463 |
+
self.channels = channels
|
464 |
+
self.hidden_channels = hidden_channels
|
465 |
+
self.kernel_size = kernel_size
|
466 |
+
self.dilation_rate = dilation_rate
|
467 |
+
self.n_layers = n_layers
|
468 |
+
self.n_flows = n_flows
|
469 |
+
self.gin_channels = gin_channels
|
470 |
+
|
471 |
+
self.flows = nn.ModuleList()
|
472 |
+
for i in range(n_flows):
|
473 |
+
self.flows.append(
|
474 |
+
modules.ResidualCouplingLayer(
|
475 |
+
channels,
|
476 |
+
hidden_channels,
|
477 |
+
kernel_size,
|
478 |
+
dilation_rate,
|
479 |
+
n_layers,
|
480 |
+
gin_channels=gin_channels,
|
481 |
+
mean_only=True,
|
482 |
+
)
|
483 |
+
)
|
484 |
+
self.flows.append(modules.Flip())
|
485 |
+
|
486 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
487 |
+
if not reverse:
|
488 |
+
for flow in self.flows:
|
489 |
+
x, _ = flow(x, x_mask, g=g, reverse=reverse)
|
490 |
+
else:
|
491 |
+
for flow in reversed(self.flows):
|
492 |
+
x = flow(x, x_mask, g=g, reverse=reverse)
|
493 |
+
return x
|
494 |
+
|
495 |
+
|
496 |
+
class PosteriorEncoder(nn.Module):
|
497 |
+
def __init__(
|
498 |
+
self,
|
499 |
+
in_channels,
|
500 |
+
out_channels,
|
501 |
+
hidden_channels,
|
502 |
+
kernel_size,
|
503 |
+
dilation_rate,
|
504 |
+
n_layers,
|
505 |
+
gin_channels=0,
|
506 |
+
):
|
507 |
+
super().__init__()
|
508 |
+
self.in_channels = in_channels
|
509 |
+
self.out_channels = out_channels
|
510 |
+
self.hidden_channels = hidden_channels
|
511 |
+
self.kernel_size = kernel_size
|
512 |
+
self.dilation_rate = dilation_rate
|
513 |
+
self.n_layers = n_layers
|
514 |
+
self.gin_channels = gin_channels
|
515 |
+
|
516 |
+
self.pre = nn.Conv1d(in_channels, hidden_channels, 1)
|
517 |
+
self.enc = modules.WN(
|
518 |
+
hidden_channels,
|
519 |
+
kernel_size,
|
520 |
+
dilation_rate,
|
521 |
+
n_layers,
|
522 |
+
gin_channels=gin_channels,
|
523 |
+
)
|
524 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels * 2, 1)
|
525 |
+
|
526 |
+
def forward(self, x, x_lengths, g=None):
|
527 |
+
x_mask = torch.unsqueeze(commons.sequence_mask(x_lengths, x.size(2)), 1).to(
|
528 |
+
x.dtype
|
529 |
+
)
|
530 |
+
x = self.pre(x) * x_mask
|
531 |
+
x = self.enc(x, x_mask, g=g)
|
532 |
+
stats = self.proj(x) * x_mask
|
533 |
+
m, logs = torch.split(stats, self.out_channels, dim=1)
|
534 |
+
z = (m + torch.randn_like(m) * torch.exp(logs)) * x_mask
|
535 |
+
return z, m, logs, x_mask
|
536 |
+
|
537 |
+
|
538 |
+
class Generator(torch.nn.Module):
|
539 |
+
def __init__(
|
540 |
+
self,
|
541 |
+
initial_channel,
|
542 |
+
resblock,
|
543 |
+
resblock_kernel_sizes,
|
544 |
+
resblock_dilation_sizes,
|
545 |
+
upsample_rates,
|
546 |
+
upsample_initial_channel,
|
547 |
+
upsample_kernel_sizes,
|
548 |
+
gin_channels=0,
|
549 |
+
):
|
550 |
+
super(Generator, self).__init__()
|
551 |
+
self.num_kernels = len(resblock_kernel_sizes)
|
552 |
+
self.num_upsamples = len(upsample_rates)
|
553 |
+
self.conv_pre = Conv1d(
|
554 |
+
initial_channel, upsample_initial_channel, 7, 1, padding=3
|
555 |
+
)
|
556 |
+
resblock = modules.ResBlock1 if resblock == "1" else modules.ResBlock2
|
557 |
+
|
558 |
+
self.ups = nn.ModuleList()
|
559 |
+
for i, (u, k) in enumerate(zip(upsample_rates, upsample_kernel_sizes)):
|
560 |
+
self.ups.append(
|
561 |
+
weight_norm(
|
562 |
+
ConvTranspose1d(
|
563 |
+
upsample_initial_channel // (2**i),
|
564 |
+
upsample_initial_channel // (2 ** (i + 1)),
|
565 |
+
k,
|
566 |
+
u,
|
567 |
+
padding=(k - u) // 2,
|
568 |
+
)
|
569 |
+
)
|
570 |
+
)
|
571 |
+
|
572 |
+
self.resblocks = nn.ModuleList()
|
573 |
+
for i in range(len(self.ups)):
|
574 |
+
ch = upsample_initial_channel // (2 ** (i + 1))
|
575 |
+
for j, (k, d) in enumerate(
|
576 |
+
zip(resblock_kernel_sizes, resblock_dilation_sizes)
|
577 |
+
):
|
578 |
+
self.resblocks.append(resblock(ch, k, d))
|
579 |
+
|
580 |
+
self.conv_post = Conv1d(ch, 1, 7, 1, padding=3, bias=False)
|
581 |
+
self.ups.apply(init_weights)
|
582 |
+
|
583 |
+
if gin_channels != 0:
|
584 |
+
self.cond = nn.Conv1d(gin_channels, upsample_initial_channel, 1)
|
585 |
+
|
586 |
+
def forward(self, x, g=None):
|
587 |
+
x = self.conv_pre(x)
|
588 |
+
if g is not None:
|
589 |
+
x = x + self.cond(g)
|
590 |
+
|
591 |
+
for i in range(self.num_upsamples):
|
592 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
593 |
+
x = self.ups[i](x)
|
594 |
+
xs = None
|
595 |
+
for j in range(self.num_kernels):
|
596 |
+
if xs is None:
|
597 |
+
xs = self.resblocks[i * self.num_kernels + j](x)
|
598 |
+
else:
|
599 |
+
xs += self.resblocks[i * self.num_kernels + j](x)
|
600 |
+
x = xs / self.num_kernels
|
601 |
+
x = F.leaky_relu(x)
|
602 |
+
x = self.conv_post(x)
|
603 |
+
x = torch.tanh(x)
|
604 |
+
|
605 |
+
return x
|
606 |
+
|
607 |
+
def remove_weight_norm(self):
|
608 |
+
print("Removing weight norm...")
|
609 |
+
for layer in self.ups:
|
610 |
+
remove_weight_norm(layer)
|
611 |
+
for layer in self.resblocks:
|
612 |
+
layer.remove_weight_norm()
|
613 |
+
|
614 |
+
|
615 |
+
class DiscriminatorP(torch.nn.Module):
|
616 |
+
def __init__(self, period, kernel_size=5, stride=3, use_spectral_norm=False):
|
617 |
+
super(DiscriminatorP, self).__init__()
|
618 |
+
self.period = period
|
619 |
+
self.use_spectral_norm = use_spectral_norm
|
620 |
+
norm_f = weight_norm if use_spectral_norm is False else spectral_norm
|
621 |
+
self.convs = nn.ModuleList(
|
622 |
+
[
|
623 |
+
norm_f(
|
624 |
+
Conv2d(
|
625 |
+
1,
|
626 |
+
32,
|
627 |
+
(kernel_size, 1),
|
628 |
+
(stride, 1),
|
629 |
+
padding=(get_padding(kernel_size, 1), 0),
|
630 |
+
)
|
631 |
+
),
|
632 |
+
norm_f(
|
633 |
+
Conv2d(
|
634 |
+
32,
|
635 |
+
128,
|
636 |
+
(kernel_size, 1),
|
637 |
+
(stride, 1),
|
638 |
+
padding=(get_padding(kernel_size, 1), 0),
|
639 |
+
)
|
640 |
+
),
|
641 |
+
norm_f(
|
642 |
+
Conv2d(
|
643 |
+
128,
|
644 |
+
512,
|
645 |
+
(kernel_size, 1),
|
646 |
+
(stride, 1),
|
647 |
+
padding=(get_padding(kernel_size, 1), 0),
|
648 |
+
)
|
649 |
+
),
|
650 |
+
norm_f(
|
651 |
+
Conv2d(
|
652 |
+
512,
|
653 |
+
1024,
|
654 |
+
(kernel_size, 1),
|
655 |
+
(stride, 1),
|
656 |
+
padding=(get_padding(kernel_size, 1), 0),
|
657 |
+
)
|
658 |
+
),
|
659 |
+
norm_f(
|
660 |
+
Conv2d(
|
661 |
+
1024,
|
662 |
+
1024,
|
663 |
+
(kernel_size, 1),
|
664 |
+
1,
|
665 |
+
padding=(get_padding(kernel_size, 1), 0),
|
666 |
+
)
|
667 |
+
),
|
668 |
+
]
|
669 |
+
)
|
670 |
+
self.conv_post = norm_f(Conv2d(1024, 1, (3, 1), 1, padding=(1, 0)))
|
671 |
+
|
672 |
+
def forward(self, x):
|
673 |
+
fmap = []
|
674 |
+
|
675 |
+
# 1d to 2d
|
676 |
+
b, c, t = x.shape
|
677 |
+
if t % self.period != 0: # pad first
|
678 |
+
n_pad = self.period - (t % self.period)
|
679 |
+
x = F.pad(x, (0, n_pad), "reflect")
|
680 |
+
t = t + n_pad
|
681 |
+
x = x.view(b, c, t // self.period, self.period)
|
682 |
+
|
683 |
+
for layer in self.convs:
|
684 |
+
x = layer(x)
|
685 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
686 |
+
fmap.append(x)
|
687 |
+
x = self.conv_post(x)
|
688 |
+
fmap.append(x)
|
689 |
+
x = torch.flatten(x, 1, -1)
|
690 |
+
|
691 |
+
return x, fmap
|
692 |
+
|
693 |
+
|
694 |
+
class DiscriminatorS(torch.nn.Module):
|
695 |
+
def __init__(self, use_spectral_norm=False):
|
696 |
+
super(DiscriminatorS, self).__init__()
|
697 |
+
norm_f = weight_norm if use_spectral_norm is False else spectral_norm
|
698 |
+
self.convs = nn.ModuleList(
|
699 |
+
[
|
700 |
+
norm_f(Conv1d(1, 16, 15, 1, padding=7)),
|
701 |
+
norm_f(Conv1d(16, 64, 41, 4, groups=4, padding=20)),
|
702 |
+
norm_f(Conv1d(64, 256, 41, 4, groups=16, padding=20)),
|
703 |
+
norm_f(Conv1d(256, 1024, 41, 4, groups=64, padding=20)),
|
704 |
+
norm_f(Conv1d(1024, 1024, 41, 4, groups=256, padding=20)),
|
705 |
+
norm_f(Conv1d(1024, 1024, 5, 1, padding=2)),
|
706 |
+
]
|
707 |
+
)
|
708 |
+
self.conv_post = norm_f(Conv1d(1024, 1, 3, 1, padding=1))
|
709 |
+
|
710 |
+
def forward(self, x):
|
711 |
+
fmap = []
|
712 |
+
|
713 |
+
for layer in self.convs:
|
714 |
+
x = layer(x)
|
715 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
716 |
+
fmap.append(x)
|
717 |
+
x = self.conv_post(x)
|
718 |
+
fmap.append(x)
|
719 |
+
x = torch.flatten(x, 1, -1)
|
720 |
+
|
721 |
+
return x, fmap
|
722 |
+
|
723 |
+
|
724 |
+
class MultiPeriodDiscriminator(torch.nn.Module):
|
725 |
+
def __init__(self, use_spectral_norm=False):
|
726 |
+
super(MultiPeriodDiscriminator, self).__init__()
|
727 |
+
periods = [2, 3, 5, 7, 11]
|
728 |
+
|
729 |
+
discs = [DiscriminatorS(use_spectral_norm=use_spectral_norm)]
|
730 |
+
discs = discs + [
|
731 |
+
DiscriminatorP(i, use_spectral_norm=use_spectral_norm) for i in periods
|
732 |
+
]
|
733 |
+
self.discriminators = nn.ModuleList(discs)
|
734 |
+
|
735 |
+
def forward(self, y, y_hat):
|
736 |
+
y_d_rs = []
|
737 |
+
y_d_gs = []
|
738 |
+
fmap_rs = []
|
739 |
+
fmap_gs = []
|
740 |
+
for i, d in enumerate(self.discriminators):
|
741 |
+
y_d_r, fmap_r = d(y)
|
742 |
+
y_d_g, fmap_g = d(y_hat)
|
743 |
+
y_d_rs.append(y_d_r)
|
744 |
+
y_d_gs.append(y_d_g)
|
745 |
+
fmap_rs.append(fmap_r)
|
746 |
+
fmap_gs.append(fmap_g)
|
747 |
+
|
748 |
+
return y_d_rs, y_d_gs, fmap_rs, fmap_gs
|
749 |
+
|
750 |
+
|
751 |
+
class ReferenceEncoder(nn.Module):
|
752 |
+
"""
|
753 |
+
inputs --- [N, Ty/r, n_mels*r] mels
|
754 |
+
outputs --- [N, ref_enc_gru_size]
|
755 |
+
"""
|
756 |
+
|
757 |
+
def __init__(self, spec_channels, gin_channels=0):
|
758 |
+
super().__init__()
|
759 |
+
self.spec_channels = spec_channels
|
760 |
+
ref_enc_filters = [32, 32, 64, 64, 128, 128]
|
761 |
+
K = len(ref_enc_filters)
|
762 |
+
filters = [1] + ref_enc_filters
|
763 |
+
convs = [
|
764 |
+
weight_norm(
|
765 |
+
nn.Conv2d(
|
766 |
+
in_channels=filters[i],
|
767 |
+
out_channels=filters[i + 1],
|
768 |
+
kernel_size=(3, 3),
|
769 |
+
stride=(2, 2),
|
770 |
+
padding=(1, 1),
|
771 |
+
)
|
772 |
+
)
|
773 |
+
for i in range(K)
|
774 |
+
]
|
775 |
+
self.convs = nn.ModuleList(convs)
|
776 |
+
# self.wns = nn.ModuleList([weight_norm(num_features=ref_enc_filters[i]) for i in range(K)]) # noqa: E501
|
777 |
+
|
778 |
+
out_channels = self.calculate_channels(spec_channels, 3, 2, 1, K)
|
779 |
+
self.gru = nn.GRU(
|
780 |
+
input_size=ref_enc_filters[-1] * out_channels,
|
781 |
+
hidden_size=256 // 2,
|
782 |
+
batch_first=True,
|
783 |
+
)
|
784 |
+
self.proj = nn.Linear(128, gin_channels)
|
785 |
+
|
786 |
+
def forward(self, inputs, mask=None):
|
787 |
+
N = inputs.size(0)
|
788 |
+
out = inputs.view(N, 1, -1, self.spec_channels) # [N, 1, Ty, n_freqs]
|
789 |
+
for conv in self.convs:
|
790 |
+
out = conv(out)
|
791 |
+
# out = wn(out)
|
792 |
+
out = F.relu(out) # [N, 128, Ty//2^K, n_mels//2^K]
|
793 |
+
|
794 |
+
out = out.transpose(1, 2) # [N, Ty//2^K, 128, n_mels//2^K]
|
795 |
+
T = out.size(1)
|
796 |
+
N = out.size(0)
|
797 |
+
out = out.contiguous().view(N, T, -1) # [N, Ty//2^K, 128*n_mels//2^K]
|
798 |
+
|
799 |
+
self.gru.flatten_parameters()
|
800 |
+
memory, out = self.gru(out) # out --- [1, N, 128]
|
801 |
+
|
802 |
+
return self.proj(out.squeeze(0))
|
803 |
+
|
804 |
+
def calculate_channels(self, L, kernel_size, stride, pad, n_convs):
|
805 |
+
for i in range(n_convs):
|
806 |
+
L = (L - kernel_size + 2 * pad) // stride + 1
|
807 |
+
return L
|
808 |
+
|
809 |
+
|
810 |
+
class SynthesizerTrn(nn.Module):
|
811 |
+
"""
|
812 |
+
Synthesizer for Training
|
813 |
+
"""
|
814 |
+
|
815 |
+
def __init__(
|
816 |
+
self,
|
817 |
+
n_vocab,
|
818 |
+
spec_channels,
|
819 |
+
segment_size,
|
820 |
+
inter_channels,
|
821 |
+
hidden_channels,
|
822 |
+
filter_channels,
|
823 |
+
n_heads,
|
824 |
+
n_layers,
|
825 |
+
kernel_size,
|
826 |
+
p_dropout,
|
827 |
+
resblock,
|
828 |
+
resblock_kernel_sizes,
|
829 |
+
resblock_dilation_sizes,
|
830 |
+
upsample_rates,
|
831 |
+
upsample_initial_channel,
|
832 |
+
upsample_kernel_sizes,
|
833 |
+
n_speakers=256,
|
834 |
+
gin_channels=256,
|
835 |
+
use_sdp=True,
|
836 |
+
n_flow_layer=4,
|
837 |
+
n_layers_trans_flow=4,
|
838 |
+
flow_share_parameter=False,
|
839 |
+
use_transformer_flow=True,
|
840 |
+
**kwargs
|
841 |
+
):
|
842 |
+
super().__init__()
|
843 |
+
self.n_vocab = n_vocab
|
844 |
+
self.spec_channels = spec_channels
|
845 |
+
self.inter_channels = inter_channels
|
846 |
+
self.hidden_channels = hidden_channels
|
847 |
+
self.filter_channels = filter_channels
|
848 |
+
self.n_heads = n_heads
|
849 |
+
self.n_layers = n_layers
|
850 |
+
self.kernel_size = kernel_size
|
851 |
+
self.p_dropout = p_dropout
|
852 |
+
self.resblock = resblock
|
853 |
+
self.resblock_kernel_sizes = resblock_kernel_sizes
|
854 |
+
self.resblock_dilation_sizes = resblock_dilation_sizes
|
855 |
+
self.upsample_rates = upsample_rates
|
856 |
+
self.upsample_initial_channel = upsample_initial_channel
|
857 |
+
self.upsample_kernel_sizes = upsample_kernel_sizes
|
858 |
+
self.segment_size = segment_size
|
859 |
+
self.n_speakers = n_speakers
|
860 |
+
self.gin_channels = gin_channels
|
861 |
+
self.n_layers_trans_flow = n_layers_trans_flow
|
862 |
+
self.use_spk_conditioned_encoder = kwargs.get(
|
863 |
+
"use_spk_conditioned_encoder", True
|
864 |
+
)
|
865 |
+
self.use_sdp = use_sdp
|
866 |
+
self.use_noise_scaled_mas = kwargs.get("use_noise_scaled_mas", False)
|
867 |
+
self.mas_noise_scale_initial = kwargs.get("mas_noise_scale_initial", 0.01)
|
868 |
+
self.noise_scale_delta = kwargs.get("noise_scale_delta", 2e-6)
|
869 |
+
self.current_mas_noise_scale = self.mas_noise_scale_initial
|
870 |
+
if self.use_spk_conditioned_encoder and gin_channels > 0:
|
871 |
+
self.enc_gin_channels = gin_channels
|
872 |
+
self.enc_p = TextEncoder(
|
873 |
+
n_vocab,
|
874 |
+
inter_channels,
|
875 |
+
hidden_channels,
|
876 |
+
filter_channels,
|
877 |
+
n_heads,
|
878 |
+
n_layers,
|
879 |
+
kernel_size,
|
880 |
+
p_dropout,
|
881 |
+
self.n_speakers,
|
882 |
+
gin_channels=self.enc_gin_channels,
|
883 |
+
)
|
884 |
+
self.dec = Generator(
|
885 |
+
inter_channels,
|
886 |
+
resblock,
|
887 |
+
resblock_kernel_sizes,
|
888 |
+
resblock_dilation_sizes,
|
889 |
+
upsample_rates,
|
890 |
+
upsample_initial_channel,
|
891 |
+
upsample_kernel_sizes,
|
892 |
+
gin_channels=gin_channels,
|
893 |
+
)
|
894 |
+
self.enc_q = PosteriorEncoder(
|
895 |
+
spec_channels,
|
896 |
+
inter_channels,
|
897 |
+
hidden_channels,
|
898 |
+
5,
|
899 |
+
1,
|
900 |
+
16,
|
901 |
+
gin_channels=gin_channels,
|
902 |
+
)
|
903 |
+
if use_transformer_flow:
|
904 |
+
self.flow = TransformerCouplingBlock(
|
905 |
+
inter_channels,
|
906 |
+
hidden_channels,
|
907 |
+
filter_channels,
|
908 |
+
n_heads,
|
909 |
+
n_layers_trans_flow,
|
910 |
+
5,
|
911 |
+
p_dropout,
|
912 |
+
n_flow_layer,
|
913 |
+
gin_channels=gin_channels,
|
914 |
+
share_parameter=flow_share_parameter,
|
915 |
+
)
|
916 |
+
else:
|
917 |
+
self.flow = ResidualCouplingBlock(
|
918 |
+
inter_channels,
|
919 |
+
hidden_channels,
|
920 |
+
5,
|
921 |
+
1,
|
922 |
+
n_flow_layer,
|
923 |
+
gin_channels=gin_channels,
|
924 |
+
)
|
925 |
+
self.sdp = StochasticDurationPredictor(
|
926 |
+
hidden_channels, 192, 3, 0.5, 4, gin_channels=gin_channels
|
927 |
+
)
|
928 |
+
self.dp = DurationPredictor(
|
929 |
+
hidden_channels, 256, 3, 0.5, gin_channels=gin_channels
|
930 |
+
)
|
931 |
+
|
932 |
+
if n_speakers >= 1:
|
933 |
+
self.emb_g = nn.Embedding(n_speakers, gin_channels)
|
934 |
+
else:
|
935 |
+
self.ref_enc = ReferenceEncoder(spec_channels, gin_channels)
|
936 |
+
|
937 |
+
def forward(
|
938 |
+
self,
|
939 |
+
x,
|
940 |
+
x_lengths,
|
941 |
+
y,
|
942 |
+
y_lengths,
|
943 |
+
sid,
|
944 |
+
tone,
|
945 |
+
language,
|
946 |
+
bert,
|
947 |
+
ja_bert,
|
948 |
+
en_bert,
|
949 |
+
emo=None,
|
950 |
+
):
|
951 |
+
if self.n_speakers > 0:
|
952 |
+
g = self.emb_g(sid).unsqueeze(-1) # [b, h, 1]
|
953 |
+
else:
|
954 |
+
g = self.ref_enc(y.transpose(1, 2)).unsqueeze(-1)
|
955 |
+
x, m_p, logs_p, x_mask, loss_commit = self.enc_p(
|
956 |
+
x, x_lengths, tone, language, bert, ja_bert, en_bert, emo, sid, g=g
|
957 |
+
)
|
958 |
+
z, m_q, logs_q, y_mask = self.enc_q(y, y_lengths, g=g)
|
959 |
+
z_p = self.flow(z, y_mask, g=g)
|
960 |
+
|
961 |
+
with torch.no_grad():
|
962 |
+
# negative cross-entropy
|
963 |
+
s_p_sq_r = torch.exp(-2 * logs_p) # [b, d, t]
|
964 |
+
neg_cent1 = torch.sum(
|
965 |
+
-0.5 * math.log(2 * math.pi) - logs_p, [1], keepdim=True
|
966 |
+
) # [b, 1, t_s]
|
967 |
+
neg_cent2 = torch.matmul(
|
968 |
+
-0.5 * (z_p**2).transpose(1, 2), s_p_sq_r
|
969 |
+
) # [b, t_t, d] x [b, d, t_s] = [b, t_t, t_s]
|
970 |
+
neg_cent3 = torch.matmul(
|
971 |
+
z_p.transpose(1, 2), (m_p * s_p_sq_r)
|
972 |
+
) # [b, t_t, d] x [b, d, t_s] = [b, t_t, t_s]
|
973 |
+
neg_cent4 = torch.sum(
|
974 |
+
-0.5 * (m_p**2) * s_p_sq_r, [1], keepdim=True
|
975 |
+
) # [b, 1, t_s]
|
976 |
+
neg_cent = neg_cent1 + neg_cent2 + neg_cent3 + neg_cent4
|
977 |
+
if self.use_noise_scaled_mas:
|
978 |
+
epsilon = (
|
979 |
+
torch.std(neg_cent)
|
980 |
+
* torch.randn_like(neg_cent)
|
981 |
+
* self.current_mas_noise_scale
|
982 |
+
)
|
983 |
+
neg_cent = neg_cent + epsilon
|
984 |
+
|
985 |
+
attn_mask = torch.unsqueeze(x_mask, 2) * torch.unsqueeze(y_mask, -1)
|
986 |
+
attn = (
|
987 |
+
monotonic_align.maximum_path(neg_cent, attn_mask.squeeze(1))
|
988 |
+
.unsqueeze(1)
|
989 |
+
.detach()
|
990 |
+
)
|
991 |
+
|
992 |
+
w = attn.sum(2)
|
993 |
+
|
994 |
+
l_length_sdp = self.sdp(x, x_mask, w, g=g)
|
995 |
+
l_length_sdp = l_length_sdp / torch.sum(x_mask)
|
996 |
+
|
997 |
+
logw_ = torch.log(w + 1e-6) * x_mask
|
998 |
+
logw = self.dp(x, x_mask, g=g)
|
999 |
+
l_length_dp = torch.sum((logw - logw_) ** 2, [1, 2]) / torch.sum(
|
1000 |
+
x_mask
|
1001 |
+
) # for averaging
|
1002 |
+
|
1003 |
+
l_length = l_length_dp + l_length_sdp
|
1004 |
+
|
1005 |
+
# expand prior
|
1006 |
+
m_p = torch.matmul(attn.squeeze(1), m_p.transpose(1, 2)).transpose(1, 2)
|
1007 |
+
logs_p = torch.matmul(attn.squeeze(1), logs_p.transpose(1, 2)).transpose(1, 2)
|
1008 |
+
|
1009 |
+
z_slice, ids_slice = commons.rand_slice_segments(
|
1010 |
+
z, y_lengths, self.segment_size
|
1011 |
+
)
|
1012 |
+
o = self.dec(z_slice, g=g)
|
1013 |
+
return (
|
1014 |
+
o,
|
1015 |
+
l_length,
|
1016 |
+
attn,
|
1017 |
+
ids_slice,
|
1018 |
+
x_mask,
|
1019 |
+
y_mask,
|
1020 |
+
(z, z_p, m_p, logs_p, m_q, logs_q),
|
1021 |
+
(x, logw, logw_),
|
1022 |
+
g,
|
1023 |
+
loss_commit,
|
1024 |
+
)
|
1025 |
+
|
1026 |
+
def infer(
|
1027 |
+
self,
|
1028 |
+
x,
|
1029 |
+
x_lengths,
|
1030 |
+
sid,
|
1031 |
+
tone,
|
1032 |
+
language,
|
1033 |
+
bert,
|
1034 |
+
ja_bert,
|
1035 |
+
en_bert,
|
1036 |
+
emo=None,
|
1037 |
+
noise_scale=0.667,
|
1038 |
+
length_scale=1,
|
1039 |
+
noise_scale_w=0.8,
|
1040 |
+
max_len=None,
|
1041 |
+
sdp_ratio=0,
|
1042 |
+
y=None,
|
1043 |
+
):
|
1044 |
+
# x, m_p, logs_p, x_mask = self.enc_p(x, x_lengths, tone, language, bert)
|
1045 |
+
# g = self.gst(y)
|
1046 |
+
if self.n_speakers > 0:
|
1047 |
+
g = self.emb_g(sid).unsqueeze(-1) # [b, h, 1]
|
1048 |
+
else:
|
1049 |
+
g = self.ref_enc(y.transpose(1, 2)).unsqueeze(-1)
|
1050 |
+
x, m_p, logs_p, x_mask, _ = self.enc_p(
|
1051 |
+
x, x_lengths, tone, language, bert, ja_bert, en_bert, emo, sid, g=g
|
1052 |
+
)
|
1053 |
+
logw = self.sdp(x, x_mask, g=g, reverse=True, noise_scale=noise_scale_w) * (
|
1054 |
+
sdp_ratio
|
1055 |
+
) + self.dp(x, x_mask, g=g) * (1 - sdp_ratio)
|
1056 |
+
w = torch.exp(logw) * x_mask * length_scale
|
1057 |
+
w_ceil = torch.ceil(w)
|
1058 |
+
y_lengths = torch.clamp_min(torch.sum(w_ceil, [1, 2]), 1).long()
|
1059 |
+
y_mask = torch.unsqueeze(commons.sequence_mask(y_lengths, None), 1).to(
|
1060 |
+
x_mask.dtype
|
1061 |
+
)
|
1062 |
+
attn_mask = torch.unsqueeze(x_mask, 2) * torch.unsqueeze(y_mask, -1)
|
1063 |
+
attn = commons.generate_path(w_ceil, attn_mask)
|
1064 |
+
|
1065 |
+
m_p = torch.matmul(attn.squeeze(1), m_p.transpose(1, 2)).transpose(
|
1066 |
+
1, 2
|
1067 |
+
) # [b, t', t], [b, t, d] -> [b, d, t']
|
1068 |
+
logs_p = torch.matmul(attn.squeeze(1), logs_p.transpose(1, 2)).transpose(
|
1069 |
+
1, 2
|
1070 |
+
) # [b, t', t], [b, t, d] -> [b, d, t']
|
1071 |
+
|
1072 |
+
z_p = m_p + torch.randn_like(m_p) * torch.exp(logs_p) * noise_scale
|
1073 |
+
z = self.flow(z_p, y_mask, g=g, reverse=True)
|
1074 |
+
o = self.dec((z * y_mask)[:, :, :max_len], g=g)
|
1075 |
+
return o, attn, y_mask, (z, z_p, m_p, logs_p)
|
modules.py
ADDED
@@ -0,0 +1,597 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch import nn
|
4 |
+
from torch.nn import functional as F
|
5 |
+
|
6 |
+
from torch.nn import Conv1d
|
7 |
+
from torch.nn.utils import weight_norm, remove_weight_norm
|
8 |
+
|
9 |
+
import commons
|
10 |
+
from commons import init_weights, get_padding
|
11 |
+
from transforms import piecewise_rational_quadratic_transform
|
12 |
+
from attentions import Encoder
|
13 |
+
|
14 |
+
LRELU_SLOPE = 0.1
|
15 |
+
|
16 |
+
|
17 |
+
class LayerNorm(nn.Module):
|
18 |
+
def __init__(self, channels, eps=1e-5):
|
19 |
+
super().__init__()
|
20 |
+
self.channels = channels
|
21 |
+
self.eps = eps
|
22 |
+
|
23 |
+
self.gamma = nn.Parameter(torch.ones(channels))
|
24 |
+
self.beta = nn.Parameter(torch.zeros(channels))
|
25 |
+
|
26 |
+
def forward(self, x):
|
27 |
+
x = x.transpose(1, -1)
|
28 |
+
x = F.layer_norm(x, (self.channels,), self.gamma, self.beta, self.eps)
|
29 |
+
return x.transpose(1, -1)
|
30 |
+
|
31 |
+
|
32 |
+
class ConvReluNorm(nn.Module):
|
33 |
+
def __init__(
|
34 |
+
self,
|
35 |
+
in_channels,
|
36 |
+
hidden_channels,
|
37 |
+
out_channels,
|
38 |
+
kernel_size,
|
39 |
+
n_layers,
|
40 |
+
p_dropout,
|
41 |
+
):
|
42 |
+
super().__init__()
|
43 |
+
self.in_channels = in_channels
|
44 |
+
self.hidden_channels = hidden_channels
|
45 |
+
self.out_channels = out_channels
|
46 |
+
self.kernel_size = kernel_size
|
47 |
+
self.n_layers = n_layers
|
48 |
+
self.p_dropout = p_dropout
|
49 |
+
assert n_layers > 1, "Number of layers should be larger than 0."
|
50 |
+
|
51 |
+
self.conv_layers = nn.ModuleList()
|
52 |
+
self.norm_layers = nn.ModuleList()
|
53 |
+
self.conv_layers.append(
|
54 |
+
nn.Conv1d(
|
55 |
+
in_channels, hidden_channels, kernel_size, padding=kernel_size // 2
|
56 |
+
)
|
57 |
+
)
|
58 |
+
self.norm_layers.append(LayerNorm(hidden_channels))
|
59 |
+
self.relu_drop = nn.Sequential(nn.ReLU(), nn.Dropout(p_dropout))
|
60 |
+
for _ in range(n_layers - 1):
|
61 |
+
self.conv_layers.append(
|
62 |
+
nn.Conv1d(
|
63 |
+
hidden_channels,
|
64 |
+
hidden_channels,
|
65 |
+
kernel_size,
|
66 |
+
padding=kernel_size // 2,
|
67 |
+
)
|
68 |
+
)
|
69 |
+
self.norm_layers.append(LayerNorm(hidden_channels))
|
70 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels, 1)
|
71 |
+
self.proj.weight.data.zero_()
|
72 |
+
self.proj.bias.data.zero_()
|
73 |
+
|
74 |
+
def forward(self, x, x_mask):
|
75 |
+
x_org = x
|
76 |
+
for i in range(self.n_layers):
|
77 |
+
x = self.conv_layers[i](x * x_mask)
|
78 |
+
x = self.norm_layers[i](x)
|
79 |
+
x = self.relu_drop(x)
|
80 |
+
x = x_org + self.proj(x)
|
81 |
+
return x * x_mask
|
82 |
+
|
83 |
+
|
84 |
+
class DDSConv(nn.Module):
|
85 |
+
"""
|
86 |
+
Dialted and Depth-Separable Convolution
|
87 |
+
"""
|
88 |
+
|
89 |
+
def __init__(self, channels, kernel_size, n_layers, p_dropout=0.0):
|
90 |
+
super().__init__()
|
91 |
+
self.channels = channels
|
92 |
+
self.kernel_size = kernel_size
|
93 |
+
self.n_layers = n_layers
|
94 |
+
self.p_dropout = p_dropout
|
95 |
+
|
96 |
+
self.drop = nn.Dropout(p_dropout)
|
97 |
+
self.convs_sep = nn.ModuleList()
|
98 |
+
self.convs_1x1 = nn.ModuleList()
|
99 |
+
self.norms_1 = nn.ModuleList()
|
100 |
+
self.norms_2 = nn.ModuleList()
|
101 |
+
for i in range(n_layers):
|
102 |
+
dilation = kernel_size**i
|
103 |
+
padding = (kernel_size * dilation - dilation) // 2
|
104 |
+
self.convs_sep.append(
|
105 |
+
nn.Conv1d(
|
106 |
+
channels,
|
107 |
+
channels,
|
108 |
+
kernel_size,
|
109 |
+
groups=channels,
|
110 |
+
dilation=dilation,
|
111 |
+
padding=padding,
|
112 |
+
)
|
113 |
+
)
|
114 |
+
self.convs_1x1.append(nn.Conv1d(channels, channels, 1))
|
115 |
+
self.norms_1.append(LayerNorm(channels))
|
116 |
+
self.norms_2.append(LayerNorm(channels))
|
117 |
+
|
118 |
+
def forward(self, x, x_mask, g=None):
|
119 |
+
if g is not None:
|
120 |
+
x = x + g
|
121 |
+
for i in range(self.n_layers):
|
122 |
+
y = self.convs_sep[i](x * x_mask)
|
123 |
+
y = self.norms_1[i](y)
|
124 |
+
y = F.gelu(y)
|
125 |
+
y = self.convs_1x1[i](y)
|
126 |
+
y = self.norms_2[i](y)
|
127 |
+
y = F.gelu(y)
|
128 |
+
y = self.drop(y)
|
129 |
+
x = x + y
|
130 |
+
return x * x_mask
|
131 |
+
|
132 |
+
|
133 |
+
class WN(torch.nn.Module):
|
134 |
+
def __init__(
|
135 |
+
self,
|
136 |
+
hidden_channels,
|
137 |
+
kernel_size,
|
138 |
+
dilation_rate,
|
139 |
+
n_layers,
|
140 |
+
gin_channels=0,
|
141 |
+
p_dropout=0,
|
142 |
+
):
|
143 |
+
super(WN, self).__init__()
|
144 |
+
assert kernel_size % 2 == 1
|
145 |
+
self.hidden_channels = hidden_channels
|
146 |
+
self.kernel_size = (kernel_size,)
|
147 |
+
self.dilation_rate = dilation_rate
|
148 |
+
self.n_layers = n_layers
|
149 |
+
self.gin_channels = gin_channels
|
150 |
+
self.p_dropout = p_dropout
|
151 |
+
|
152 |
+
self.in_layers = torch.nn.ModuleList()
|
153 |
+
self.res_skip_layers = torch.nn.ModuleList()
|
154 |
+
self.drop = nn.Dropout(p_dropout)
|
155 |
+
|
156 |
+
if gin_channels != 0:
|
157 |
+
cond_layer = torch.nn.Conv1d(
|
158 |
+
gin_channels, 2 * hidden_channels * n_layers, 1
|
159 |
+
)
|
160 |
+
self.cond_layer = torch.nn.utils.weight_norm(cond_layer, name="weight")
|
161 |
+
|
162 |
+
for i in range(n_layers):
|
163 |
+
dilation = dilation_rate**i
|
164 |
+
padding = int((kernel_size * dilation - dilation) / 2)
|
165 |
+
in_layer = torch.nn.Conv1d(
|
166 |
+
hidden_channels,
|
167 |
+
2 * hidden_channels,
|
168 |
+
kernel_size,
|
169 |
+
dilation=dilation,
|
170 |
+
padding=padding,
|
171 |
+
)
|
172 |
+
in_layer = torch.nn.utils.weight_norm(in_layer, name="weight")
|
173 |
+
self.in_layers.append(in_layer)
|
174 |
+
|
175 |
+
# last one is not necessary
|
176 |
+
if i < n_layers - 1:
|
177 |
+
res_skip_channels = 2 * hidden_channels
|
178 |
+
else:
|
179 |
+
res_skip_channels = hidden_channels
|
180 |
+
|
181 |
+
res_skip_layer = torch.nn.Conv1d(hidden_channels, res_skip_channels, 1)
|
182 |
+
res_skip_layer = torch.nn.utils.weight_norm(res_skip_layer, name="weight")
|
183 |
+
self.res_skip_layers.append(res_skip_layer)
|
184 |
+
|
185 |
+
def forward(self, x, x_mask, g=None, **kwargs):
|
186 |
+
output = torch.zeros_like(x)
|
187 |
+
n_channels_tensor = torch.IntTensor([self.hidden_channels])
|
188 |
+
|
189 |
+
if g is not None:
|
190 |
+
g = self.cond_layer(g)
|
191 |
+
|
192 |
+
for i in range(self.n_layers):
|
193 |
+
x_in = self.in_layers[i](x)
|
194 |
+
if g is not None:
|
195 |
+
cond_offset = i * 2 * self.hidden_channels
|
196 |
+
g_l = g[:, cond_offset : cond_offset + 2 * self.hidden_channels, :]
|
197 |
+
else:
|
198 |
+
g_l = torch.zeros_like(x_in)
|
199 |
+
|
200 |
+
acts = commons.fused_add_tanh_sigmoid_multiply(x_in, g_l, n_channels_tensor)
|
201 |
+
acts = self.drop(acts)
|
202 |
+
|
203 |
+
res_skip_acts = self.res_skip_layers[i](acts)
|
204 |
+
if i < self.n_layers - 1:
|
205 |
+
res_acts = res_skip_acts[:, : self.hidden_channels, :]
|
206 |
+
x = (x + res_acts) * x_mask
|
207 |
+
output = output + res_skip_acts[:, self.hidden_channels :, :]
|
208 |
+
else:
|
209 |
+
output = output + res_skip_acts
|
210 |
+
return output * x_mask
|
211 |
+
|
212 |
+
def remove_weight_norm(self):
|
213 |
+
if self.gin_channels != 0:
|
214 |
+
torch.nn.utils.remove_weight_norm(self.cond_layer)
|
215 |
+
for l in self.in_layers:
|
216 |
+
torch.nn.utils.remove_weight_norm(l)
|
217 |
+
for l in self.res_skip_layers:
|
218 |
+
torch.nn.utils.remove_weight_norm(l)
|
219 |
+
|
220 |
+
|
221 |
+
class ResBlock1(torch.nn.Module):
|
222 |
+
def __init__(self, channels, kernel_size=3, dilation=(1, 3, 5)):
|
223 |
+
super(ResBlock1, self).__init__()
|
224 |
+
self.convs1 = nn.ModuleList(
|
225 |
+
[
|
226 |
+
weight_norm(
|
227 |
+
Conv1d(
|
228 |
+
channels,
|
229 |
+
channels,
|
230 |
+
kernel_size,
|
231 |
+
1,
|
232 |
+
dilation=dilation[0],
|
233 |
+
padding=get_padding(kernel_size, dilation[0]),
|
234 |
+
)
|
235 |
+
),
|
236 |
+
weight_norm(
|
237 |
+
Conv1d(
|
238 |
+
channels,
|
239 |
+
channels,
|
240 |
+
kernel_size,
|
241 |
+
1,
|
242 |
+
dilation=dilation[1],
|
243 |
+
padding=get_padding(kernel_size, dilation[1]),
|
244 |
+
)
|
245 |
+
),
|
246 |
+
weight_norm(
|
247 |
+
Conv1d(
|
248 |
+
channels,
|
249 |
+
channels,
|
250 |
+
kernel_size,
|
251 |
+
1,
|
252 |
+
dilation=dilation[2],
|
253 |
+
padding=get_padding(kernel_size, dilation[2]),
|
254 |
+
)
|
255 |
+
),
|
256 |
+
]
|
257 |
+
)
|
258 |
+
self.convs1.apply(init_weights)
|
259 |
+
|
260 |
+
self.convs2 = nn.ModuleList(
|
261 |
+
[
|
262 |
+
weight_norm(
|
263 |
+
Conv1d(
|
264 |
+
channels,
|
265 |
+
channels,
|
266 |
+
kernel_size,
|
267 |
+
1,
|
268 |
+
dilation=1,
|
269 |
+
padding=get_padding(kernel_size, 1),
|
270 |
+
)
|
271 |
+
),
|
272 |
+
weight_norm(
|
273 |
+
Conv1d(
|
274 |
+
channels,
|
275 |
+
channels,
|
276 |
+
kernel_size,
|
277 |
+
1,
|
278 |
+
dilation=1,
|
279 |
+
padding=get_padding(kernel_size, 1),
|
280 |
+
)
|
281 |
+
),
|
282 |
+
weight_norm(
|
283 |
+
Conv1d(
|
284 |
+
channels,
|
285 |
+
channels,
|
286 |
+
kernel_size,
|
287 |
+
1,
|
288 |
+
dilation=1,
|
289 |
+
padding=get_padding(kernel_size, 1),
|
290 |
+
)
|
291 |
+
),
|
292 |
+
]
|
293 |
+
)
|
294 |
+
self.convs2.apply(init_weights)
|
295 |
+
|
296 |
+
def forward(self, x, x_mask=None):
|
297 |
+
for c1, c2 in zip(self.convs1, self.convs2):
|
298 |
+
xt = F.leaky_relu(x, LRELU_SLOPE)
|
299 |
+
if x_mask is not None:
|
300 |
+
xt = xt * x_mask
|
301 |
+
xt = c1(xt)
|
302 |
+
xt = F.leaky_relu(xt, LRELU_SLOPE)
|
303 |
+
if x_mask is not None:
|
304 |
+
xt = xt * x_mask
|
305 |
+
xt = c2(xt)
|
306 |
+
x = xt + x
|
307 |
+
if x_mask is not None:
|
308 |
+
x = x * x_mask
|
309 |
+
return x
|
310 |
+
|
311 |
+
def remove_weight_norm(self):
|
312 |
+
for l in self.convs1:
|
313 |
+
remove_weight_norm(l)
|
314 |
+
for l in self.convs2:
|
315 |
+
remove_weight_norm(l)
|
316 |
+
|
317 |
+
|
318 |
+
class ResBlock2(torch.nn.Module):
|
319 |
+
def __init__(self, channels, kernel_size=3, dilation=(1, 3)):
|
320 |
+
super(ResBlock2, self).__init__()
|
321 |
+
self.convs = nn.ModuleList(
|
322 |
+
[
|
323 |
+
weight_norm(
|
324 |
+
Conv1d(
|
325 |
+
channels,
|
326 |
+
channels,
|
327 |
+
kernel_size,
|
328 |
+
1,
|
329 |
+
dilation=dilation[0],
|
330 |
+
padding=get_padding(kernel_size, dilation[0]),
|
331 |
+
)
|
332 |
+
),
|
333 |
+
weight_norm(
|
334 |
+
Conv1d(
|
335 |
+
channels,
|
336 |
+
channels,
|
337 |
+
kernel_size,
|
338 |
+
1,
|
339 |
+
dilation=dilation[1],
|
340 |
+
padding=get_padding(kernel_size, dilation[1]),
|
341 |
+
)
|
342 |
+
),
|
343 |
+
]
|
344 |
+
)
|
345 |
+
self.convs.apply(init_weights)
|
346 |
+
|
347 |
+
def forward(self, x, x_mask=None):
|
348 |
+
for c in self.convs:
|
349 |
+
xt = F.leaky_relu(x, LRELU_SLOPE)
|
350 |
+
if x_mask is not None:
|
351 |
+
xt = xt * x_mask
|
352 |
+
xt = c(xt)
|
353 |
+
x = xt + x
|
354 |
+
if x_mask is not None:
|
355 |
+
x = x * x_mask
|
356 |
+
return x
|
357 |
+
|
358 |
+
def remove_weight_norm(self):
|
359 |
+
for l in self.convs:
|
360 |
+
remove_weight_norm(l)
|
361 |
+
|
362 |
+
|
363 |
+
class Log(nn.Module):
|
364 |
+
def forward(self, x, x_mask, reverse=False, **kwargs):
|
365 |
+
if not reverse:
|
366 |
+
y = torch.log(torch.clamp_min(x, 1e-5)) * x_mask
|
367 |
+
logdet = torch.sum(-y, [1, 2])
|
368 |
+
return y, logdet
|
369 |
+
else:
|
370 |
+
x = torch.exp(x) * x_mask
|
371 |
+
return x
|
372 |
+
|
373 |
+
|
374 |
+
class Flip(nn.Module):
|
375 |
+
def forward(self, x, *args, reverse=False, **kwargs):
|
376 |
+
x = torch.flip(x, [1])
|
377 |
+
if not reverse:
|
378 |
+
logdet = torch.zeros(x.size(0)).to(dtype=x.dtype, device=x.device)
|
379 |
+
return x, logdet
|
380 |
+
else:
|
381 |
+
return x
|
382 |
+
|
383 |
+
|
384 |
+
class ElementwiseAffine(nn.Module):
|
385 |
+
def __init__(self, channels):
|
386 |
+
super().__init__()
|
387 |
+
self.channels = channels
|
388 |
+
self.m = nn.Parameter(torch.zeros(channels, 1))
|
389 |
+
self.logs = nn.Parameter(torch.zeros(channels, 1))
|
390 |
+
|
391 |
+
def forward(self, x, x_mask, reverse=False, **kwargs):
|
392 |
+
if not reverse:
|
393 |
+
y = self.m + torch.exp(self.logs) * x
|
394 |
+
y = y * x_mask
|
395 |
+
logdet = torch.sum(self.logs * x_mask, [1, 2])
|
396 |
+
return y, logdet
|
397 |
+
else:
|
398 |
+
x = (x - self.m) * torch.exp(-self.logs) * x_mask
|
399 |
+
return x
|
400 |
+
|
401 |
+
|
402 |
+
class ResidualCouplingLayer(nn.Module):
|
403 |
+
def __init__(
|
404 |
+
self,
|
405 |
+
channels,
|
406 |
+
hidden_channels,
|
407 |
+
kernel_size,
|
408 |
+
dilation_rate,
|
409 |
+
n_layers,
|
410 |
+
p_dropout=0,
|
411 |
+
gin_channels=0,
|
412 |
+
mean_only=False,
|
413 |
+
):
|
414 |
+
assert channels % 2 == 0, "channels should be divisible by 2"
|
415 |
+
super().__init__()
|
416 |
+
self.channels = channels
|
417 |
+
self.hidden_channels = hidden_channels
|
418 |
+
self.kernel_size = kernel_size
|
419 |
+
self.dilation_rate = dilation_rate
|
420 |
+
self.n_layers = n_layers
|
421 |
+
self.half_channels = channels // 2
|
422 |
+
self.mean_only = mean_only
|
423 |
+
|
424 |
+
self.pre = nn.Conv1d(self.half_channels, hidden_channels, 1)
|
425 |
+
self.enc = WN(
|
426 |
+
hidden_channels,
|
427 |
+
kernel_size,
|
428 |
+
dilation_rate,
|
429 |
+
n_layers,
|
430 |
+
p_dropout=p_dropout,
|
431 |
+
gin_channels=gin_channels,
|
432 |
+
)
|
433 |
+
self.post = nn.Conv1d(hidden_channels, self.half_channels * (2 - mean_only), 1)
|
434 |
+
self.post.weight.data.zero_()
|
435 |
+
self.post.bias.data.zero_()
|
436 |
+
|
437 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
438 |
+
x0, x1 = torch.split(x, [self.half_channels] * 2, 1)
|
439 |
+
h = self.pre(x0) * x_mask
|
440 |
+
h = self.enc(h, x_mask, g=g)
|
441 |
+
stats = self.post(h) * x_mask
|
442 |
+
if not self.mean_only:
|
443 |
+
m, logs = torch.split(stats, [self.half_channels] * 2, 1)
|
444 |
+
else:
|
445 |
+
m = stats
|
446 |
+
logs = torch.zeros_like(m)
|
447 |
+
|
448 |
+
if not reverse:
|
449 |
+
x1 = m + x1 * torch.exp(logs) * x_mask
|
450 |
+
x = torch.cat([x0, x1], 1)
|
451 |
+
logdet = torch.sum(logs, [1, 2])
|
452 |
+
return x, logdet
|
453 |
+
else:
|
454 |
+
x1 = (x1 - m) * torch.exp(-logs) * x_mask
|
455 |
+
x = torch.cat([x0, x1], 1)
|
456 |
+
return x
|
457 |
+
|
458 |
+
|
459 |
+
class ConvFlow(nn.Module):
|
460 |
+
def __init__(
|
461 |
+
self,
|
462 |
+
in_channels,
|
463 |
+
filter_channels,
|
464 |
+
kernel_size,
|
465 |
+
n_layers,
|
466 |
+
num_bins=10,
|
467 |
+
tail_bound=5.0,
|
468 |
+
):
|
469 |
+
super().__init__()
|
470 |
+
self.in_channels = in_channels
|
471 |
+
self.filter_channels = filter_channels
|
472 |
+
self.kernel_size = kernel_size
|
473 |
+
self.n_layers = n_layers
|
474 |
+
self.num_bins = num_bins
|
475 |
+
self.tail_bound = tail_bound
|
476 |
+
self.half_channels = in_channels // 2
|
477 |
+
|
478 |
+
self.pre = nn.Conv1d(self.half_channels, filter_channels, 1)
|
479 |
+
self.convs = DDSConv(filter_channels, kernel_size, n_layers, p_dropout=0.0)
|
480 |
+
self.proj = nn.Conv1d(
|
481 |
+
filter_channels, self.half_channels * (num_bins * 3 - 1), 1
|
482 |
+
)
|
483 |
+
self.proj.weight.data.zero_()
|
484 |
+
self.proj.bias.data.zero_()
|
485 |
+
|
486 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
487 |
+
x0, x1 = torch.split(x, [self.half_channels] * 2, 1)
|
488 |
+
h = self.pre(x0)
|
489 |
+
h = self.convs(h, x_mask, g=g)
|
490 |
+
h = self.proj(h) * x_mask
|
491 |
+
|
492 |
+
b, c, t = x0.shape
|
493 |
+
h = h.reshape(b, c, -1, t).permute(0, 1, 3, 2) # [b, cx?, t] -> [b, c, t, ?]
|
494 |
+
|
495 |
+
unnormalized_widths = h[..., : self.num_bins] / math.sqrt(self.filter_channels)
|
496 |
+
unnormalized_heights = h[..., self.num_bins : 2 * self.num_bins] / math.sqrt(
|
497 |
+
self.filter_channels
|
498 |
+
)
|
499 |
+
unnormalized_derivatives = h[..., 2 * self.num_bins :]
|
500 |
+
|
501 |
+
x1, logabsdet = piecewise_rational_quadratic_transform(
|
502 |
+
x1,
|
503 |
+
unnormalized_widths,
|
504 |
+
unnormalized_heights,
|
505 |
+
unnormalized_derivatives,
|
506 |
+
inverse=reverse,
|
507 |
+
tails="linear",
|
508 |
+
tail_bound=self.tail_bound,
|
509 |
+
)
|
510 |
+
|
511 |
+
x = torch.cat([x0, x1], 1) * x_mask
|
512 |
+
logdet = torch.sum(logabsdet * x_mask, [1, 2])
|
513 |
+
if not reverse:
|
514 |
+
return x, logdet
|
515 |
+
else:
|
516 |
+
return x
|
517 |
+
|
518 |
+
|
519 |
+
class TransformerCouplingLayer(nn.Module):
|
520 |
+
def __init__(
|
521 |
+
self,
|
522 |
+
channels,
|
523 |
+
hidden_channels,
|
524 |
+
kernel_size,
|
525 |
+
n_layers,
|
526 |
+
n_heads,
|
527 |
+
p_dropout=0,
|
528 |
+
filter_channels=0,
|
529 |
+
mean_only=False,
|
530 |
+
wn_sharing_parameter=None,
|
531 |
+
gin_channels=0,
|
532 |
+
):
|
533 |
+
assert channels % 2 == 0, "channels should be divisible by 2"
|
534 |
+
super().__init__()
|
535 |
+
self.channels = channels
|
536 |
+
self.hidden_channels = hidden_channels
|
537 |
+
self.kernel_size = kernel_size
|
538 |
+
self.n_layers = n_layers
|
539 |
+
self.half_channels = channels // 2
|
540 |
+
self.mean_only = mean_only
|
541 |
+
|
542 |
+
self.pre = nn.Conv1d(self.half_channels, hidden_channels, 1)
|
543 |
+
self.enc = (
|
544 |
+
Encoder(
|
545 |
+
hidden_channels,
|
546 |
+
filter_channels,
|
547 |
+
n_heads,
|
548 |
+
n_layers,
|
549 |
+
kernel_size,
|
550 |
+
p_dropout,
|
551 |
+
isflow=True,
|
552 |
+
gin_channels=gin_channels,
|
553 |
+
)
|
554 |
+
if wn_sharing_parameter is None
|
555 |
+
else wn_sharing_parameter
|
556 |
+
)
|
557 |
+
self.post = nn.Conv1d(hidden_channels, self.half_channels * (2 - mean_only), 1)
|
558 |
+
self.post.weight.data.zero_()
|
559 |
+
self.post.bias.data.zero_()
|
560 |
+
|
561 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
562 |
+
x0, x1 = torch.split(x, [self.half_channels] * 2, 1)
|
563 |
+
h = self.pre(x0) * x_mask
|
564 |
+
h = self.enc(h, x_mask, g=g)
|
565 |
+
stats = self.post(h) * x_mask
|
566 |
+
if not self.mean_only:
|
567 |
+
m, logs = torch.split(stats, [self.half_channels] * 2, 1)
|
568 |
+
else:
|
569 |
+
m = stats
|
570 |
+
logs = torch.zeros_like(m)
|
571 |
+
|
572 |
+
if not reverse:
|
573 |
+
x1 = m + x1 * torch.exp(logs) * x_mask
|
574 |
+
x = torch.cat([x0, x1], 1)
|
575 |
+
logdet = torch.sum(logs, [1, 2])
|
576 |
+
return x, logdet
|
577 |
+
else:
|
578 |
+
x1 = (x1 - m) * torch.exp(-logs) * x_mask
|
579 |
+
x = torch.cat([x0, x1], 1)
|
580 |
+
return x
|
581 |
+
|
582 |
+
x1, logabsdet = piecewise_rational_quadratic_transform(
|
583 |
+
x1,
|
584 |
+
unnormalized_widths,
|
585 |
+
unnormalized_heights,
|
586 |
+
unnormalized_derivatives,
|
587 |
+
inverse=reverse,
|
588 |
+
tails="linear",
|
589 |
+
tail_bound=self.tail_bound,
|
590 |
+
)
|
591 |
+
|
592 |
+
x = torch.cat([x0, x1], 1) * x_mask
|
593 |
+
logdet = torch.sum(logabsdet * x_mask, [1, 2])
|
594 |
+
if not reverse:
|
595 |
+
return x, logdet
|
596 |
+
else:
|
597 |
+
return x
|
monotonic_align/__init__.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from numpy import zeros, int32, float32
|
2 |
+
from torch import from_numpy
|
3 |
+
|
4 |
+
from .core import maximum_path_jit
|
5 |
+
|
6 |
+
|
7 |
+
def maximum_path(neg_cent, mask):
|
8 |
+
device = neg_cent.device
|
9 |
+
dtype = neg_cent.dtype
|
10 |
+
neg_cent = neg_cent.data.cpu().numpy().astype(float32)
|
11 |
+
path = zeros(neg_cent.shape, dtype=int32)
|
12 |
+
|
13 |
+
t_t_max = mask.sum(1)[:, 0].data.cpu().numpy().astype(int32)
|
14 |
+
t_s_max = mask.sum(2)[:, 0].data.cpu().numpy().astype(int32)
|
15 |
+
maximum_path_jit(path, neg_cent, t_t_max, t_s_max)
|
16 |
+
return from_numpy(path).to(device=device, dtype=dtype)
|
monotonic_align/core.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numba
|
2 |
+
|
3 |
+
|
4 |
+
@numba.jit(
|
5 |
+
numba.void(
|
6 |
+
numba.int32[:, :, ::1],
|
7 |
+
numba.float32[:, :, ::1],
|
8 |
+
numba.int32[::1],
|
9 |
+
numba.int32[::1],
|
10 |
+
),
|
11 |
+
nopython=True,
|
12 |
+
nogil=True,
|
13 |
+
)
|
14 |
+
def maximum_path_jit(paths, values, t_ys, t_xs):
|
15 |
+
b = paths.shape[0]
|
16 |
+
max_neg_val = -1e9
|
17 |
+
for i in range(int(b)):
|
18 |
+
path = paths[i]
|
19 |
+
value = values[i]
|
20 |
+
t_y = t_ys[i]
|
21 |
+
t_x = t_xs[i]
|
22 |
+
|
23 |
+
v_prev = v_cur = 0.0
|
24 |
+
index = t_x - 1
|
25 |
+
|
26 |
+
for y in range(t_y):
|
27 |
+
for x in range(max(0, t_x + y - t_y), min(t_x, y + 1)):
|
28 |
+
if x == y:
|
29 |
+
v_cur = max_neg_val
|
30 |
+
else:
|
31 |
+
v_cur = value[y - 1, x]
|
32 |
+
if x == 0:
|
33 |
+
if y == 0:
|
34 |
+
v_prev = 0.0
|
35 |
+
else:
|
36 |
+
v_prev = max_neg_val
|
37 |
+
else:
|
38 |
+
v_prev = value[y - 1, x - 1]
|
39 |
+
value[y, x] += max(v_prev, v_cur)
|
40 |
+
|
41 |
+
for y in range(t_y - 1, -1, -1):
|
42 |
+
path[y, index] = 1
|
43 |
+
if index != 0 and (
|
44 |
+
index == y or value[y - 1, index] < value[y - 1, index - 1]
|
45 |
+
):
|
46 |
+
index = index - 1
|
nltk_data/corpora/cmudict/README
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
The Carnegie Mellon Pronouncing Dictionary [cmudict.0.7a]
|
2 |
+
|
3 |
+
ftp://ftp.cs.cmu.edu/project/speech/dict/
|
4 |
+
https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/cmudict/cmudict.0.7a
|
5 |
+
|
6 |
+
Copyright (C) 1993-2008 Carnegie Mellon University. All rights reserved.
|
7 |
+
|
8 |
+
File Format: Each line consists of an uppercased word,
|
9 |
+
a counter (for alternative pronunciations), and a transcription.
|
10 |
+
Vowels are marked for stress (1=primary, 2=secondary, 0=no stress).
|
11 |
+
E.g.: NATURAL 1 N AE1 CH ER0 AH0 L
|
12 |
+
|
13 |
+
The dictionary contains 127069 entries. Of these, 119400 words are assigned
|
14 |
+
a unique pronunciation, 6830 words have two pronunciations, and 839 words have
|
15 |
+
three or more pronunciations. Many of these are fast-speech variants.
|
16 |
+
|
17 |
+
Phonemes: There are 39 phonemes, as shown below:
|
18 |
+
|
19 |
+
Phoneme Example Translation Phoneme Example Translation
|
20 |
+
------- ------- ----------- ------- ------- -----------
|
21 |
+
AA odd AA D AE at AE T
|
22 |
+
AH hut HH AH T AO ought AO T
|
23 |
+
AW cow K AW AY hide HH AY D
|
24 |
+
B be B IY CH cheese CH IY Z
|
25 |
+
D dee D IY DH thee DH IY
|
26 |
+
EH Ed EH D ER hurt HH ER T
|
27 |
+
EY ate EY T F fee F IY
|
28 |
+
G green G R IY N HH he HH IY
|
29 |
+
IH it IH T IY eat IY T
|
30 |
+
JH gee JH IY K key K IY
|
31 |
+
L lee L IY M me M IY
|
32 |
+
N knee N IY NG ping P IH NG
|
33 |
+
OW oat OW T OY toy T OY
|
34 |
+
P pee P IY R read R IY D
|
35 |
+
S sea S IY SH she SH IY
|
36 |
+
T tea T IY TH theta TH EY T AH
|
37 |
+
UH hood HH UH D UW two T UW
|
38 |
+
V vee V IY W we W IY
|
39 |
+
Y yield Y IY L D Z zee Z IY
|
40 |
+
ZH seizure S IY ZH ER
|
41 |
+
|
42 |
+
(For NLTK, entries have been sorted so that, e.g. FIRE 1 and FIRE 2
|
43 |
+
are contiguous, and not separated by FIRE'S 1.)
|
44 |
+
|
45 |
+
Redistribution and use in source and binary forms, with or without
|
46 |
+
modification, are permitted provided that the following conditions
|
47 |
+
are met:
|
48 |
+
|
49 |
+
1. Redistributions of source code must retain the above copyright
|
50 |
+
notice, this list of conditions and the following disclaimer.
|
51 |
+
The contents of this file are deemed to be source code.
|
52 |
+
|
53 |
+
2. Redistributions in binary form must reproduce the above copyright
|
54 |
+
notice, this list of conditions and the following disclaimer in
|
55 |
+
the documentation and/or other materials provided with the
|
56 |
+
distribution.
|
57 |
+
|
58 |
+
This work was supported in part by funding from the Defense Advanced
|
59 |
+
Research Projects Agency, the Office of Naval Research and the National
|
60 |
+
Science Foundation of the United States of America, and by member
|
61 |
+
companies of the Carnegie Mellon Sphinx Speech Consortium. We acknowledge
|
62 |
+
the contributions of many volunteers to the expansion and improvement of
|
63 |
+
this dictionary.
|
64 |
+
|
65 |
+
THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
|
66 |
+
ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
67 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
68 |
+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
|
69 |
+
NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
70 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
71 |
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
72 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
73 |
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
74 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
75 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
76 |
+
|
nltk_data/corpora/cmudict/cmudict
ADDED
The diff for this file is too large to render.
See raw diff
|
|