Spaces:
Running
Running
Push version 1 F5-TTS-Vietnamese-100h spaces
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- app.py +1 -0
- pyproject.toml +62 -0
- requirements.txt +1 -3
- src/f5_tts.egg-info/PKG-INFO +99 -0
- src/f5_tts.egg-info/SOURCES.txt +81 -0
- src/f5_tts.egg-info/dependency_links.txt +1 -0
- src/f5_tts.egg-info/entry_points.txt +5 -0
- src/f5_tts.egg-info/requires.txt +36 -0
- src/f5_tts.egg-info/top_level.txt +1 -0
- src/f5_tts/__pycache__/api.cpython-310.pyc +0 -0
- src/f5_tts/api.py +165 -0
- src/f5_tts/configs/E2TTS_Base.yaml +49 -0
- src/f5_tts/configs/E2TTS_Small.yaml +49 -0
- src/f5_tts/configs/F5TTS_Base.yaml +52 -0
- src/f5_tts/configs/F5TTS_Small.yaml +52 -0
- src/f5_tts/configs/F5TTS_v1_Base.yaml +53 -0
- src/f5_tts/eval/README.md +52 -0
- src/f5_tts/eval/ecapa_tdnn.py +330 -0
- src/f5_tts/eval/eval_infer_batch.py +202 -0
- src/f5_tts/eval/eval_infer_batch.sh +18 -0
- src/f5_tts/eval/eval_librispeech_test_clean.py +90 -0
- src/f5_tts/eval/eval_seedtts_testset.py +89 -0
- src/f5_tts/eval/eval_utmos.py +42 -0
- src/f5_tts/eval/utils_eval.py +418 -0
- src/f5_tts/infer/README.md +154 -0
- src/f5_tts/infer/SHARED.md +174 -0
- src/f5_tts/infer/__pycache__/infer_cli.cpython-310.pyc +0 -0
- src/f5_tts/infer/__pycache__/utils_infer.cpython-310.pyc +0 -0
- src/f5_tts/infer/examples/basic/basic.toml +11 -0
- src/f5_tts/infer/examples/basic/basic_ref_en.wav +0 -0
- src/f5_tts/infer/examples/basic/basic_ref_zh.wav +0 -0
- src/f5_tts/infer/examples/multi/country.flac +0 -0
- src/f5_tts/infer/examples/multi/main.flac +0 -0
- src/f5_tts/infer/examples/multi/story.toml +20 -0
- src/f5_tts/infer/examples/multi/story.txt +1 -0
- src/f5_tts/infer/examples/multi/town.flac +0 -0
- src/f5_tts/infer/examples/vocab.txt +2545 -0
- src/f5_tts/infer/infer_cli.py +355 -0
- src/f5_tts/infer/infer_gradio.py +927 -0
- src/f5_tts/infer/speech_edit.py +200 -0
- src/f5_tts/infer/utils_infer.py +589 -0
- src/f5_tts/model/__init__.py +10 -0
- src/f5_tts/model/__pycache__/__init__.cpython-310.pyc +0 -0
- src/f5_tts/model/__pycache__/cfm.cpython-310.pyc +0 -0
- src/f5_tts/model/__pycache__/dataset.cpython-310.pyc +0 -0
- src/f5_tts/model/__pycache__/modules.cpython-310.pyc +0 -0
- src/f5_tts/model/__pycache__/trainer.cpython-310.pyc +0 -0
- src/f5_tts/model/__pycache__/utils.cpython-310.pyc +0 -0
- src/f5_tts/model/backbones/README.md +20 -0
- src/f5_tts/model/backbones/__pycache__/dit.cpython-310.pyc +0 -0
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import spaces
|
2 |
import os
|
|
|
3 |
from huggingface_hub import login
|
4 |
import gradio as gr
|
5 |
from cached_path import cached_path
|
|
|
1 |
import spaces
|
2 |
import os
|
3 |
+
os.system("pip install -e.")
|
4 |
from huggingface_hub import login
|
5 |
import gradio as gr
|
6 |
from cached_path import cached_path
|
pyproject.toml
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[build-system]
|
2 |
+
requires = ["setuptools >= 61.0", "setuptools-scm>=8.0"]
|
3 |
+
build-backend = "setuptools.build_meta"
|
4 |
+
|
5 |
+
[project]
|
6 |
+
name = "f5-tts"
|
7 |
+
version = "1.0.1"
|
8 |
+
description = "F5-TTS: A Fairytaler that Fakes Fluent and Faithful Speech with Flow Matching"
|
9 |
+
readme = "README.md"
|
10 |
+
license = {text = "MIT License"}
|
11 |
+
classifiers = [
|
12 |
+
"License :: OSI Approved :: MIT License",
|
13 |
+
"Operating System :: OS Independent",
|
14 |
+
"Programming Language :: Python :: 3",
|
15 |
+
]
|
16 |
+
dependencies = [
|
17 |
+
"accelerate>=0.33.0",
|
18 |
+
"bitsandbytes>0.37.0; platform_machine != 'arm64' and platform_system != 'Darwin'",
|
19 |
+
"cached_path",
|
20 |
+
"click",
|
21 |
+
"datasets",
|
22 |
+
"ema_pytorch>=0.5.2",
|
23 |
+
"gradio>=3.45.2",
|
24 |
+
"hydra-core>=1.3.0",
|
25 |
+
"jieba",
|
26 |
+
"librosa",
|
27 |
+
"matplotlib",
|
28 |
+
"numpy<=1.26.4",
|
29 |
+
"pydub",
|
30 |
+
"pypinyin",
|
31 |
+
"safetensors",
|
32 |
+
"soundfile",
|
33 |
+
"tomli",
|
34 |
+
"torch>=2.0.0",
|
35 |
+
"torchaudio>=2.0.0",
|
36 |
+
"torchdiffeq",
|
37 |
+
"tqdm>=4.65.0",
|
38 |
+
"transformers",
|
39 |
+
"transformers_stream_generator",
|
40 |
+
"vocos",
|
41 |
+
"wandb",
|
42 |
+
"x_transformers>=1.31.14",
|
43 |
+
]
|
44 |
+
|
45 |
+
[project.optional-dependencies]
|
46 |
+
eval = [
|
47 |
+
"faster_whisper==0.10.1",
|
48 |
+
"funasr",
|
49 |
+
"jiwer",
|
50 |
+
"modelscope",
|
51 |
+
"zhconv",
|
52 |
+
"zhon",
|
53 |
+
]
|
54 |
+
|
55 |
+
[project.urls]
|
56 |
+
Homepage = "https://github.com/SWivid/F5-TTS"
|
57 |
+
|
58 |
+
[project.scripts]
|
59 |
+
"f5-tts_infer-cli" = "f5_tts.infer.infer_cli:main"
|
60 |
+
"f5-tts_infer-gradio" = "f5_tts.infer.infer_gradio:main"
|
61 |
+
"f5-tts_finetune-cli" = "f5_tts.train.finetune_cli:main"
|
62 |
+
"f5-tts_finetune-gradio" = "f5_tts.train.finetune_gradio:main"
|
requirements.txt
CHANGED
@@ -2,7 +2,5 @@ torch
|
|
2 |
torchaudio
|
3 |
soundfile
|
4 |
transformers
|
5 |
-
f5_tts @ git+https://github.com/nguyenthienhy/F5-TTS-Vietnamese.git
|
6 |
bitsandbytes>0.37.0
|
7 |
-
vinorm
|
8 |
-
librosa
|
|
|
2 |
torchaudio
|
3 |
soundfile
|
4 |
transformers
|
|
|
5 |
bitsandbytes>0.37.0
|
6 |
+
vinorm
|
|
src/f5_tts.egg-info/PKG-INFO
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.4
|
2 |
+
Name: f5-tts
|
3 |
+
Version: 1.0.1
|
4 |
+
Summary: F5-TTS: A Fairytaler that Fakes Fluent and Faithful Speech with Flow Matching
|
5 |
+
License: MIT License
|
6 |
+
Project-URL: Homepage, https://github.com/SWivid/F5-TTS
|
7 |
+
Classifier: License :: OSI Approved :: MIT License
|
8 |
+
Classifier: Operating System :: OS Independent
|
9 |
+
Classifier: Programming Language :: Python :: 3
|
10 |
+
Description-Content-Type: text/markdown
|
11 |
+
License-File: LICENSE
|
12 |
+
Requires-Dist: accelerate>=0.33.0
|
13 |
+
Requires-Dist: bitsandbytes>0.37.0; platform_machine != "arm64" and platform_system != "Darwin"
|
14 |
+
Requires-Dist: cached_path
|
15 |
+
Requires-Dist: click
|
16 |
+
Requires-Dist: datasets
|
17 |
+
Requires-Dist: ema_pytorch>=0.5.2
|
18 |
+
Requires-Dist: gradio>=3.45.2
|
19 |
+
Requires-Dist: hydra-core>=1.3.0
|
20 |
+
Requires-Dist: jieba
|
21 |
+
Requires-Dist: librosa
|
22 |
+
Requires-Dist: matplotlib
|
23 |
+
Requires-Dist: numpy<=1.26.4
|
24 |
+
Requires-Dist: pydub
|
25 |
+
Requires-Dist: pypinyin
|
26 |
+
Requires-Dist: safetensors
|
27 |
+
Requires-Dist: soundfile
|
28 |
+
Requires-Dist: tomli
|
29 |
+
Requires-Dist: torch>=2.0.0
|
30 |
+
Requires-Dist: torchaudio>=2.0.0
|
31 |
+
Requires-Dist: torchdiffeq
|
32 |
+
Requires-Dist: tqdm>=4.65.0
|
33 |
+
Requires-Dist: transformers
|
34 |
+
Requires-Dist: transformers_stream_generator
|
35 |
+
Requires-Dist: vocos
|
36 |
+
Requires-Dist: wandb
|
37 |
+
Requires-Dist: x_transformers>=1.31.14
|
38 |
+
Provides-Extra: eval
|
39 |
+
Requires-Dist: faster_whisper==0.10.1; extra == "eval"
|
40 |
+
Requires-Dist: funasr; extra == "eval"
|
41 |
+
Requires-Dist: jiwer; extra == "eval"
|
42 |
+
Requires-Dist: modelscope; extra == "eval"
|
43 |
+
Requires-Dist: zhconv; extra == "eval"
|
44 |
+
Requires-Dist: zhon; extra == "eval"
|
45 |
+
Dynamic: license-file
|
46 |
+
|
47 |
+
# F5-TTS-Vietnamese
|
48 |
+
Fine-tuning pipline for training a Vietnamese speech synthesis model using the F5-TTS architecture.
|
49 |
+
|
50 |
+
## Installation
|
51 |
+
|
52 |
+
### Create a separate environment if needed
|
53 |
+
|
54 |
+
```bash
|
55 |
+
# Create a python 3.10 conda env (you could also use virtualenv)
|
56 |
+
conda create -n f5-tts python=3.10
|
57 |
+
conda activate f5-tts
|
58 |
+
```
|
59 |
+
|
60 |
+
### Install PyTorch
|
61 |
+
|
62 |
+
> ```bash
|
63 |
+
> # Install pytorch with your CUDA version, e.g.
|
64 |
+
> pip install torch==2.4.0+cu124 torchaudio==2.4.0+cu124 --extra-index-url https://download.pytorch.org/whl/cu124
|
65 |
+
> ```
|
66 |
+
|
67 |
+
### Install f5-tts module:
|
68 |
+
|
69 |
+
> ```bash
|
70 |
+
> cd F5-TTS-Vietnamese
|
71 |
+
> pip install -e .
|
72 |
+
> ```
|
73 |
+
|
74 |
+
### Install sox, ffmpeg
|
75 |
+
|
76 |
+
> ```bash
|
77 |
+
> sudo apt-get update
|
78 |
+
> sudo apt-get install sox ffmpeg
|
79 |
+
> ```
|
80 |
+
|
81 |
+
## Fine-tuning pipline
|
82 |
+
|
83 |
+
Steps:
|
84 |
+
|
85 |
+
- Prepare audio_name data and corresponding text
|
86 |
+
- Add vocabulary from your dataset that is not present in the pretrained model's vocabulary
|
87 |
+
- Expand the pretrained model's embedding to support the new vocabulary set
|
88 |
+
- Feature extraction
|
89 |
+
- Perform fine-tuning
|
90 |
+
|
91 |
+
```bash
|
92 |
+
bash fine-tuning.sh
|
93 |
+
```
|
94 |
+
|
95 |
+
### Inference
|
96 |
+
|
97 |
+
```bash
|
98 |
+
bash infer.sh
|
99 |
+
```
|
src/f5_tts.egg-info/SOURCES.txt
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.gitignore
|
2 |
+
.gitmodules
|
3 |
+
Dockerfile
|
4 |
+
LICENSE
|
5 |
+
README.md
|
6 |
+
check_vocab_pretrained.py
|
7 |
+
convert_sr.py
|
8 |
+
extend_embedding_pretrained.py
|
9 |
+
fine_tuning.sh
|
10 |
+
infer.sh
|
11 |
+
prepare_metadata.py
|
12 |
+
pyproject.toml
|
13 |
+
ref.wav
|
14 |
+
data/Emilia_ZH_EN_pinyin/vocab.txt
|
15 |
+
src/f5_tts/api.py
|
16 |
+
src/f5_tts/socket_client.py
|
17 |
+
src/f5_tts/socket_server.py
|
18 |
+
src/f5_tts.egg-info/PKG-INFO
|
19 |
+
src/f5_tts.egg-info/SOURCES.txt
|
20 |
+
src/f5_tts.egg-info/dependency_links.txt
|
21 |
+
src/f5_tts.egg-info/entry_points.txt
|
22 |
+
src/f5_tts.egg-info/requires.txt
|
23 |
+
src/f5_tts.egg-info/top_level.txt
|
24 |
+
src/f5_tts/configs/E2TTS_Base.yaml
|
25 |
+
src/f5_tts/configs/E2TTS_Small.yaml
|
26 |
+
src/f5_tts/configs/F5TTS_Base.yaml
|
27 |
+
src/f5_tts/configs/F5TTS_Small.yaml
|
28 |
+
src/f5_tts/configs/F5TTS_v1_Base.yaml
|
29 |
+
src/f5_tts/eval/README.md
|
30 |
+
src/f5_tts/eval/ecapa_tdnn.py
|
31 |
+
src/f5_tts/eval/eval_infer_batch.py
|
32 |
+
src/f5_tts/eval/eval_infer_batch.sh
|
33 |
+
src/f5_tts/eval/eval_librispeech_test_clean.py
|
34 |
+
src/f5_tts/eval/eval_seedtts_testset.py
|
35 |
+
src/f5_tts/eval/eval_utmos.py
|
36 |
+
src/f5_tts/eval/utils_eval.py
|
37 |
+
src/f5_tts/infer/README.md
|
38 |
+
src/f5_tts/infer/SHARED.md
|
39 |
+
src/f5_tts/infer/infer_cli.py
|
40 |
+
src/f5_tts/infer/infer_gradio.py
|
41 |
+
src/f5_tts/infer/speech_edit.py
|
42 |
+
src/f5_tts/infer/utils_infer.py
|
43 |
+
src/f5_tts/infer/examples/vocab.txt
|
44 |
+
src/f5_tts/infer/examples/basic/basic.toml
|
45 |
+
src/f5_tts/infer/examples/basic/basic_ref_en.wav
|
46 |
+
src/f5_tts/infer/examples/basic/basic_ref_zh.wav
|
47 |
+
src/f5_tts/infer/examples/multi/country.flac
|
48 |
+
src/f5_tts/infer/examples/multi/main.flac
|
49 |
+
src/f5_tts/infer/examples/multi/story.toml
|
50 |
+
src/f5_tts/infer/examples/multi/story.txt
|
51 |
+
src/f5_tts/infer/examples/multi/town.flac
|
52 |
+
src/f5_tts/model/__init__.py
|
53 |
+
src/f5_tts/model/cfm.py
|
54 |
+
src/f5_tts/model/dataset.py
|
55 |
+
src/f5_tts/model/modules.py
|
56 |
+
src/f5_tts/model/trainer.py
|
57 |
+
src/f5_tts/model/utils.py
|
58 |
+
src/f5_tts/model/__pycache__/__init__.cpython-310.pyc
|
59 |
+
src/f5_tts/model/__pycache__/cfm.cpython-310.pyc
|
60 |
+
src/f5_tts/model/__pycache__/dataset.cpython-310.pyc
|
61 |
+
src/f5_tts/model/__pycache__/modules.cpython-310.pyc
|
62 |
+
src/f5_tts/model/__pycache__/trainer.cpython-310.pyc
|
63 |
+
src/f5_tts/model/__pycache__/utils.cpython-310.pyc
|
64 |
+
src/f5_tts/model/backbones/README.md
|
65 |
+
src/f5_tts/model/backbones/dit.py
|
66 |
+
src/f5_tts/model/backbones/mmdit.py
|
67 |
+
src/f5_tts/model/backbones/unett.py
|
68 |
+
src/f5_tts/model/backbones/__pycache__/dit.cpython-310.pyc
|
69 |
+
src/f5_tts/model/backbones/__pycache__/mmdit.cpython-310.pyc
|
70 |
+
src/f5_tts/model/backbones/__pycache__/unett.cpython-310.pyc
|
71 |
+
src/f5_tts/scripts/count_max_epoch.py
|
72 |
+
src/f5_tts/scripts/count_params_gflops.py
|
73 |
+
src/f5_tts/train/README.md
|
74 |
+
src/f5_tts/train/finetune_cli.py
|
75 |
+
src/f5_tts/train/finetune_gradio.py
|
76 |
+
src/f5_tts/train/train.py
|
77 |
+
src/f5_tts/train/datasets/prepare_csv_wavs.py
|
78 |
+
src/f5_tts/train/datasets/prepare_emilia.py
|
79 |
+
src/f5_tts/train/datasets/prepare_libritts.py
|
80 |
+
src/f5_tts/train/datasets/prepare_ljspeech.py
|
81 |
+
src/f5_tts/train/datasets/prepare_wenetspeech4tts.py
|
src/f5_tts.egg-info/dependency_links.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
|
src/f5_tts.egg-info/entry_points.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[console_scripts]
|
2 |
+
f5-tts_finetune-cli = f5_tts.train.finetune_cli:main
|
3 |
+
f5-tts_finetune-gradio = f5_tts.train.finetune_gradio:main
|
4 |
+
f5-tts_infer-cli = f5_tts.infer.infer_cli:main
|
5 |
+
f5-tts_infer-gradio = f5_tts.infer.infer_gradio:main
|
src/f5_tts.egg-info/requires.txt
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
accelerate>=0.33.0
|
2 |
+
cached_path
|
3 |
+
click
|
4 |
+
datasets
|
5 |
+
ema_pytorch>=0.5.2
|
6 |
+
gradio>=3.45.2
|
7 |
+
hydra-core>=1.3.0
|
8 |
+
jieba
|
9 |
+
librosa
|
10 |
+
matplotlib
|
11 |
+
numpy<=1.26.4
|
12 |
+
pydub
|
13 |
+
pypinyin
|
14 |
+
safetensors
|
15 |
+
soundfile
|
16 |
+
tomli
|
17 |
+
torch>=2.0.0
|
18 |
+
torchaudio>=2.0.0
|
19 |
+
torchdiffeq
|
20 |
+
tqdm>=4.65.0
|
21 |
+
transformers
|
22 |
+
transformers_stream_generator
|
23 |
+
vocos
|
24 |
+
wandb
|
25 |
+
x_transformers>=1.31.14
|
26 |
+
|
27 |
+
[:platform_machine != "arm64" and platform_system != "Darwin"]
|
28 |
+
bitsandbytes>0.37.0
|
29 |
+
|
30 |
+
[eval]
|
31 |
+
faster_whisper==0.10.1
|
32 |
+
funasr
|
33 |
+
jiwer
|
34 |
+
modelscope
|
35 |
+
zhconv
|
36 |
+
zhon
|
src/f5_tts.egg-info/top_level.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
f5_tts
|
src/f5_tts/__pycache__/api.cpython-310.pyc
ADDED
Binary file (3.97 kB). View file
|
|
src/f5_tts/api.py
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
import sys
|
3 |
+
from importlib.resources import files
|
4 |
+
|
5 |
+
import soundfile as sf
|
6 |
+
import tqdm
|
7 |
+
from cached_path import cached_path
|
8 |
+
from omegaconf import OmegaConf
|
9 |
+
|
10 |
+
from f5_tts.infer.utils_infer import (
|
11 |
+
load_model,
|
12 |
+
load_vocoder,
|
13 |
+
transcribe,
|
14 |
+
preprocess_ref_audio_text,
|
15 |
+
infer_process,
|
16 |
+
remove_silence_for_generated_wav,
|
17 |
+
save_spectrogram,
|
18 |
+
)
|
19 |
+
from f5_tts.model import DiT, UNetT # noqa: F401. used for config
|
20 |
+
from f5_tts.model.utils import seed_everything
|
21 |
+
|
22 |
+
|
23 |
+
class F5TTS:
|
24 |
+
def __init__(
|
25 |
+
self,
|
26 |
+
model="F5TTS_v1_Base",
|
27 |
+
ckpt_file="",
|
28 |
+
vocab_file="",
|
29 |
+
ode_method="euler",
|
30 |
+
use_ema=True,
|
31 |
+
vocoder_local_path=None,
|
32 |
+
device=None,
|
33 |
+
hf_cache_dir=None,
|
34 |
+
):
|
35 |
+
model_cfg = OmegaConf.load(str(files("f5_tts").joinpath(f"configs/{model}.yaml")))
|
36 |
+
model_cls = globals()[model_cfg.model.backbone]
|
37 |
+
model_arc = model_cfg.model.arch
|
38 |
+
|
39 |
+
self.mel_spec_type = model_cfg.model.mel_spec.mel_spec_type
|
40 |
+
self.target_sample_rate = model_cfg.model.mel_spec.target_sample_rate
|
41 |
+
|
42 |
+
self.ode_method = ode_method
|
43 |
+
self.use_ema = use_ema
|
44 |
+
|
45 |
+
if device is not None:
|
46 |
+
self.device = device
|
47 |
+
else:
|
48 |
+
import torch
|
49 |
+
|
50 |
+
self.device = (
|
51 |
+
"cuda"
|
52 |
+
if torch.cuda.is_available()
|
53 |
+
else "xpu"
|
54 |
+
if torch.xpu.is_available()
|
55 |
+
else "mps"
|
56 |
+
if torch.backends.mps.is_available()
|
57 |
+
else "cpu"
|
58 |
+
)
|
59 |
+
|
60 |
+
# Load models
|
61 |
+
self.vocoder = load_vocoder(
|
62 |
+
self.mel_spec_type, vocoder_local_path is not None, vocoder_local_path, self.device, hf_cache_dir
|
63 |
+
)
|
64 |
+
|
65 |
+
repo_name, ckpt_step, ckpt_type = "F5-TTS", 1250000, "safetensors"
|
66 |
+
|
67 |
+
# override for previous models
|
68 |
+
if model == "F5TTS_Base":
|
69 |
+
if self.mel_spec_type == "vocos":
|
70 |
+
ckpt_step = 1200000
|
71 |
+
elif self.mel_spec_type == "bigvgan":
|
72 |
+
model = "F5TTS_Base_bigvgan"
|
73 |
+
ckpt_type = "pt"
|
74 |
+
elif model == "E2TTS_Base":
|
75 |
+
repo_name = "E2-TTS"
|
76 |
+
ckpt_step = 1200000
|
77 |
+
else:
|
78 |
+
raise ValueError(f"Unknown model type: {model}")
|
79 |
+
|
80 |
+
if not ckpt_file:
|
81 |
+
ckpt_file = str(
|
82 |
+
cached_path(f"hf://SWivid/{repo_name}/{model}/model_{ckpt_step}.{ckpt_type}", cache_dir=hf_cache_dir)
|
83 |
+
)
|
84 |
+
self.ema_model = load_model(
|
85 |
+
model_cls, model_arc, ckpt_file, self.mel_spec_type, vocab_file, self.ode_method, self.use_ema, self.device
|
86 |
+
)
|
87 |
+
|
88 |
+
def transcribe(self, ref_audio, language=None):
|
89 |
+
return transcribe(ref_audio, language)
|
90 |
+
|
91 |
+
def export_wav(self, wav, file_wave, remove_silence=False):
|
92 |
+
sf.write(file_wave, wav, self.target_sample_rate)
|
93 |
+
|
94 |
+
if remove_silence:
|
95 |
+
remove_silence_for_generated_wav(file_wave)
|
96 |
+
|
97 |
+
def export_spectrogram(self, spec, file_spec):
|
98 |
+
save_spectrogram(spec, file_spec)
|
99 |
+
|
100 |
+
def infer(
|
101 |
+
self,
|
102 |
+
ref_file,
|
103 |
+
ref_text,
|
104 |
+
gen_text,
|
105 |
+
show_info=print,
|
106 |
+
progress=tqdm,
|
107 |
+
target_rms=0.1,
|
108 |
+
cross_fade_duration=0.15,
|
109 |
+
sway_sampling_coef=-1,
|
110 |
+
cfg_strength=2,
|
111 |
+
nfe_step=32,
|
112 |
+
speed=1.0,
|
113 |
+
fix_duration=None,
|
114 |
+
remove_silence=False,
|
115 |
+
file_wave=None,
|
116 |
+
file_spec=None,
|
117 |
+
seed=None,
|
118 |
+
):
|
119 |
+
if seed is None:
|
120 |
+
self.seed = random.randint(0, sys.maxsize)
|
121 |
+
seed_everything(self.seed)
|
122 |
+
|
123 |
+
ref_file, ref_text = preprocess_ref_audio_text(ref_file, ref_text, device=self.device)
|
124 |
+
|
125 |
+
wav, sr, spec = infer_process(
|
126 |
+
ref_file,
|
127 |
+
ref_text,
|
128 |
+
gen_text,
|
129 |
+
self.ema_model,
|
130 |
+
self.vocoder,
|
131 |
+
self.mel_spec_type,
|
132 |
+
show_info=show_info,
|
133 |
+
progress=progress,
|
134 |
+
target_rms=target_rms,
|
135 |
+
cross_fade_duration=cross_fade_duration,
|
136 |
+
nfe_step=nfe_step,
|
137 |
+
cfg_strength=cfg_strength,
|
138 |
+
sway_sampling_coef=sway_sampling_coef,
|
139 |
+
speed=speed,
|
140 |
+
fix_duration=fix_duration,
|
141 |
+
device=self.device,
|
142 |
+
)
|
143 |
+
|
144 |
+
if file_wave is not None:
|
145 |
+
self.export_wav(wav, file_wave, remove_silence)
|
146 |
+
|
147 |
+
if file_spec is not None:
|
148 |
+
self.export_spectrogram(spec, file_spec)
|
149 |
+
|
150 |
+
return wav, sr, spec
|
151 |
+
|
152 |
+
|
153 |
+
if __name__ == "__main__":
|
154 |
+
f5tts = F5TTS()
|
155 |
+
|
156 |
+
wav, sr, spec = f5tts.infer(
|
157 |
+
ref_file=str(files("f5_tts").joinpath("infer/examples/basic/basic_ref_en.wav")),
|
158 |
+
ref_text="some call me nature, others call me mother nature.",
|
159 |
+
gen_text="""I don't really care what you call me. I've been a silent spectator, watching species evolve, empires rise and fall. But always remember, I am mighty and enduring. Respect me and I'll nurture you; ignore me and you shall face the consequences.""",
|
160 |
+
file_wave=str(files("f5_tts").joinpath("../../tests/api_out.wav")),
|
161 |
+
file_spec=str(files("f5_tts").joinpath("../../tests/api_out.png")),
|
162 |
+
seed=None,
|
163 |
+
)
|
164 |
+
|
165 |
+
print("seed :", f5tts.seed)
|
src/f5_tts/configs/E2TTS_Base.yaml
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
hydra:
|
2 |
+
run:
|
3 |
+
dir: ckpts/${model.name}_${model.mel_spec.mel_spec_type}_${model.tokenizer}_${datasets.name}/${now:%Y-%m-%d}/${now:%H-%M-%S}
|
4 |
+
|
5 |
+
datasets:
|
6 |
+
name: Emilia_ZH_EN # dataset name
|
7 |
+
batch_size_per_gpu: 38400 # 8 GPUs, 8 * 38400 = 307200
|
8 |
+
batch_size_type: frame # frame | sample
|
9 |
+
max_samples: 64 # max sequences per batch if use frame-wise batch_size. we set 32 for small models, 64 for base models
|
10 |
+
num_workers: 16
|
11 |
+
|
12 |
+
optim:
|
13 |
+
epochs: 11
|
14 |
+
learning_rate: 7.5e-5
|
15 |
+
num_warmup_updates: 20000 # warmup updates
|
16 |
+
grad_accumulation_steps: 1 # note: updates = steps / grad_accumulation_steps
|
17 |
+
max_grad_norm: 1.0 # gradient clipping
|
18 |
+
bnb_optimizer: False # use bnb 8bit AdamW optimizer or not
|
19 |
+
|
20 |
+
model:
|
21 |
+
name: E2TTS_Base
|
22 |
+
tokenizer: pinyin
|
23 |
+
tokenizer_path: null # if 'custom' tokenizer, define the path want to use (should be vocab.txt)
|
24 |
+
backbone: UNetT
|
25 |
+
arch:
|
26 |
+
dim: 1024
|
27 |
+
depth: 24
|
28 |
+
heads: 16
|
29 |
+
ff_mult: 4
|
30 |
+
text_mask_padding: False
|
31 |
+
pe_attn_head: 1
|
32 |
+
mel_spec:
|
33 |
+
target_sample_rate: 24000
|
34 |
+
n_mel_channels: 100
|
35 |
+
hop_length: 256
|
36 |
+
win_length: 1024
|
37 |
+
n_fft: 1024
|
38 |
+
mel_spec_type: vocos # vocos | bigvgan
|
39 |
+
vocoder:
|
40 |
+
is_local: False # use local offline ckpt or not
|
41 |
+
local_path: null # local vocoder path
|
42 |
+
|
43 |
+
ckpts:
|
44 |
+
logger: wandb # wandb | tensorboard | null
|
45 |
+
log_samples: True # infer random sample per save checkpoint. wip, normal to fail with extra long samples
|
46 |
+
save_per_updates: 50000 # save checkpoint per updates
|
47 |
+
keep_last_n_checkpoints: -1 # -1 to keep all, 0 to not save intermediate, > 0 to keep last N checkpoints
|
48 |
+
last_per_updates: 5000 # save last checkpoint per updates
|
49 |
+
save_dir: ckpts/${model.name}_${model.mel_spec.mel_spec_type}_${model.tokenizer}_${datasets.name}
|
src/f5_tts/configs/E2TTS_Small.yaml
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
hydra:
|
2 |
+
run:
|
3 |
+
dir: ckpts/${model.name}_${model.mel_spec.mel_spec_type}_${model.tokenizer}_${datasets.name}/${now:%Y-%m-%d}/${now:%H-%M-%S}
|
4 |
+
|
5 |
+
datasets:
|
6 |
+
name: Emilia_ZH_EN
|
7 |
+
batch_size_per_gpu: 38400 # 8 GPUs, 8 * 38400 = 307200
|
8 |
+
batch_size_type: frame # frame | sample
|
9 |
+
max_samples: 64 # max sequences per batch if use frame-wise batch_size. we set 32 for small models, 64 for base models
|
10 |
+
num_workers: 16
|
11 |
+
|
12 |
+
optim:
|
13 |
+
epochs: 11
|
14 |
+
learning_rate: 7.5e-5
|
15 |
+
num_warmup_updates: 20000 # warmup updates
|
16 |
+
grad_accumulation_steps: 1 # note: updates = steps / grad_accumulation_steps
|
17 |
+
max_grad_norm: 1.0
|
18 |
+
bnb_optimizer: False
|
19 |
+
|
20 |
+
model:
|
21 |
+
name: E2TTS_Small
|
22 |
+
tokenizer: pinyin
|
23 |
+
tokenizer_path: null # if 'custom' tokenizer, define the path want to use (should be vocab.txt)
|
24 |
+
backbone: UNetT
|
25 |
+
arch:
|
26 |
+
dim: 768
|
27 |
+
depth: 20
|
28 |
+
heads: 12
|
29 |
+
ff_mult: 4
|
30 |
+
text_mask_padding: False
|
31 |
+
pe_attn_head: 1
|
32 |
+
mel_spec:
|
33 |
+
target_sample_rate: 24000
|
34 |
+
n_mel_channels: 100
|
35 |
+
hop_length: 256
|
36 |
+
win_length: 1024
|
37 |
+
n_fft: 1024
|
38 |
+
mel_spec_type: vocos # vocos | bigvgan
|
39 |
+
vocoder:
|
40 |
+
is_local: False # use local offline ckpt or not
|
41 |
+
local_path: null # local vocoder path
|
42 |
+
|
43 |
+
ckpts:
|
44 |
+
logger: wandb # wandb | tensorboard | null
|
45 |
+
log_samples: True # infer random sample per save checkpoint. wip, normal to fail with extra long samples
|
46 |
+
save_per_updates: 50000 # save checkpoint per updates
|
47 |
+
keep_last_n_checkpoints: -1 # -1 to keep all, 0 to not save intermediate, > 0 to keep last N checkpoints
|
48 |
+
last_per_updates: 5000 # save last checkpoint per updates
|
49 |
+
save_dir: ckpts/${model.name}_${model.mel_spec.mel_spec_type}_${model.tokenizer}_${datasets.name}
|
src/f5_tts/configs/F5TTS_Base.yaml
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
hydra:
|
2 |
+
run:
|
3 |
+
dir: ckpts/${model.name}_${model.mel_spec.mel_spec_type}_${model.tokenizer}_${datasets.name}/${now:%Y-%m-%d}/${now:%H-%M-%S}
|
4 |
+
|
5 |
+
datasets:
|
6 |
+
name: your_training_dataset # dataset name
|
7 |
+
batch_size_per_gpu: 38400 # 8 GPUs, 8 * 38400 = 307200
|
8 |
+
batch_size_type: frame # frame | sample
|
9 |
+
max_samples: 64 # max sequences per batch if use frame-wise batch_size. we set 32 for small models, 64 for base models
|
10 |
+
num_workers: 16
|
11 |
+
|
12 |
+
optim:
|
13 |
+
epochs: 11
|
14 |
+
learning_rate: 7.5e-5
|
15 |
+
num_warmup_updates: 20000 # warmup updates
|
16 |
+
grad_accumulation_steps: 1 # note: updates = steps / grad_accumulation_steps
|
17 |
+
max_grad_norm: 1.0 # gradient clipping
|
18 |
+
bnb_optimizer: False # use bnb 8bit AdamW optimizer or not
|
19 |
+
|
20 |
+
model:
|
21 |
+
name: F5TTS_Base # model name
|
22 |
+
tokenizer: char # tokenizer type
|
23 |
+
tokenizer_path: null # if 'custom' tokenizer, define the path want to use (should be vocab.txt)
|
24 |
+
backbone: DiT
|
25 |
+
arch:
|
26 |
+
dim: 1024
|
27 |
+
depth: 22
|
28 |
+
heads: 16
|
29 |
+
ff_mult: 2
|
30 |
+
text_dim: 512
|
31 |
+
text_mask_padding: False
|
32 |
+
conv_layers: 4
|
33 |
+
pe_attn_head: 1
|
34 |
+
checkpoint_activations: False # recompute activations and save memory for extra compute
|
35 |
+
mel_spec:
|
36 |
+
target_sample_rate: 24000
|
37 |
+
n_mel_channels: 100
|
38 |
+
hop_length: 256
|
39 |
+
win_length: 1024
|
40 |
+
n_fft: 1024
|
41 |
+
mel_spec_type: vocos # vocos | bigvgan
|
42 |
+
vocoder:
|
43 |
+
is_local: False # use local offline ckpt or not
|
44 |
+
local_path: null # local vocoder path
|
45 |
+
|
46 |
+
ckpts:
|
47 |
+
logger: tensorboard # wandb | tensorboard | null
|
48 |
+
log_samples: True # infer random sample per save checkpoint. wip, normal to fail with extra long samples
|
49 |
+
save_per_updates: 50000 # save checkpoint per updates
|
50 |
+
keep_last_n_checkpoints: -1 # -1 to keep all, 0 to not save intermediate, > 0 to keep last N checkpoints
|
51 |
+
last_per_updates: 5000 # save last checkpoint per updates
|
52 |
+
save_dir: ckpts/${model.name}_${model.mel_spec.mel_spec_type}_${model.tokenizer}_${datasets.name}
|
src/f5_tts/configs/F5TTS_Small.yaml
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
hydra:
|
2 |
+
run:
|
3 |
+
dir: ckpts/${model.name}_${model.mel_spec.mel_spec_type}_${model.tokenizer}_${datasets.name}/${now:%Y-%m-%d}/${now:%H-%M-%S}
|
4 |
+
|
5 |
+
datasets:
|
6 |
+
name: Emilia_ZH_EN
|
7 |
+
batch_size_per_gpu: 38400 # 8 GPUs, 8 * 38400 = 307200
|
8 |
+
batch_size_type: frame # frame | sample
|
9 |
+
max_samples: 64 # max sequences per batch if use frame-wise batch_size. we set 32 for small models, 64 for base models
|
10 |
+
num_workers: 16
|
11 |
+
|
12 |
+
optim:
|
13 |
+
epochs: 11
|
14 |
+
learning_rate: 7.5e-5
|
15 |
+
num_warmup_updates: 20000 # warmup updates
|
16 |
+
grad_accumulation_steps: 1 # note: updates = steps / grad_accumulation_steps
|
17 |
+
max_grad_norm: 1.0 # gradient clipping
|
18 |
+
bnb_optimizer: False # use bnb 8bit AdamW optimizer or not
|
19 |
+
|
20 |
+
model:
|
21 |
+
name: F5TTS_Small
|
22 |
+
tokenizer: pinyin
|
23 |
+
tokenizer_path: null # if 'custom' tokenizer, define the path want to use (should be vocab.txt)
|
24 |
+
backbone: DiT
|
25 |
+
arch:
|
26 |
+
dim: 768
|
27 |
+
depth: 18
|
28 |
+
heads: 12
|
29 |
+
ff_mult: 2
|
30 |
+
text_dim: 512
|
31 |
+
text_mask_padding: False
|
32 |
+
conv_layers: 4
|
33 |
+
pe_attn_head: 1
|
34 |
+
checkpoint_activations: False # recompute activations and save memory for extra compute
|
35 |
+
mel_spec:
|
36 |
+
target_sample_rate: 24000
|
37 |
+
n_mel_channels: 100
|
38 |
+
hop_length: 256
|
39 |
+
win_length: 1024
|
40 |
+
n_fft: 1024
|
41 |
+
mel_spec_type: vocos # vocos | bigvgan
|
42 |
+
vocoder:
|
43 |
+
is_local: False # use local offline ckpt or not
|
44 |
+
local_path: null # local vocoder path
|
45 |
+
|
46 |
+
ckpts:
|
47 |
+
logger: wandb # wandb | tensorboard | null
|
48 |
+
log_samples: True # infer random sample per save checkpoint. wip, normal to fail with extra long samples
|
49 |
+
save_per_updates: 50000 # save checkpoint per updates
|
50 |
+
keep_last_n_checkpoints: -1 # -1 to keep all, 0 to not save intermediate, > 0 to keep last N checkpoints
|
51 |
+
last_per_updates: 5000 # save last checkpoint per updates
|
52 |
+
save_dir: ckpts/${model.name}_${model.mel_spec.mel_spec_type}_${model.tokenizer}_${datasets.name}
|
src/f5_tts/configs/F5TTS_v1_Base.yaml
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
hydra:
|
2 |
+
run:
|
3 |
+
dir: ckpts/${model.name}_${model.mel_spec.mel_spec_type}_${model.tokenizer}_${datasets.name}/${now:%Y-%m-%d}/${now:%H-%M-%S}
|
4 |
+
|
5 |
+
datasets:
|
6 |
+
name: Emilia_ZH_EN # dataset name
|
7 |
+
batch_size_per_gpu: 38400 # 8 GPUs, 8 * 38400 = 307200
|
8 |
+
batch_size_type: frame # frame | sample
|
9 |
+
max_samples: 64 # max sequences per batch if use frame-wise batch_size. we set 32 for small models, 64 for base models
|
10 |
+
num_workers: 16
|
11 |
+
|
12 |
+
optim:
|
13 |
+
epochs: 11
|
14 |
+
learning_rate: 7.5e-5
|
15 |
+
num_warmup_updates: 20000 # warmup updates
|
16 |
+
grad_accumulation_steps: 1 # note: updates = steps / grad_accumulation_steps
|
17 |
+
max_grad_norm: 1.0 # gradient clipping
|
18 |
+
bnb_optimizer: False # use bnb 8bit AdamW optimizer or not
|
19 |
+
|
20 |
+
model:
|
21 |
+
name: F5TTS_v1_Base # model name
|
22 |
+
tokenizer: pinyin # tokenizer type
|
23 |
+
tokenizer_path: null # if 'custom' tokenizer, define the path want to use (should be vocab.txt)
|
24 |
+
backbone: DiT
|
25 |
+
arch:
|
26 |
+
dim: 1024
|
27 |
+
depth: 22
|
28 |
+
heads: 16
|
29 |
+
ff_mult: 2
|
30 |
+
text_dim: 512
|
31 |
+
text_mask_padding: True
|
32 |
+
qk_norm: null # null | rms_norm
|
33 |
+
conv_layers: 4
|
34 |
+
pe_attn_head: null
|
35 |
+
checkpoint_activations: False # recompute activations and save memory for extra compute
|
36 |
+
mel_spec:
|
37 |
+
target_sample_rate: 24000
|
38 |
+
n_mel_channels: 100
|
39 |
+
hop_length: 256
|
40 |
+
win_length: 1024
|
41 |
+
n_fft: 1024
|
42 |
+
mel_spec_type: vocos # vocos | bigvgan
|
43 |
+
vocoder:
|
44 |
+
is_local: False # use local offline ckpt or not
|
45 |
+
local_path: null # local vocoder path
|
46 |
+
|
47 |
+
ckpts:
|
48 |
+
logger: wandb # wandb | tensorboard | null
|
49 |
+
log_samples: True # infer random sample per save checkpoint. wip, normal to fail with extra long samples
|
50 |
+
save_per_updates: 50000 # save checkpoint per updates
|
51 |
+
keep_last_n_checkpoints: -1 # -1 to keep all, 0 to not save intermediate, > 0 to keep last N checkpoints
|
52 |
+
last_per_updates: 5000 # save last checkpoint per updates
|
53 |
+
save_dir: ckpts/${model.name}_${model.mel_spec.mel_spec_type}_${model.tokenizer}_${datasets.name}
|
src/f5_tts/eval/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# Evaluation
|
3 |
+
|
4 |
+
Install packages for evaluation:
|
5 |
+
|
6 |
+
```bash
|
7 |
+
pip install -e .[eval]
|
8 |
+
```
|
9 |
+
|
10 |
+
## Generating Samples for Evaluation
|
11 |
+
|
12 |
+
### Prepare Test Datasets
|
13 |
+
|
14 |
+
1. *Seed-TTS testset*: Download from [seed-tts-eval](https://github.com/BytedanceSpeech/seed-tts-eval).
|
15 |
+
2. *LibriSpeech test-clean*: Download from [OpenSLR](http://www.openslr.org/12/).
|
16 |
+
3. Unzip the downloaded datasets and place them in the `data/` directory.
|
17 |
+
4. Update the path for *LibriSpeech test-clean* data in `src/f5_tts/eval/eval_infer_batch.py`
|
18 |
+
5. Our filtered LibriSpeech-PC 4-10s subset: `data/librispeech_pc_test_clean_cross_sentence.lst`
|
19 |
+
|
20 |
+
### Batch Inference for Test Set
|
21 |
+
|
22 |
+
To run batch inference for evaluations, execute the following commands:
|
23 |
+
|
24 |
+
```bash
|
25 |
+
# batch inference for evaluations
|
26 |
+
accelerate config # if not set before
|
27 |
+
bash src/f5_tts/eval/eval_infer_batch.sh
|
28 |
+
```
|
29 |
+
|
30 |
+
## Objective Evaluation on Generated Results
|
31 |
+
|
32 |
+
### Download Evaluation Model Checkpoints
|
33 |
+
|
34 |
+
1. Chinese ASR Model: [Paraformer-zh](https://huggingface.co/funasr/paraformer-zh)
|
35 |
+
2. English ASR Model: [Faster-Whisper](https://huggingface.co/Systran/faster-whisper-large-v3)
|
36 |
+
3. WavLM Model: Download from [Google Drive](https://drive.google.com/file/d/1-aE1NfzpRCLxA4GUxX9ITI3F9LlbtEGP/view).
|
37 |
+
|
38 |
+
Then update in the following scripts with the paths you put evaluation model ckpts to.
|
39 |
+
|
40 |
+
### Objective Evaluation
|
41 |
+
|
42 |
+
Update the path with your batch-inferenced results, and carry out WER / SIM / UTMOS evaluations:
|
43 |
+
```bash
|
44 |
+
# Evaluation [WER] for Seed-TTS test [ZH] set
|
45 |
+
python src/f5_tts/eval/eval_seedtts_testset.py --eval_task wer --lang zh --gen_wav_dir <GEN_WAV_DIR> --gpu_nums 8
|
46 |
+
|
47 |
+
# Evaluation [SIM] for LibriSpeech-PC test-clean (cross-sentence)
|
48 |
+
python src/f5_tts/eval/eval_librispeech_test_clean.py --eval_task sim --gen_wav_dir <GEN_WAV_DIR> --librispeech_test_clean_path <TEST_CLEAN_PATH>
|
49 |
+
|
50 |
+
# Evaluation [UTMOS]. --ext: Audio extension
|
51 |
+
python src/f5_t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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# just for speaker similarity evaluation, third-party code
|
2 |
+
|
3 |
+
# From https://github.com/microsoft/UniSpeech/blob/main/downstreams/speaker_verification/models/
|
4 |
+
# part of the code is borrowed from https://github.com/lawlict/ECAPA-TDNN
|
5 |
+
|
6 |
+
import os
|
7 |
+
import torch
|
8 |
+
import torch.nn as nn
|
9 |
+
import torch.nn.functional as F
|
10 |
+
|
11 |
+
|
12 |
+
""" Res2Conv1d + BatchNorm1d + ReLU
|
13 |
+
"""
|
14 |
+
|
15 |
+
|
16 |
+
class Res2Conv1dReluBn(nn.Module):
|
17 |
+
"""
|
18 |
+
in_channels == out_channels == channels
|
19 |
+
"""
|
20 |
+
|
21 |
+
def __init__(self, channels, kernel_size=1, stride=1, padding=0, dilation=1, bias=True, scale=4):
|
22 |
+
super().__init__()
|
23 |
+
assert channels % scale == 0, "{} % {} != 0".format(channels, scale)
|
24 |
+
self.scale = scale
|
25 |
+
self.width = channels // scale
|
26 |
+
self.nums = scale if scale == 1 else scale - 1
|
27 |
+
|
28 |
+
self.convs = []
|
29 |
+
self.bns = []
|
30 |
+
for i in range(self.nums):
|
31 |
+
self.convs.append(nn.Conv1d(self.width, self.width, kernel_size, stride, padding, dilation, bias=bias))
|
32 |
+
self.bns.append(nn.BatchNorm1d(self.width))
|
33 |
+
self.convs = nn.ModuleList(self.convs)
|
34 |
+
self.bns = nn.ModuleList(self.bns)
|
35 |
+
|
36 |
+
def forward(self, x):
|
37 |
+
out = []
|
38 |
+
spx = torch.split(x, self.width, 1)
|
39 |
+
for i in range(self.nums):
|
40 |
+
if i == 0:
|
41 |
+
sp = spx[i]
|
42 |
+
else:
|
43 |
+
sp = sp + spx[i]
|
44 |
+
# Order: conv -> relu -> bn
|
45 |
+
sp = self.convs[i](sp)
|
46 |
+
sp = self.bns[i](F.relu(sp))
|
47 |
+
out.append(sp)
|
48 |
+
if self.scale != 1:
|
49 |
+
out.append(spx[self.nums])
|
50 |
+
out = torch.cat(out, dim=1)
|
51 |
+
|
52 |
+
return out
|
53 |
+
|
54 |
+
|
55 |
+
""" Conv1d + BatchNorm1d + ReLU
|
56 |
+
"""
|
57 |
+
|
58 |
+
|
59 |
+
class Conv1dReluBn(nn.Module):
|
60 |
+
def __init__(self, in_channels, out_channels, kernel_size=1, stride=1, padding=0, dilation=1, bias=True):
|
61 |
+
super().__init__()
|
62 |
+
self.conv = nn.Conv1d(in_channels, out_channels, kernel_size, stride, padding, dilation, bias=bias)
|
63 |
+
self.bn = nn.BatchNorm1d(out_channels)
|
64 |
+
|
65 |
+
def forward(self, x):
|
66 |
+
return self.bn(F.relu(self.conv(x)))
|
67 |
+
|
68 |
+
|
69 |
+
""" The SE connection of 1D case.
|
70 |
+
"""
|
71 |
+
|
72 |
+
|
73 |
+
class SE_Connect(nn.Module):
|
74 |
+
def __init__(self, channels, se_bottleneck_dim=128):
|
75 |
+
super().__init__()
|
76 |
+
self.linear1 = nn.Linear(channels, se_bottleneck_dim)
|
77 |
+
self.linear2 = nn.Linear(se_bottleneck_dim, channels)
|
78 |
+
|
79 |
+
def forward(self, x):
|
80 |
+
out = x.mean(dim=2)
|
81 |
+
out = F.relu(self.linear1(out))
|
82 |
+
out = torch.sigmoid(self.linear2(out))
|
83 |
+
out = x * out.unsqueeze(2)
|
84 |
+
|
85 |
+
return out
|
86 |
+
|
87 |
+
|
88 |
+
""" SE-Res2Block of the ECAPA-TDNN architecture.
|
89 |
+
"""
|
90 |
+
|
91 |
+
# def SE_Res2Block(channels, kernel_size, stride, padding, dilation, scale):
|
92 |
+
# return nn.Sequential(
|
93 |
+
# Conv1dReluBn(channels, 512, kernel_size=1, stride=1, padding=0),
|
94 |
+
# Res2Conv1dReluBn(512, kernel_size, stride, padding, dilation, scale=scale),
|
95 |
+
# Conv1dReluBn(512, channels, kernel_size=1, stride=1, padding=0),
|
96 |
+
# SE_Connect(channels)
|
97 |
+
# )
|
98 |
+
|
99 |
+
|
100 |
+
class SE_Res2Block(nn.Module):
|
101 |
+
def __init__(self, in_channels, out_channels, kernel_size, stride, padding, dilation, scale, se_bottleneck_dim):
|
102 |
+
super().__init__()
|
103 |
+
self.Conv1dReluBn1 = Conv1dReluBn(in_channels, out_channels, kernel_size=1, stride=1, padding=0)
|
104 |
+
self.Res2Conv1dReluBn = Res2Conv1dReluBn(out_channels, kernel_size, stride, padding, dilation, scale=scale)
|
105 |
+
self.Conv1dReluBn2 = Conv1dReluBn(out_channels, out_channels, kernel_size=1, stride=1, padding=0)
|
106 |
+
self.SE_Connect = SE_Connect(out_channels, se_bottleneck_dim)
|
107 |
+
|
108 |
+
self.shortcut = None
|
109 |
+
if in_channels != out_channels:
|
110 |
+
self.shortcut = nn.Conv1d(
|
111 |
+
in_channels=in_channels,
|
112 |
+
out_channels=out_channels,
|
113 |
+
kernel_size=1,
|
114 |
+
)
|
115 |
+
|
116 |
+
def forward(self, x):
|
117 |
+
residual = x
|
118 |
+
if self.shortcut:
|
119 |
+
residual = self.shortcut(x)
|
120 |
+
|
121 |
+
x = self.Conv1dReluBn1(x)
|
122 |
+
x = self.Res2Conv1dReluBn(x)
|
123 |
+
x = self.Conv1dReluBn2(x)
|
124 |
+
x = self.SE_Connect(x)
|
125 |
+
|
126 |
+
return x + residual
|
127 |
+
|
128 |
+
|
129 |
+
""" Attentive weighted mean and standard deviation pooling.
|
130 |
+
"""
|
131 |
+
|
132 |
+
|
133 |
+
class AttentiveStatsPool(nn.Module):
|
134 |
+
def __init__(self, in_dim, attention_channels=128, global_context_att=False):
|
135 |
+
super().__init__()
|
136 |
+
self.global_context_att = global_context_att
|
137 |
+
|
138 |
+
# Use Conv1d with stride == 1 rather than Linear, then we don't need to transpose inputs.
|
139 |
+
if global_context_att:
|
140 |
+
self.linear1 = nn.Conv1d(in_dim * 3, attention_channels, kernel_size=1) # equals W and b in the paper
|
141 |
+
else:
|
142 |
+
self.linear1 = nn.Conv1d(in_dim, attention_channels, kernel_size=1) # equals W and b in the paper
|
143 |
+
self.linear2 = nn.Conv1d(attention_channels, in_dim, kernel_size=1) # equals V and k in the paper
|
144 |
+
|
145 |
+
def forward(self, x):
|
146 |
+
if self.global_context_att:
|
147 |
+
context_mean = torch.mean(x, dim=-1, keepdim=True).expand_as(x)
|
148 |
+
context_std = torch.sqrt(torch.var(x, dim=-1, keepdim=True) + 1e-10).expand_as(x)
|
149 |
+
x_in = torch.cat((x, context_mean, context_std), dim=1)
|
150 |
+
else:
|
151 |
+
x_in = x
|
152 |
+
|
153 |
+
# DON'T use ReLU here! In experiments, I find ReLU hard to converge.
|
154 |
+
alpha = torch.tanh(self.linear1(x_in))
|
155 |
+
# alpha = F.relu(self.linear1(x_in))
|
156 |
+
alpha = torch.softmax(self.linear2(alpha), dim=2)
|
157 |
+
mean = torch.sum(alpha * x, dim=2)
|
158 |
+
residuals = torch.sum(alpha * (x**2), dim=2) - mean**2
|
159 |
+
std = torch.sqrt(residuals.clamp(min=1e-9))
|
160 |
+
return torch.cat([mean, std], dim=1)
|
161 |
+
|
162 |
+
|
163 |
+
class ECAPA_TDNN(nn.Module):
|
164 |
+
def __init__(
|
165 |
+
self,
|
166 |
+
feat_dim=80,
|
167 |
+
channels=512,
|
168 |
+
emb_dim=192,
|
169 |
+
global_context_att=False,
|
170 |
+
feat_type="wavlm_large",
|
171 |
+
sr=16000,
|
172 |
+
feature_selection="hidden_states",
|
173 |
+
update_extract=False,
|
174 |
+
config_path=None,
|
175 |
+
):
|
176 |
+
super().__init__()
|
177 |
+
|
178 |
+
self.feat_type = feat_type
|
179 |
+
self.feature_selection = feature_selection
|
180 |
+
self.update_extract = update_extract
|
181 |
+
self.sr = sr
|
182 |
+
|
183 |
+
torch.hub._validate_not_a_forked_repo = lambda a, b, c: True
|
184 |
+
try:
|
185 |
+
local_s3prl_path = os.path.expanduser("~/.cache/torch/hub/s3prl_s3prl_main")
|
186 |
+
self.feature_extract = torch.hub.load(local_s3prl_path, feat_type, source="local", config_path=config_path)
|
187 |
+
except: # noqa: E722
|
188 |
+
self.feature_extract = torch.hub.load("s3prl/s3prl", feat_type)
|
189 |
+
|
190 |
+
if len(self.feature_extract.model.encoder.layers) == 24 and hasattr(
|
191 |
+
self.feature_extract.model.encoder.layers[23].self_attn, "fp32_attention"
|
192 |
+
):
|
193 |
+
self.feature_extract.model.encoder.layers[23].self_attn.fp32_attention = False
|
194 |
+
if len(self.feature_extract.model.encoder.layers) == 24 and hasattr(
|
195 |
+
self.feature_extract.model.encoder.layers[11].self_attn, "fp32_attention"
|
196 |
+
):
|
197 |
+
self.feature_extract.model.encoder.layers[11].self_attn.fp32_attention = False
|
198 |
+
|
199 |
+
self.feat_num = self.get_feat_num()
|
200 |
+
self.feature_weight = nn.Parameter(torch.zeros(self.feat_num))
|
201 |
+
|
202 |
+
if feat_type != "fbank" and feat_type != "mfcc":
|
203 |
+
freeze_list = ["final_proj", "label_embs_concat", "mask_emb", "project_q", "quantizer"]
|
204 |
+
for name, param in self.feature_extract.named_parameters():
|
205 |
+
for freeze_val in freeze_list:
|
206 |
+
if freeze_val in name:
|
207 |
+
param.requires_grad = False
|
208 |
+
break
|
209 |
+
|
210 |
+
if not self.update_extract:
|
211 |
+
for param in self.feature_extract.parameters():
|
212 |
+
param.requires_grad = False
|
213 |
+
|
214 |
+
self.instance_norm = nn.InstanceNorm1d(feat_dim)
|
215 |
+
# self.channels = [channels] * 4 + [channels * 3]
|
216 |
+
self.channels = [channels] * 4 + [1536]
|
217 |
+
|
218 |
+
self.layer1 = Conv1dReluBn(feat_dim, self.channels[0], kernel_size=5, padding=2)
|
219 |
+
self.layer2 = SE_Res2Block(
|
220 |
+
self.channels[0],
|
221 |
+
self.channels[1],
|
222 |
+
kernel_size=3,
|
223 |
+
stride=1,
|
224 |
+
padding=2,
|
225 |
+
dilation=2,
|
226 |
+
scale=8,
|
227 |
+
se_bottleneck_dim=128,
|
228 |
+
)
|
229 |
+
self.layer3 = SE_Res2Block(
|
230 |
+
self.channels[1],
|
231 |
+
self.channels[2],
|
232 |
+
kernel_size=3,
|
233 |
+
stride=1,
|
234 |
+
padding=3,
|
235 |
+
dilation=3,
|
236 |
+
scale=8,
|
237 |
+
se_bottleneck_dim=128,
|
238 |
+
)
|
239 |
+
self.layer4 = SE_Res2Block(
|
240 |
+
self.channels[2],
|
241 |
+
self.channels[3],
|
242 |
+
kernel_size=3,
|
243 |
+
stride=1,
|
244 |
+
padding=4,
|
245 |
+
dilation=4,
|
246 |
+
scale=8,
|
247 |
+
se_bottleneck_dim=128,
|
248 |
+
)
|
249 |
+
|
250 |
+
# self.conv = nn.Conv1d(self.channels[-1], self.channels[-1], kernel_size=1)
|
251 |
+
cat_channels = channels * 3
|
252 |
+
self.conv = nn.Conv1d(cat_channels, self.channels[-1], kernel_size=1)
|
253 |
+
self.pooling = AttentiveStatsPool(
|
254 |
+
self.channels[-1], attention_channels=128, global_context_att=global_context_att
|
255 |
+
)
|
256 |
+
self.bn = nn.BatchNorm1d(self.channels[-1] * 2)
|
257 |
+
self.linear = nn.Linear(self.channels[-1] * 2, emb_dim)
|
258 |
+
|
259 |
+
def get_feat_num(self):
|
260 |
+
self.feature_extract.eval()
|
261 |
+
wav = [torch.randn(self.sr).to(next(self.feature_extract.parameters()).device)]
|
262 |
+
with torch.no_grad():
|
263 |
+
features = self.feature_extract(wav)
|
264 |
+
select_feature = features[self.feature_selection]
|
265 |
+
if isinstance(select_feature, (list, tuple)):
|
266 |
+
return len(select_feature)
|
267 |
+
else:
|
268 |
+
return 1
|
269 |
+
|
270 |
+
def get_feat(self, x):
|
271 |
+
if self.update_extract:
|
272 |
+
x = self.feature_extract([sample for sample in x])
|
273 |
+
else:
|
274 |
+
with torch.no_grad():
|
275 |
+
if self.feat_type == "fbank" or self.feat_type == "mfcc":
|
276 |
+
x = self.feature_extract(x) + 1e-6 # B x feat_dim x time_len
|
277 |
+
else:
|
278 |
+
x = self.feature_extract([sample for sample in x])
|
279 |
+
|
280 |
+
if self.feat_type == "fbank":
|
281 |
+
x = x.log()
|
282 |
+
|
283 |
+
if self.feat_type != "fbank" and self.feat_type != "mfcc":
|
284 |
+
x = x[self.feature_selection]
|
285 |
+
if isinstance(x, (list, tuple)):
|
286 |
+
x = torch.stack(x, dim=0)
|
287 |
+
else:
|
288 |
+
x = x.unsqueeze(0)
|
289 |
+
norm_weights = F.softmax(self.feature_weight, dim=-1).unsqueeze(-1).unsqueeze(-1).unsqueeze(-1)
|
290 |
+
x = (norm_weights * x).sum(dim=0)
|
291 |
+
x = torch.transpose(x, 1, 2) + 1e-6
|
292 |
+
|
293 |
+
x = self.instance_norm(x)
|
294 |
+
return x
|
295 |
+
|
296 |
+
def forward(self, x):
|
297 |
+
x = self.get_feat(x)
|
298 |
+
|
299 |
+
out1 = self.layer1(x)
|
300 |
+
out2 = self.layer2(out1)
|
301 |
+
out3 = self.layer3(out2)
|
302 |
+
out4 = self.layer4(out3)
|
303 |
+
|
304 |
+
out = torch.cat([out2, out3, out4], dim=1)
|
305 |
+
out = F.relu(self.conv(out))
|
306 |
+
out = self.bn(self.pooling(out))
|
307 |
+
out = self.linear(out)
|
308 |
+
|
309 |
+
return out
|
310 |
+
|
311 |
+
|
312 |
+
def ECAPA_TDNN_SMALL(
|
313 |
+
feat_dim,
|
314 |
+
emb_dim=256,
|
315 |
+
feat_type="wavlm_large",
|
316 |
+
sr=16000,
|
317 |
+
feature_selection="hidden_states",
|
318 |
+
update_extract=False,
|
319 |
+
config_path=None,
|
320 |
+
):
|
321 |
+
return ECAPA_TDNN(
|
322 |
+
feat_dim=feat_dim,
|
323 |
+
channels=512,
|
324 |
+
emb_dim=emb_dim,
|
325 |
+
feat_type=feat_type,
|
326 |
+
sr=sr,
|
327 |
+
feature_selection=feature_selection,
|
328 |
+
update_extract=update_extract,
|
329 |
+
config_path=config_path,
|
330 |
+
)
|
src/f5_tts/eval/eval_infer_batch.py
ADDED
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
|
4 |
+
sys.path.append(os.getcwd())
|
5 |
+
|
6 |
+
import argparse
|
7 |
+
import time
|
8 |
+
from importlib.resources import files
|
9 |
+
|
10 |
+
import torch
|
11 |
+
import torchaudio
|
12 |
+
from accelerate import Accelerator
|
13 |
+
from omegaconf import OmegaConf
|
14 |
+
from tqdm import tqdm
|
15 |
+
|
16 |
+
from f5_tts.eval.utils_eval import (
|
17 |
+
get_inference_prompt,
|
18 |
+
get_librispeech_test_clean_metainfo,
|
19 |
+
get_seedtts_testset_metainfo,
|
20 |
+
)
|
21 |
+
from f5_tts.infer.utils_infer import load_checkpoint, load_vocoder
|
22 |
+
from f5_tts.model import CFM, DiT, UNetT # noqa: F401. used for config
|
23 |
+
from f5_tts.model.utils import get_tokenizer
|
24 |
+
|
25 |
+
accelerator = Accelerator()
|
26 |
+
device = f"cuda:{accelerator.process_index}"
|
27 |
+
|
28 |
+
|
29 |
+
use_ema = True
|
30 |
+
target_rms = 0.1
|
31 |
+
|
32 |
+
|
33 |
+
rel_path = str(files("f5_tts").joinpath("../../"))
|
34 |
+
|
35 |
+
|
36 |
+
def main():
|
37 |
+
parser = argparse.ArgumentParser(description="batch inference")
|
38 |
+
|
39 |
+
parser.add_argument("-s", "--seed", default=None, type=int)
|
40 |
+
parser.add_argument("-n", "--expname", required=True)
|
41 |
+
parser.add_argument("-c", "--ckptstep", default=1250000, type=int)
|
42 |
+
|
43 |
+
parser.add_argument("-nfe", "--nfestep", default=32, type=int)
|
44 |
+
parser.add_argument("-o", "--odemethod", default="euler")
|
45 |
+
parser.add_argument("-ss", "--swaysampling", default=-1, type=float)
|
46 |
+
|
47 |
+
parser.add_argument("-t", "--testset", required=True)
|
48 |
+
|
49 |
+
args = parser.parse_args()
|
50 |
+
|
51 |
+
seed = args.seed
|
52 |
+
exp_name = args.expname
|
53 |
+
ckpt_step = args.ckptstep
|
54 |
+
|
55 |
+
nfe_step = args.nfestep
|
56 |
+
ode_method = args.odemethod
|
57 |
+
sway_sampling_coef = args.swaysampling
|
58 |
+
|
59 |
+
testset = args.testset
|
60 |
+
|
61 |
+
infer_batch_size = 1 # max frames. 1 for ddp single inference (recommended)
|
62 |
+
cfg_strength = 2.0
|
63 |
+
speed = 1.0
|
64 |
+
use_truth_duration = False
|
65 |
+
no_ref_audio = False
|
66 |
+
|
67 |
+
model_cfg = OmegaConf.load(str(files("f5_tts").joinpath(f"configs/{exp_name}.yaml")))
|
68 |
+
model_cls = globals()[model_cfg.model.backbone]
|
69 |
+
model_arc = model_cfg.model.arch
|
70 |
+
|
71 |
+
dataset_name = model_cfg.datasets.name
|
72 |
+
tokenizer = model_cfg.model.tokenizer
|
73 |
+
|
74 |
+
mel_spec_type = model_cfg.model.mel_spec.mel_spec_type
|
75 |
+
target_sample_rate = model_cfg.model.mel_spec.target_sample_rate
|
76 |
+
n_mel_channels = model_cfg.model.mel_spec.n_mel_channels
|
77 |
+
hop_length = model_cfg.model.mel_spec.hop_length
|
78 |
+
win_length = model_cfg.model.mel_spec.win_length
|
79 |
+
n_fft = model_cfg.model.mel_spec.n_fft
|
80 |
+
|
81 |
+
if testset == "ls_pc_test_clean":
|
82 |
+
metalst = rel_path + "/data/librispeech_pc_test_clean_cross_sentence.lst"
|
83 |
+
librispeech_test_clean_path = "<SOME_PATH>/LibriSpeech/test-clean" # test-clean path
|
84 |
+
metainfo = get_librispeech_test_clean_metainfo(metalst, librispeech_test_clean_path)
|
85 |
+
|
86 |
+
elif testset == "seedtts_test_zh":
|
87 |
+
metalst = rel_path + "/data/seedtts_testset/zh/meta.lst"
|
88 |
+
metainfo = get_seedtts_testset_metainfo(metalst)
|
89 |
+
|
90 |
+
elif testset == "seedtts_test_en":
|
91 |
+
metalst = rel_path + "/data/seedtts_testset/en/meta.lst"
|
92 |
+
metainfo = get_seedtts_testset_metainfo(metalst)
|
93 |
+
|
94 |
+
# path to save genereted wavs
|
95 |
+
output_dir = (
|
96 |
+
f"{rel_path}/"
|
97 |
+
f"results/{exp_name}_{ckpt_step}/{testset}/"
|
98 |
+
f"seed{seed}_{ode_method}_nfe{nfe_step}_{mel_spec_type}"
|
99 |
+
f"{f'_ss{sway_sampling_coef}' if sway_sampling_coef else ''}"
|
100 |
+
f"_cfg{cfg_strength}_speed{speed}"
|
101 |
+
f"{'_gt-dur' if use_truth_duration else ''}"
|
102 |
+
f"{'_no-ref-audio' if no_ref_audio else ''}"
|
103 |
+
)
|
104 |
+
|
105 |
+
# -------------------------------------------------#
|
106 |
+
|
107 |
+
prompts_all = get_inference_prompt(
|
108 |
+
metainfo,
|
109 |
+
speed=speed,
|
110 |
+
tokenizer=tokenizer,
|
111 |
+
target_sample_rate=target_sample_rate,
|
112 |
+
n_mel_channels=n_mel_channels,
|
113 |
+
hop_length=hop_length,
|
114 |
+
mel_spec_type=mel_spec_type,
|
115 |
+
target_rms=target_rms,
|
116 |
+
use_truth_duration=use_truth_duration,
|
117 |
+
infer_batch_size=infer_batch_size,
|
118 |
+
)
|
119 |
+
|
120 |
+
# Vocoder model
|
121 |
+
local = False
|
122 |
+
if mel_spec_type == "vocos":
|
123 |
+
vocoder_local_path = "../checkpoints/charactr/vocos-mel-24khz"
|
124 |
+
elif mel_spec_type == "bigvgan":
|
125 |
+
vocoder_local_path = "../checkpoints/bigvgan_v2_24khz_100band_256x"
|
126 |
+
vocoder = load_vocoder(vocoder_name=mel_spec_type, is_local=local, local_path=vocoder_local_path)
|
127 |
+
|
128 |
+
# Tokenizer
|
129 |
+
vocab_char_map, vocab_size = get_tokenizer(dataset_name, tokenizer)
|
130 |
+
|
131 |
+
# Model
|
132 |
+
model = CFM(
|
133 |
+
transformer=model_cls(**model_arc, text_num_embeds=vocab_size, mel_dim=n_mel_channels),
|
134 |
+
mel_spec_kwargs=dict(
|
135 |
+
n_fft=n_fft,
|
136 |
+
hop_length=hop_length,
|
137 |
+
win_length=win_length,
|
138 |
+
n_mel_channels=n_mel_channels,
|
139 |
+
target_sample_rate=target_sample_rate,
|
140 |
+
mel_spec_type=mel_spec_type,
|
141 |
+
),
|
142 |
+
odeint_kwargs=dict(
|
143 |
+
method=ode_method,
|
144 |
+
),
|
145 |
+
vocab_char_map=vocab_char_map,
|
146 |
+
).to(device)
|
147 |
+
|
148 |
+
ckpt_path = rel_path + f"/ckpts/{exp_name}/model_{ckpt_step}.pt"
|
149 |
+
if not os.path.exists(ckpt_path):
|
150 |
+
print("Loading from self-organized training checkpoints rather than released pretrained.")
|
151 |
+
ckpt_path = rel_path + f"/{model_cfg.ckpts.save_dir}/model_{ckpt_step}.pt"
|
152 |
+
dtype = torch.float32 if mel_spec_type == "bigvgan" else None
|
153 |
+
model = load_checkpoint(model, ckpt_path, device, dtype=dtype, use_ema=use_ema)
|
154 |
+
|
155 |
+
if not os.path.exists(output_dir) and accelerator.is_main_process:
|
156 |
+
os.makedirs(output_dir)
|
157 |
+
|
158 |
+
# start batch inference
|
159 |
+
accelerator.wait_for_everyone()
|
160 |
+
start = time.time()
|
161 |
+
|
162 |
+
with accelerator.split_between_processes(prompts_all) as prompts:
|
163 |
+
for prompt in tqdm(prompts, disable=not accelerator.is_local_main_process):
|
164 |
+
utts, ref_rms_list, ref_mels, ref_mel_lens, total_mel_lens, final_text_list = prompt
|
165 |
+
ref_mels = ref_mels.to(device)
|
166 |
+
ref_mel_lens = torch.tensor(ref_mel_lens, dtype=torch.long).to(device)
|
167 |
+
total_mel_lens = torch.tensor(total_mel_lens, dtype=torch.long).to(device)
|
168 |
+
|
169 |
+
# Inference
|
170 |
+
with torch.inference_mode():
|
171 |
+
generated, _ = model.sample(
|
172 |
+
cond=ref_mels,
|
173 |
+
text=final_text_list,
|
174 |
+
duration=total_mel_lens,
|
175 |
+
lens=ref_mel_lens,
|
176 |
+
steps=nfe_step,
|
177 |
+
cfg_strength=cfg_strength,
|
178 |
+
sway_sampling_coef=sway_sampling_coef,
|
179 |
+
no_ref_audio=no_ref_audio,
|
180 |
+
seed=seed,
|
181 |
+
)
|
182 |
+
# Final result
|
183 |
+
for i, gen in enumerate(generated):
|
184 |
+
gen = gen[ref_mel_lens[i] : total_mel_lens[i], :].unsqueeze(0)
|
185 |
+
gen_mel_spec = gen.permute(0, 2, 1).to(torch.float32)
|
186 |
+
if mel_spec_type == "vocos":
|
187 |
+
generated_wave = vocoder.decode(gen_mel_spec).cpu()
|
188 |
+
elif mel_spec_type == "bigvgan":
|
189 |
+
generated_wave = vocoder(gen_mel_spec).squeeze(0).cpu()
|
190 |
+
|
191 |
+
if ref_rms_list[i] < target_rms:
|
192 |
+
generated_wave = generated_wave * ref_rms_list[i] / target_rms
|
193 |
+
torchaudio.save(f"{output_dir}/{utts[i]}.wav", generated_wave, target_sample_rate)
|
194 |
+
|
195 |
+
accelerator.wait_for_everyone()
|
196 |
+
if accelerator.is_main_process:
|
197 |
+
timediff = time.time() - start
|
198 |
+
print(f"Done batch inference in {timediff / 60 :.2f} minutes.")
|
199 |
+
|
200 |
+
|
201 |
+
if __name__ == "__main__":
|
202 |
+
main()
|
src/f5_tts/eval/eval_infer_batch.sh
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# e.g. F5-TTS, 16 NFE
|
4 |
+
accelerate launch src/f5_tts/eval/eval_infer_batch.py -s 0 -n "F5TTS_v1_Base" -t "seedtts_test_zh" -nfe 16
|
5 |
+
accelerate launch src/f5_tts/eval/eval_infer_batch.py -s 0 -n "F5TTS_v1_Base" -t "seedtts_test_en" -nfe 16
|
6 |
+
accelerate launch src/f5_tts/eval/eval_infer_batch.py -s 0 -n "F5TTS_v1_Base" -t "ls_pc_test_clean" -nfe 16
|
7 |
+
|
8 |
+
# e.g. Vanilla E2 TTS, 32 NFE
|
9 |
+
accelerate launch src/f5_tts/eval/eval_infer_batch.py -s 0 -n "E2TTS_Base" -c 1200000 -t "seedtts_test_zh" -o "midpoint" -ss 0
|
10 |
+
accelerate launch src/f5_tts/eval/eval_infer_batch.py -s 0 -n "E2TTS_Base" -c 1200000 -t "seedtts_test_en" -o "midpoint" -ss 0
|
11 |
+
accelerate launch src/f5_tts/eval/eval_infer_batch.py -s 0 -n "E2TTS_Base" -c 1200000 -t "ls_pc_test_clean" -o "midpoint" -ss 0
|
12 |
+
|
13 |
+
# e.g. evaluate F5-TTS 16 NFE result on Seed-TTS test-zh
|
14 |
+
python src/f5_tts/eval/eval_seedtts_testset.py -e wer -l zh --gen_wav_dir results/F5TTS_v1_Base_1250000/seedtts_test_zh/seed0_euler_nfe32_vocos_ss-1_cfg2.0_speed1.0 --gpu_nums 8
|
15 |
+
python src/f5_tts/eval/eval_seedtts_testset.py -e sim -l zh --gen_wav_dir results/F5TTS_v1_Base_1250000/seedtts_test_zh/seed0_euler_nfe32_vocos_ss-1_cfg2.0_speed1.0 --gpu_nums 8
|
16 |
+
python src/f5_tts/eval/eval_utmos.py --audio_dir results/F5TTS_v1_Base_1250000/seedtts_test_zh/seed0_euler_nfe32_vocos_ss-1_cfg2.0_speed1.0
|
17 |
+
|
18 |
+
# etc.
|
src/f5_tts/eval/eval_librispeech_test_clean.py
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Evaluate with Librispeech test-clean, ~3s prompt to generate 4-10s audio (the way of valle/voicebox evaluation)
|
2 |
+
|
3 |
+
import argparse
|
4 |
+
import json
|
5 |
+
import os
|
6 |
+
import sys
|
7 |
+
|
8 |
+
sys.path.append(os.getcwd())
|
9 |
+
|
10 |
+
import multiprocessing as mp
|
11 |
+
from importlib.resources import files
|
12 |
+
|
13 |
+
import numpy as np
|
14 |
+
from f5_tts.eval.utils_eval import (
|
15 |
+
get_librispeech_test,
|
16 |
+
run_asr_wer,
|
17 |
+
run_sim,
|
18 |
+
)
|
19 |
+
|
20 |
+
rel_path = str(files("f5_tts").joinpath("../../"))
|
21 |
+
|
22 |
+
|
23 |
+
def get_args():
|
24 |
+
parser = argparse.ArgumentParser()
|
25 |
+
parser.add_argument("-e", "--eval_task", type=str, default="wer", choices=["sim", "wer"])
|
26 |
+
parser.add_argument("-l", "--lang", type=str, default="en")
|
27 |
+
parser.add_argument("-g", "--gen_wav_dir", type=str, required=True)
|
28 |
+
parser.add_argument("-p", "--librispeech_test_clean_path", type=str, required=True)
|
29 |
+
parser.add_argument("-n", "--gpu_nums", type=int, default=8, help="Number of GPUs to use")
|
30 |
+
parser.add_argument("--local", action="store_true", help="Use local custom checkpoint directory")
|
31 |
+
return parser.parse_args()
|
32 |
+
|
33 |
+
|
34 |
+
def main():
|
35 |
+
args = get_args()
|
36 |
+
eval_task = args.eval_task
|
37 |
+
lang = args.lang
|
38 |
+
librispeech_test_clean_path = args.librispeech_test_clean_path # test-clean path
|
39 |
+
gen_wav_dir = args.gen_wav_dir
|
40 |
+
metalst = rel_path + "/data/librispeech_pc_test_clean_cross_sentence.lst"
|
41 |
+
|
42 |
+
gpus = list(range(args.gpu_nums))
|
43 |
+
test_set = get_librispeech_test(metalst, gen_wav_dir, gpus, librispeech_test_clean_path)
|
44 |
+
|
45 |
+
## In LibriSpeech, some speakers utilized varying voice characteristics for different characters in the book,
|
46 |
+
## leading to a low similarity for the ground truth in some cases.
|
47 |
+
# test_set = get_librispeech_test(metalst, gen_wav_dir, gpus, librispeech_test_clean_path, eval_ground_truth = True) # eval ground truth
|
48 |
+
|
49 |
+
local = args.local
|
50 |
+
if local: # use local custom checkpoint dir
|
51 |
+
asr_ckpt_dir = "../checkpoints/Systran/faster-whisper-large-v3"
|
52 |
+
else:
|
53 |
+
asr_ckpt_dir = "" # auto download to cache dir
|
54 |
+
wavlm_ckpt_dir = "../checkpoints/UniSpeech/wavlm_large_finetune.pth"
|
55 |
+
|
56 |
+
# --------------------------------------------------------------------------
|
57 |
+
|
58 |
+
full_results = []
|
59 |
+
metrics = []
|
60 |
+
|
61 |
+
if eval_task == "wer":
|
62 |
+
with mp.Pool(processes=len(gpus)) as pool:
|
63 |
+
args = [(rank, lang, sub_test_set, asr_ckpt_dir) for (rank, sub_test_set) in test_set]
|
64 |
+
results = pool.map(run_asr_wer, args)
|
65 |
+
for r in results:
|
66 |
+
full_results.extend(r)
|
67 |
+
elif eval_task == "sim":
|
68 |
+
with mp.Pool(processes=len(gpus)) as pool:
|
69 |
+
args = [(rank, sub_test_set, wavlm_ckpt_dir) for (rank, sub_test_set) in test_set]
|
70 |
+
results = pool.map(run_sim, args)
|
71 |
+
for r in results:
|
72 |
+
full_results.extend(r)
|
73 |
+
else:
|
74 |
+
raise ValueError(f"Unknown metric type: {eval_task}")
|
75 |
+
|
76 |
+
result_path = f"{gen_wav_dir}/_{eval_task}_results.jsonl"
|
77 |
+
with open(result_path, "w") as f:
|
78 |
+
for line in full_results:
|
79 |
+
metrics.append(line[eval_task])
|
80 |
+
f.write(json.dumps(line, ensure_ascii=False) + "\n")
|
81 |
+
metric = round(np.mean(metrics), 5)
|
82 |
+
f.write(f"\n{eval_task.upper()}: {metric}\n")
|
83 |
+
|
84 |
+
print(f"\nTotal {len(metrics)} samples")
|
85 |
+
print(f"{eval_task.upper()}: {metric}")
|
86 |
+
print(f"{eval_task.upper()} results saved to {result_path}")
|
87 |
+
|
88 |
+
|
89 |
+
if __name__ == "__main__":
|
90 |
+
main()
|
src/f5_tts/eval/eval_seedtts_testset.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Evaluate with Seed-TTS testset
|
2 |
+
|
3 |
+
import argparse
|
4 |
+
import json
|
5 |
+
import os
|
6 |
+
import sys
|
7 |
+
|
8 |
+
sys.path.append(os.getcwd())
|
9 |
+
|
10 |
+
import multiprocessing as mp
|
11 |
+
from importlib.resources import files
|
12 |
+
|
13 |
+
import numpy as np
|
14 |
+
from f5_tts.eval.utils_eval import (
|
15 |
+
get_seed_tts_test,
|
16 |
+
run_asr_wer,
|
17 |
+
run_sim,
|
18 |
+
)
|
19 |
+
|
20 |
+
rel_path = str(files("f5_tts").joinpath("../../"))
|
21 |
+
|
22 |
+
|
23 |
+
def get_args():
|
24 |
+
parser = argparse.ArgumentParser()
|
25 |
+
parser.add_argument("-e", "--eval_task", type=str, default="wer", choices=["sim", "wer"])
|
26 |
+
parser.add_argument("-l", "--lang", type=str, default="en", choices=["zh", "en"])
|
27 |
+
parser.add_argument("-g", "--gen_wav_dir", type=str, required=True)
|
28 |
+
parser.add_argument("-n", "--gpu_nums", type=int, default=8, help="Number of GPUs to use")
|
29 |
+
parser.add_argument("--local", action="store_true", help="Use local custom checkpoint directory")
|
30 |
+
return parser.parse_args()
|
31 |
+
|
32 |
+
|
33 |
+
def main():
|
34 |
+
args = get_args()
|
35 |
+
eval_task = args.eval_task
|
36 |
+
lang = args.lang
|
37 |
+
gen_wav_dir = args.gen_wav_dir
|
38 |
+
metalst = rel_path + f"/data/seedtts_testset/{lang}/meta.lst" # seed-tts testset
|
39 |
+
|
40 |
+
# NOTE. paraformer-zh result will be slightly different according to the number of gpus, cuz batchsize is different
|
41 |
+
# zh 1.254 seems a result of 4 workers wer_seed_tts
|
42 |
+
gpus = list(range(args.gpu_nums))
|
43 |
+
test_set = get_seed_tts_test(metalst, gen_wav_dir, gpus)
|
44 |
+
|
45 |
+
local = args.local
|
46 |
+
if local: # use local custom checkpoint dir
|
47 |
+
if lang == "zh":
|
48 |
+
asr_ckpt_dir = "../checkpoints/funasr" # paraformer-zh dir under funasr
|
49 |
+
elif lang == "en":
|
50 |
+
asr_ckpt_dir = "../checkpoints/Systran/faster-whisper-large-v3"
|
51 |
+
else:
|
52 |
+
asr_ckpt_dir = "" # auto download to cache dir
|
53 |
+
wavlm_ckpt_dir = "../checkpoints/UniSpeech/wavlm_large_finetune.pth"
|
54 |
+
|
55 |
+
# --------------------------------------------------------------------------
|
56 |
+
|
57 |
+
full_results = []
|
58 |
+
metrics = []
|
59 |
+
|
60 |
+
if eval_task == "wer":
|
61 |
+
with mp.Pool(processes=len(gpus)) as pool:
|
62 |
+
args = [(rank, lang, sub_test_set, asr_ckpt_dir) for (rank, sub_test_set) in test_set]
|
63 |
+
results = pool.map(run_asr_wer, args)
|
64 |
+
for r in results:
|
65 |
+
full_results.extend(r)
|
66 |
+
elif eval_task == "sim":
|
67 |
+
with mp.Pool(processes=len(gpus)) as pool:
|
68 |
+
args = [(rank, sub_test_set, wavlm_ckpt_dir) for (rank, sub_test_set) in test_set]
|
69 |
+
results = pool.map(run_sim, args)
|
70 |
+
for r in results:
|
71 |
+
full_results.extend(r)
|
72 |
+
else:
|
73 |
+
raise ValueError(f"Unknown metric type: {eval_task}")
|
74 |
+
|
75 |
+
result_path = f"{gen_wav_dir}/_{eval_task}_results.jsonl"
|
76 |
+
with open(result_path, "w") as f:
|
77 |
+
for line in full_results:
|
78 |
+
metrics.append(line[eval_task])
|
79 |
+
f.write(json.dumps(line, ensure_ascii=False) + "\n")
|
80 |
+
metric = round(np.mean(metrics), 5)
|
81 |
+
f.write(f"\n{eval_task.upper()}: {metric}\n")
|
82 |
+
|
83 |
+
print(f"\nTotal {len(metrics)} samples")
|
84 |
+
print(f"{eval_task.upper()}: {metric}")
|
85 |
+
print(f"{eval_task.upper()} results saved to {result_path}")
|
86 |
+
|
87 |
+
|
88 |
+
if __name__ == "__main__":
|
89 |
+
main()
|
src/f5_tts/eval/eval_utmos.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import json
|
3 |
+
from pathlib import Path
|
4 |
+
|
5 |
+
import librosa
|
6 |
+
import torch
|
7 |
+
from tqdm import tqdm
|
8 |
+
|
9 |
+
|
10 |
+
def main():
|
11 |
+
parser = argparse.ArgumentParser(description="UTMOS Evaluation")
|
12 |
+
parser.add_argument("--audio_dir", type=str, required=True, help="Audio file path.")
|
13 |
+
parser.add_argument("--ext", type=str, default="wav", help="Audio extension.")
|
14 |
+
args = parser.parse_args()
|
15 |
+
|
16 |
+
device = "cuda" if torch.cuda.is_available() else "xpu" if torch.xpu.is_available() else "cpu"
|
17 |
+
|
18 |
+
predictor = torch.hub.load("tarepan/SpeechMOS:v1.2.0", "utmos22_strong", trust_repo=True)
|
19 |
+
predictor = predictor.to(device)
|
20 |
+
|
21 |
+
audio_paths = list(Path(args.audio_dir).rglob(f"*.{args.ext}"))
|
22 |
+
utmos_score = 0
|
23 |
+
|
24 |
+
utmos_result_path = Path(args.audio_dir) / "_utmos_results.jsonl"
|
25 |
+
with open(utmos_result_path, "w", encoding="utf-8") as f:
|
26 |
+
for audio_path in tqdm(audio_paths, desc="Processing"):
|
27 |
+
wav, sr = librosa.load(audio_path, sr=None, mono=True)
|
28 |
+
wav_tensor = torch.from_numpy(wav).to(device).unsqueeze(0)
|
29 |
+
score = predictor(wav_tensor, sr)
|
30 |
+
line = {}
|
31 |
+
line["wav"], line["utmos"] = str(audio_path.stem), score.item()
|
32 |
+
utmos_score += score.item()
|
33 |
+
f.write(json.dumps(line, ensure_ascii=False) + "\n")
|
34 |
+
avg_score = utmos_score / len(audio_paths) if len(audio_paths) > 0 else 0
|
35 |
+
f.write(f"\nUTMOS: {avg_score:.4f}\n")
|
36 |
+
|
37 |
+
print(f"UTMOS: {avg_score:.4f}")
|
38 |
+
print(f"UTMOS results saved to {utmos_result_path}")
|
39 |
+
|
40 |
+
|
41 |
+
if __name__ == "__main__":
|
42 |
+
main()
|
src/f5_tts/eval/utils_eval.py
ADDED
@@ -0,0 +1,418 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import os
|
3 |
+
import random
|
4 |
+
import string
|
5 |
+
from pathlib import Path
|
6 |
+
|
7 |
+
import torch
|
8 |
+
import torch.nn.functional as F
|
9 |
+
import torchaudio
|
10 |
+
from tqdm import tqdm
|
11 |
+
|
12 |
+
from f5_tts.eval.ecapa_tdnn import ECAPA_TDNN_SMALL
|
13 |
+
from f5_tts.model.modules import MelSpec
|
14 |
+
from f5_tts.model.utils import convert_char_to_pinyin
|
15 |
+
|
16 |
+
|
17 |
+
# seedtts testset metainfo: utt, prompt_text, prompt_wav, gt_text, gt_wav
|
18 |
+
def get_seedtts_testset_metainfo(metalst):
|
19 |
+
f = open(metalst)
|
20 |
+
lines = f.readlines()
|
21 |
+
f.close()
|
22 |
+
metainfo = []
|
23 |
+
for line in lines:
|
24 |
+
if len(line.strip().split("|")) == 5:
|
25 |
+
utt, prompt_text, prompt_wav, gt_text, gt_wav = line.strip().split("|")
|
26 |
+
elif len(line.strip().split("|")) == 4:
|
27 |
+
utt, prompt_text, prompt_wav, gt_text = line.strip().split("|")
|
28 |
+
gt_wav = os.path.join(os.path.dirname(metalst), "wavs", utt + ".wav")
|
29 |
+
if not os.path.isabs(prompt_wav):
|
30 |
+
prompt_wav = os.path.join(os.path.dirname(metalst), prompt_wav)
|
31 |
+
metainfo.append((utt, prompt_text, prompt_wav, gt_text, gt_wav))
|
32 |
+
return metainfo
|
33 |
+
|
34 |
+
|
35 |
+
# librispeech test-clean metainfo: gen_utt, ref_txt, ref_wav, gen_txt, gen_wav
|
36 |
+
def get_librispeech_test_clean_metainfo(metalst, librispeech_test_clean_path):
|
37 |
+
f = open(metalst)
|
38 |
+
lines = f.readlines()
|
39 |
+
f.close()
|
40 |
+
metainfo = []
|
41 |
+
for line in lines:
|
42 |
+
ref_utt, ref_dur, ref_txt, gen_utt, gen_dur, gen_txt = line.strip().split("\t")
|
43 |
+
|
44 |
+
# ref_txt = ref_txt[0] + ref_txt[1:].lower() + '.' # if use librispeech test-clean (no-pc)
|
45 |
+
ref_spk_id, ref_chaptr_id, _ = ref_utt.split("-")
|
46 |
+
ref_wav = os.path.join(librispeech_test_clean_path, ref_spk_id, ref_chaptr_id, ref_utt + ".flac")
|
47 |
+
|
48 |
+
# gen_txt = gen_txt[0] + gen_txt[1:].lower() + '.' # if use librispeech test-clean (no-pc)
|
49 |
+
gen_spk_id, gen_chaptr_id, _ = gen_utt.split("-")
|
50 |
+
gen_wav = os.path.join(librispeech_test_clean_path, gen_spk_id, gen_chaptr_id, gen_utt + ".flac")
|
51 |
+
|
52 |
+
metainfo.append((gen_utt, ref_txt, ref_wav, " " + gen_txt, gen_wav))
|
53 |
+
|
54 |
+
return metainfo
|
55 |
+
|
56 |
+
|
57 |
+
# padded to max length mel batch
|
58 |
+
def padded_mel_batch(ref_mels):
|
59 |
+
max_mel_length = torch.LongTensor([mel.shape[-1] for mel in ref_mels]).amax()
|
60 |
+
padded_ref_mels = []
|
61 |
+
for mel in ref_mels:
|
62 |
+
padded_ref_mel = F.pad(mel, (0, max_mel_length - mel.shape[-1]), value=0)
|
63 |
+
padded_ref_mels.append(padded_ref_mel)
|
64 |
+
padded_ref_mels = torch.stack(padded_ref_mels)
|
65 |
+
padded_ref_mels = padded_ref_mels.permute(0, 2, 1)
|
66 |
+
return padded_ref_mels
|
67 |
+
|
68 |
+
|
69 |
+
# get prompts from metainfo containing: utt, prompt_text, prompt_wav, gt_text, gt_wav
|
70 |
+
|
71 |
+
|
72 |
+
def get_inference_prompt(
|
73 |
+
metainfo,
|
74 |
+
speed=1.0,
|
75 |
+
tokenizer="pinyin",
|
76 |
+
polyphone=True,
|
77 |
+
target_sample_rate=24000,
|
78 |
+
n_fft=1024,
|
79 |
+
win_length=1024,
|
80 |
+
n_mel_channels=100,
|
81 |
+
hop_length=256,
|
82 |
+
mel_spec_type="vocos",
|
83 |
+
target_rms=0.1,
|
84 |
+
use_truth_duration=False,
|
85 |
+
infer_batch_size=1,
|
86 |
+
num_buckets=200,
|
87 |
+
min_secs=3,
|
88 |
+
max_secs=40,
|
89 |
+
):
|
90 |
+
prompts_all = []
|
91 |
+
|
92 |
+
min_tokens = min_secs * target_sample_rate // hop_length
|
93 |
+
max_tokens = max_secs * target_sample_rate // hop_length
|
94 |
+
|
95 |
+
batch_accum = [0] * num_buckets
|
96 |
+
utts, ref_rms_list, ref_mels, ref_mel_lens, total_mel_lens, final_text_list = (
|
97 |
+
[[] for _ in range(num_buckets)] for _ in range(6)
|
98 |
+
)
|
99 |
+
|
100 |
+
mel_spectrogram = MelSpec(
|
101 |
+
n_fft=n_fft,
|
102 |
+
hop_length=hop_length,
|
103 |
+
win_length=win_length,
|
104 |
+
n_mel_channels=n_mel_channels,
|
105 |
+
target_sample_rate=target_sample_rate,
|
106 |
+
mel_spec_type=mel_spec_type,
|
107 |
+
)
|
108 |
+
|
109 |
+
for utt, prompt_text, prompt_wav, gt_text, gt_wav in tqdm(metainfo, desc="Processing prompts..."):
|
110 |
+
# Audio
|
111 |
+
ref_audio, ref_sr = torchaudio.load(prompt_wav)
|
112 |
+
ref_rms = torch.sqrt(torch.mean(torch.square(ref_audio)))
|
113 |
+
if ref_rms < target_rms:
|
114 |
+
ref_audio = ref_audio * target_rms / ref_rms
|
115 |
+
assert ref_audio.shape[-1] > 5000, f"Empty prompt wav: {prompt_wav}, or torchaudio backend issue."
|
116 |
+
if ref_sr != target_sample_rate:
|
117 |
+
resampler = torchaudio.transforms.Resample(ref_sr, target_sample_rate)
|
118 |
+
ref_audio = resampler(ref_audio)
|
119 |
+
|
120 |
+
# Text
|
121 |
+
if len(prompt_text[-1].encode("utf-8")) == 1:
|
122 |
+
prompt_text = prompt_text + " "
|
123 |
+
text = [prompt_text + gt_text]
|
124 |
+
if tokenizer == "pinyin":
|
125 |
+
text_list = convert_char_to_pinyin(text, polyphone=polyphone)
|
126 |
+
else:
|
127 |
+
text_list = text
|
128 |
+
|
129 |
+
# Duration, mel frame length
|
130 |
+
ref_mel_len = ref_audio.shape[-1] // hop_length
|
131 |
+
if use_truth_duration:
|
132 |
+
gt_audio, gt_sr = torchaudio.load(gt_wav)
|
133 |
+
if gt_sr != target_sample_rate:
|
134 |
+
resampler = torchaudio.transforms.Resample(gt_sr, target_sample_rate)
|
135 |
+
gt_audio = resampler(gt_audio)
|
136 |
+
total_mel_len = ref_mel_len + int(gt_audio.shape[-1] / hop_length / speed)
|
137 |
+
|
138 |
+
# # test vocoder resynthesis
|
139 |
+
# ref_audio = gt_audio
|
140 |
+
else:
|
141 |
+
ref_text_len = len(prompt_text.encode("utf-8"))
|
142 |
+
gen_text_len = len(gt_text.encode("utf-8"))
|
143 |
+
total_mel_len = ref_mel_len + int(ref_mel_len / ref_text_len * gen_text_len / speed)
|
144 |
+
|
145 |
+
# to mel spectrogram
|
146 |
+
ref_mel = mel_spectrogram(ref_audio)
|
147 |
+
ref_mel = ref_mel.squeeze(0)
|
148 |
+
|
149 |
+
# deal with batch
|
150 |
+
assert infer_batch_size > 0, "infer_batch_size should be greater than 0."
|
151 |
+
assert (
|
152 |
+
min_tokens <= total_mel_len <= max_tokens
|
153 |
+
), f"Audio {utt} has duration {total_mel_len*hop_length//target_sample_rate}s out of range [{min_secs}, {max_secs}]."
|
154 |
+
bucket_i = math.floor((total_mel_len - min_tokens) / (max_tokens - min_tokens + 1) * num_buckets)
|
155 |
+
|
156 |
+
utts[bucket_i].append(utt)
|
157 |
+
ref_rms_list[bucket_i].append(ref_rms)
|
158 |
+
ref_mels[bucket_i].append(ref_mel)
|
159 |
+
ref_mel_lens[bucket_i].append(ref_mel_len)
|
160 |
+
total_mel_lens[bucket_i].append(total_mel_len)
|
161 |
+
final_text_list[bucket_i].extend(text_list)
|
162 |
+
|
163 |
+
batch_accum[bucket_i] += total_mel_len
|
164 |
+
|
165 |
+
if batch_accum[bucket_i] >= infer_batch_size:
|
166 |
+
# print(f"\n{len(ref_mels[bucket_i][0][0])}\n{ref_mel_lens[bucket_i]}\n{total_mel_lens[bucket_i]}")
|
167 |
+
prompts_all.append(
|
168 |
+
(
|
169 |
+
utts[bucket_i],
|
170 |
+
ref_rms_list[bucket_i],
|
171 |
+
padded_mel_batch(ref_mels[bucket_i]),
|
172 |
+
ref_mel_lens[bucket_i],
|
173 |
+
total_mel_lens[bucket_i],
|
174 |
+
final_text_list[bucket_i],
|
175 |
+
)
|
176 |
+
)
|
177 |
+
batch_accum[bucket_i] = 0
|
178 |
+
(
|
179 |
+
utts[bucket_i],
|
180 |
+
ref_rms_list[bucket_i],
|
181 |
+
ref_mels[bucket_i],
|
182 |
+
ref_mel_lens[bucket_i],
|
183 |
+
total_mel_lens[bucket_i],
|
184 |
+
final_text_list[bucket_i],
|
185 |
+
) = [], [], [], [], [], []
|
186 |
+
|
187 |
+
# add residual
|
188 |
+
for bucket_i, bucket_frames in enumerate(batch_accum):
|
189 |
+
if bucket_frames > 0:
|
190 |
+
prompts_all.append(
|
191 |
+
(
|
192 |
+
utts[bucket_i],
|
193 |
+
ref_rms_list[bucket_i],
|
194 |
+
padded_mel_batch(ref_mels[bucket_i]),
|
195 |
+
ref_mel_lens[bucket_i],
|
196 |
+
total_mel_lens[bucket_i],
|
197 |
+
final_text_list[bucket_i],
|
198 |
+
)
|
199 |
+
)
|
200 |
+
# not only leave easy work for last workers
|
201 |
+
random.seed(666)
|
202 |
+
random.shuffle(prompts_all)
|
203 |
+
|
204 |
+
return prompts_all
|
205 |
+
|
206 |
+
|
207 |
+
# get wav_res_ref_text of seed-tts test metalst
|
208 |
+
# https://github.com/BytedanceSpeech/seed-tts-eval
|
209 |
+
|
210 |
+
|
211 |
+
def get_seed_tts_test(metalst, gen_wav_dir, gpus):
|
212 |
+
f = open(metalst)
|
213 |
+
lines = f.readlines()
|
214 |
+
f.close()
|
215 |
+
|
216 |
+
test_set_ = []
|
217 |
+
for line in tqdm(lines):
|
218 |
+
if len(line.strip().split("|")) == 5:
|
219 |
+
utt, prompt_text, prompt_wav, gt_text, gt_wav = line.strip().split("|")
|
220 |
+
elif len(line.strip().split("|")) == 4:
|
221 |
+
utt, prompt_text, prompt_wav, gt_text = line.strip().split("|")
|
222 |
+
|
223 |
+
if not os.path.exists(os.path.join(gen_wav_dir, utt + ".wav")):
|
224 |
+
continue
|
225 |
+
gen_wav = os.path.join(gen_wav_dir, utt + ".wav")
|
226 |
+
if not os.path.isabs(prompt_wav):
|
227 |
+
prompt_wav = os.path.join(os.path.dirname(metalst), prompt_wav)
|
228 |
+
|
229 |
+
test_set_.append((gen_wav, prompt_wav, gt_text))
|
230 |
+
|
231 |
+
num_jobs = len(gpus)
|
232 |
+
if num_jobs == 1:
|
233 |
+
return [(gpus[0], test_set_)]
|
234 |
+
|
235 |
+
wav_per_job = len(test_set_) // num_jobs + 1
|
236 |
+
test_set = []
|
237 |
+
for i in range(num_jobs):
|
238 |
+
test_set.append((gpus[i], test_set_[i * wav_per_job : (i + 1) * wav_per_job]))
|
239 |
+
|
240 |
+
return test_set
|
241 |
+
|
242 |
+
|
243 |
+
# get librispeech test-clean cross sentence test
|
244 |
+
|
245 |
+
|
246 |
+
def get_librispeech_test(metalst, gen_wav_dir, gpus, librispeech_test_clean_path, eval_ground_truth=False):
|
247 |
+
f = open(metalst)
|
248 |
+
lines = f.readlines()
|
249 |
+
f.close()
|
250 |
+
|
251 |
+
test_set_ = []
|
252 |
+
for line in tqdm(lines):
|
253 |
+
ref_utt, ref_dur, ref_txt, gen_utt, gen_dur, gen_txt = line.strip().split("\t")
|
254 |
+
|
255 |
+
if eval_ground_truth:
|
256 |
+
gen_spk_id, gen_chaptr_id, _ = gen_utt.split("-")
|
257 |
+
gen_wav = os.path.join(librispeech_test_clean_path, gen_spk_id, gen_chaptr_id, gen_utt + ".flac")
|
258 |
+
else:
|
259 |
+
if not os.path.exists(os.path.join(gen_wav_dir, gen_utt + ".wav")):
|
260 |
+
raise FileNotFoundError(f"Generated wav not found: {gen_utt}")
|
261 |
+
gen_wav = os.path.join(gen_wav_dir, gen_utt + ".wav")
|
262 |
+
|
263 |
+
ref_spk_id, ref_chaptr_id, _ = ref_utt.split("-")
|
264 |
+
ref_wav = os.path.join(librispeech_test_clean_path, ref_spk_id, ref_chaptr_id, ref_utt + ".flac")
|
265 |
+
|
266 |
+
test_set_.append((gen_wav, ref_wav, gen_txt))
|
267 |
+
|
268 |
+
num_jobs = len(gpus)
|
269 |
+
if num_jobs == 1:
|
270 |
+
return [(gpus[0], test_set_)]
|
271 |
+
|
272 |
+
wav_per_job = len(test_set_) // num_jobs + 1
|
273 |
+
test_set = []
|
274 |
+
for i in range(num_jobs):
|
275 |
+
test_set.append((gpus[i], test_set_[i * wav_per_job : (i + 1) * wav_per_job]))
|
276 |
+
|
277 |
+
return test_set
|
278 |
+
|
279 |
+
|
280 |
+
# load asr model
|
281 |
+
|
282 |
+
|
283 |
+
def load_asr_model(lang, ckpt_dir=""):
|
284 |
+
if lang == "zh":
|
285 |
+
from funasr import AutoModel
|
286 |
+
|
287 |
+
model = AutoModel(
|
288 |
+
model=os.path.join(ckpt_dir, "paraformer-zh"),
|
289 |
+
# vad_model = os.path.join(ckpt_dir, "fsmn-vad"),
|
290 |
+
# punc_model = os.path.join(ckpt_dir, "ct-punc"),
|
291 |
+
# spk_model = os.path.join(ckpt_dir, "cam++"),
|
292 |
+
disable_update=True,
|
293 |
+
) # following seed-tts setting
|
294 |
+
elif lang == "en":
|
295 |
+
from faster_whisper import WhisperModel
|
296 |
+
|
297 |
+
model_size = "large-v3" if ckpt_dir == "" else ckpt_dir
|
298 |
+
model = WhisperModel(model_size, device="cuda", compute_type="float16")
|
299 |
+
return model
|
300 |
+
|
301 |
+
|
302 |
+
# WER Evaluation, the way Seed-TTS does
|
303 |
+
|
304 |
+
|
305 |
+
def run_asr_wer(args):
|
306 |
+
rank, lang, test_set, ckpt_dir = args
|
307 |
+
|
308 |
+
if lang == "zh":
|
309 |
+
import zhconv
|
310 |
+
|
311 |
+
torch.cuda.set_device(rank)
|
312 |
+
elif lang == "en":
|
313 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = str(rank)
|
314 |
+
else:
|
315 |
+
raise NotImplementedError(
|
316 |
+
"lang support only 'zh' (funasr paraformer-zh), 'en' (faster-whisper-large-v3), for now."
|
317 |
+
)
|
318 |
+
|
319 |
+
asr_model = load_asr_model(lang, ckpt_dir=ckpt_dir)
|
320 |
+
|
321 |
+
from zhon.hanzi import punctuation
|
322 |
+
|
323 |
+
punctuation_all = punctuation + string.punctuation
|
324 |
+
wer_results = []
|
325 |
+
|
326 |
+
from jiwer import compute_measures
|
327 |
+
|
328 |
+
for gen_wav, prompt_wav, truth in tqdm(test_set):
|
329 |
+
if lang == "zh":
|
330 |
+
res = asr_model.generate(input=gen_wav, batch_size_s=300, disable_pbar=True)
|
331 |
+
hypo = res[0]["text"]
|
332 |
+
hypo = zhconv.convert(hypo, "zh-cn")
|
333 |
+
elif lang == "en":
|
334 |
+
segments, _ = asr_model.transcribe(gen_wav, beam_size=5, language="en")
|
335 |
+
hypo = ""
|
336 |
+
for segment in segments:
|
337 |
+
hypo = hypo + " " + segment.text
|
338 |
+
|
339 |
+
raw_truth = truth
|
340 |
+
raw_hypo = hypo
|
341 |
+
|
342 |
+
for x in punctuation_all:
|
343 |
+
truth = truth.replace(x, "")
|
344 |
+
hypo = hypo.replace(x, "")
|
345 |
+
|
346 |
+
truth = truth.replace(" ", " ")
|
347 |
+
hypo = hypo.replace(" ", " ")
|
348 |
+
|
349 |
+
if lang == "zh":
|
350 |
+
truth = " ".join([x for x in truth])
|
351 |
+
hypo = " ".join([x for x in hypo])
|
352 |
+
elif lang == "en":
|
353 |
+
truth = truth.lower()
|
354 |
+
hypo = hypo.lower()
|
355 |
+
|
356 |
+
measures = compute_measures(truth, hypo)
|
357 |
+
wer = measures["wer"]
|
358 |
+
|
359 |
+
# ref_list = truth.split(" ")
|
360 |
+
# subs = measures["substitutions"] / len(ref_list)
|
361 |
+
# dele = measures["deletions"] / len(ref_list)
|
362 |
+
# inse = measures["insertions"] / len(ref_list)
|
363 |
+
|
364 |
+
wer_results.append(
|
365 |
+
{
|
366 |
+
"wav": Path(gen_wav).stem,
|
367 |
+
"truth": raw_truth,
|
368 |
+
"hypo": raw_hypo,
|
369 |
+
"wer": wer,
|
370 |
+
}
|
371 |
+
)
|
372 |
+
|
373 |
+
return wer_results
|
374 |
+
|
375 |
+
|
376 |
+
# SIM Evaluation
|
377 |
+
|
378 |
+
|
379 |
+
def run_sim(args):
|
380 |
+
rank, test_set, ckpt_dir = args
|
381 |
+
device = f"cuda:{rank}"
|
382 |
+
|
383 |
+
model = ECAPA_TDNN_SMALL(feat_dim=1024, feat_type="wavlm_large", config_path=None)
|
384 |
+
state_dict = torch.load(ckpt_dir, weights_only=True, map_location=lambda storage, loc: storage)
|
385 |
+
model.load_state_dict(state_dict["model"], strict=False)
|
386 |
+
|
387 |
+
use_gpu = True if torch.cuda.is_available() else False
|
388 |
+
if use_gpu:
|
389 |
+
model = model.cuda(device)
|
390 |
+
model.eval()
|
391 |
+
|
392 |
+
sim_results = []
|
393 |
+
for gen_wav, prompt_wav, truth in tqdm(test_set):
|
394 |
+
wav1, sr1 = torchaudio.load(gen_wav)
|
395 |
+
wav2, sr2 = torchaudio.load(prompt_wav)
|
396 |
+
|
397 |
+
resample1 = torchaudio.transforms.Resample(orig_freq=sr1, new_freq=16000)
|
398 |
+
resample2 = torchaudio.transforms.Resample(orig_freq=sr2, new_freq=16000)
|
399 |
+
wav1 = resample1(wav1)
|
400 |
+
wav2 = resample2(wav2)
|
401 |
+
|
402 |
+
if use_gpu:
|
403 |
+
wav1 = wav1.cuda(device)
|
404 |
+
wav2 = wav2.cuda(device)
|
405 |
+
with torch.no_grad():
|
406 |
+
emb1 = model(wav1)
|
407 |
+
emb2 = model(wav2)
|
408 |
+
|
409 |
+
sim = F.cosine_similarity(emb1, emb2)[0].item()
|
410 |
+
# print(f"VSim score between two audios: {sim:.4f} (-1.0, 1.0).")
|
411 |
+
sim_results.append(
|
412 |
+
{
|
413 |
+
"wav": Path(gen_wav).stem,
|
414 |
+
"sim": sim,
|
415 |
+
}
|
416 |
+
)
|
417 |
+
|
418 |
+
return sim_results
|
src/f5_tts/infer/README.md
ADDED
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Inference
|
2 |
+
|
3 |
+
The pretrained model checkpoints can be reached at [🤗 Hugging Face](https://huggingface.co/SWivid/F5-TTS) and [🤖 Model Scope](https://www.modelscope.cn/models/SWivid/F5-TTS_Emilia-ZH-EN), or will be automatically downloaded when running inference scripts.
|
4 |
+
|
5 |
+
**More checkpoints with whole community efforts can be found in [SHARED.md](SHARED.md), supporting more languages.**
|
6 |
+
|
7 |
+
Currently support **30s for a single** generation, which is the **total length** including both prompt and output audio. However, you can provide `infer_cli` and `infer_gradio` with longer text, will automatically do chunk generation. Long reference audio will be **clip short to ~15s**.
|
8 |
+
|
9 |
+
To avoid possible inference failures, make sure you have seen through the following instructions.
|
10 |
+
|
11 |
+
- Use reference audio <15s and leave some silence (e.g. 1s) at the end. Otherwise there is a risk of truncating in the middle of word, leading to suboptimal generation.
|
12 |
+
- Uppercased letters will be uttered letter by letter, so use lowercased letters for normal words.
|
13 |
+
- Add some spaces (blank: " ") or punctuations (e.g. "," ".") to explicitly introduce some pauses.
|
14 |
+
- Preprocess numbers to Chinese letters if you want to have them read in Chinese, otherwise in English.
|
15 |
+
- If the generation output is blank (pure silence), check for ffmpeg installation (various tutorials online, blogs, videos, etc.).
|
16 |
+
- Try turn off use_ema if using an early-stage finetuned checkpoint (which goes just few updates).
|
17 |
+
|
18 |
+
|
19 |
+
## Gradio App
|
20 |
+
|
21 |
+
Currently supported features:
|
22 |
+
|
23 |
+
- Basic TTS with Chunk Inference
|
24 |
+
- Multi-Style / Multi-Speaker Generation
|
25 |
+
- Voice Chat powered by Qwen2.5-3B-Instruct
|
26 |
+
- [Custom inference with more language support](src/f5_tts/infer/SHARED.md)
|
27 |
+
|
28 |
+
The cli command `f5-tts_infer-gradio` equals to `python src/f5_tts/infer/infer_gradio.py`, which launches a Gradio APP (web interface) for inference.
|
29 |
+
|
30 |
+
The script will load model checkpoints from Huggingface. You can also manually download files and update the path to `load_model()` in `infer_gradio.py`. Currently only load TTS models first, will load ASR model to do transcription if `ref_text` not provided, will load LLM model if use Voice Chat.
|
31 |
+
|
32 |
+
More flags options:
|
33 |
+
|
34 |
+
```bash
|
35 |
+
# Automatically launch the interface in the default web browser
|
36 |
+
f5-tts_infer-gradio --inbrowser
|
37 |
+
|
38 |
+
# Set the root path of the application, if it's not served from the root ("/") of the domain
|
39 |
+
# For example, if the application is served at "https://example.com/myapp"
|
40 |
+
f5-tts_infer-gradio --root_path "/myapp"
|
41 |
+
```
|
42 |
+
|
43 |
+
Could also be used as a component for larger application:
|
44 |
+
```python
|
45 |
+
import gradio as gr
|
46 |
+
from f5_tts.infer.infer_gradio import app
|
47 |
+
|
48 |
+
with gr.Blocks() as main_app:
|
49 |
+
gr.Markdown("# This is an example of using F5-TTS within a bigger Gradio app")
|
50 |
+
|
51 |
+
# ... other Gradio components
|
52 |
+
|
53 |
+
app.render()
|
54 |
+
|
55 |
+
main_app.launch()
|
56 |
+
```
|
57 |
+
|
58 |
+
|
59 |
+
## CLI Inference
|
60 |
+
|
61 |
+
The cli command `f5-tts_infer-cli` equals to `python src/f5_tts/infer/infer_cli.py`, which is a command line tool for inference.
|
62 |
+
|
63 |
+
The script will load model checkpoints from Huggingface. You can also manually download files and use `--ckpt_file` to specify the model you want to load, or directly update in `infer_cli.py`.
|
64 |
+
|
65 |
+
For change vocab.txt use `--vocab_file` to provide your `vocab.txt` file.
|
66 |
+
|
67 |
+
Basically you can inference with flags:
|
68 |
+
```bash
|
69 |
+
# Leave --ref_text "" will have ASR model transcribe (extra GPU memory usage)
|
70 |
+
f5-tts_infer-cli \
|
71 |
+
--model F5TTS_v1_Base \
|
72 |
+
--ref_audio "ref_audio.wav" \
|
73 |
+
--ref_text "The content, subtitle or transcription of reference audio." \
|
74 |
+
--gen_text "Some text you want TTS model generate for you."
|
75 |
+
|
76 |
+
# Use BigVGAN as vocoder. Currently only support F5TTS_Base.
|
77 |
+
f5-tts_infer-cli --model F5TTS_Base --vocoder_name bigvgan --load_vocoder_from_local
|
78 |
+
|
79 |
+
# Use custom path checkpoint, e.g.
|
80 |
+
f5-tts_infer-cli --ckpt_file ckpts/F5TTS_v1_Base/model_1250000.safetensors
|
81 |
+
|
82 |
+
# More instructions
|
83 |
+
f5-tts_infer-cli --help
|
84 |
+
```
|
85 |
+
|
86 |
+
And a `.toml` file would help with more flexible usage.
|
87 |
+
|
88 |
+
```bash
|
89 |
+
f5-tts_infer-cli -c custom.toml
|
90 |
+
```
|
91 |
+
|
92 |
+
For example, you can use `.toml` to pass in variables, refer to `src/f5_tts/infer/examples/basic/basic.toml`:
|
93 |
+
|
94 |
+
```toml
|
95 |
+
# F5TTS_v1_Base | E2TTS_Base
|
96 |
+
model = "F5TTS_v1_Base"
|
97 |
+
ref_audio = "infer/examples/basic/basic_ref_en.wav"
|
98 |
+
# If an empty "", transcribes the reference audio automatically.
|
99 |
+
ref_text = "Some call me nature, others call me mother nature."
|
100 |
+
gen_text = "I don't really care what you call me. I've been a silent spectator, watching species evolve, empires rise and fall. But always remember, I am mighty and enduring."
|
101 |
+
# File with text to generate. Ignores the text above.
|
102 |
+
gen_file = ""
|
103 |
+
remove_silence = false
|
104 |
+
output_dir = "tests"
|
105 |
+
```
|
106 |
+
|
107 |
+
You can also leverage `.toml` file to do multi-style generation, refer to `src/f5_tts/infer/examples/multi/story.toml`.
|
108 |
+
|
109 |
+
```toml
|
110 |
+
# F5TTS_v1_Base | E2TTS_Base
|
111 |
+
model = "F5TTS_v1_Base"
|
112 |
+
ref_audio = "infer/examples/multi/main.flac"
|
113 |
+
# If an empty "", transcribes the reference audio automatically.
|
114 |
+
ref_text = ""
|
115 |
+
gen_text = ""
|
116 |
+
# File with text to generate. Ignores the text above.
|
117 |
+
gen_file = "infer/examples/multi/story.txt"
|
118 |
+
remove_silence = true
|
119 |
+
output_dir = "tests"
|
120 |
+
|
121 |
+
[voices.town]
|
122 |
+
ref_audio = "infer/examples/multi/town.flac"
|
123 |
+
ref_text = ""
|
124 |
+
|
125 |
+
[voices.country]
|
126 |
+
ref_audio = "infer/examples/multi/country.flac"
|
127 |
+
ref_text = ""
|
128 |
+
```
|
129 |
+
You should mark the voice with `[main]` `[town]` `[country]` whenever you want to change voice, refer to `src/f5_tts/infer/examples/multi/story.txt`.
|
130 |
+
|
131 |
+
## Socket Real-time Service
|
132 |
+
|
133 |
+
Real-time voice output with chunk stream:
|
134 |
+
|
135 |
+
```bash
|
136 |
+
# Start socket server
|
137 |
+
python src/f5_tts/socket_server.py
|
138 |
+
|
139 |
+
# If PyAudio not installed
|
140 |
+
sudo apt-get install portaudio19-dev
|
141 |
+
pip install pyaudio
|
142 |
+
|
143 |
+
# Communicate with socket client
|
144 |
+
python src/f5_tts/socket_client.py
|
145 |
+
```
|
146 |
+
|
147 |
+
## Speech Editing
|
148 |
+
|
149 |
+
To test speech editing capabilities, use the following command:
|
150 |
+
|
151 |
+
```bash
|
152 |
+
python src/f5_tts/infer/speech_edit.py
|
153 |
+
```
|
154 |
+
|
src/f5_tts/infer/SHARED.md
ADDED
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!-- omit in toc -->
|
2 |
+
# Shared Model Cards
|
3 |
+
|
4 |
+
<!-- omit in toc -->
|
5 |
+
### **Prerequisites of using**
|
6 |
+
- This document is serving as a quick lookup table for the community training/finetuning result, with various language support.
|
7 |
+
- The models in this repository are open source and are based on voluntary contributions from contributors.
|
8 |
+
- The use of models must be conditioned on respect for the respective creators. The convenience brought comes from their efforts.
|
9 |
+
|
10 |
+
<!-- omit in toc -->
|
11 |
+
### **Welcome to share here**
|
12 |
+
- Have a pretrained/finetuned result: model checkpoint (pruned best to facilitate inference, i.e. leave only `ema_model_state_dict`) and corresponding vocab file (for tokenization).
|
13 |
+
- Host a public [huggingface model repository](https://huggingface.co/new) and upload the model related files.
|
14 |
+
- Make a pull request adding a model card to the current page, i.e. `src\f5_tts\infer\SHARED.md`.
|
15 |
+
|
16 |
+
<!-- omit in toc -->
|
17 |
+
### Supported Languages
|
18 |
+
- [Multilingual](#multilingual)
|
19 |
+
- [F5-TTS v1 v0 Base @ zh \& en @ F5-TTS](#f5-tts-v1-v0-base--zh--en--f5-tts)
|
20 |
+
- [English](#english)
|
21 |
+
- [Finnish](#finnish)
|
22 |
+
- [F5-TTS Base @ fi @ AsmoKoskinen](#f5-tts-base--fi--asmokoskinen)
|
23 |
+
- [French](#french)
|
24 |
+
- [F5-TTS Base @ fr @ RASPIAUDIO](#f5-tts-base--fr--raspiaudio)
|
25 |
+
- [Hindi](#hindi)
|
26 |
+
- [F5-TTS Small @ hi @ SPRINGLab](#f5-tts-small--hi--springlab)
|
27 |
+
- [Italian](#italian)
|
28 |
+
- [F5-TTS Base @ it @ alien79](#f5-tts-base--it--alien79)
|
29 |
+
- [Japanese](#japanese)
|
30 |
+
- [F5-TTS Base @ ja @ Jmica](#f5-tts-base--ja--jmica)
|
31 |
+
- [Mandarin](#mandarin)
|
32 |
+
- [Russian](#russian)
|
33 |
+
- [F5-TTS Base @ ru @ HotDro4illa](#f5-tts-base--ru--hotdro4illa)
|
34 |
+
- [Spanish](#spanish)
|
35 |
+
- [F5-TTS Base @ es @ jpgallegoar](#f5-tts-base--es--jpgallegoar)
|
36 |
+
|
37 |
+
|
38 |
+
## Multilingual
|
39 |
+
|
40 |
+
#### F5-TTS v1 v0 Base @ zh & en @ F5-TTS
|
41 |
+
|Model|🤗Hugging Face|Data (Hours)|Model License|
|
42 |
+
|:---:|:------------:|:-----------:|:-------------:|
|
43 |
+
|F5-TTS v1 Base|[ckpt & vocab](https://huggingface.co/SWivid/F5-TTS/tree/main/F5TTS_v1_Base)|[Emilia 95K zh&en](https://huggingface.co/datasets/amphion/Emilia-Dataset/tree/fc71e07)|cc-by-nc-4.0|
|
44 |
+
|
45 |
+
```bash
|
46 |
+
Model: hf://SWivid/F5-TTS/F5TTS_v1_Base/model_1250000.safetensors
|
47 |
+
Vocab: hf://SWivid/F5-TTS/F5TTS_v1_Base/vocab.txt
|
48 |
+
Config: {"dim": 1024, "depth": 22, "heads": 16, "ff_mult": 2, "text_dim": 512, "conv_layers": 4}
|
49 |
+
```
|
50 |
+
|
51 |
+
|Model|🤗Hugging Face|Data (Hours)|Model License|
|
52 |
+
|:---:|:------------:|:-----------:|:-------------:|
|
53 |
+
|F5-TTS Base|[ckpt & vocab](https://huggingface.co/SWivid/F5-TTS/tree/main/F5TTS_Base)|[Emilia 95K zh&en](https://huggingface.co/datasets/amphion/Emilia-Dataset/tree/fc71e07)|cc-by-nc-4.0|
|
54 |
+
|
55 |
+
```bash
|
56 |
+
Model: hf://SWivid/F5-TTS/F5TTS_Base/model_1200000.safetensors
|
57 |
+
Vocab: hf://SWivid/F5-TTS/F5TTS_Base/vocab.txt
|
58 |
+
Config: {"dim": 1024, "depth": 22, "heads": 16, "ff_mult": 2, "text_dim": 512, "text_mask_padding": False, "conv_layers": 4, "pe_attn_head": 1}
|
59 |
+
```
|
60 |
+
|
61 |
+
*Other infos, e.g. Author info, Github repo, Link to some sampled results, Usage instruction, Tutorial (Blog, Video, etc.) ...*
|
62 |
+
|
63 |
+
|
64 |
+
## English
|
65 |
+
|
66 |
+
|
67 |
+
## Finnish
|
68 |
+
|
69 |
+
#### F5-TTS Base @ fi @ AsmoKoskinen
|
70 |
+
|Model|🤗Hugging Face|Data|Model License|
|
71 |
+
|:---:|:------------:|:-----------:|:-------------:|
|
72 |
+
|F5-TTS Base|[ckpt & vocab](https://huggingface.co/AsmoKoskinen/F5-TTS_Finnish_Model)|[Common Voice](https://huggingface.co/datasets/mozilla-foundation/common_voice_17_0), [Vox Populi](https://huggingface.co/datasets/facebook/voxpopuli)|cc-by-nc-4.0|
|
73 |
+
|
74 |
+
```bash
|
75 |
+
Model: hf://AsmoKoskinen/F5-TTS_Finnish_Model/model_common_voice_fi_vox_populi_fi_20241206.safetensors
|
76 |
+
Vocab: hf://AsmoKoskinen/F5-TTS_Finnish_Model/vocab.txt
|
77 |
+
Config: {"dim": 1024, "depth": 22, "heads": 16, "ff_mult": 2, "text_dim": 512, "text_mask_padding": False, "conv_layers": 4, "pe_attn_head": 1}
|
78 |
+
```
|
79 |
+
|
80 |
+
|
81 |
+
## French
|
82 |
+
|
83 |
+
#### F5-TTS Base @ fr @ RASPIAUDIO
|
84 |
+
|Model|🤗Hugging Face|Data (Hours)|Model License|
|
85 |
+
|:---:|:------------:|:-----------:|:-------------:|
|
86 |
+
|F5-TTS Base|[ckpt & vocab](https://huggingface.co/RASPIAUDIO/F5-French-MixedSpeakers-reduced)|[LibriVox](https://librivox.org/)|cc-by-nc-4.0|
|
87 |
+
|
88 |
+
```bash
|
89 |
+
Model: hf://RASPIAUDIO/F5-French-MixedSpeakers-reduced/model_last_reduced.pt
|
90 |
+
Vocab: hf://RASPIAUDIO/F5-French-MixedSpeakers-reduced/vocab.txt
|
91 |
+
Config: {"dim": 1024, "depth": 22, "heads": 16, "ff_mult": 2, "text_dim": 512, "text_mask_padding": False, "conv_layers": 4, "pe_attn_head": 1}
|
92 |
+
```
|
93 |
+
|
94 |
+
- [Online Inference with Hugging Face Space](https://huggingface.co/spaces/RASPIAUDIO/f5-tts_french).
|
95 |
+
- [Tutorial video to train a new language model](https://www.youtube.com/watch?v=UO4usaOojys).
|
96 |
+
- [Discussion about this training can be found here](https://github.com/SWivid/F5-TTS/issues/434).
|
97 |
+
|
98 |
+
|
99 |
+
## Hindi
|
100 |
+
|
101 |
+
#### F5-TTS Small @ hi @ SPRINGLab
|
102 |
+
|Model|🤗Hugging Face|Data (Hours)|Model License|
|
103 |
+
|:---:|:------------:|:-----------:|:-------------:|
|
104 |
+
|F5-TTS Small|[ckpt & vocab](https://huggingface.co/SPRINGLab/F5-Hindi-24KHz)|[IndicTTS Hi](https://huggingface.co/datasets/SPRINGLab/IndicTTS-Hindi) & [IndicVoices-R Hi](https://huggingface.co/datasets/SPRINGLab/IndicVoices-R_Hindi) |cc-by-4.0|
|
105 |
+
|
106 |
+
```bash
|
107 |
+
Model: hf://SPRINGLab/F5-Hindi-24KHz/model_2500000.safetensors
|
108 |
+
Vocab: hf://SPRINGLab/F5-Hindi-24KHz/vocab.txt
|
109 |
+
Config: {"dim": 768, "depth": 18, "heads": 12, "ff_mult": 2, "text_dim": 512, "text_mask_padding": False, "conv_layers": 4, "pe_attn_head": 1}
|
110 |
+
```
|
111 |
+
|
112 |
+
- Authors: SPRING Lab, Indian Institute of Technology, Madras
|
113 |
+
- Website: https://asr.iitm.ac.in/
|
114 |
+
|
115 |
+
|
116 |
+
## Italian
|
117 |
+
|
118 |
+
#### F5-TTS Base @ it @ alien79
|
119 |
+
|Model|🤗Hugging Face|Data|Model License|
|
120 |
+
|:---:|:------------:|:-----------:|:-------------:|
|
121 |
+
|F5-TTS Base|[ckpt & vocab](https://huggingface.co/alien79/F5-TTS-italian)|[ylacombe/cml-tts](https://huggingface.co/datasets/ylacombe/cml-tts) |cc-by-nc-4.0|
|
122 |
+
|
123 |
+
```bash
|
124 |
+
Model: hf://alien79/F5-TTS-italian/model_159600.safetensors
|
125 |
+
Vocab: hf://alien79/F5-TTS-italian/vocab.txt
|
126 |
+
Config: {"dim": 1024, "depth": 22, "heads": 16, "ff_mult": 2, "text_dim": 512, "text_mask_padding": False, "conv_layers": 4, "pe_attn_head": 1}
|
127 |
+
```
|
128 |
+
|
129 |
+
- Trained by [Mithril Man](https://github.com/MithrilMan)
|
130 |
+
- Model details on [hf project home](https://huggingface.co/alien79/F5-TTS-italian)
|
131 |
+
- Open to collaborations to further improve the model
|
132 |
+
|
133 |
+
|
134 |
+
## Japanese
|
135 |
+
|
136 |
+
#### F5-TTS Base @ ja @ Jmica
|
137 |
+
|Model|🤗Hugging Face|Data (Hours)|Model License|
|
138 |
+
|:---:|:------------:|:-----------:|:-------------:|
|
139 |
+
|F5-TTS Base|[ckpt & vocab](https://huggingface.co/Jmica/F5TTS/tree/main/JA_25498980)|[Emilia 1.7k JA](https://huggingface.co/datasets/amphion/Emilia-Dataset/tree/fc71e07) & [Galgame Dataset 5.4k](https://huggingface.co/datasets/OOPPEENN/Galgame_Dataset)|cc-by-nc-4.0|
|
140 |
+
|
141 |
+
```bash
|
142 |
+
Model: hf://Jmica/F5TTS/JA_25498980/model_25498980.pt
|
143 |
+
Vocab: hf://Jmica/F5TTS/JA_25498980/vocab_updated.txt
|
144 |
+
Config: {"dim": 1024, "depth": 22, "heads": 16, "ff_mult": 2, "text_dim": 512, "text_mask_padding": False, "conv_layers": 4, "pe_attn_head": 1}
|
145 |
+
```
|
146 |
+
|
147 |
+
|
148 |
+
## Mandarin
|
149 |
+
|
150 |
+
|
151 |
+
## Russian
|
152 |
+
|
153 |
+
#### F5-TTS Base @ ru @ HotDro4illa
|
154 |
+
|Model|🤗Hugging Face|Data (Hours)|Model License|
|
155 |
+
|:---:|:------------:|:-----------:|:-------------:|
|
156 |
+
|F5-TTS Base|[ckpt & vocab](https://huggingface.co/hotstone228/F5-TTS-Russian)|[Common voice](https://huggingface.co/datasets/mozilla-foundation/common_voice_17_0)|cc-by-nc-4.0|
|
157 |
+
|
158 |
+
```bash
|
159 |
+
Model: hf://hotstone228/F5-TTS-Russian/model_last.safetensors
|
160 |
+
Vocab: hf://hotstone228/F5-TTS-Russian/vocab.txt
|
161 |
+
Config: {"dim": 1024, "depth": 22, "heads": 16, "ff_mult": 2, "text_dim": 512, "text_mask_padding": False, "conv_layers": 4, "pe_attn_head": 1}
|
162 |
+
```
|
163 |
+
- Finetuned by [HotDro4illa](https://github.com/HotDro4illa)
|
164 |
+
- Any improvements are welcome
|
165 |
+
|
166 |
+
|
167 |
+
## Spanish
|
168 |
+
|
169 |
+
#### F5-TTS Base @ es @ jpgallegoar
|
170 |
+
|Model|🤗Hugging Face|Data (Hours)|Model License|
|
171 |
+
|:---:|:------------:|:-----------:|:-------------:|
|
172 |
+
|F5-TTS Base|[ckpt & vocab](https://huggingface.co/jpgallegoar/F5-Spanish)|[Voxpopuli](https://huggingface.co/datasets/facebook/voxpopuli) & Crowdsourced & TEDx, 218 hours|cc0-1.0|
|
173 |
+
|
174 |
+
- @jpgallegoar [GitHub repo](https://github.com/jpgallegoar/Spanish-F5), Jupyter Notebook and Gradio usage for Spanish model.
|
src/f5_tts/infer/__pycache__/infer_cli.cpython-310.pyc
ADDED
Binary file (7.17 kB). View file
|
|
src/f5_tts/infer/__pycache__/utils_infer.cpython-310.pyc
ADDED
Binary file (12.4 kB). View file
|
|
src/f5_tts/infer/examples/basic/basic.toml
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# F5TTS_v1_Base | E2TTS_Base
|
2 |
+
model = "F5TTS_v1_Base"
|
3 |
+
ref_audio = "infer/examples/basic/basic_ref_en.wav"
|
4 |
+
# If an empty "", transcribes the reference audio automatically.
|
5 |
+
ref_text = "Some call me nature, others call me mother nature."
|
6 |
+
gen_text = "I don't really care what you call me. I've been a silent spectator, watching species evolve, empires rise and fall. But always remember, I am mighty and enduring."
|
7 |
+
# File with text to generate. Ignores the text above.
|
8 |
+
gen_file = ""
|
9 |
+
remove_silence = false
|
10 |
+
output_dir = "tests"
|
11 |
+
output_file = "infer_cli_basic.wav"
|
src/f5_tts/infer/examples/basic/basic_ref_en.wav
ADDED
Binary file (256 kB). View file
|
|
src/f5_tts/infer/examples/basic/basic_ref_zh.wav
ADDED
Binary file (325 kB). View file
|
|
src/f5_tts/infer/examples/multi/country.flac
ADDED
Binary file (180 kB). View file
|
|
src/f5_tts/infer/examples/multi/main.flac
ADDED
Binary file (279 kB). View file
|
|
src/f5_tts/infer/examples/multi/story.toml
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# F5TTS_v1_Base | E2TTS_Base
|
2 |
+
model = "F5TTS_v1_Base"
|
3 |
+
ref_audio = "infer/examples/multi/main.flac"
|
4 |
+
# If an empty "", transcribes the reference audio automatically.
|
5 |
+
ref_text = ""
|
6 |
+
gen_text = ""
|
7 |
+
# File with text to generate. Ignores the text above.
|
8 |
+
gen_file = "infer/examples/multi/story.txt"
|
9 |
+
remove_silence = true
|
10 |
+
output_dir = "tests"
|
11 |
+
output_file = "infer_cli_story.wav"
|
12 |
+
|
13 |
+
[voices.town]
|
14 |
+
ref_audio = "infer/examples/multi/town.flac"
|
15 |
+
ref_text = ""
|
16 |
+
|
17 |
+
[voices.country]
|
18 |
+
ref_audio = "infer/examples/multi/country.flac"
|
19 |
+
ref_text = ""
|
20 |
+
|
src/f5_tts/infer/examples/multi/story.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
A Town Mouse and a Country Mouse were acquaintances, and the Country Mouse one day invited his friend to come and see him at his home in the fields. The Town Mouse came, and they sat down to a dinner of barleycorns and roots, the latter of which had a distinctly earthy flavour. The fare was not much to the taste of the guest, and presently he broke out with [town] “My poor dear friend, you live here no better than the ants. Now, you should just see how I fare! My larder is a regular horn of plenty. You must come and stay with me, and I promise you you shall live on the fat of the land.” [main] So when he returned to town he took the Country Mouse with him, and showed him into a larder containing flour and oatmeal and figs and honey and dates. The Country Mouse had never seen anything like it, and sat down to enjoy the luxuries his friend provided: but before they had well begun, the door of the larder opened and someone came in. The two Mice scampered off and hid themselves in a narrow and exceedingly uncomfortable hole. Presently, when all was quiet, they ventured out again; but someone else came in, and off they scuttled again. This was too much for the visitor. [country] “Goodbye,” [main] said he, [country] “I’m off. You live in the lap of luxury, I can see, but you are surrounded by dangers; whereas at home I can enjoy my simple dinner of roots and corn in peace.”
|
src/f5_tts/infer/examples/multi/town.flac
ADDED
Binary file (229 kB). View file
|
|
src/f5_tts/infer/examples/vocab.txt
ADDED
@@ -0,0 +1,2545 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
_
|
63 |
+
a
|
64 |
+
a1
|
65 |
+
ai1
|
66 |
+
ai2
|
67 |
+
ai3
|
68 |
+
ai4
|
69 |
+
an1
|
70 |
+
an3
|
71 |
+
an4
|
72 |
+
ang1
|
73 |
+
ang2
|
74 |
+
ang4
|
75 |
+
ao1
|
76 |
+
ao2
|
77 |
+
ao3
|
78 |
+
ao4
|
79 |
+
b
|
80 |
+
ba
|
81 |
+
ba1
|
82 |
+
ba2
|
83 |
+
ba3
|
84 |
+
ba4
|
85 |
+
bai1
|
86 |
+
bai2
|
87 |
+
bai3
|
88 |
+
bai4
|
89 |
+
ban1
|
90 |
+
ban2
|
91 |
+
ban3
|
92 |
+
ban4
|
93 |
+
bang1
|
94 |
+
bang2
|
95 |
+
bang3
|
96 |
+
bang4
|
97 |
+
bao1
|
98 |
+
bao2
|
99 |
+
bao3
|
100 |
+
bao4
|
101 |
+
bei
|
102 |
+
bei1
|
103 |
+
bei2
|
104 |
+
bei3
|
105 |
+
bei4
|
106 |
+
ben1
|
107 |
+
ben2
|
108 |
+
ben3
|
109 |
+
ben4
|
110 |
+
beng
|
111 |
+
beng1
|
112 |
+
beng2
|
113 |
+
beng3
|
114 |
+
beng4
|
115 |
+
bi1
|
116 |
+
bi2
|
117 |
+
bi3
|
118 |
+
bi4
|
119 |
+
bian1
|
120 |
+
bian2
|
121 |
+
bian3
|
122 |
+
bian4
|
123 |
+
biao1
|
124 |
+
biao2
|
125 |
+
biao3
|
126 |
+
bie1
|
127 |
+
bie2
|
128 |
+
bie3
|
129 |
+
bie4
|
130 |
+
bin1
|
131 |
+
bin4
|
132 |
+
bing1
|
133 |
+
bing2
|
134 |
+
bing3
|
135 |
+
bing4
|
136 |
+
bo
|
137 |
+
bo1
|
138 |
+
bo2
|
139 |
+
bo3
|
140 |
+
bo4
|
141 |
+
bu2
|
142 |
+
bu3
|
143 |
+
bu4
|
144 |
+
c
|
145 |
+
ca1
|
146 |
+
cai1
|
147 |
+
cai2
|
148 |
+
cai3
|
149 |
+
cai4
|
150 |
+
can1
|
151 |
+
can2
|
152 |
+
can3
|
153 |
+
can4
|
154 |
+
cang1
|
155 |
+
cang2
|
156 |
+
cao1
|
157 |
+
cao2
|
158 |
+
cao3
|
159 |
+
ce4
|
160 |
+
cen1
|
161 |
+
cen2
|
162 |
+
ceng1
|
163 |
+
ceng2
|
164 |
+
ceng4
|
165 |
+
cha1
|
166 |
+
cha2
|
167 |
+
cha3
|
168 |
+
cha4
|
169 |
+
chai1
|
170 |
+
chai2
|
171 |
+
chan1
|
172 |
+
chan2
|
173 |
+
chan3
|
174 |
+
chan4
|
175 |
+
chang1
|
176 |
+
chang2
|
177 |
+
chang3
|
178 |
+
chang4
|
179 |
+
chao1
|
180 |
+
chao2
|
181 |
+
chao3
|
182 |
+
che1
|
183 |
+
che2
|
184 |
+
che3
|
185 |
+
che4
|
186 |
+
chen1
|
187 |
+
chen2
|
188 |
+
chen3
|
189 |
+
chen4
|
190 |
+
cheng1
|
191 |
+
cheng2
|
192 |
+
cheng3
|
193 |
+
cheng4
|
194 |
+
chi1
|
195 |
+
chi2
|
196 |
+
chi3
|
197 |
+
chi4
|
198 |
+
chong1
|
199 |
+
chong2
|
200 |
+
chong3
|
201 |
+
chong4
|
202 |
+
chou1
|
203 |
+
chou2
|
204 |
+
chou3
|
205 |
+
chou4
|
206 |
+
chu1
|
207 |
+
chu2
|
208 |
+
chu3
|
209 |
+
chu4
|
210 |
+
chua1
|
211 |
+
chuai1
|
212 |
+
chuai2
|
213 |
+
chuai3
|
214 |
+
chuai4
|
215 |
+
chuan1
|
216 |
+
chuan2
|
217 |
+
chuan3
|
218 |
+
chuan4
|
219 |
+
chuang1
|
220 |
+
chuang2
|
221 |
+
chuang3
|
222 |
+
chuang4
|
223 |
+
chui1
|
224 |
+
chui2
|
225 |
+
chun1
|
226 |
+
chun2
|
227 |
+
chun3
|
228 |
+
chuo1
|
229 |
+
chuo4
|
230 |
+
ci1
|
231 |
+
ci2
|
232 |
+
ci3
|
233 |
+
ci4
|
234 |
+
cong1
|
235 |
+
cong2
|
236 |
+
cou4
|
237 |
+
cu1
|
238 |
+
cu4
|
239 |
+
cuan1
|
240 |
+
cuan2
|
241 |
+
cuan4
|
242 |
+
cui1
|
243 |
+
cui3
|
244 |
+
cui4
|
245 |
+
cun1
|
246 |
+
cun2
|
247 |
+
cun4
|
248 |
+
cuo1
|
249 |
+
cuo2
|
250 |
+
cuo4
|
251 |
+
d
|
252 |
+
da
|
253 |
+
da1
|
254 |
+
da2
|
255 |
+
da3
|
256 |
+
da4
|
257 |
+
dai1
|
258 |
+
dai2
|
259 |
+
dai3
|
260 |
+
dai4
|
261 |
+
dan1
|
262 |
+
dan2
|
263 |
+
dan3
|
264 |
+
dan4
|
265 |
+
dang1
|
266 |
+
dang2
|
267 |
+
dang3
|
268 |
+
dang4
|
269 |
+
dao1
|
270 |
+
dao2
|
271 |
+
dao3
|
272 |
+
dao4
|
273 |
+
de
|
274 |
+
de1
|
275 |
+
de2
|
276 |
+
dei3
|
277 |
+
den4
|
278 |
+
deng1
|
279 |
+
deng2
|
280 |
+
deng3
|
281 |
+
deng4
|
282 |
+
di1
|
283 |
+
di2
|
284 |
+
di3
|
285 |
+
di4
|
286 |
+
dia3
|
287 |
+
dian1
|
288 |
+
dian2
|
289 |
+
dian3
|
290 |
+
dian4
|
291 |
+
diao1
|
292 |
+
diao3
|
293 |
+
diao4
|
294 |
+
die1
|
295 |
+
die2
|
296 |
+
die4
|
297 |
+
ding1
|
298 |
+
ding2
|
299 |
+
ding3
|
300 |
+
ding4
|
301 |
+
diu1
|
302 |
+
dong1
|
303 |
+
dong3
|
304 |
+
dong4
|
305 |
+
dou1
|
306 |
+
dou2
|
307 |
+
dou3
|
308 |
+
dou4
|
309 |
+
du1
|
310 |
+
du2
|
311 |
+
du3
|
312 |
+
du4
|
313 |
+
duan1
|
314 |
+
duan2
|
315 |
+
duan3
|
316 |
+
duan4
|
317 |
+
dui1
|
318 |
+
dui4
|
319 |
+
dun1
|
320 |
+
dun3
|
321 |
+
dun4
|
322 |
+
duo1
|
323 |
+
duo2
|
324 |
+
duo3
|
325 |
+
duo4
|
326 |
+
e
|
327 |
+
e1
|
328 |
+
e2
|
329 |
+
e3
|
330 |
+
e4
|
331 |
+
ei2
|
332 |
+
en1
|
333 |
+
en4
|
334 |
+
er
|
335 |
+
er2
|
336 |
+
er3
|
337 |
+
er4
|
338 |
+
f
|
339 |
+
fa1
|
340 |
+
fa2
|
341 |
+
fa3
|
342 |
+
fa4
|
343 |
+
fan1
|
344 |
+
fan2
|
345 |
+
fan3
|
346 |
+
fan4
|
347 |
+
fang1
|
348 |
+
fang2
|
349 |
+
fang3
|
350 |
+
fang4
|
351 |
+
fei1
|
352 |
+
fei2
|
353 |
+
fei3
|
354 |
+
fei4
|
355 |
+
fen1
|
356 |
+
fen2
|
357 |
+
fen3
|
358 |
+
fen4
|
359 |
+
feng1
|
360 |
+
feng2
|
361 |
+
feng3
|
362 |
+
feng4
|
363 |
+
fo2
|
364 |
+
fou2
|
365 |
+
fou3
|
366 |
+
fu1
|
367 |
+
fu2
|
368 |
+
fu3
|
369 |
+
fu4
|
370 |
+
g
|
371 |
+
ga1
|
372 |
+
ga2
|
373 |
+
ga3
|
374 |
+
ga4
|
375 |
+
gai1
|
376 |
+
gai2
|
377 |
+
gai3
|
378 |
+
gai4
|
379 |
+
gan1
|
380 |
+
gan2
|
381 |
+
gan3
|
382 |
+
gan4
|
383 |
+
gang1
|
384 |
+
gang2
|
385 |
+
gang3
|
386 |
+
gang4
|
387 |
+
gao1
|
388 |
+
gao2
|
389 |
+
gao3
|
390 |
+
gao4
|
391 |
+
ge1
|
392 |
+
ge2
|
393 |
+
ge3
|
394 |
+
ge4
|
395 |
+
gei2
|
396 |
+
gei3
|
397 |
+
gen1
|
398 |
+
gen2
|
399 |
+
gen3
|
400 |
+
gen4
|
401 |
+
geng1
|
402 |
+
geng3
|
403 |
+
geng4
|
404 |
+
gong1
|
405 |
+
gong3
|
406 |
+
gong4
|
407 |
+
gou1
|
408 |
+
gou2
|
409 |
+
gou3
|
410 |
+
gou4
|
411 |
+
gu
|
412 |
+
gu1
|
413 |
+
gu2
|
414 |
+
gu3
|
415 |
+
gu4
|
416 |
+
gua1
|
417 |
+
gua2
|
418 |
+
gua3
|
419 |
+
gua4
|
420 |
+
guai1
|
421 |
+
guai2
|
422 |
+
guai3
|
423 |
+
guai4
|
424 |
+
guan1
|
425 |
+
guan2
|
426 |
+
guan3
|
427 |
+
guan4
|
428 |
+
guang1
|
429 |
+
guang2
|
430 |
+
guang3
|
431 |
+
guang4
|
432 |
+
gui1
|
433 |
+
gui2
|
434 |
+
gui3
|
435 |
+
gui4
|
436 |
+
gun3
|
437 |
+
gun4
|
438 |
+
guo1
|
439 |
+
guo2
|
440 |
+
guo3
|
441 |
+
guo4
|
442 |
+
h
|
443 |
+
ha1
|
444 |
+
ha2
|
445 |
+
ha3
|
446 |
+
hai1
|
447 |
+
hai2
|
448 |
+
hai3
|
449 |
+
hai4
|
450 |
+
han1
|
451 |
+
han2
|
452 |
+
han3
|
453 |
+
han4
|
454 |
+
hang1
|
455 |
+
hang2
|
456 |
+
hang4
|
457 |
+
hao1
|
458 |
+
hao2
|
459 |
+
hao3
|
460 |
+
hao4
|
461 |
+
he1
|
462 |
+
he2
|
463 |
+
he4
|
464 |
+
hei1
|
465 |
+
hen2
|
466 |
+
hen3
|
467 |
+
hen4
|
468 |
+
heng1
|
469 |
+
heng2
|
470 |
+
heng4
|
471 |
+
hong1
|
472 |
+
hong2
|
473 |
+
hong3
|
474 |
+
hong4
|
475 |
+
hou1
|
476 |
+
hou2
|
477 |
+
hou3
|
478 |
+
hou4
|
479 |
+
hu1
|
480 |
+
hu2
|
481 |
+
hu3
|
482 |
+
hu4
|
483 |
+
hua1
|
484 |
+
hua2
|
485 |
+
hua4
|
486 |
+
huai2
|
487 |
+
huai4
|
488 |
+
huan1
|
489 |
+
huan2
|
490 |
+
huan3
|
491 |
+
huan4
|
492 |
+
huang1
|
493 |
+
huang2
|
494 |
+
huang3
|
495 |
+
huang4
|
496 |
+
hui1
|
497 |
+
hui2
|
498 |
+
hui3
|
499 |
+
hui4
|
500 |
+
hun1
|
501 |
+
hun2
|
502 |
+
hun4
|
503 |
+
huo
|
504 |
+
huo1
|
505 |
+
huo2
|
506 |
+
huo3
|
507 |
+
huo4
|
508 |
+
i
|
509 |
+
j
|
510 |
+
ji1
|
511 |
+
ji2
|
512 |
+
ji3
|
513 |
+
ji4
|
514 |
+
jia
|
515 |
+
jia1
|
516 |
+
jia2
|
517 |
+
jia3
|
518 |
+
jia4
|
519 |
+
jian1
|
520 |
+
jian2
|
521 |
+
jian3
|
522 |
+
jian4
|
523 |
+
jiang1
|
524 |
+
jiang2
|
525 |
+
jiang3
|
526 |
+
jiang4
|
527 |
+
jiao1
|
528 |
+
jiao2
|
529 |
+
jiao3
|
530 |
+
jiao4
|
531 |
+
jie1
|
532 |
+
jie2
|
533 |
+
jie3
|
534 |
+
jie4
|
535 |
+
jin1
|
536 |
+
jin2
|
537 |
+
jin3
|
538 |
+
jin4
|
539 |
+
jing1
|
540 |
+
jing2
|
541 |
+
jing3
|
542 |
+
jing4
|
543 |
+
jiong3
|
544 |
+
jiu1
|
545 |
+
jiu2
|
546 |
+
jiu3
|
547 |
+
jiu4
|
548 |
+
ju1
|
549 |
+
ju2
|
550 |
+
ju3
|
551 |
+
ju4
|
552 |
+
juan1
|
553 |
+
juan2
|
554 |
+
juan3
|
555 |
+
juan4
|
556 |
+
jue1
|
557 |
+
jue2
|
558 |
+
jue4
|
559 |
+
jun1
|
560 |
+
jun4
|
561 |
+
k
|
562 |
+
ka1
|
563 |
+
ka2
|
564 |
+
ka3
|
565 |
+
kai1
|
566 |
+
kai2
|
567 |
+
kai3
|
568 |
+
kai4
|
569 |
+
kan1
|
570 |
+
kan2
|
571 |
+
kan3
|
572 |
+
kan4
|
573 |
+
kang1
|
574 |
+
kang2
|
575 |
+
kang4
|
576 |
+
kao1
|
577 |
+
kao2
|
578 |
+
kao3
|
579 |
+
kao4
|
580 |
+
ke1
|
581 |
+
ke2
|
582 |
+
ke3
|
583 |
+
ke4
|
584 |
+
ken3
|
585 |
+
keng1
|
586 |
+
kong1
|
587 |
+
kong3
|
588 |
+
kong4
|
589 |
+
kou1
|
590 |
+
kou2
|
591 |
+
kou3
|
592 |
+
kou4
|
593 |
+
ku1
|
594 |
+
ku2
|
595 |
+
ku3
|
596 |
+
ku4
|
597 |
+
kua1
|
598 |
+
kua3
|
599 |
+
kua4
|
600 |
+
kuai3
|
601 |
+
kuai4
|
602 |
+
kuan1
|
603 |
+
kuan2
|
604 |
+
kuan3
|
605 |
+
kuang1
|
606 |
+
kuang2
|
607 |
+
kuang4
|
608 |
+
kui1
|
609 |
+
kui2
|
610 |
+
kui3
|
611 |
+
kui4
|
612 |
+
kun1
|
613 |
+
kun3
|
614 |
+
kun4
|
615 |
+
kuo4
|
616 |
+
l
|
617 |
+
la
|
618 |
+
la1
|
619 |
+
la2
|
620 |
+
la3
|
621 |
+
la4
|
622 |
+
lai2
|
623 |
+
lai4
|
624 |
+
lan2
|
625 |
+
lan3
|
626 |
+
lan4
|
627 |
+
lang1
|
628 |
+
lang2
|
629 |
+
lang3
|
630 |
+
lang4
|
631 |
+
lao1
|
632 |
+
lao2
|
633 |
+
lao3
|
634 |
+
lao4
|
635 |
+
le
|
636 |
+
le1
|
637 |
+
le4
|
638 |
+
lei
|
639 |
+
lei1
|
640 |
+
lei2
|
641 |
+
lei3
|
642 |
+
lei4
|
643 |
+
leng1
|
644 |
+
leng2
|
645 |
+
leng3
|
646 |
+
leng4
|
647 |
+
li
|
648 |
+
li1
|
649 |
+
li2
|
650 |
+
li3
|
651 |
+
li4
|
652 |
+
lia3
|
653 |
+
lian2
|
654 |
+
lian3
|
655 |
+
lian4
|
656 |
+
liang2
|
657 |
+
liang3
|
658 |
+
liang4
|
659 |
+
liao1
|
660 |
+
liao2
|
661 |
+
liao3
|
662 |
+
liao4
|
663 |
+
lie1
|
664 |
+
lie2
|
665 |
+
lie3
|
666 |
+
lie4
|
667 |
+
lin1
|
668 |
+
lin2
|
669 |
+
lin3
|
670 |
+
lin4
|
671 |
+
ling2
|
672 |
+
ling3
|
673 |
+
ling4
|
674 |
+
liu1
|
675 |
+
liu2
|
676 |
+
liu3
|
677 |
+
liu4
|
678 |
+
long1
|
679 |
+
long2
|
680 |
+
long3
|
681 |
+
long4
|
682 |
+
lou1
|
683 |
+
lou2
|
684 |
+
lou3
|
685 |
+
lou4
|
686 |
+
lu1
|
687 |
+
lu2
|
688 |
+
lu3
|
689 |
+
lu4
|
690 |
+
luan2
|
691 |
+
luan3
|
692 |
+
luan4
|
693 |
+
lun1
|
694 |
+
lun2
|
695 |
+
lun4
|
696 |
+
luo1
|
697 |
+
luo2
|
698 |
+
luo3
|
699 |
+
luo4
|
700 |
+
lv2
|
701 |
+
lv3
|
702 |
+
lv4
|
703 |
+
lve3
|
704 |
+
lve4
|
705 |
+
m
|
706 |
+
ma
|
707 |
+
ma1
|
708 |
+
ma2
|
709 |
+
ma3
|
710 |
+
ma4
|
711 |
+
mai2
|
712 |
+
mai3
|
713 |
+
mai4
|
714 |
+
man1
|
715 |
+
man2
|
716 |
+
man3
|
717 |
+
man4
|
718 |
+
mang2
|
719 |
+
mang3
|
720 |
+
mao1
|
721 |
+
mao2
|
722 |
+
mao3
|
723 |
+
mao4
|
724 |
+
me
|
725 |
+
mei2
|
726 |
+
mei3
|
727 |
+
mei4
|
728 |
+
men
|
729 |
+
men1
|
730 |
+
men2
|
731 |
+
men4
|
732 |
+
meng
|
733 |
+
meng1
|
734 |
+
meng2
|
735 |
+
meng3
|
736 |
+
meng4
|
737 |
+
mi1
|
738 |
+
mi2
|
739 |
+
mi3
|
740 |
+
mi4
|
741 |
+
mian2
|
742 |
+
mian3
|
743 |
+
mian4
|
744 |
+
miao1
|
745 |
+
miao2
|
746 |
+
miao3
|
747 |
+
miao4
|
748 |
+
mie1
|
749 |
+
mie4
|
750 |
+
min2
|
751 |
+
min3
|
752 |
+
ming2
|
753 |
+
ming3
|
754 |
+
ming4
|
755 |
+
miu4
|
756 |
+
mo1
|
757 |
+
mo2
|
758 |
+
mo3
|
759 |
+
mo4
|
760 |
+
mou1
|
761 |
+
mou2
|
762 |
+
mou3
|
763 |
+
mu2
|
764 |
+
mu3
|
765 |
+
mu4
|
766 |
+
n
|
767 |
+
n2
|
768 |
+
na1
|
769 |
+
na2
|
770 |
+
na3
|
771 |
+
na4
|
772 |
+
nai2
|
773 |
+
nai3
|
774 |
+
nai4
|
775 |
+
nan1
|
776 |
+
nan2
|
777 |
+
nan3
|
778 |
+
nan4
|
779 |
+
nang1
|
780 |
+
nang2
|
781 |
+
nang3
|
782 |
+
nao1
|
783 |
+
nao2
|
784 |
+
nao3
|
785 |
+
nao4
|
786 |
+
ne
|
787 |
+
ne2
|
788 |
+
ne4
|
789 |
+
nei3
|
790 |
+
nei4
|
791 |
+
nen4
|
792 |
+
neng2
|
793 |
+
ni1
|
794 |
+
ni2
|
795 |
+
ni3
|
796 |
+
ni4
|
797 |
+
nian1
|
798 |
+
nian2
|
799 |
+
nian3
|
800 |
+
nian4
|
801 |
+
niang2
|
802 |
+
niang4
|
803 |
+
niao2
|
804 |
+
niao3
|
805 |
+
niao4
|
806 |
+
nie1
|
807 |
+
nie4
|
808 |
+
nin2
|
809 |
+
ning2
|
810 |
+
ning3
|
811 |
+
ning4
|
812 |
+
niu1
|
813 |
+
niu2
|
814 |
+
niu3
|
815 |
+
niu4
|
816 |
+
nong2
|
817 |
+
nong4
|
818 |
+
nou4
|
819 |
+
nu2
|
820 |
+
nu3
|
821 |
+
nu4
|
822 |
+
nuan3
|
823 |
+
nuo2
|
824 |
+
nuo4
|
825 |
+
nv2
|
826 |
+
nv3
|
827 |
+
nve4
|
828 |
+
o
|
829 |
+
o1
|
830 |
+
o2
|
831 |
+
ou1
|
832 |
+
ou2
|
833 |
+
ou3
|
834 |
+
ou4
|
835 |
+
p
|
836 |
+
pa1
|
837 |
+
pa2
|
838 |
+
pa4
|
839 |
+
pai1
|
840 |
+
pai2
|
841 |
+
pai3
|
842 |
+
pai4
|
843 |
+
pan1
|
844 |
+
pan2
|
845 |
+
pan4
|
846 |
+
pang1
|
847 |
+
pang2
|
848 |
+
pang4
|
849 |
+
pao1
|
850 |
+
pao2
|
851 |
+
pao3
|
852 |
+
pao4
|
853 |
+
pei1
|
854 |
+
pei2
|
855 |
+
pei4
|
856 |
+
pen1
|
857 |
+
pen2
|
858 |
+
pen4
|
859 |
+
peng1
|
860 |
+
peng2
|
861 |
+
peng3
|
862 |
+
peng4
|
863 |
+
pi1
|
864 |
+
pi2
|
865 |
+
pi3
|
866 |
+
pi4
|
867 |
+
pian1
|
868 |
+
pian2
|
869 |
+
pian4
|
870 |
+
piao1
|
871 |
+
piao2
|
872 |
+
piao3
|
873 |
+
piao4
|
874 |
+
pie1
|
875 |
+
pie2
|
876 |
+
pie3
|
877 |
+
pin1
|
878 |
+
pin2
|
879 |
+
pin3
|
880 |
+
pin4
|
881 |
+
ping1
|
882 |
+
ping2
|
883 |
+
po1
|
884 |
+
po2
|
885 |
+
po3
|
886 |
+
po4
|
887 |
+
pou1
|
888 |
+
pu1
|
889 |
+
pu2
|
890 |
+
pu3
|
891 |
+
pu4
|
892 |
+
q
|
893 |
+
qi1
|
894 |
+
qi2
|
895 |
+
qi3
|
896 |
+
qi4
|
897 |
+
qia1
|
898 |
+
qia3
|
899 |
+
qia4
|
900 |
+
qian1
|
901 |
+
qian2
|
902 |
+
qian3
|
903 |
+
qian4
|
904 |
+
qiang1
|
905 |
+
qiang2
|
906 |
+
qiang3
|
907 |
+
qiang4
|
908 |
+
qiao1
|
909 |
+
qiao2
|
910 |
+
qiao3
|
911 |
+
qiao4
|
912 |
+
qie1
|
913 |
+
qie2
|
914 |
+
qie3
|
915 |
+
qie4
|
916 |
+
qin1
|
917 |
+
qin2
|
918 |
+
qin3
|
919 |
+
qin4
|
920 |
+
qing1
|
921 |
+
qing2
|
922 |
+
qing3
|
923 |
+
qing4
|
924 |
+
qiong1
|
925 |
+
qiong2
|
926 |
+
qiu1
|
927 |
+
qiu2
|
928 |
+
qiu3
|
929 |
+
qu1
|
930 |
+
qu2
|
931 |
+
qu3
|
932 |
+
qu4
|
933 |
+
quan1
|
934 |
+
quan2
|
935 |
+
quan3
|
936 |
+
quan4
|
937 |
+
que1
|
938 |
+
que2
|
939 |
+
que4
|
940 |
+
qun2
|
941 |
+
r
|
942 |
+
ran2
|
943 |
+
ran3
|
944 |
+
rang1
|
945 |
+
rang2
|
946 |
+
rang3
|
947 |
+
rang4
|
948 |
+
rao2
|
949 |
+
rao3
|
950 |
+
rao4
|
951 |
+
re2
|
952 |
+
re3
|
953 |
+
re4
|
954 |
+
ren2
|
955 |
+
ren3
|
956 |
+
ren4
|
957 |
+
reng1
|
958 |
+
reng2
|
959 |
+
ri4
|
960 |
+
rong1
|
961 |
+
rong2
|
962 |
+
rong3
|
963 |
+
rou2
|
964 |
+
rou4
|
965 |
+
ru2
|
966 |
+
ru3
|
967 |
+
ru4
|
968 |
+
ruan2
|
969 |
+
ruan3
|
970 |
+
rui3
|
971 |
+
rui4
|
972 |
+
run4
|
973 |
+
ruo4
|
974 |
+
s
|
975 |
+
sa1
|
976 |
+
sa2
|
977 |
+
sa3
|
978 |
+
sa4
|
979 |
+
sai1
|
980 |
+
sai4
|
981 |
+
san1
|
982 |
+
san2
|
983 |
+
san3
|
984 |
+
san4
|
985 |
+
sang1
|
986 |
+
sang3
|
987 |
+
sang4
|
988 |
+
sao1
|
989 |
+
sao2
|
990 |
+
sao3
|
991 |
+
sao4
|
992 |
+
se4
|
993 |
+
sen1
|
994 |
+
seng1
|
995 |
+
sha1
|
996 |
+
sha2
|
997 |
+
sha3
|
998 |
+
sha4
|
999 |
+
shai1
|
1000 |
+
shai2
|
1001 |
+
shai3
|
1002 |
+
shai4
|
1003 |
+
shan1
|
1004 |
+
shan3
|
1005 |
+
shan4
|
1006 |
+
shang
|
1007 |
+
shang1
|
1008 |
+
shang3
|
1009 |
+
shang4
|
1010 |
+
shao1
|
1011 |
+
shao2
|
1012 |
+
shao3
|
1013 |
+
shao4
|
1014 |
+
she1
|
1015 |
+
she2
|
1016 |
+
she3
|
1017 |
+
she4
|
1018 |
+
shei2
|
1019 |
+
shen1
|
1020 |
+
shen2
|
1021 |
+
shen3
|
1022 |
+
shen4
|
1023 |
+
sheng1
|
1024 |
+
sheng2
|
1025 |
+
sheng3
|
1026 |
+
sheng4
|
1027 |
+
shi
|
1028 |
+
shi1
|
1029 |
+
shi2
|
1030 |
+
shi3
|
1031 |
+
shi4
|
1032 |
+
shou1
|
1033 |
+
shou2
|
1034 |
+
shou3
|
1035 |
+
shou4
|
1036 |
+
shu1
|
1037 |
+
shu2
|
1038 |
+
shu3
|
1039 |
+
shu4
|
1040 |
+
shua1
|
1041 |
+
shua2
|
1042 |
+
shua3
|
1043 |
+
shua4
|
1044 |
+
shuai1
|
1045 |
+
shuai3
|
1046 |
+
shuai4
|
1047 |
+
shuan1
|
1048 |
+
shuan4
|
1049 |
+
shuang1
|
1050 |
+
shuang3
|
1051 |
+
shui2
|
1052 |
+
shui3
|
1053 |
+
shui4
|
1054 |
+
shun3
|
1055 |
+
shun4
|
1056 |
+
shuo1
|
1057 |
+
shuo4
|
1058 |
+
si1
|
1059 |
+
si2
|
1060 |
+
si3
|
1061 |
+
si4
|
1062 |
+
song1
|
1063 |
+
song3
|
1064 |
+
song4
|
1065 |
+
sou1
|
1066 |
+
sou3
|
1067 |
+
sou4
|
1068 |
+
su1
|
1069 |
+
su2
|
1070 |
+
su4
|
1071 |
+
suan1
|
1072 |
+
suan4
|
1073 |
+
sui1
|
1074 |
+
sui2
|
1075 |
+
sui3
|
1076 |
+
sui4
|
1077 |
+
sun1
|
1078 |
+
sun3
|
1079 |
+
suo
|
1080 |
+
suo1
|
1081 |
+
suo2
|
1082 |
+
suo3
|
1083 |
+
t
|
1084 |
+
ta1
|
1085 |
+
ta2
|
1086 |
+
ta3
|
1087 |
+
ta4
|
1088 |
+
tai1
|
1089 |
+
tai2
|
1090 |
+
tai4
|
1091 |
+
tan1
|
1092 |
+
tan2
|
1093 |
+
tan3
|
1094 |
+
tan4
|
1095 |
+
tang1
|
1096 |
+
tang2
|
1097 |
+
tang3
|
1098 |
+
tang4
|
1099 |
+
tao1
|
1100 |
+
tao2
|
1101 |
+
tao3
|
1102 |
+
tao4
|
1103 |
+
te4
|
1104 |
+
teng2
|
1105 |
+
ti1
|
1106 |
+
ti2
|
1107 |
+
ti3
|
1108 |
+
ti4
|
1109 |
+
tian1
|
1110 |
+
tian2
|
1111 |
+
tian3
|
1112 |
+
tiao1
|
1113 |
+
tiao2
|
1114 |
+
tiao3
|
1115 |
+
tiao4
|
1116 |
+
tie1
|
1117 |
+
tie2
|
1118 |
+
tie3
|
1119 |
+
tie4
|
1120 |
+
ting1
|
1121 |
+
ting2
|
1122 |
+
ting3
|
1123 |
+
tong1
|
1124 |
+
tong2
|
1125 |
+
tong3
|
1126 |
+
tong4
|
1127 |
+
tou
|
1128 |
+
tou1
|
1129 |
+
tou2
|
1130 |
+
tou4
|
1131 |
+
tu1
|
1132 |
+
tu2
|
1133 |
+
tu3
|
1134 |
+
tu4
|
1135 |
+
tuan1
|
1136 |
+
tuan2
|
1137 |
+
tui1
|
1138 |
+
tui2
|
1139 |
+
tui3
|
1140 |
+
tui4
|
1141 |
+
tun1
|
1142 |
+
tun2
|
1143 |
+
tun4
|
1144 |
+
tuo1
|
1145 |
+
tuo2
|
1146 |
+
tuo3
|
1147 |
+
tuo4
|
1148 |
+
u
|
1149 |
+
v
|
1150 |
+
w
|
1151 |
+
wa
|
1152 |
+
wa1
|
1153 |
+
wa2
|
1154 |
+
wa3
|
1155 |
+
wa4
|
1156 |
+
wai1
|
1157 |
+
wai3
|
1158 |
+
wai4
|
1159 |
+
wan1
|
1160 |
+
wan2
|
1161 |
+
wan3
|
1162 |
+
wan4
|
1163 |
+
wang1
|
1164 |
+
wang2
|
1165 |
+
wang3
|
1166 |
+
wang4
|
1167 |
+
wei1
|
1168 |
+
wei2
|
1169 |
+
wei3
|
1170 |
+
wei4
|
1171 |
+
wen1
|
1172 |
+
wen2
|
1173 |
+
wen3
|
1174 |
+
wen4
|
1175 |
+
weng1
|
1176 |
+
weng4
|
1177 |
+
wo1
|
1178 |
+
wo2
|
1179 |
+
wo3
|
1180 |
+
wo4
|
1181 |
+
wu1
|
1182 |
+
wu2
|
1183 |
+
wu3
|
1184 |
+
wu4
|
1185 |
+
x
|
1186 |
+
xi1
|
1187 |
+
xi2
|
1188 |
+
xi3
|
1189 |
+
xi4
|
1190 |
+
xia1
|
1191 |
+
xia2
|
1192 |
+
xia4
|
1193 |
+
xian1
|
1194 |
+
xian2
|
1195 |
+
xian3
|
1196 |
+
xian4
|
1197 |
+
xiang1
|
1198 |
+
xiang2
|
1199 |
+
xiang3
|
1200 |
+
xiang4
|
1201 |
+
xiao1
|
1202 |
+
xiao2
|
1203 |
+
xiao3
|
1204 |
+
xiao4
|
1205 |
+
xie1
|
1206 |
+
xie2
|
1207 |
+
xie3
|
1208 |
+
xie4
|
1209 |
+
xin1
|
1210 |
+
xin2
|
1211 |
+
xin4
|
1212 |
+
xing1
|
1213 |
+
xing2
|
1214 |
+
xing3
|
1215 |
+
xing4
|
1216 |
+
xiong1
|
1217 |
+
xiong2
|
1218 |
+
xiu1
|
1219 |
+
xiu3
|
1220 |
+
xiu4
|
1221 |
+
xu
|
1222 |
+
xu1
|
1223 |
+
xu2
|
1224 |
+
xu3
|
1225 |
+
xu4
|
1226 |
+
xuan1
|
1227 |
+
xuan2
|
1228 |
+
xuan3
|
1229 |
+
xuan4
|
1230 |
+
xue1
|
1231 |
+
xue2
|
1232 |
+
xue3
|
1233 |
+
xue4
|
1234 |
+
xun1
|
1235 |
+
xun2
|
1236 |
+
xun4
|
1237 |
+
y
|
1238 |
+
ya
|
1239 |
+
ya1
|
1240 |
+
ya2
|
1241 |
+
ya3
|
1242 |
+
ya4
|
1243 |
+
yan1
|
1244 |
+
yan2
|
1245 |
+
yan3
|
1246 |
+
yan4
|
1247 |
+
yang1
|
1248 |
+
yang2
|
1249 |
+
yang3
|
1250 |
+
yang4
|
1251 |
+
yao1
|
1252 |
+
yao2
|
1253 |
+
yao3
|
1254 |
+
yao4
|
1255 |
+
ye1
|
1256 |
+
ye2
|
1257 |
+
ye3
|
1258 |
+
ye4
|
1259 |
+
yi
|
1260 |
+
yi1
|
1261 |
+
yi2
|
1262 |
+
yi3
|
1263 |
+
yi4
|
1264 |
+
yin1
|
1265 |
+
yin2
|
1266 |
+
yin3
|
1267 |
+
yin4
|
1268 |
+
ying1
|
1269 |
+
ying2
|
1270 |
+
ying3
|
1271 |
+
ying4
|
1272 |
+
yo1
|
1273 |
+
yong1
|
1274 |
+
yong2
|
1275 |
+
yong3
|
1276 |
+
yong4
|
1277 |
+
you1
|
1278 |
+
you2
|
1279 |
+
you3
|
1280 |
+
you4
|
1281 |
+
yu1
|
1282 |
+
yu2
|
1283 |
+
yu3
|
1284 |
+
yu4
|
1285 |
+
yuan1
|
1286 |
+
yuan2
|
1287 |
+
yuan3
|
1288 |
+
yuan4
|
1289 |
+
yue1
|
1290 |
+
yue4
|
1291 |
+
yun1
|
1292 |
+
yun2
|
1293 |
+
yun3
|
1294 |
+
yun4
|
1295 |
+
z
|
1296 |
+
za1
|
1297 |
+
za2
|
1298 |
+
za3
|
1299 |
+
zai1
|
1300 |
+
zai3
|
1301 |
+
zai4
|
1302 |
+
zan1
|
1303 |
+
zan2
|
1304 |
+
zan3
|
1305 |
+
zan4
|
1306 |
+
zang1
|
1307 |
+
zang4
|
1308 |
+
zao1
|
1309 |
+
zao2
|
1310 |
+
zao3
|
1311 |
+
zao4
|
1312 |
+
ze2
|
1313 |
+
ze4
|
1314 |
+
zei2
|
1315 |
+
zen3
|
1316 |
+
zeng1
|
1317 |
+
zeng4
|
1318 |
+
zha1
|
1319 |
+
zha2
|
1320 |
+
zha3
|
1321 |
+
zha4
|
1322 |
+
zhai1
|
1323 |
+
zhai2
|
1324 |
+
zhai3
|
1325 |
+
zhai4
|
1326 |
+
zhan1
|
1327 |
+
zhan2
|
1328 |
+
zhan3
|
1329 |
+
zhan4
|
1330 |
+
zhang1
|
1331 |
+
zhang2
|
1332 |
+
zhang3
|
1333 |
+
zhang4
|
1334 |
+
zhao1
|
1335 |
+
zhao2
|
1336 |
+
zhao3
|
1337 |
+
zhao4
|
1338 |
+
zhe
|
1339 |
+
zhe1
|
1340 |
+
zhe2
|
1341 |
+
zhe3
|
1342 |
+
zhe4
|
1343 |
+
zhen1
|
1344 |
+
zhen2
|
1345 |
+
zhen3
|
1346 |
+
zhen4
|
1347 |
+
zheng1
|
1348 |
+
zheng2
|
1349 |
+
zheng3
|
1350 |
+
zheng4
|
1351 |
+
zhi1
|
1352 |
+
zhi2
|
1353 |
+
zhi3
|
1354 |
+
zhi4
|
1355 |
+
zhong1
|
1356 |
+
zhong2
|
1357 |
+
zhong3
|
1358 |
+
zhong4
|
1359 |
+
zhou1
|
1360 |
+
zhou2
|
1361 |
+
zhou3
|
1362 |
+
zhou4
|
1363 |
+
zhu1
|
1364 |
+
zhu2
|
1365 |
+
zhu3
|
1366 |
+
zhu4
|
1367 |
+
zhua1
|
1368 |
+
zhua2
|
1369 |
+
zhua3
|
1370 |
+
zhuai1
|
1371 |
+
zhuai3
|
1372 |
+
zhuai4
|
1373 |
+
zhuan1
|
1374 |
+
zhuan2
|
1375 |
+
zhuan3
|
1376 |
+
zhuan4
|
1377 |
+
zhuang1
|
1378 |
+
zhuang4
|
1379 |
+
zhui1
|
1380 |
+
zhui4
|
1381 |
+
zhun1
|
1382 |
+
zhun2
|
1383 |
+
zhun3
|
1384 |
+
zhuo1
|
1385 |
+
zhuo2
|
1386 |
+
zi
|
1387 |
+
zi1
|
1388 |
+
zi2
|
1389 |
+
zi3
|
1390 |
+
zi4
|
1391 |
+
zong1
|
1392 |
+
zong2
|
1393 |
+
zong3
|
1394 |
+
zong4
|
1395 |
+
zou1
|
1396 |
+
zou2
|
1397 |
+
zou3
|
1398 |
+
zou4
|
1399 |
+
zu1
|
1400 |
+
zu2
|
1401 |
+
zu3
|
1402 |
+
zuan1
|
1403 |
+
zuan3
|
1404 |
+
zuan4
|
1405 |
+
zui2
|
1406 |
+
zui3
|
1407 |
+
zui4
|
1408 |
+
zun1
|
1409 |
+
zuo
|
1410 |
+
zuo1
|
1411 |
+
zuo2
|
1412 |
+
zuo3
|
1413 |
+
zuo4
|
1414 |
+
{
|
1415 |
+
~
|
1416 |
+
¡
|
1417 |
+
¢
|
1418 |
+
£
|
1419 |
+
¥
|
1420 |
+
§
|
1421 |
+
¨
|
1422 |
+
©
|
1423 |
+
«
|
1424 |
+
®
|
1425 |
+
¯
|
1426 |
+
°
|
1427 |
+
±
|
1428 |
+
²
|
1429 |
+
³
|
1430 |
+
´
|
1431 |
+
µ
|
1432 |
+
·
|
1433 |
+
¹
|
1434 |
+
º
|
1435 |
+
»
|
1436 |
+
¼
|
1437 |
+
½
|
1438 |
+
¾
|
1439 |
+
¿
|
1440 |
+
À
|
1441 |
+
Á
|
1442 |
+
Â
|
1443 |
+
Ã
|
1444 |
+
Ä
|
1445 |
+
Å
|
1446 |
+
Æ
|
1447 |
+
Ç
|
1448 |
+
È
|
1449 |
+
É
|
1450 |
+
Ê
|
1451 |
+
Í
|
1452 |
+
Î
|
1453 |
+
Ñ
|
1454 |
+
Ó
|
1455 |
+
Ö
|
1456 |
+
×
|
1457 |
+
Ø
|
1458 |
+
Ú
|
1459 |
+
Ü
|
1460 |
+
Ý
|
1461 |
+
Þ
|
1462 |
+
ß
|
1463 |
+
à
|
1464 |
+
á
|
1465 |
+
â
|
1466 |
+
ã
|
1467 |
+
ä
|
1468 |
+
å
|
1469 |
+
æ
|
1470 |
+
ç
|
1471 |
+
è
|
1472 |
+
é
|
1473 |
+
ê
|
1474 |
+
ë
|
1475 |
+
ì
|
1476 |
+
í
|
1477 |
+
î
|
1478 |
+
ï
|
1479 |
+
ð
|
1480 |
+
ñ
|
1481 |
+
ò
|
1482 |
+
ó
|
1483 |
+
ô
|
1484 |
+
õ
|
1485 |
+
ö
|
1486 |
+
ø
|
1487 |
+
ù
|
1488 |
+
ú
|
1489 |
+
û
|
1490 |
+
ü
|
1491 |
+
ý
|
1492 |
+
Ā
|
1493 |
+
ā
|
1494 |
+
ă
|
1495 |
+
ą
|
1496 |
+
ć
|
1497 |
+
Č
|
1498 |
+
č
|
1499 |
+
Đ
|
1500 |
+
đ
|
1501 |
+
ē
|
1502 |
+
ė
|
1503 |
+
ę
|
1504 |
+
ě
|
1505 |
+
ĝ
|
1506 |
+
ğ
|
1507 |
+
ħ
|
1508 |
+
ī
|
1509 |
+
į
|
1510 |
+
İ
|
1511 |
+
ı
|
1512 |
+
Ł
|
1513 |
+
ł
|
1514 |
+
ń
|
1515 |
+
ņ
|
1516 |
+
ň
|
1517 |
+
ŋ
|
1518 |
+
Ō
|
1519 |
+
ō
|
1520 |
+
ő
|
1521 |
+
œ
|
1522 |
+
ř
|
1523 |
+
Ś
|
1524 |
+
ś
|
1525 |
+
Ş
|
1526 |
+
ş
|
1527 |
+
Š
|
1528 |
+
š
|
1529 |
+
Ť
|
1530 |
+
ť
|
1531 |
+
ũ
|
1532 |
+
ū
|
1533 |
+
ź
|
1534 |
+
Ż
|
1535 |
+
ż
|
1536 |
+
Ž
|
1537 |
+
ž
|
1538 |
+
ơ
|
1539 |
+
ư
|
1540 |
+
ǎ
|
1541 |
+
ǐ
|
1542 |
+
ǒ
|
1543 |
+
ǔ
|
1544 |
+
ǚ
|
1545 |
+
ș
|
1546 |
+
ț
|
1547 |
+
ɑ
|
1548 |
+
ɔ
|
1549 |
+
ɕ
|
1550 |
+
ə
|
1551 |
+
ɛ
|
1552 |
+
ɜ
|
1553 |
+
ɡ
|
1554 |
+
ɣ
|
1555 |
+
ɪ
|
1556 |
+
ɫ
|
1557 |
+
ɴ
|
1558 |
+
ɹ
|
1559 |
+
ɾ
|
1560 |
+
ʃ
|
1561 |
+
ʊ
|
1562 |
+
ʌ
|
1563 |
+
ʒ
|
1564 |
+
ʔ
|
1565 |
+
ʰ
|
1566 |
+
ʷ
|
1567 |
+
ʻ
|
1568 |
+
ʾ
|
1569 |
+
ʿ
|
1570 |
+
ˈ
|
1571 |
+
ː
|
1572 |
+
˙
|
1573 |
+
˜
|
1574 |
+
ˢ
|
1575 |
+
́
|
1576 |
+
̅
|
1577 |
+
Α
|
1578 |
+
Β
|
1579 |
+
Δ
|
1580 |
+
Ε
|
1581 |
+
Θ
|
1582 |
+
Κ
|
1583 |
+
Λ
|
1584 |
+
Μ
|
1585 |
+
Ξ
|
1586 |
+
Π
|
1587 |
+
Σ
|
1588 |
+
Τ
|
1589 |
+
Φ
|
1590 |
+
Χ
|
1591 |
+
Ψ
|
1592 |
+
Ω
|
1593 |
+
ά
|
1594 |
+
έ
|
1595 |
+
ή
|
1596 |
+
ί
|
1597 |
+
α
|
1598 |
+
β
|
1599 |
+
γ
|
1600 |
+
δ
|
1601 |
+
ε
|
1602 |
+
ζ
|
1603 |
+
η
|
1604 |
+
θ
|
1605 |
+
ι
|
1606 |
+
κ
|
1607 |
+
λ
|
1608 |
+
μ
|
1609 |
+
ν
|
1610 |
+
ξ
|
1611 |
+
ο
|
1612 |
+
π
|
1613 |
+
ρ
|
1614 |
+
ς
|
1615 |
+
σ
|
1616 |
+
τ
|
1617 |
+
υ
|
1618 |
+
φ
|
1619 |
+
χ
|
1620 |
+
ψ
|
1621 |
+
ω
|
1622 |
+
ϊ
|
1623 |
+
ό
|
1624 |
+
ύ
|
1625 |
+
ώ
|
1626 |
+
ϕ
|
1627 |
+
ϵ
|
1628 |
+
Ё
|
1629 |
+
А
|
1630 |
+
Б
|
1631 |
+
В
|
1632 |
+
Г
|
1633 |
+
Д
|
1634 |
+
Е
|
1635 |
+
Ж
|
1636 |
+
З
|
1637 |
+
И
|
1638 |
+
Й
|
1639 |
+
К
|
1640 |
+
Л
|
1641 |
+
М
|
1642 |
+
Н
|
1643 |
+
О
|
1644 |
+
П
|
1645 |
+
Р
|
1646 |
+
С
|
1647 |
+
Т
|
1648 |
+
У
|
1649 |
+
Ф
|
1650 |
+
Х
|
1651 |
+
Ц
|
1652 |
+
Ч
|
1653 |
+
Ш
|
1654 |
+
Щ
|
1655 |
+
Ы
|
1656 |
+
Ь
|
1657 |
+
Э
|
1658 |
+
Ю
|
1659 |
+
Я
|
1660 |
+
а
|
1661 |
+
б
|
1662 |
+
в
|
1663 |
+
г
|
1664 |
+
д
|
1665 |
+
е
|
1666 |
+
ж
|
1667 |
+
з
|
1668 |
+
и
|
1669 |
+
й
|
1670 |
+
к
|
1671 |
+
л
|
1672 |
+
м
|
1673 |
+
н
|
1674 |
+
о
|
1675 |
+
п
|
1676 |
+
р
|
1677 |
+
с
|
1678 |
+
т
|
1679 |
+
у
|
1680 |
+
ф
|
1681 |
+
х
|
1682 |
+
ц
|
1683 |
+
ч
|
1684 |
+
ш
|
1685 |
+
щ
|
1686 |
+
ъ
|
1687 |
+
ы
|
1688 |
+
ь
|
1689 |
+
э
|
1690 |
+
ю
|
1691 |
+
я
|
1692 |
+
ё
|
1693 |
+
і
|
1694 |
+
ְ
|
1695 |
+
ִ
|
1696 |
+
ֵ
|
1697 |
+
ֶ
|
1698 |
+
ַ
|
1699 |
+
ָ
|
1700 |
+
ֹ
|
1701 |
+
ּ
|
1702 |
+
־
|
1703 |
+
ׁ
|
1704 |
+
א
|
1705 |
+
ב
|
1706 |
+
ג
|
1707 |
+
ד
|
1708 |
+
ה
|
1709 |
+
ו
|
1710 |
+
ז
|
1711 |
+
ח
|
1712 |
+
ט
|
1713 |
+
י
|
1714 |
+
כ
|
1715 |
+
ל
|
1716 |
+
ם
|
1717 |
+
מ
|
1718 |
+
ן
|
1719 |
+
נ
|
1720 |
+
ס
|
1721 |
+
ע
|
1722 |
+
פ
|
1723 |
+
ק
|
1724 |
+
ר
|
1725 |
+
ש
|
1726 |
+
ת
|
1727 |
+
أ
|
1728 |
+
ب
|
1729 |
+
ة
|
1730 |
+
ت
|
1731 |
+
ج
|
1732 |
+
ح
|
1733 |
+
د
|
1734 |
+
ر
|
1735 |
+
ز
|
1736 |
+
س
|
1737 |
+
ص
|
1738 |
+
ط
|
1739 |
+
ع
|
1740 |
+
ق
|
1741 |
+
ك
|
1742 |
+
ل
|
1743 |
+
م
|
1744 |
+
ن
|
1745 |
+
ه
|
1746 |
+
و
|
1747 |
+
ي
|
1748 |
+
َ
|
1749 |
+
ُ
|
1750 |
+
ِ
|
1751 |
+
ْ
|
1752 |
+
ก
|
1753 |
+
ข
|
1754 |
+
ง
|
1755 |
+
จ
|
1756 |
+
ต
|
1757 |
+
ท
|
1758 |
+
น
|
1759 |
+
ป
|
1760 |
+
ย
|
1761 |
+
ร
|
1762 |
+
ว
|
1763 |
+
ส
|
1764 |
+
ห
|
1765 |
+
อ
|
1766 |
+
ฮ
|
1767 |
+
ั
|
1768 |
+
า
|
1769 |
+
ี
|
1770 |
+
ึ
|
1771 |
+
โ
|
1772 |
+
ใ
|
1773 |
+
ไ
|
1774 |
+
่
|
1775 |
+
้
|
1776 |
+
์
|
1777 |
+
ḍ
|
1778 |
+
Ḥ
|
1779 |
+
ḥ
|
1780 |
+
ṁ
|
1781 |
+
ṃ
|
1782 |
+
ṅ
|
1783 |
+
ṇ
|
1784 |
+
Ṛ
|
1785 |
+
ṛ
|
1786 |
+
Ṣ
|
1787 |
+
ṣ
|
1788 |
+
Ṭ
|
1789 |
+
ṭ
|
1790 |
+
ạ
|
1791 |
+
ả
|
1792 |
+
Ấ
|
1793 |
+
ấ
|
1794 |
+
ầ
|
1795 |
+
ậ
|
1796 |
+
ắ
|
1797 |
+
ằ
|
1798 |
+
ẻ
|
1799 |
+
ẽ
|
1800 |
+
ế
|
1801 |
+
ề
|
1802 |
+
ể
|
1803 |
+
ễ
|
1804 |
+
ệ
|
1805 |
+
ị
|
1806 |
+
ọ
|
1807 |
+
ỏ
|
1808 |
+
ố
|
1809 |
+
ồ
|
1810 |
+
ộ
|
1811 |
+
ớ
|
1812 |
+
ờ
|
1813 |
+
ở
|
1814 |
+
ụ
|
1815 |
+
ủ
|
1816 |
+
ứ
|
1817 |
+
ữ
|
1818 |
+
ἀ
|
1819 |
+
ἁ
|
1820 |
+
Ἀ
|
1821 |
+
ἐ
|
1822 |
+
ἔ
|
1823 |
+
ἰ
|
1824 |
+
ἱ
|
1825 |
+
ὀ
|
1826 |
+
ὁ
|
1827 |
+
ὐ
|
1828 |
+
ὲ
|
1829 |
+
ὸ
|
1830 |
+
���
|
1831 |
+
᾽
|
1832 |
+
ῆ
|
1833 |
+
ῇ
|
1834 |
+
ῶ
|
1835 |
+
|
1836 |
+
‑
|
1837 |
+
‒
|
1838 |
+
–
|
1839 |
+
—
|
1840 |
+
―
|
1841 |
+
‖
|
1842 |
+
†
|
1843 |
+
‡
|
1844 |
+
•
|
1845 |
+
…
|
1846 |
+
‧
|
1847 |
+
|
1848 |
+
′
|
1849 |
+
″
|
1850 |
+
⁄
|
1851 |
+
|
1852 |
+
⁰
|
1853 |
+
⁴
|
1854 |
+
⁵
|
1855 |
+
⁶
|
1856 |
+
⁷
|
1857 |
+
⁸
|
1858 |
+
⁹
|
1859 |
+
₁
|
1860 |
+
₂
|
1861 |
+
₃
|
1862 |
+
€
|
1863 |
+
₱
|
1864 |
+
₹
|
1865 |
+
₽
|
1866 |
+
℃
|
1867 |
+
ℏ
|
1868 |
+
ℓ
|
1869 |
+
№
|
1870 |
+
ℝ
|
1871 |
+
™
|
1872 |
+
⅓
|
1873 |
+
⅔
|
1874 |
+
⅛
|
1875 |
+
→
|
1876 |
+
∂
|
1877 |
+
∈
|
1878 |
+
∑
|
1879 |
+
−
|
1880 |
+
∗
|
1881 |
+
√
|
1882 |
+
∞
|
1883 |
+
∫
|
1884 |
+
≈
|
1885 |
+
≠
|
1886 |
+
≡
|
1887 |
+
≤
|
1888 |
+
≥
|
1889 |
+
⋅
|
1890 |
+
⋯
|
1891 |
+
█
|
1892 |
+
♪
|
1893 |
+
⟨
|
1894 |
+
⟩
|
1895 |
+
、
|
1896 |
+
。
|
1897 |
+
《
|
1898 |
+
》
|
1899 |
+
「
|
1900 |
+
」
|
1901 |
+
【
|
1902 |
+
】
|
1903 |
+
あ
|
1904 |
+
う
|
1905 |
+
え
|
1906 |
+
お
|
1907 |
+
か
|
1908 |
+
が
|
1909 |
+
き
|
1910 |
+
ぎ
|
1911 |
+
く
|
1912 |
+
ぐ
|
1913 |
+
け
|
1914 |
+
げ
|
1915 |
+
こ
|
1916 |
+
ご
|
1917 |
+
さ
|
1918 |
+
し
|
1919 |
+
じ
|
1920 |
+
す
|
1921 |
+
ず
|
1922 |
+
せ
|
1923 |
+
ぜ
|
1924 |
+
そ
|
1925 |
+
ぞ
|
1926 |
+
た
|
1927 |
+
だ
|
1928 |
+
ち
|
1929 |
+
っ
|
1930 |
+
つ
|
1931 |
+
で
|
1932 |
+
と
|
1933 |
+
ど
|
1934 |
+
な
|
1935 |
+
に
|
1936 |
+
ね
|
1937 |
+
の
|
1938 |
+
は
|
1939 |
+
ば
|
1940 |
+
ひ
|
1941 |
+
ぶ
|
1942 |
+
へ
|
1943 |
+
べ
|
1944 |
+
ま
|
1945 |
+
み
|
1946 |
+
む
|
1947 |
+
め
|
1948 |
+
も
|
1949 |
+
ゃ
|
1950 |
+
や
|
1951 |
+
ゆ
|
1952 |
+
ょ
|
1953 |
+
よ
|
1954 |
+
ら
|
1955 |
+
り
|
1956 |
+
る
|
1957 |
+
れ
|
1958 |
+
ろ
|
1959 |
+
わ
|
1960 |
+
を
|
1961 |
+
ん
|
1962 |
+
ァ
|
1963 |
+
ア
|
1964 |
+
ィ
|
1965 |
+
イ
|
1966 |
+
ウ
|
1967 |
+
ェ
|
1968 |
+
エ
|
1969 |
+
オ
|
1970 |
+
カ
|
1971 |
+
ガ
|
1972 |
+
キ
|
1973 |
+
ク
|
1974 |
+
ケ
|
1975 |
+
ゲ
|
1976 |
+
コ
|
1977 |
+
ゴ
|
1978 |
+
サ
|
1979 |
+
ザ
|
1980 |
+
シ
|
1981 |
+
ジ
|
1982 |
+
ス
|
1983 |
+
ズ
|
1984 |
+
セ
|
1985 |
+
ゾ
|
1986 |
+
タ
|
1987 |
+
ダ
|
1988 |
+
チ
|
1989 |
+
ッ
|
1990 |
+
ツ
|
1991 |
+
テ
|
1992 |
+
デ
|
1993 |
+
ト
|
1994 |
+
ド
|
1995 |
+
ナ
|
1996 |
+
ニ
|
1997 |
+
ネ
|
1998 |
+
ノ
|
1999 |
+
バ
|
2000 |
+
パ
|
2001 |
+
ビ
|
2002 |
+
ピ
|
2003 |
+
フ
|
2004 |
+
プ
|
2005 |
+
ヘ
|
2006 |
+
ベ
|
2007 |
+
ペ
|
2008 |
+
ホ
|
2009 |
+
ボ
|
2010 |
+
ポ
|
2011 |
+
マ
|
2012 |
+
ミ
|
2013 |
+
ム
|
2014 |
+
メ
|
2015 |
+
モ
|
2016 |
+
ャ
|
2017 |
+
ヤ
|
2018 |
+
ュ
|
2019 |
+
ユ
|
2020 |
+
ョ
|
2021 |
+
ヨ
|
2022 |
+
ラ
|
2023 |
+
リ
|
2024 |
+
ル
|
2025 |
+
レ
|
2026 |
+
ロ
|
2027 |
+
ワ
|
2028 |
+
ン
|
2029 |
+
・
|
2030 |
+
ー
|
2031 |
+
ㄋ
|
2032 |
+
ㄍ
|
2033 |
+
ㄎ
|
2034 |
+
ㄏ
|
2035 |
+
ㄓ
|
2036 |
+
ㄕ
|
2037 |
+
ㄚ
|
2038 |
+
ㄜ
|
2039 |
+
ㄟ
|
2040 |
+
ㄤ
|
2041 |
+
ㄥ
|
2042 |
+
ㄧ
|
2043 |
+
ㄱ
|
2044 |
+
ㄴ
|
2045 |
+
ㄷ
|
2046 |
+
ㄹ
|
2047 |
+
ㅁ
|
2048 |
+
ㅂ
|
2049 |
+
ㅅ
|
2050 |
+
ㅈ
|
2051 |
+
ㅍ
|
2052 |
+
ㅎ
|
2053 |
+
ㅏ
|
2054 |
+
ㅓ
|
2055 |
+
ㅗ
|
2056 |
+
ㅜ
|
2057 |
+
ㅡ
|
2058 |
+
ㅣ
|
2059 |
+
㗎
|
2060 |
+
가
|
2061 |
+
각
|
2062 |
+
간
|
2063 |
+
갈
|
2064 |
+
감
|
2065 |
+
갑
|
2066 |
+
갓
|
2067 |
+
갔
|
2068 |
+
강
|
2069 |
+
같
|
2070 |
+
개
|
2071 |
+
거
|
2072 |
+
건
|
2073 |
+
걸
|
2074 |
+
겁
|
2075 |
+
것
|
2076 |
+
겉
|
2077 |
+
게
|
2078 |
+
겠
|
2079 |
+
겨
|
2080 |
+
결
|
2081 |
+
겼
|
2082 |
+
경
|
2083 |
+
계
|
2084 |
+
고
|
2085 |
+
곤
|
2086 |
+
골
|
2087 |
+
곱
|
2088 |
+
공
|
2089 |
+
과
|
2090 |
+
관
|
2091 |
+
광
|
2092 |
+
교
|
2093 |
+
구
|
2094 |
+
국
|
2095 |
+
굴
|
2096 |
+
귀
|
2097 |
+
귄
|
2098 |
+
그
|
2099 |
+
근
|
2100 |
+
글
|
2101 |
+
금
|
2102 |
+
기
|
2103 |
+
긴
|
2104 |
+
길
|
2105 |
+
까
|
2106 |
+
깍
|
2107 |
+
깔
|
2108 |
+
깜
|
2109 |
+
깨
|
2110 |
+
께
|
2111 |
+
꼬
|
2112 |
+
꼭
|
2113 |
+
꽃
|
2114 |
+
꾸
|
2115 |
+
꿔
|
2116 |
+
끔
|
2117 |
+
끗
|
2118 |
+
끝
|
2119 |
+
끼
|
2120 |
+
나
|
2121 |
+
난
|
2122 |
+
날
|
2123 |
+
남
|
2124 |
+
납
|
2125 |
+
내
|
2126 |
+
냐
|
2127 |
+
냥
|
2128 |
+
너
|
2129 |
+
넘
|
2130 |
+
넣
|
2131 |
+
네
|
2132 |
+
녁
|
2133 |
+
년
|
2134 |
+
녕
|
2135 |
+
노
|
2136 |
+
녹
|
2137 |
+
놀
|
2138 |
+
누
|
2139 |
+
눈
|
2140 |
+
느
|
2141 |
+
는
|
2142 |
+
늘
|
2143 |
+
니
|
2144 |
+
님
|
2145 |
+
닙
|
2146 |
+
다
|
2147 |
+
닥
|
2148 |
+
단
|
2149 |
+
달
|
2150 |
+
닭
|
2151 |
+
당
|
2152 |
+
대
|
2153 |
+
더
|
2154 |
+
덕
|
2155 |
+
던
|
2156 |
+
덥
|
2157 |
+
데
|
2158 |
+
도
|
2159 |
+
독
|
2160 |
+
동
|
2161 |
+
돼
|
2162 |
+
됐
|
2163 |
+
되
|
2164 |
+
된
|
2165 |
+
될
|
2166 |
+
두
|
2167 |
+
둑
|
2168 |
+
둥
|
2169 |
+
드
|
2170 |
+
들
|
2171 |
+
등
|
2172 |
+
디
|
2173 |
+
따
|
2174 |
+
딱
|
2175 |
+
딸
|
2176 |
+
땅
|
2177 |
+
때
|
2178 |
+
떤
|
2179 |
+
떨
|
2180 |
+
떻
|
2181 |
+
또
|
2182 |
+
똑
|
2183 |
+
뚱
|
2184 |
+
뛰
|
2185 |
+
뜻
|
2186 |
+
띠
|
2187 |
+
라
|
2188 |
+
락
|
2189 |
+
란
|
2190 |
+
람
|
2191 |
+
랍
|
2192 |
+
랑
|
2193 |
+
래
|
2194 |
+
랜
|
2195 |
+
러
|
2196 |
+
런
|
2197 |
+
럼
|
2198 |
+
렇
|
2199 |
+
레
|
2200 |
+
려
|
2201 |
+
력
|
2202 |
+
렵
|
2203 |
+
렸
|
2204 |
+
로
|
2205 |
+
록
|
2206 |
+
롬
|
2207 |
+
루
|
2208 |
+
르
|
2209 |
+
른
|
2210 |
+
를
|
2211 |
+
름
|
2212 |
+
릉
|
2213 |
+
리
|
2214 |
+
릴
|
2215 |
+
림
|
2216 |
+
마
|
2217 |
+
막
|
2218 |
+
만
|
2219 |
+
많
|
2220 |
+
말
|
2221 |
+
맑
|
2222 |
+
맙
|
2223 |
+
맛
|
2224 |
+
매
|
2225 |
+
머
|
2226 |
+
먹
|
2227 |
+
멍
|
2228 |
+
메
|
2229 |
+
면
|
2230 |
+
명
|
2231 |
+
몇
|
2232 |
+
모
|
2233 |
+
목
|
2234 |
+
몸
|
2235 |
+
못
|
2236 |
+
무
|
2237 |
+
문
|
2238 |
+
물
|
2239 |
+
뭐
|
2240 |
+
뭘
|
2241 |
+
미
|
2242 |
+
민
|
2243 |
+
밌
|
2244 |
+
밑
|
2245 |
+
바
|
2246 |
+
박
|
2247 |
+
밖
|
2248 |
+
반
|
2249 |
+
받
|
2250 |
+
발
|
2251 |
+
밤
|
2252 |
+
밥
|
2253 |
+
방
|
2254 |
+
배
|
2255 |
+
백
|
2256 |
+
밸
|
2257 |
+
뱀
|
2258 |
+
버
|
2259 |
+
번
|
2260 |
+
벌
|
2261 |
+
벚
|
2262 |
+
베
|
2263 |
+
벼
|
2264 |
+
벽
|
2265 |
+
별
|
2266 |
+
병
|
2267 |
+
보
|
2268 |
+
복
|
2269 |
+
본
|
2270 |
+
볼
|
2271 |
+
봐
|
2272 |
+
봤
|
2273 |
+
부
|
2274 |
+
분
|
2275 |
+
불
|
2276 |
+
비
|
2277 |
+
빔
|
2278 |
+
빛
|
2279 |
+
빠
|
2280 |
+
빨
|
2281 |
+
뼈
|
2282 |
+
뽀
|
2283 |
+
뿅
|
2284 |
+
쁘
|
2285 |
+
사
|
2286 |
+
산
|
2287 |
+
살
|
2288 |
+
삼
|
2289 |
+
샀
|
2290 |
+
상
|
2291 |
+
새
|
2292 |
+
색
|
2293 |
+
생
|
2294 |
+
서
|
2295 |
+
선
|
2296 |
+
설
|
2297 |
+
섭
|
2298 |
+
섰
|
2299 |
+
성
|
2300 |
+
세
|
2301 |
+
셔
|
2302 |
+
션
|
2303 |
+
셨
|
2304 |
+
소
|
2305 |
+
속
|
2306 |
+
손
|
2307 |
+
송
|
2308 |
+
수
|
2309 |
+
숙
|
2310 |
+
순
|
2311 |
+
술
|
2312 |
+
숫
|
2313 |
+
숭
|
2314 |
+
숲
|
2315 |
+
쉬
|
2316 |
+
쉽
|
2317 |
+
스
|
2318 |
+
슨
|
2319 |
+
습
|
2320 |
+
슷
|
2321 |
+
시
|
2322 |
+
식
|
2323 |
+
신
|
2324 |
+
실
|
2325 |
+
싫
|
2326 |
+
심
|
2327 |
+
십
|
2328 |
+
싶
|
2329 |
+
싸
|
2330 |
+
써
|
2331 |
+
쓰
|
2332 |
+
쓴
|
2333 |
+
씌
|
2334 |
+
씨
|
2335 |
+
씩
|
2336 |
+
씬
|
2337 |
+
아
|
2338 |
+
악
|
2339 |
+
안
|
2340 |
+
않
|
2341 |
+
알
|
2342 |
+
야
|
2343 |
+
약
|
2344 |
+
얀
|
2345 |
+
양
|
2346 |
+
얘
|
2347 |
+
어
|
2348 |
+
언
|
2349 |
+
얼
|
2350 |
+
엄
|
2351 |
+
업
|
2352 |
+
없
|
2353 |
+
었
|
2354 |
+
엉
|
2355 |
+
에
|
2356 |
+
여
|
2357 |
+
역
|
2358 |
+
연
|
2359 |
+
염
|
2360 |
+
엽
|
2361 |
+
영
|
2362 |
+
옆
|
2363 |
+
예
|
2364 |
+
옛
|
2365 |
+
오
|
2366 |
+
온
|
2367 |
+
올
|
2368 |
+
옷
|
2369 |
+
옹
|
2370 |
+
와
|
2371 |
+
왔
|
2372 |
+
왜
|
2373 |
+
요
|
2374 |
+
욕
|
2375 |
+
용
|
2376 |
+
우
|
2377 |
+
운
|
2378 |
+
울
|
2379 |
+
웃
|
2380 |
+
워
|
2381 |
+
원
|
2382 |
+
월
|
2383 |
+
웠
|
2384 |
+
위
|
2385 |
+
윙
|
2386 |
+
유
|
2387 |
+
육
|
2388 |
+
윤
|
2389 |
+
으
|
2390 |
+
은
|
2391 |
+
을
|
2392 |
+
음
|
2393 |
+
응
|
2394 |
+
의
|
2395 |
+
이
|
2396 |
+
익
|
2397 |
+
인
|
2398 |
+
일
|
2399 |
+
읽
|
2400 |
+
임
|
2401 |
+
입
|
2402 |
+
있
|
2403 |
+
자
|
2404 |
+
작
|
2405 |
+
잔
|
2406 |
+
잖
|
2407 |
+
잘
|
2408 |
+
잡
|
2409 |
+
잤
|
2410 |
+
장
|
2411 |
+
재
|
2412 |
+
저
|
2413 |
+
전
|
2414 |
+
점
|
2415 |
+
정
|
2416 |
+
제
|
2417 |
+
져
|
2418 |
+
졌
|
2419 |
+
조
|
2420 |
+
족
|
2421 |
+
좀
|
2422 |
+
종
|
2423 |
+
좋
|
2424 |
+
죠
|
2425 |
+
주
|
2426 |
+
준
|
2427 |
+
줄
|
2428 |
+
중
|
2429 |
+
줘
|
2430 |
+
즈
|
2431 |
+
즐
|
2432 |
+
즘
|
2433 |
+
지
|
2434 |
+
진
|
2435 |
+
집
|
2436 |
+
짜
|
2437 |
+
짝
|
2438 |
+
쩌
|
2439 |
+
쪼
|
2440 |
+
쪽
|
2441 |
+
쫌
|
2442 |
+
쭈
|
2443 |
+
쯔
|
2444 |
+
찌
|
2445 |
+
찍
|
2446 |
+
차
|
2447 |
+
착
|
2448 |
+
찾
|
2449 |
+
책
|
2450 |
+
처
|
2451 |
+
천
|
2452 |
+
철
|
2453 |
+
체
|
2454 |
+
쳐
|
2455 |
+
쳤
|
2456 |
+
초
|
2457 |
+
촌
|
2458 |
+
추
|
2459 |
+
출
|
2460 |
+
춤
|
2461 |
+
춥
|
2462 |
+
춰
|
2463 |
+
치
|
2464 |
+
친
|
2465 |
+
칠
|
2466 |
+
침
|
2467 |
+
칩
|
2468 |
+
칼
|
2469 |
+
커
|
2470 |
+
켓
|
2471 |
+
코
|
2472 |
+
콩
|
2473 |
+
쿠
|
2474 |
+
퀴
|
2475 |
+
크
|
2476 |
+
큰
|
2477 |
+
큽
|
2478 |
+
키
|
2479 |
+
킨
|
2480 |
+
타
|
2481 |
+
태
|
2482 |
+
터
|
2483 |
+
턴
|
2484 |
+
털
|
2485 |
+
테
|
2486 |
+
토
|
2487 |
+
통
|
2488 |
+
투
|
2489 |
+
트
|
2490 |
+
특
|
2491 |
+
튼
|
2492 |
+
틀
|
2493 |
+
티
|
2494 |
+
팀
|
2495 |
+
파
|
2496 |
+
팔
|
2497 |
+
패
|
2498 |
+
페
|
2499 |
+
펜
|
2500 |
+
펭
|
2501 |
+
평
|
2502 |
+
포
|
2503 |
+
폭
|
2504 |
+
표
|
2505 |
+
품
|
2506 |
+
풍
|
2507 |
+
프
|
2508 |
+
플
|
2509 |
+
피
|
2510 |
+
필
|
2511 |
+
하
|
2512 |
+
학
|
2513 |
+
한
|
2514 |
+
할
|
2515 |
+
함
|
2516 |
+
합
|
2517 |
+
항
|
2518 |
+
해
|
2519 |
+
햇
|
2520 |
+
했
|
2521 |
+
행
|
2522 |
+
허
|
2523 |
+
험
|
2524 |
+
형
|
2525 |
+
혜
|
2526 |
+
호
|
2527 |
+
혼
|
2528 |
+
홀
|
2529 |
+
화
|
2530 |
+
회
|
2531 |
+
획
|
2532 |
+
후
|
2533 |
+
휴
|
2534 |
+
흐
|
2535 |
+
흔
|
2536 |
+
희
|
2537 |
+
히
|
2538 |
+
힘
|
2539 |
+
ﷺ
|
2540 |
+
ﷻ
|
2541 |
+
!
|
2542 |
+
,
|
2543 |
+
?
|
2544 |
+
�
|
2545 |
+
𠮶
|
src/f5_tts/infer/infer_cli.py
ADDED
@@ -0,0 +1,355 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
+
from datetime import datetime
|
6 |
+
from importlib.resources import files
|
7 |
+
from pathlib import Path
|
8 |
+
|
9 |
+
import numpy as np
|
10 |
+
import soundfile as sf
|
11 |
+
import tomli
|
12 |
+
from cached_path import cached_path
|
13 |
+
from omegaconf import OmegaConf
|
14 |
+
|
15 |
+
from f5_tts.infer.utils_infer import (
|
16 |
+
mel_spec_type,
|
17 |
+
target_rms,
|
18 |
+
cross_fade_duration,
|
19 |
+
nfe_step,
|
20 |
+
cfg_strength,
|
21 |
+
sway_sampling_coef,
|
22 |
+
speed,
|
23 |
+
fix_duration,
|
24 |
+
infer_process,
|
25 |
+
load_model,
|
26 |
+
load_vocoder,
|
27 |
+
preprocess_ref_audio_text,
|
28 |
+
remove_silence_for_generated_wav,
|
29 |
+
)
|
30 |
+
from f5_tts.model import DiT, UNetT # noqa: F401. used for config
|
31 |
+
|
32 |
+
|
33 |
+
parser = argparse.ArgumentParser(
|
34 |
+
prog="python3 infer-cli.py",
|
35 |
+
description="Commandline interface for E2/F5 TTS with Advanced Batch Processing.",
|
36 |
+
epilog="Specify options above to override one or more settings from config.",
|
37 |
+
)
|
38 |
+
parser.add_argument(
|
39 |
+
"-c",
|
40 |
+
"--config",
|
41 |
+
type=str,
|
42 |
+
default=os.path.join(files("f5_tts").joinpath("infer/examples/basic"), "basic.toml"),
|
43 |
+
help="The configuration file, default see infer/examples/basic/basic.toml",
|
44 |
+
)
|
45 |
+
|
46 |
+
|
47 |
+
# Note. Not to provide default value here in order to read default from config file
|
48 |
+
|
49 |
+
parser.add_argument(
|
50 |
+
"-m",
|
51 |
+
"--model",
|
52 |
+
type=str,
|
53 |
+
help="The model name: F5TTS_v1_Base | F5TTS_Base | E2TTS_Base | etc.",
|
54 |
+
)
|
55 |
+
parser.add_argument(
|
56 |
+
"-mc",
|
57 |
+
"--model_cfg",
|
58 |
+
type=str,
|
59 |
+
help="The path to F5-TTS model config file .yaml",
|
60 |
+
)
|
61 |
+
parser.add_argument(
|
62 |
+
"-p",
|
63 |
+
"--ckpt_file",
|
64 |
+
type=str,
|
65 |
+
help="The path to model checkpoint .pt, leave blank to use default",
|
66 |
+
)
|
67 |
+
parser.add_argument(
|
68 |
+
"-v",
|
69 |
+
"--vocab_file",
|
70 |
+
type=str,
|
71 |
+
help="The path to vocab file .txt, leave blank to use default",
|
72 |
+
)
|
73 |
+
parser.add_argument(
|
74 |
+
"-r",
|
75 |
+
"--ref_audio",
|
76 |
+
type=str,
|
77 |
+
help="The reference audio file.",
|
78 |
+
)
|
79 |
+
parser.add_argument(
|
80 |
+
"-s",
|
81 |
+
"--ref_text",
|
82 |
+
type=str,
|
83 |
+
help="The transcript/subtitle for the reference audio",
|
84 |
+
)
|
85 |
+
parser.add_argument(
|
86 |
+
"-t",
|
87 |
+
"--gen_text",
|
88 |
+
type=str,
|
89 |
+
help="The text to make model synthesize a speech",
|
90 |
+
)
|
91 |
+
parser.add_argument(
|
92 |
+
"-f",
|
93 |
+
"--gen_file",
|
94 |
+
type=str,
|
95 |
+
help="The file with text to generate, will ignore --gen_text",
|
96 |
+
)
|
97 |
+
parser.add_argument(
|
98 |
+
"-o",
|
99 |
+
"--output_dir",
|
100 |
+
type=str,
|
101 |
+
help="The path to output folder",
|
102 |
+
)
|
103 |
+
parser.add_argument(
|
104 |
+
"-w",
|
105 |
+
"--output_file",
|
106 |
+
type=str,
|
107 |
+
help="The name of output file",
|
108 |
+
)
|
109 |
+
parser.add_argument(
|
110 |
+
"--save_chunk",
|
111 |
+
action="store_true",
|
112 |
+
help="To save each audio chunks during inference",
|
113 |
+
)
|
114 |
+
parser.add_argument(
|
115 |
+
"--remove_silence",
|
116 |
+
action="store_true",
|
117 |
+
help="To remove long silence found in ouput",
|
118 |
+
)
|
119 |
+
parser.add_argument(
|
120 |
+
"--load_vocoder_from_local",
|
121 |
+
action="store_true",
|
122 |
+
help="To load vocoder from local dir, default to ../checkpoints/vocos-mel-24khz",
|
123 |
+
)
|
124 |
+
parser.add_argument(
|
125 |
+
"--vocoder_name",
|
126 |
+
type=str,
|
127 |
+
choices=["vocos", "bigvgan"],
|
128 |
+
help=f"Used vocoder name: vocos | bigvgan, default {mel_spec_type}",
|
129 |
+
)
|
130 |
+
parser.add_argument(
|
131 |
+
"--target_rms",
|
132 |
+
type=float,
|
133 |
+
help=f"Target output speech loudness normalization value, default {target_rms}",
|
134 |
+
)
|
135 |
+
parser.add_argument(
|
136 |
+
"--cross_fade_duration",
|
137 |
+
type=float,
|
138 |
+
help=f"Duration of cross-fade between audio segments in seconds, default {cross_fade_duration}",
|
139 |
+
)
|
140 |
+
parser.add_argument(
|
141 |
+
"--nfe_step",
|
142 |
+
type=int,
|
143 |
+
help=f"The number of function evaluation (denoising steps), default {nfe_step}",
|
144 |
+
)
|
145 |
+
parser.add_argument(
|
146 |
+
"--cfg_strength",
|
147 |
+
type=float,
|
148 |
+
help=f"Classifier-free guidance strength, default {cfg_strength}",
|
149 |
+
)
|
150 |
+
parser.add_argument(
|
151 |
+
"--sway_sampling_coef",
|
152 |
+
type=float,
|
153 |
+
help=f"Sway Sampling coefficient, default {sway_sampling_coef}",
|
154 |
+
)
|
155 |
+
parser.add_argument(
|
156 |
+
"--speed",
|
157 |
+
type=float,
|
158 |
+
help=f"The speed of the generated audio, default {speed}",
|
159 |
+
)
|
160 |
+
parser.add_argument(
|
161 |
+
"--fix_duration",
|
162 |
+
type=float,
|
163 |
+
help=f"Fix the total duration (ref and gen audios) in seconds, default {fix_duration}",
|
164 |
+
)
|
165 |
+
args = parser.parse_args()
|
166 |
+
|
167 |
+
|
168 |
+
# config file
|
169 |
+
|
170 |
+
config = tomli.load(open(args.config, "rb"))
|
171 |
+
|
172 |
+
|
173 |
+
# command-line interface parameters
|
174 |
+
|
175 |
+
model = args.model or config.get("model", "F5TTS_v1_Base")
|
176 |
+
ckpt_file = args.ckpt_file or config.get("ckpt_file", "")
|
177 |
+
vocab_file = args.vocab_file or config.get("vocab_file", "")
|
178 |
+
|
179 |
+
ref_audio = args.ref_audio or config.get("ref_audio", "infer/examples/basic/basic_ref_en.wav")
|
180 |
+
ref_text = (
|
181 |
+
args.ref_text
|
182 |
+
if args.ref_text is not None
|
183 |
+
else config.get("ref_text", "Some call me nature, others call me mother nature.")
|
184 |
+
)
|
185 |
+
gen_text = args.gen_text or config.get("gen_text", "Here we generate something just for test.")
|
186 |
+
gen_file = args.gen_file or config.get("gen_file", "")
|
187 |
+
|
188 |
+
output_dir = args.output_dir or config.get("output_dir", "tests")
|
189 |
+
output_file = args.output_file or config.get(
|
190 |
+
"output_file", f"infer_cli_{datetime.now().strftime(r'%Y%m%d_%H%M%S')}.wav"
|
191 |
+
)
|
192 |
+
|
193 |
+
save_chunk = args.save_chunk or config.get("save_chunk", False)
|
194 |
+
remove_silence = args.remove_silence or config.get("remove_silence", False)
|
195 |
+
load_vocoder_from_local = args.load_vocoder_from_local or config.get("load_vocoder_from_local", False)
|
196 |
+
|
197 |
+
vocoder_name = args.vocoder_name or config.get("vocoder_name", mel_spec_type)
|
198 |
+
target_rms = args.target_rms or config.get("target_rms", target_rms)
|
199 |
+
cross_fade_duration = args.cross_fade_duration or config.get("cross_fade_duration", cross_fade_duration)
|
200 |
+
nfe_step = args.nfe_step or config.get("nfe_step", nfe_step)
|
201 |
+
cfg_strength = args.cfg_strength or config.get("cfg_strength", cfg_strength)
|
202 |
+
sway_sampling_coef = args.sway_sampling_coef or config.get("sway_sampling_coef", sway_sampling_coef)
|
203 |
+
speed = args.speed or config.get("speed", speed)
|
204 |
+
fix_duration = args.fix_duration or config.get("fix_duration", fix_duration)
|
205 |
+
|
206 |
+
|
207 |
+
# patches for pip pkg user
|
208 |
+
if "infer/examples/" in ref_audio:
|
209 |
+
ref_audio = str(files("f5_tts").joinpath(f"{ref_audio}"))
|
210 |
+
if "infer/examples/" in gen_file:
|
211 |
+
gen_file = str(files("f5_tts").joinpath(f"{gen_file}"))
|
212 |
+
if "voices" in config:
|
213 |
+
for voice in config["voices"]:
|
214 |
+
voice_ref_audio = config["voices"][voice]["ref_audio"]
|
215 |
+
if "infer/examples/" in voice_ref_audio:
|
216 |
+
config["voices"][voice]["ref_audio"] = str(files("f5_tts").joinpath(f"{voice_ref_audio}"))
|
217 |
+
|
218 |
+
|
219 |
+
# ignore gen_text if gen_file provided
|
220 |
+
|
221 |
+
if gen_file:
|
222 |
+
gen_text = codecs.open(gen_file, "r", "utf-8").read()
|
223 |
+
|
224 |
+
|
225 |
+
# output path
|
226 |
+
|
227 |
+
wave_path = Path(output_dir) / output_file
|
228 |
+
# spectrogram_path = Path(output_dir) / "infer_cli_out.png"
|
229 |
+
if save_chunk:
|
230 |
+
output_chunk_dir = os.path.join(output_dir, f"{Path(output_file).stem}_chunks")
|
231 |
+
if not os.path.exists(output_chunk_dir):
|
232 |
+
os.makedirs(output_chunk_dir)
|
233 |
+
|
234 |
+
|
235 |
+
# load vocoder
|
236 |
+
|
237 |
+
if vocoder_name == "vocos":
|
238 |
+
vocoder_local_path = "../checkpoints/vocos-mel-24khz"
|
239 |
+
elif vocoder_name == "bigvgan":
|
240 |
+
vocoder_local_path = "../checkpoints/bigvgan_v2_24khz_100band_256x"
|
241 |
+
|
242 |
+
vocoder = load_vocoder(vocoder_name=vocoder_name, is_local=load_vocoder_from_local, local_path=vocoder_local_path)
|
243 |
+
|
244 |
+
|
245 |
+
# load TTS model
|
246 |
+
|
247 |
+
model_cfg = OmegaConf.load(
|
248 |
+
args.model_cfg or config.get("model_cfg", str(files("f5_tts").joinpath(f"configs/{model}.yaml")))
|
249 |
+
).model
|
250 |
+
model_cls = globals()[model_cfg.backbone]
|
251 |
+
|
252 |
+
repo_name, ckpt_step, ckpt_type = "F5-TTS", 1250000, "safetensors"
|
253 |
+
|
254 |
+
if model != "F5TTS_Base":
|
255 |
+
assert vocoder_name == model_cfg.mel_spec.mel_spec_type
|
256 |
+
|
257 |
+
# override for previous models
|
258 |
+
if model == "F5TTS_Base":
|
259 |
+
if vocoder_name == "vocos":
|
260 |
+
ckpt_step = 1200000
|
261 |
+
elif vocoder_name == "bigvgan":
|
262 |
+
model = "F5TTS_Base_bigvgan"
|
263 |
+
ckpt_type = "pt"
|
264 |
+
elif model == "E2TTS_Base":
|
265 |
+
repo_name = "E2-TTS"
|
266 |
+
ckpt_step = 1200000
|
267 |
+
|
268 |
+
if not ckpt_file:
|
269 |
+
ckpt_file = str(cached_path(f"hf://SWivid/{repo_name}/{model}/model_{ckpt_step}.{ckpt_type}"))
|
270 |
+
|
271 |
+
print(f"Using {model}...")
|
272 |
+
ema_model = load_model(model_cls, model_cfg.arch, ckpt_file, mel_spec_type=vocoder_name, vocab_file=vocab_file)
|
273 |
+
|
274 |
+
|
275 |
+
# inference process
|
276 |
+
|
277 |
+
|
278 |
+
def main():
|
279 |
+
main_voice = {"ref_audio": ref_audio, "ref_text": ref_text}
|
280 |
+
if "voices" not in config:
|
281 |
+
voices = {"main": main_voice}
|
282 |
+
else:
|
283 |
+
voices = config["voices"]
|
284 |
+
voices["main"] = main_voice
|
285 |
+
for voice in voices:
|
286 |
+
print("Voice:", voice)
|
287 |
+
print("ref_audio ", voices[voice]["ref_audio"])
|
288 |
+
voices[voice]["ref_audio"], voices[voice]["ref_text"] = preprocess_ref_audio_text(
|
289 |
+
voices[voice]["ref_audio"], voices[voice]["ref_text"]
|
290 |
+
)
|
291 |
+
print("ref_audio_", voices[voice]["ref_audio"], "\n\n")
|
292 |
+
|
293 |
+
generated_audio_segments = []
|
294 |
+
reg1 = r"(?=\[\w+\])"
|
295 |
+
chunks = re.split(reg1, gen_text)
|
296 |
+
reg2 = r"\[(\w+)\]"
|
297 |
+
for text in chunks:
|
298 |
+
if not text.strip():
|
299 |
+
continue
|
300 |
+
match = re.match(reg2, text)
|
301 |
+
if match:
|
302 |
+
voice = match[1]
|
303 |
+
else:
|
304 |
+
print("No voice tag found, using main.")
|
305 |
+
voice = "main"
|
306 |
+
if voice not in voices:
|
307 |
+
print(f"Voice {voice} not found, using main.")
|
308 |
+
voice = "main"
|
309 |
+
text = re.sub(reg2, "", text)
|
310 |
+
ref_audio_ = voices[voice]["ref_audio"]
|
311 |
+
ref_text_ = voices[voice]["ref_text"]
|
312 |
+
gen_text_ = text.strip()
|
313 |
+
print(f"Voice: {voice}")
|
314 |
+
audio_segment, final_sample_rate, spectragram = infer_process(
|
315 |
+
ref_audio_,
|
316 |
+
ref_text_,
|
317 |
+
gen_text_,
|
318 |
+
ema_model,
|
319 |
+
vocoder,
|
320 |
+
mel_spec_type=vocoder_name,
|
321 |
+
target_rms=target_rms,
|
322 |
+
cross_fade_duration=cross_fade_duration,
|
323 |
+
nfe_step=nfe_step,
|
324 |
+
cfg_strength=cfg_strength,
|
325 |
+
sway_sampling_coef=sway_sampling_coef,
|
326 |
+
speed=speed,
|
327 |
+
fix_duration=fix_duration,
|
328 |
+
)
|
329 |
+
generated_audio_segments.append(audio_segment)
|
330 |
+
|
331 |
+
if save_chunk:
|
332 |
+
if len(gen_text_) > 200:
|
333 |
+
gen_text_ = gen_text_[:200] + " ... "
|
334 |
+
sf.write(
|
335 |
+
os.path.join(output_chunk_dir, f"{len(generated_audio_segments)-1}_{gen_text_}.wav"),
|
336 |
+
audio_segment,
|
337 |
+
final_sample_rate,
|
338 |
+
)
|
339 |
+
|
340 |
+
if generated_audio_segments:
|
341 |
+
final_wave = np.concatenate(generated_audio_segments)
|
342 |
+
|
343 |
+
if not os.path.exists(output_dir):
|
344 |
+
os.makedirs(output_dir)
|
345 |
+
|
346 |
+
with open(wave_path, "wb") as f:
|
347 |
+
sf.write(f.name, final_wave, final_sample_rate)
|
348 |
+
# Remove silence
|
349 |
+
if remove_silence:
|
350 |
+
remove_silence_for_generated_wav(f.name)
|
351 |
+
print(f.name)
|
352 |
+
|
353 |
+
|
354 |
+
if __name__ == "__main__":
|
355 |
+
main()
|
src/f5_tts/infer/infer_gradio.py
ADDED
@@ -0,0 +1,927 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ruff: noqa: E402
|
2 |
+
# Above allows ruff to ignore E402: module level import not at top of file
|
3 |
+
|
4 |
+
import json
|
5 |
+
import re
|
6 |
+
import tempfile
|
7 |
+
from collections import OrderedDict
|
8 |
+
from importlib.resources import files
|
9 |
+
|
10 |
+
import click
|
11 |
+
import gradio as gr
|
12 |
+
import numpy as np
|
13 |
+
import soundfile as sf
|
14 |
+
import torchaudio
|
15 |
+
from cached_path import cached_path
|
16 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
17 |
+
|
18 |
+
try:
|
19 |
+
import spaces
|
20 |
+
|
21 |
+
USING_SPACES = True
|
22 |
+
except ImportError:
|
23 |
+
USING_SPACES = False
|
24 |
+
|
25 |
+
|
26 |
+
def gpu_decorator(func):
|
27 |
+
if USING_SPACES:
|
28 |
+
return spaces.GPU(func)
|
29 |
+
else:
|
30 |
+
return func
|
31 |
+
|
32 |
+
|
33 |
+
from f5_tts.model import DiT, UNetT
|
34 |
+
from f5_tts.infer.utils_infer import (
|
35 |
+
load_vocoder,
|
36 |
+
load_model,
|
37 |
+
preprocess_ref_audio_text,
|
38 |
+
infer_process,
|
39 |
+
remove_silence_for_generated_wav,
|
40 |
+
save_spectrogram,
|
41 |
+
)
|
42 |
+
|
43 |
+
|
44 |
+
DEFAULT_TTS_MODEL = "F5-TTS_v1"
|
45 |
+
tts_model_choice = DEFAULT_TTS_MODEL
|
46 |
+
|
47 |
+
DEFAULT_TTS_MODEL_CFG = [
|
48 |
+
"hf://SWivid/F5-TTS/F5TTS_v1_Base/model_1250000.safetensors",
|
49 |
+
"hf://SWivid/F5-TTS/F5TTS_v1_Base/vocab.txt",
|
50 |
+
json.dumps(dict(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, conv_layers=4)),
|
51 |
+
]
|
52 |
+
|
53 |
+
|
54 |
+
# load models
|
55 |
+
|
56 |
+
vocoder = load_vocoder()
|
57 |
+
|
58 |
+
|
59 |
+
def load_f5tts():
|
60 |
+
ckpt_path = str(cached_path(DEFAULT_TTS_MODEL_CFG[0]))
|
61 |
+
F5TTS_model_cfg = json.loads(DEFAULT_TTS_MODEL_CFG[2])
|
62 |
+
return load_model(DiT, F5TTS_model_cfg, ckpt_path)
|
63 |
+
|
64 |
+
|
65 |
+
def load_e2tts():
|
66 |
+
ckpt_path = str(cached_path("hf://SWivid/E2-TTS/E2TTS_Base/model_1200000.safetensors"))
|
67 |
+
E2TTS_model_cfg = dict(dim=1024, depth=24, heads=16, ff_mult=4, text_mask_padding=False, pe_attn_head=1)
|
68 |
+
return load_model(UNetT, E2TTS_model_cfg, ckpt_path)
|
69 |
+
|
70 |
+
|
71 |
+
def load_custom(ckpt_path: str, vocab_path="", model_cfg=None):
|
72 |
+
ckpt_path, vocab_path = ckpt_path.strip(), vocab_path.strip()
|
73 |
+
if ckpt_path.startswith("hf://"):
|
74 |
+
ckpt_path = str(cached_path(ckpt_path))
|
75 |
+
if vocab_path.startswith("hf://"):
|
76 |
+
vocab_path = str(cached_path(vocab_path))
|
77 |
+
if model_cfg is None:
|
78 |
+
model_cfg = json.loads(DEFAULT_TTS_MODEL_CFG[2])
|
79 |
+
return load_model(DiT, model_cfg, ckpt_path, vocab_file=vocab_path)
|
80 |
+
|
81 |
+
|
82 |
+
F5TTS_ema_model = load_f5tts()
|
83 |
+
E2TTS_ema_model = load_e2tts() if USING_SPACES else None
|
84 |
+
custom_ema_model, pre_custom_path = None, ""
|
85 |
+
|
86 |
+
chat_model_state = None
|
87 |
+
chat_tokenizer_state = None
|
88 |
+
|
89 |
+
|
90 |
+
@gpu_decorator
|
91 |
+
def generate_response(messages, model, tokenizer):
|
92 |
+
"""Generate response using Qwen"""
|
93 |
+
text = tokenizer.apply_chat_template(
|
94 |
+
messages,
|
95 |
+
tokenize=False,
|
96 |
+
add_generation_prompt=True,
|
97 |
+
)
|
98 |
+
|
99 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
100 |
+
generated_ids = model.generate(
|
101 |
+
**model_inputs,
|
102 |
+
max_new_tokens=512,
|
103 |
+
temperature=0.7,
|
104 |
+
top_p=0.95,
|
105 |
+
)
|
106 |
+
|
107 |
+
generated_ids = [
|
108 |
+
output_ids[len(input_ids) :] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
109 |
+
]
|
110 |
+
return tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
111 |
+
|
112 |
+
|
113 |
+
@gpu_decorator
|
114 |
+
def infer(
|
115 |
+
ref_audio_orig,
|
116 |
+
ref_text,
|
117 |
+
gen_text,
|
118 |
+
model,
|
119 |
+
remove_silence,
|
120 |
+
cross_fade_duration=0.15,
|
121 |
+
nfe_step=32,
|
122 |
+
speed=1,
|
123 |
+
show_info=gr.Info,
|
124 |
+
):
|
125 |
+
if not ref_audio_orig:
|
126 |
+
gr.Warning("Please provide reference audio.")
|
127 |
+
return gr.update(), gr.update(), ref_text
|
128 |
+
|
129 |
+
if not gen_text.strip():
|
130 |
+
gr.Warning("Please enter text to generate.")
|
131 |
+
return gr.update(), gr.update(), ref_text
|
132 |
+
|
133 |
+
ref_audio, ref_text = preprocess_ref_audio_text(ref_audio_orig, ref_text, show_info=show_info)
|
134 |
+
|
135 |
+
if model == DEFAULT_TTS_MODEL:
|
136 |
+
ema_model = F5TTS_ema_model
|
137 |
+
elif model == "E2-TTS":
|
138 |
+
global E2TTS_ema_model
|
139 |
+
if E2TTS_ema_model is None:
|
140 |
+
show_info("Loading E2-TTS model...")
|
141 |
+
E2TTS_ema_model = load_e2tts()
|
142 |
+
ema_model = E2TTS_ema_model
|
143 |
+
elif isinstance(model, list) and model[0] == "Custom":
|
144 |
+
assert not USING_SPACES, "Only official checkpoints allowed in Spaces."
|
145 |
+
global custom_ema_model, pre_custom_path
|
146 |
+
if pre_custom_path != model[1]:
|
147 |
+
show_info("Loading Custom TTS model...")
|
148 |
+
custom_ema_model = load_custom(model[1], vocab_path=model[2], model_cfg=model[3])
|
149 |
+
pre_custom_path = model[1]
|
150 |
+
ema_model = custom_ema_model
|
151 |
+
|
152 |
+
final_wave, final_sample_rate, combined_spectrogram = infer_process(
|
153 |
+
ref_audio,
|
154 |
+
ref_text,
|
155 |
+
gen_text,
|
156 |
+
ema_model,
|
157 |
+
vocoder,
|
158 |
+
cross_fade_duration=cross_fade_duration,
|
159 |
+
nfe_step=nfe_step,
|
160 |
+
speed=speed,
|
161 |
+
show_info=show_info,
|
162 |
+
progress=gr.Progress(),
|
163 |
+
)
|
164 |
+
|
165 |
+
# Remove silence
|
166 |
+
if remove_silence:
|
167 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as f:
|
168 |
+
sf.write(f.name, final_wave, final_sample_rate)
|
169 |
+
remove_silence_for_generated_wav(f.name)
|
170 |
+
final_wave, _ = torchaudio.load(f.name)
|
171 |
+
final_wave = final_wave.squeeze().cpu().numpy()
|
172 |
+
|
173 |
+
# Save the spectrogram
|
174 |
+
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp_spectrogram:
|
175 |
+
spectrogram_path = tmp_spectrogram.name
|
176 |
+
save_spectrogram(combined_spectrogram, spectrogram_path)
|
177 |
+
|
178 |
+
return (final_sample_rate, final_wave), spectrogram_path, ref_text
|
179 |
+
|
180 |
+
|
181 |
+
with gr.Blocks() as app_credits:
|
182 |
+
gr.Markdown("""
|
183 |
+
# Credits
|
184 |
+
|
185 |
+
* [mrfakename](https://github.com/fakerybakery) for the original [online demo](https://huggingface.co/spaces/mrfakename/E2-F5-TTS)
|
186 |
+
* [RootingInLoad](https://github.com/RootingInLoad) for initial chunk generation and podcast app exploration
|
187 |
+
* [jpgallegoar](https://github.com/jpgallegoar) for multiple speech-type generation & voice chat
|
188 |
+
""")
|
189 |
+
with gr.Blocks() as app_tts:
|
190 |
+
gr.Markdown("# Batched TTS")
|
191 |
+
ref_audio_input = gr.Audio(label="Reference Audio", type="filepath")
|
192 |
+
gen_text_input = gr.Textbox(label="Text to Generate", lines=10)
|
193 |
+
generate_btn = gr.Button("Synthesize", variant="primary")
|
194 |
+
with gr.Accordion("Advanced Settings", open=False):
|
195 |
+
ref_text_input = gr.Textbox(
|
196 |
+
label="Reference Text",
|
197 |
+
info="Leave blank to automatically transcribe the reference audio. If you enter text it will override automatic transcription.",
|
198 |
+
lines=2,
|
199 |
+
)
|
200 |
+
remove_silence = gr.Checkbox(
|
201 |
+
label="Remove Silences",
|
202 |
+
info="The model tends to produce silences, especially on longer audio. We can manually remove silences if needed. Note that this is an experimental feature and may produce strange results. This will also increase generation time.",
|
203 |
+
value=False,
|
204 |
+
)
|
205 |
+
speed_slider = gr.Slider(
|
206 |
+
label="Speed",
|
207 |
+
minimum=0.3,
|
208 |
+
maximum=2.0,
|
209 |
+
value=1.0,
|
210 |
+
step=0.1,
|
211 |
+
info="Adjust the speed of the audio.",
|
212 |
+
)
|
213 |
+
nfe_slider = gr.Slider(
|
214 |
+
label="NFE Steps",
|
215 |
+
minimum=4,
|
216 |
+
maximum=64,
|
217 |
+
value=32,
|
218 |
+
step=2,
|
219 |
+
info="Set the number of denoising steps.",
|
220 |
+
)
|
221 |
+
cross_fade_duration_slider = gr.Slider(
|
222 |
+
label="Cross-Fade Duration (s)",
|
223 |
+
minimum=0.0,
|
224 |
+
maximum=1.0,
|
225 |
+
value=0.15,
|
226 |
+
step=0.01,
|
227 |
+
info="Set the duration of the cross-fade between audio clips.",
|
228 |
+
)
|
229 |
+
|
230 |
+
audio_output = gr.Audio(label="Synthesized Audio")
|
231 |
+
spectrogram_output = gr.Image(label="Spectrogram")
|
232 |
+
|
233 |
+
@gpu_decorator
|
234 |
+
def basic_tts(
|
235 |
+
ref_audio_input,
|
236 |
+
ref_text_input,
|
237 |
+
gen_text_input,
|
238 |
+
remove_silence,
|
239 |
+
cross_fade_duration_slider,
|
240 |
+
nfe_slider,
|
241 |
+
speed_slider,
|
242 |
+
):
|
243 |
+
audio_out, spectrogram_path, ref_text_out = infer(
|
244 |
+
ref_audio_input,
|
245 |
+
ref_text_input,
|
246 |
+
gen_text_input,
|
247 |
+
tts_model_choice,
|
248 |
+
remove_silence,
|
249 |
+
cross_fade_duration=cross_fade_duration_slider,
|
250 |
+
nfe_step=nfe_slider,
|
251 |
+
speed=speed_slider,
|
252 |
+
)
|
253 |
+
return audio_out, spectrogram_path, ref_text_out
|
254 |
+
|
255 |
+
generate_btn.click(
|
256 |
+
basic_tts,
|
257 |
+
inputs=[
|
258 |
+
ref_audio_input,
|
259 |
+
ref_text_input,
|
260 |
+
gen_text_input,
|
261 |
+
remove_silence,
|
262 |
+
cross_fade_duration_slider,
|
263 |
+
nfe_slider,
|
264 |
+
speed_slider,
|
265 |
+
],
|
266 |
+
outputs=[audio_output, spectrogram_output, ref_text_input],
|
267 |
+
)
|
268 |
+
|
269 |
+
|
270 |
+
def parse_speechtypes_text(gen_text):
|
271 |
+
# Pattern to find {speechtype}
|
272 |
+
pattern = r"\{(.*?)\}"
|
273 |
+
|
274 |
+
# Split the text by the pattern
|
275 |
+
tokens = re.split(pattern, gen_text)
|
276 |
+
|
277 |
+
segments = []
|
278 |
+
|
279 |
+
current_style = "Regular"
|
280 |
+
|
281 |
+
for i in range(len(tokens)):
|
282 |
+
if i % 2 == 0:
|
283 |
+
# This is text
|
284 |
+
text = tokens[i].strip()
|
285 |
+
if text:
|
286 |
+
segments.append({"style": current_style, "text": text})
|
287 |
+
else:
|
288 |
+
# This is style
|
289 |
+
style = tokens[i].strip()
|
290 |
+
current_style = style
|
291 |
+
|
292 |
+
return segments
|
293 |
+
|
294 |
+
|
295 |
+
with gr.Blocks() as app_multistyle:
|
296 |
+
# New section for multistyle generation
|
297 |
+
gr.Markdown(
|
298 |
+
"""
|
299 |
+
# Multiple Speech-Type Generation
|
300 |
+
|
301 |
+
This section allows you to generate multiple speech types or multiple people's voices. Enter your text in the format shown below, and the system will generate speech using the appropriate type. If unspecified, the model will use the regular speech type. The current speech type will be used until the next speech type is specified.
|
302 |
+
"""
|
303 |
+
)
|
304 |
+
|
305 |
+
with gr.Row():
|
306 |
+
gr.Markdown(
|
307 |
+
"""
|
308 |
+
**Example Input:**
|
309 |
+
{Regular} Hello, I'd like to order a sandwich please.
|
310 |
+
{Surprised} What do you mean you're out of bread?
|
311 |
+
{Sad} I really wanted a sandwich though...
|
312 |
+
{Angry} You know what, darn you and your little shop!
|
313 |
+
{Whisper} I'll just go back home and cry now.
|
314 |
+
{Shouting} Why me?!
|
315 |
+
"""
|
316 |
+
)
|
317 |
+
|
318 |
+
gr.Markdown(
|
319 |
+
"""
|
320 |
+
**Example Input 2:**
|
321 |
+
{Speaker1_Happy} Hello, I'd like to order a sandwich please.
|
322 |
+
{Speaker2_Regular} Sorry, we're out of bread.
|
323 |
+
{Speaker1_Sad} I really wanted a sandwich though...
|
324 |
+
{Speaker2_Whisper} I'll give you the last one I was hiding.
|
325 |
+
"""
|
326 |
+
)
|
327 |
+
|
328 |
+
gr.Markdown(
|
329 |
+
"Upload different audio clips for each speech type. The first speech type is mandatory. You can add additional speech types by clicking the 'Add Speech Type' button."
|
330 |
+
)
|
331 |
+
|
332 |
+
# Regular speech type (mandatory)
|
333 |
+
with gr.Row() as regular_row:
|
334 |
+
with gr.Column():
|
335 |
+
regular_name = gr.Textbox(value="Regular", label="Speech Type Name")
|
336 |
+
regular_insert = gr.Button("Insert Label", variant="secondary")
|
337 |
+
regular_audio = gr.Audio(label="Regular Reference Audio", type="filepath")
|
338 |
+
regular_ref_text = gr.Textbox(label="Reference Text (Regular)", lines=2)
|
339 |
+
|
340 |
+
# Regular speech type (max 100)
|
341 |
+
max_speech_types = 100
|
342 |
+
speech_type_rows = [regular_row]
|
343 |
+
speech_type_names = [regular_name]
|
344 |
+
speech_type_audios = [regular_audio]
|
345 |
+
speech_type_ref_texts = [regular_ref_text]
|
346 |
+
speech_type_delete_btns = [None]
|
347 |
+
speech_type_insert_btns = [regular_insert]
|
348 |
+
|
349 |
+
# Additional speech types (99 more)
|
350 |
+
for i in range(max_speech_types - 1):
|
351 |
+
with gr.Row(visible=False) as row:
|
352 |
+
with gr.Column():
|
353 |
+
name_input = gr.Textbox(label="Speech Type Name")
|
354 |
+
delete_btn = gr.Button("Delete Type", variant="secondary")
|
355 |
+
insert_btn = gr.Button("Insert Label", variant="secondary")
|
356 |
+
audio_input = gr.Audio(label="Reference Audio", type="filepath")
|
357 |
+
ref_text_input = gr.Textbox(label="Reference Text", lines=2)
|
358 |
+
speech_type_rows.append(row)
|
359 |
+
speech_type_names.append(name_input)
|
360 |
+
speech_type_audios.append(audio_input)
|
361 |
+
speech_type_ref_texts.append(ref_text_input)
|
362 |
+
speech_type_delete_btns.append(delete_btn)
|
363 |
+
speech_type_insert_btns.append(insert_btn)
|
364 |
+
|
365 |
+
# Button to add speech type
|
366 |
+
add_speech_type_btn = gr.Button("Add Speech Type")
|
367 |
+
|
368 |
+
# Keep track of autoincrement of speech types, no roll back
|
369 |
+
speech_type_count = 1
|
370 |
+
|
371 |
+
# Function to add a speech type
|
372 |
+
def add_speech_type_fn():
|
373 |
+
row_updates = [gr.update() for _ in range(max_speech_types)]
|
374 |
+
global speech_type_count
|
375 |
+
if speech_type_count < max_speech_types:
|
376 |
+
row_updates[speech_type_count] = gr.update(visible=True)
|
377 |
+
speech_type_count += 1
|
378 |
+
else:
|
379 |
+
gr.Warning("Exhausted maximum number of speech types. Consider restart the app.")
|
380 |
+
return row_updates
|
381 |
+
|
382 |
+
add_speech_type_btn.click(add_speech_type_fn, outputs=speech_type_rows)
|
383 |
+
|
384 |
+
# Function to delete a speech type
|
385 |
+
def delete_speech_type_fn():
|
386 |
+
return gr.update(visible=False), None, None, None
|
387 |
+
|
388 |
+
# Update delete button clicks
|
389 |
+
for i in range(1, len(speech_type_delete_btns)):
|
390 |
+
speech_type_delete_btns[i].click(
|
391 |
+
delete_speech_type_fn,
|
392 |
+
outputs=[speech_type_rows[i], speech_type_names[i], speech_type_audios[i], speech_type_ref_texts[i]],
|
393 |
+
)
|
394 |
+
|
395 |
+
# Text input for the prompt
|
396 |
+
gen_text_input_multistyle = gr.Textbox(
|
397 |
+
label="Text to Generate",
|
398 |
+
lines=10,
|
399 |
+
placeholder="Enter the script with speaker names (or emotion types) at the start of each block, e.g.:\n\n{Regular} Hello, I'd like to order a sandwich please.\n{Surprised} What do you mean you're out of bread?\n{Sad} I really wanted a sandwich though...\n{Angry} You know what, darn you and your little shop!\n{Whisper} I'll just go back home and cry now.\n{Shouting} Why me?!",
|
400 |
+
)
|
401 |
+
|
402 |
+
def make_insert_speech_type_fn(index):
|
403 |
+
def insert_speech_type_fn(current_text, speech_type_name):
|
404 |
+
current_text = current_text or ""
|
405 |
+
speech_type_name = speech_type_name or "None"
|
406 |
+
updated_text = current_text + f"{{{speech_type_name}}} "
|
407 |
+
return updated_text
|
408 |
+
|
409 |
+
return insert_speech_type_fn
|
410 |
+
|
411 |
+
for i, insert_btn in enumerate(speech_type_insert_btns):
|
412 |
+
insert_fn = make_insert_speech_type_fn(i)
|
413 |
+
insert_btn.click(
|
414 |
+
insert_fn,
|
415 |
+
inputs=[gen_text_input_multistyle, speech_type_names[i]],
|
416 |
+
outputs=gen_text_input_multistyle,
|
417 |
+
)
|
418 |
+
|
419 |
+
with gr.Accordion("Advanced Settings", open=False):
|
420 |
+
remove_silence_multistyle = gr.Checkbox(
|
421 |
+
label="Remove Silences",
|
422 |
+
value=True,
|
423 |
+
)
|
424 |
+
|
425 |
+
# Generate button
|
426 |
+
generate_multistyle_btn = gr.Button("Generate Multi-Style Speech", variant="primary")
|
427 |
+
|
428 |
+
# Output audio
|
429 |
+
audio_output_multistyle = gr.Audio(label="Synthesized Audio")
|
430 |
+
|
431 |
+
@gpu_decorator
|
432 |
+
def generate_multistyle_speech(
|
433 |
+
gen_text,
|
434 |
+
*args,
|
435 |
+
):
|
436 |
+
speech_type_names_list = args[:max_speech_types]
|
437 |
+
speech_type_audios_list = args[max_speech_types : 2 * max_speech_types]
|
438 |
+
speech_type_ref_texts_list = args[2 * max_speech_types : 3 * max_speech_types]
|
439 |
+
remove_silence = args[3 * max_speech_types]
|
440 |
+
# Collect the speech types and their audios into a dict
|
441 |
+
speech_types = OrderedDict()
|
442 |
+
|
443 |
+
ref_text_idx = 0
|
444 |
+
for name_input, audio_input, ref_text_input in zip(
|
445 |
+
speech_type_names_list, speech_type_audios_list, speech_type_ref_texts_list
|
446 |
+
):
|
447 |
+
if name_input and audio_input:
|
448 |
+
speech_types[name_input] = {"audio": audio_input, "ref_text": ref_text_input}
|
449 |
+
else:
|
450 |
+
speech_types[f"@{ref_text_idx}@"] = {"audio": "", "ref_text": ""}
|
451 |
+
ref_text_idx += 1
|
452 |
+
|
453 |
+
# Parse the gen_text into segments
|
454 |
+
segments = parse_speechtypes_text(gen_text)
|
455 |
+
|
456 |
+
# For each segment, generate speech
|
457 |
+
generated_audio_segments = []
|
458 |
+
current_style = "Regular"
|
459 |
+
|
460 |
+
for segment in segments:
|
461 |
+
style = segment["style"]
|
462 |
+
text = segment["text"]
|
463 |
+
|
464 |
+
if style in speech_types:
|
465 |
+
current_style = style
|
466 |
+
else:
|
467 |
+
gr.Warning(f"Type {style} is not available, will use Regular as default.")
|
468 |
+
current_style = "Regular"
|
469 |
+
|
470 |
+
try:
|
471 |
+
ref_audio = speech_types[current_style]["audio"]
|
472 |
+
except KeyError:
|
473 |
+
gr.Warning(f"Please provide reference audio for type {current_style}.")
|
474 |
+
return [None] + [speech_types[style]["ref_text"] for style in speech_types]
|
475 |
+
ref_text = speech_types[current_style].get("ref_text", "")
|
476 |
+
|
477 |
+
# Generate speech for this segment
|
478 |
+
audio_out, _, ref_text_out = infer(
|
479 |
+
ref_audio, ref_text, text, tts_model_choice, remove_silence, 0, show_info=print
|
480 |
+
) # show_info=print no pull to top when generating
|
481 |
+
sr, audio_data = audio_out
|
482 |
+
|
483 |
+
generated_audio_segments.append(audio_data)
|
484 |
+
speech_types[current_style]["ref_text"] = ref_text_out
|
485 |
+
|
486 |
+
# Concatenate all audio segments
|
487 |
+
if generated_audio_segments:
|
488 |
+
final_audio_data = np.concatenate(generated_audio_segments)
|
489 |
+
return [(sr, final_audio_data)] + [speech_types[style]["ref_text"] for style in speech_types]
|
490 |
+
else:
|
491 |
+
gr.Warning("No audio generated.")
|
492 |
+
return [None] + [speech_types[style]["ref_text"] for style in speech_types]
|
493 |
+
|
494 |
+
generate_multistyle_btn.click(
|
495 |
+
generate_multistyle_speech,
|
496 |
+
inputs=[
|
497 |
+
gen_text_input_multistyle,
|
498 |
+
]
|
499 |
+
+ speech_type_names
|
500 |
+
+ speech_type_audios
|
501 |
+
+ speech_type_ref_texts
|
502 |
+
+ [
|
503 |
+
remove_silence_multistyle,
|
504 |
+
],
|
505 |
+
outputs=[audio_output_multistyle] + speech_type_ref_texts,
|
506 |
+
)
|
507 |
+
|
508 |
+
# Validation function to disable Generate button if speech types are missing
|
509 |
+
def validate_speech_types(gen_text, regular_name, *args):
|
510 |
+
speech_type_names_list = args
|
511 |
+
|
512 |
+
# Collect the speech types names
|
513 |
+
speech_types_available = set()
|
514 |
+
if regular_name:
|
515 |
+
speech_types_available.add(regular_name)
|
516 |
+
for name_input in speech_type_names_list:
|
517 |
+
if name_input:
|
518 |
+
speech_types_available.add(name_input)
|
519 |
+
|
520 |
+
# Parse the gen_text to get the speech types used
|
521 |
+
segments = parse_speechtypes_text(gen_text)
|
522 |
+
speech_types_in_text = set(segment["style"] for segment in segments)
|
523 |
+
|
524 |
+
# Check if all speech types in text are available
|
525 |
+
missing_speech_types = speech_types_in_text - speech_types_available
|
526 |
+
|
527 |
+
if missing_speech_types:
|
528 |
+
# Disable the generate button
|
529 |
+
return gr.update(interactive=False)
|
530 |
+
else:
|
531 |
+
# Enable the generate button
|
532 |
+
return gr.update(interactive=True)
|
533 |
+
|
534 |
+
gen_text_input_multistyle.change(
|
535 |
+
validate_speech_types,
|
536 |
+
inputs=[gen_text_input_multistyle, regular_name] + speech_type_names,
|
537 |
+
outputs=generate_multistyle_btn,
|
538 |
+
)
|
539 |
+
|
540 |
+
|
541 |
+
with gr.Blocks() as app_chat:
|
542 |
+
gr.Markdown(
|
543 |
+
"""
|
544 |
+
# Voice Chat
|
545 |
+
Have a conversation with an AI using your reference voice!
|
546 |
+
1. Upload a reference audio clip and optionally its transcript.
|
547 |
+
2. Load the chat model.
|
548 |
+
3. Record your message through your microphone.
|
549 |
+
4. The AI will respond using the reference voice.
|
550 |
+
"""
|
551 |
+
)
|
552 |
+
|
553 |
+
if not USING_SPACES:
|
554 |
+
load_chat_model_btn = gr.Button("Load Chat Model", variant="primary")
|
555 |
+
|
556 |
+
chat_interface_container = gr.Column(visible=False)
|
557 |
+
|
558 |
+
@gpu_decorator
|
559 |
+
def load_chat_model():
|
560 |
+
global chat_model_state, chat_tokenizer_state
|
561 |
+
if chat_model_state is None:
|
562 |
+
show_info = gr.Info
|
563 |
+
show_info("Loading chat model...")
|
564 |
+
model_name = "Qwen/Qwen2.5-3B-Instruct"
|
565 |
+
chat_model_state = AutoModelForCausalLM.from_pretrained(
|
566 |
+
model_name, torch_dtype="auto", device_map="auto"
|
567 |
+
)
|
568 |
+
chat_tokenizer_state = AutoTokenizer.from_pretrained(model_name)
|
569 |
+
show_info("Chat model loaded.")
|
570 |
+
|
571 |
+
return gr.update(visible=False), gr.update(visible=True)
|
572 |
+
|
573 |
+
load_chat_model_btn.click(load_chat_model, outputs=[load_chat_model_btn, chat_interface_container])
|
574 |
+
|
575 |
+
else:
|
576 |
+
chat_interface_container = gr.Column()
|
577 |
+
|
578 |
+
if chat_model_state is None:
|
579 |
+
model_name = "Qwen/Qwen2.5-3B-Instruct"
|
580 |
+
chat_model_state = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", device_map="auto")
|
581 |
+
chat_tokenizer_state = AutoTokenizer.from_pretrained(model_name)
|
582 |
+
|
583 |
+
with chat_interface_container:
|
584 |
+
with gr.Row():
|
585 |
+
with gr.Column():
|
586 |
+
ref_audio_chat = gr.Audio(label="Reference Audio", type="filepath")
|
587 |
+
with gr.Column():
|
588 |
+
with gr.Accordion("Advanced Settings", open=False):
|
589 |
+
remove_silence_chat = gr.Checkbox(
|
590 |
+
label="Remove Silences",
|
591 |
+
value=True,
|
592 |
+
)
|
593 |
+
ref_text_chat = gr.Textbox(
|
594 |
+
label="Reference Text",
|
595 |
+
info="Optional: Leave blank to auto-transcribe",
|
596 |
+
lines=2,
|
597 |
+
)
|
598 |
+
system_prompt_chat = gr.Textbox(
|
599 |
+
label="System Prompt",
|
600 |
+
value="You are not an AI assistant, you are whoever the user says you are. You must stay in character. Keep your responses concise since they will be spoken out loud.",
|
601 |
+
lines=2,
|
602 |
+
)
|
603 |
+
|
604 |
+
chatbot_interface = gr.Chatbot(label="Conversation")
|
605 |
+
|
606 |
+
with gr.Row():
|
607 |
+
with gr.Column():
|
608 |
+
audio_input_chat = gr.Microphone(
|
609 |
+
label="Speak your message",
|
610 |
+
type="filepath",
|
611 |
+
)
|
612 |
+
audio_output_chat = gr.Audio(autoplay=True)
|
613 |
+
with gr.Column():
|
614 |
+
text_input_chat = gr.Textbox(
|
615 |
+
label="Type your message",
|
616 |
+
lines=1,
|
617 |
+
)
|
618 |
+
send_btn_chat = gr.Button("Send Message")
|
619 |
+
clear_btn_chat = gr.Button("Clear Conversation")
|
620 |
+
|
621 |
+
conversation_state = gr.State(
|
622 |
+
value=[
|
623 |
+
{
|
624 |
+
"role": "system",
|
625 |
+
"content": "You are not an AI assistant, you are whoever the user says you are. You must stay in character. Keep your responses concise since they will be spoken out loud.",
|
626 |
+
}
|
627 |
+
]
|
628 |
+
)
|
629 |
+
|
630 |
+
# Modify process_audio_input to use model and tokenizer from state
|
631 |
+
@gpu_decorator
|
632 |
+
def process_audio_input(audio_path, text, history, conv_state):
|
633 |
+
"""Handle audio or text input from user"""
|
634 |
+
|
635 |
+
if not audio_path and not text.strip():
|
636 |
+
return history, conv_state, ""
|
637 |
+
|
638 |
+
if audio_path:
|
639 |
+
text = preprocess_ref_audio_text(audio_path, text)[1]
|
640 |
+
|
641 |
+
if not text.strip():
|
642 |
+
return history, conv_state, ""
|
643 |
+
|
644 |
+
conv_state.append({"role": "user", "content": text})
|
645 |
+
history.append((text, None))
|
646 |
+
|
647 |
+
response = generate_response(conv_state, chat_model_state, chat_tokenizer_state)
|
648 |
+
|
649 |
+
conv_state.append({"role": "assistant", "content": response})
|
650 |
+
history[-1] = (text, response)
|
651 |
+
|
652 |
+
return history, conv_state, ""
|
653 |
+
|
654 |
+
@gpu_decorator
|
655 |
+
def generate_audio_response(history, ref_audio, ref_text, remove_silence):
|
656 |
+
"""Generate TTS audio for AI response"""
|
657 |
+
if not history or not ref_audio:
|
658 |
+
return None
|
659 |
+
|
660 |
+
last_user_message, last_ai_response = history[-1]
|
661 |
+
if not last_ai_response:
|
662 |
+
return None
|
663 |
+
|
664 |
+
audio_result, _, ref_text_out = infer(
|
665 |
+
ref_audio,
|
666 |
+
ref_text,
|
667 |
+
last_ai_response,
|
668 |
+
tts_model_choice,
|
669 |
+
remove_silence,
|
670 |
+
cross_fade_duration=0.15,
|
671 |
+
speed=1.0,
|
672 |
+
show_info=print, # show_info=print no pull to top when generating
|
673 |
+
)
|
674 |
+
return audio_result, ref_text_out
|
675 |
+
|
676 |
+
def clear_conversation():
|
677 |
+
"""Reset the conversation"""
|
678 |
+
return [], [
|
679 |
+
{
|
680 |
+
"role": "system",
|
681 |
+
"content": "You are not an AI assistant, you are whoever the user says you are. You must stay in character. Keep your responses concise since they will be spoken out loud.",
|
682 |
+
}
|
683 |
+
]
|
684 |
+
|
685 |
+
def update_system_prompt(new_prompt):
|
686 |
+
"""Update the system prompt and reset the conversation"""
|
687 |
+
new_conv_state = [{"role": "system", "content": new_prompt}]
|
688 |
+
return [], new_conv_state
|
689 |
+
|
690 |
+
# Handle audio input
|
691 |
+
audio_input_chat.stop_recording(
|
692 |
+
process_audio_input,
|
693 |
+
inputs=[audio_input_chat, text_input_chat, chatbot_interface, conversation_state],
|
694 |
+
outputs=[chatbot_interface, conversation_state],
|
695 |
+
).then(
|
696 |
+
generate_audio_response,
|
697 |
+
inputs=[chatbot_interface, ref_audio_chat, ref_text_chat, remove_silence_chat],
|
698 |
+
outputs=[audio_output_chat, ref_text_chat],
|
699 |
+
).then(
|
700 |
+
lambda: None,
|
701 |
+
None,
|
702 |
+
audio_input_chat,
|
703 |
+
)
|
704 |
+
|
705 |
+
# Handle text input
|
706 |
+
text_input_chat.submit(
|
707 |
+
process_audio_input,
|
708 |
+
inputs=[audio_input_chat, text_input_chat, chatbot_interface, conversation_state],
|
709 |
+
outputs=[chatbot_interface, conversation_state],
|
710 |
+
).then(
|
711 |
+
generate_audio_response,
|
712 |
+
inputs=[chatbot_interface, ref_audio_chat, ref_text_chat, remove_silence_chat],
|
713 |
+
outputs=[audio_output_chat, ref_text_chat],
|
714 |
+
).then(
|
715 |
+
lambda: None,
|
716 |
+
None,
|
717 |
+
text_input_chat,
|
718 |
+
)
|
719 |
+
|
720 |
+
# Handle send button
|
721 |
+
send_btn_chat.click(
|
722 |
+
process_audio_input,
|
723 |
+
inputs=[audio_input_chat, text_input_chat, chatbot_interface, conversation_state],
|
724 |
+
outputs=[chatbot_interface, conversation_state],
|
725 |
+
).then(
|
726 |
+
generate_audio_response,
|
727 |
+
inputs=[chatbot_interface, ref_audio_chat, ref_text_chat, remove_silence_chat],
|
728 |
+
outputs=[audio_output_chat, ref_text_chat],
|
729 |
+
).then(
|
730 |
+
lambda: None,
|
731 |
+
None,
|
732 |
+
text_input_chat,
|
733 |
+
)
|
734 |
+
|
735 |
+
# Handle clear button
|
736 |
+
clear_btn_chat.click(
|
737 |
+
clear_conversation,
|
738 |
+
outputs=[chatbot_interface, conversation_state],
|
739 |
+
)
|
740 |
+
|
741 |
+
# Handle system prompt change and reset conversation
|
742 |
+
system_prompt_chat.change(
|
743 |
+
update_system_prompt,
|
744 |
+
inputs=system_prompt_chat,
|
745 |
+
outputs=[chatbot_interface, conversation_state],
|
746 |
+
)
|
747 |
+
|
748 |
+
|
749 |
+
with gr.Blocks() as app:
|
750 |
+
gr.Markdown(
|
751 |
+
f"""
|
752 |
+
# E2/F5 TTS
|
753 |
+
|
754 |
+
This is {"a local web UI for [F5 TTS](https://github.com/SWivid/F5-TTS)" if not USING_SPACES else "an online demo for [F5-TTS](https://github.com/SWivid/F5-TTS)"} with advanced batch processing support. This app supports the following TTS models:
|
755 |
+
|
756 |
+
* [F5-TTS](https://arxiv.org/abs/2410.06885) (A Fairytaler that Fakes Fluent and Faithful Speech with Flow Matching)
|
757 |
+
* [E2 TTS](https://arxiv.org/abs/2406.18009) (Embarrassingly Easy Fully Non-Autoregressive Zero-Shot TTS)
|
758 |
+
|
759 |
+
The checkpoints currently support English and Chinese.
|
760 |
+
|
761 |
+
If you're having issues, try converting your reference audio to WAV or MP3, clipping it to 15s with ✂ in the bottom right corner (otherwise might have non-optimal auto-trimmed result).
|
762 |
+
|
763 |
+
**NOTE: Reference text will be automatically transcribed with Whisper if not provided. For best results, keep your reference clips short (<15s). Ensure the audio is fully uploaded before generating.**
|
764 |
+
"""
|
765 |
+
)
|
766 |
+
|
767 |
+
last_used_custom = files("f5_tts").joinpath("infer/.cache/last_used_custom_model_info_v1.txt")
|
768 |
+
|
769 |
+
def load_last_used_custom():
|
770 |
+
try:
|
771 |
+
custom = []
|
772 |
+
with open(last_used_custom, "r", encoding="utf-8") as f:
|
773 |
+
for line in f:
|
774 |
+
custom.append(line.strip())
|
775 |
+
return custom
|
776 |
+
except FileNotFoundError:
|
777 |
+
last_used_custom.parent.mkdir(parents=True, exist_ok=True)
|
778 |
+
return DEFAULT_TTS_MODEL_CFG
|
779 |
+
|
780 |
+
def switch_tts_model(new_choice):
|
781 |
+
global tts_model_choice
|
782 |
+
if new_choice == "Custom": # override in case webpage is refreshed
|
783 |
+
custom_ckpt_path, custom_vocab_path, custom_model_cfg = load_last_used_custom()
|
784 |
+
tts_model_choice = ["Custom", custom_ckpt_path, custom_vocab_path, json.loads(custom_model_cfg)]
|
785 |
+
return (
|
786 |
+
gr.update(visible=True, value=custom_ckpt_path),
|
787 |
+
gr.update(visible=True, value=custom_vocab_path),
|
788 |
+
gr.update(visible=True, value=custom_model_cfg),
|
789 |
+
)
|
790 |
+
else:
|
791 |
+
tts_model_choice = new_choice
|
792 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
793 |
+
|
794 |
+
def set_custom_model(custom_ckpt_path, custom_vocab_path, custom_model_cfg):
|
795 |
+
global tts_model_choice
|
796 |
+
tts_model_choice = ["Custom", custom_ckpt_path, custom_vocab_path, json.loads(custom_model_cfg)]
|
797 |
+
with open(last_used_custom, "w", encoding="utf-8") as f:
|
798 |
+
f.write(custom_ckpt_path + "\n" + custom_vocab_path + "\n" + custom_model_cfg + "\n")
|
799 |
+
|
800 |
+
with gr.Row():
|
801 |
+
if not USING_SPACES:
|
802 |
+
choose_tts_model = gr.Radio(
|
803 |
+
choices=[DEFAULT_TTS_MODEL, "E2-TTS", "Custom"], label="Choose TTS Model", value=DEFAULT_TTS_MODEL
|
804 |
+
)
|
805 |
+
else:
|
806 |
+
choose_tts_model = gr.Radio(
|
807 |
+
choices=[DEFAULT_TTS_MODEL, "E2-TTS"], label="Choose TTS Model", value=DEFAULT_TTS_MODEL
|
808 |
+
)
|
809 |
+
custom_ckpt_path = gr.Dropdown(
|
810 |
+
choices=[DEFAULT_TTS_MODEL_CFG[0]],
|
811 |
+
value=load_last_used_custom()[0],
|
812 |
+
allow_custom_value=True,
|
813 |
+
label="Model: local_path | hf://user_id/repo_id/model_ckpt",
|
814 |
+
visible=False,
|
815 |
+
)
|
816 |
+
custom_vocab_path = gr.Dropdown(
|
817 |
+
choices=[DEFAULT_TTS_MODEL_CFG[1]],
|
818 |
+
value=load_last_used_custom()[1],
|
819 |
+
allow_custom_value=True,
|
820 |
+
label="Vocab: local_path | hf://user_id/repo_id/vocab_file",
|
821 |
+
visible=False,
|
822 |
+
)
|
823 |
+
custom_model_cfg = gr.Dropdown(
|
824 |
+
choices=[
|
825 |
+
DEFAULT_TTS_MODEL_CFG[2],
|
826 |
+
json.dumps(
|
827 |
+
dict(
|
828 |
+
dim=1024,
|
829 |
+
depth=22,
|
830 |
+
heads=16,
|
831 |
+
ff_mult=2,
|
832 |
+
text_dim=512,
|
833 |
+
text_mask_padding=False,
|
834 |
+
conv_layers=4,
|
835 |
+
pe_attn_head=1,
|
836 |
+
)
|
837 |
+
),
|
838 |
+
json.dumps(
|
839 |
+
dict(
|
840 |
+
dim=768,
|
841 |
+
depth=18,
|
842 |
+
heads=12,
|
843 |
+
ff_mult=2,
|
844 |
+
text_dim=512,
|
845 |
+
text_mask_padding=False,
|
846 |
+
conv_layers=4,
|
847 |
+
pe_attn_head=1,
|
848 |
+
)
|
849 |
+
),
|
850 |
+
],
|
851 |
+
value=load_last_used_custom()[2],
|
852 |
+
allow_custom_value=True,
|
853 |
+
label="Config: in a dictionary form",
|
854 |
+
visible=False,
|
855 |
+
)
|
856 |
+
|
857 |
+
choose_tts_model.change(
|
858 |
+
switch_tts_model,
|
859 |
+
inputs=[choose_tts_model],
|
860 |
+
outputs=[custom_ckpt_path, custom_vocab_path, custom_model_cfg],
|
861 |
+
show_progress="hidden",
|
862 |
+
)
|
863 |
+
custom_ckpt_path.change(
|
864 |
+
set_custom_model,
|
865 |
+
inputs=[custom_ckpt_path, custom_vocab_path, custom_model_cfg],
|
866 |
+
show_progress="hidden",
|
867 |
+
)
|
868 |
+
custom_vocab_path.change(
|
869 |
+
set_custom_model,
|
870 |
+
inputs=[custom_ckpt_path, custom_vocab_path, custom_model_cfg],
|
871 |
+
show_progress="hidden",
|
872 |
+
)
|
873 |
+
custom_model_cfg.change(
|
874 |
+
set_custom_model,
|
875 |
+
inputs=[custom_ckpt_path, custom_vocab_path, custom_model_cfg],
|
876 |
+
show_progress="hidden",
|
877 |
+
)
|
878 |
+
|
879 |
+
gr.TabbedInterface(
|
880 |
+
[app_tts, app_multistyle, app_chat, app_credits],
|
881 |
+
["Basic-TTS", "Multi-Speech", "Voice-Chat", "Credits"],
|
882 |
+
)
|
883 |
+
|
884 |
+
|
885 |
+
@click.command()
|
886 |
+
@click.option("--port", "-p", default=None, type=int, help="Port to run the app on")
|
887 |
+
@click.option("--host", "-H", default=None, help="Host to run the app on")
|
888 |
+
@click.option(
|
889 |
+
"--share",
|
890 |
+
"-s",
|
891 |
+
default=False,
|
892 |
+
is_flag=True,
|
893 |
+
help="Share the app via Gradio share link",
|
894 |
+
)
|
895 |
+
@click.option("--api", "-a", default=True, is_flag=True, help="Allow API access")
|
896 |
+
@click.option(
|
897 |
+
"--root_path",
|
898 |
+
"-r",
|
899 |
+
default=None,
|
900 |
+
type=str,
|
901 |
+
help='The root path (or "mount point") of the application, if it\'s not served from the root ("/") of the domain. Often used when the application is behind a reverse proxy that forwards requests to the application, e.g. set "/myapp" or full URL for application served at "https://example.com/myapp".',
|
902 |
+
)
|
903 |
+
@click.option(
|
904 |
+
"--inbrowser",
|
905 |
+
"-i",
|
906 |
+
is_flag=True,
|
907 |
+
default=False,
|
908 |
+
help="Automatically launch the interface in the default web browser",
|
909 |
+
)
|
910 |
+
def main(port, host, share, api, root_path, inbrowser):
|
911 |
+
global app
|
912 |
+
print("Starting app...")
|
913 |
+
app.queue(api_open=api).launch(
|
914 |
+
server_name=host,
|
915 |
+
server_port=port,
|
916 |
+
share=share,
|
917 |
+
show_api=api,
|
918 |
+
root_path=root_path,
|
919 |
+
inbrowser=inbrowser,
|
920 |
+
)
|
921 |
+
|
922 |
+
|
923 |
+
if __name__ == "__main__":
|
924 |
+
if not USING_SPACES:
|
925 |
+
main()
|
926 |
+
else:
|
927 |
+
app.queue().launch()
|
src/f5_tts/infer/speech_edit.py
ADDED
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" # for MPS device compatibility
|
4 |
+
|
5 |
+
from importlib.resources import files
|
6 |
+
|
7 |
+
import torch
|
8 |
+
import torch.nn.functional as F
|
9 |
+
import torchaudio
|
10 |
+
from omegaconf import OmegaConf
|
11 |
+
|
12 |
+
from f5_tts.infer.utils_infer import load_checkpoint, load_vocoder, save_spectrogram
|
13 |
+
from f5_tts.model import CFM, DiT, UNetT # noqa: F401. used for config
|
14 |
+
from f5_tts.model.utils import convert_char_to_pinyin, get_tokenizer
|
15 |
+
|
16 |
+
device = (
|
17 |
+
"cuda"
|
18 |
+
if torch.cuda.is_available()
|
19 |
+
else "xpu"
|
20 |
+
if torch.xpu.is_available()
|
21 |
+
else "mps"
|
22 |
+
if torch.backends.mps.is_available()
|
23 |
+
else "cpu"
|
24 |
+
)
|
25 |
+
|
26 |
+
|
27 |
+
# ---------------------- infer setting ---------------------- #
|
28 |
+
|
29 |
+
seed = None # int | None
|
30 |
+
|
31 |
+
exp_name = "F5TTS_v1_Base" # F5TTS_v1_Base | E2TTS_Base
|
32 |
+
ckpt_step = 1250000
|
33 |
+
|
34 |
+
nfe_step = 32 # 16, 32
|
35 |
+
cfg_strength = 2.0
|
36 |
+
ode_method = "euler" # euler | midpoint
|
37 |
+
sway_sampling_coef = -1.0
|
38 |
+
speed = 1.0
|
39 |
+
target_rms = 0.1
|
40 |
+
|
41 |
+
|
42 |
+
model_cfg = OmegaConf.load(str(files("f5_tts").joinpath(f"configs/{exp_name}.yaml")))
|
43 |
+
model_cls = globals()[model_cfg.model.backbone]
|
44 |
+
model_arc = model_cfg.model.arch
|
45 |
+
|
46 |
+
dataset_name = model_cfg.datasets.name
|
47 |
+
tokenizer = model_cfg.model.tokenizer
|
48 |
+
|
49 |
+
mel_spec_type = model_cfg.model.mel_spec.mel_spec_type
|
50 |
+
target_sample_rate = model_cfg.model.mel_spec.target_sample_rate
|
51 |
+
n_mel_channels = model_cfg.model.mel_spec.n_mel_channels
|
52 |
+
hop_length = model_cfg.model.mel_spec.hop_length
|
53 |
+
win_length = model_cfg.model.mel_spec.win_length
|
54 |
+
n_fft = model_cfg.model.mel_spec.n_fft
|
55 |
+
|
56 |
+
|
57 |
+
ckpt_path = str(files("f5_tts").joinpath("../../")) + f"ckpts/{exp_name}/model_{ckpt_step}.safetensors"
|
58 |
+
output_dir = "tests"
|
59 |
+
|
60 |
+
|
61 |
+
# [leverage https://github.com/MahmoudAshraf97/ctc-forced-aligner to get char level alignment]
|
62 |
+
# pip install git+https://github.com/MahmoudAshraf97/ctc-forced-aligner.git
|
63 |
+
# [write the origin_text into a file, e.g. tests/test_edit.txt]
|
64 |
+
# ctc-forced-aligner --audio_path "src/f5_tts/infer/examples/basic/basic_ref_en.wav" --text_path "tests/test_edit.txt" --language "zho" --romanize --split_size "char"
|
65 |
+
# [result will be saved at same path of audio file]
|
66 |
+
# [--language "zho" for Chinese, "eng" for English]
|
67 |
+
# [if local ckpt, set --alignment_model "../checkpoints/mms-300m-1130-forced-aligner"]
|
68 |
+
|
69 |
+
audio_to_edit = str(files("f5_tts").joinpath("infer/examples/basic/basic_ref_en.wav"))
|
70 |
+
origin_text = "Some call me nature, others call me mother nature."
|
71 |
+
target_text = "Some call me optimist, others call me realist."
|
72 |
+
parts_to_edit = [
|
73 |
+
[1.42, 2.44],
|
74 |
+
[4.04, 4.9],
|
75 |
+
] # stard_ends of "nature" & "mother nature", in seconds
|
76 |
+
fix_duration = [
|
77 |
+
1.2,
|
78 |
+
1,
|
79 |
+
] # fix duration for "optimist" & "realist", in seconds
|
80 |
+
|
81 |
+
# audio_to_edit = "src/f5_tts/infer/examples/basic/basic_ref_zh.wav"
|
82 |
+
# origin_text = "对,这就是我,万人敬仰的太乙真人。"
|
83 |
+
# target_text = "对,那就是你,万人敬仰的太白金星。"
|
84 |
+
# parts_to_edit = [[0.84, 1.4], [1.92, 2.4], [4.26, 6.26], ]
|
85 |
+
# fix_duration = None # use origin text duration
|
86 |
+
|
87 |
+
|
88 |
+
# -------------------------------------------------#
|
89 |
+
|
90 |
+
use_ema = True
|
91 |
+
|
92 |
+
if not os.path.exists(output_dir):
|
93 |
+
os.makedirs(output_dir)
|
94 |
+
|
95 |
+
# Vocoder model
|
96 |
+
local = False
|
97 |
+
if mel_spec_type == "vocos":
|
98 |
+
vocoder_local_path = "../checkpoints/charactr/vocos-mel-24khz"
|
99 |
+
elif mel_spec_type == "bigvgan":
|
100 |
+
vocoder_local_path = "../checkpoints/bigvgan_v2_24khz_100band_256x"
|
101 |
+
vocoder = load_vocoder(vocoder_name=mel_spec_type, is_local=local, local_path=vocoder_local_path)
|
102 |
+
|
103 |
+
# Tokenizer
|
104 |
+
vocab_char_map, vocab_size = get_tokenizer(dataset_name, tokenizer)
|
105 |
+
|
106 |
+
# Model
|
107 |
+
model = CFM(
|
108 |
+
transformer=model_cls(**model_arc, text_num_embeds=vocab_size, mel_dim=n_mel_channels),
|
109 |
+
mel_spec_kwargs=dict(
|
110 |
+
n_fft=n_fft,
|
111 |
+
hop_length=hop_length,
|
112 |
+
win_length=win_length,
|
113 |
+
n_mel_channels=n_mel_channels,
|
114 |
+
target_sample_rate=target_sample_rate,
|
115 |
+
mel_spec_type=mel_spec_type,
|
116 |
+
),
|
117 |
+
odeint_kwargs=dict(
|
118 |
+
method=ode_method,
|
119 |
+
),
|
120 |
+
vocab_char_map=vocab_char_map,
|
121 |
+
).to(device)
|
122 |
+
|
123 |
+
dtype = torch.float32 if mel_spec_type == "bigvgan" else None
|
124 |
+
model = load_checkpoint(model, ckpt_path, device, dtype=dtype, use_ema=use_ema)
|
125 |
+
|
126 |
+
# Audio
|
127 |
+
audio, sr = torchaudio.load(audio_to_edit)
|
128 |
+
if audio.shape[0] > 1:
|
129 |
+
audio = torch.mean(audio, dim=0, keepdim=True)
|
130 |
+
rms = torch.sqrt(torch.mean(torch.square(audio)))
|
131 |
+
if rms < target_rms:
|
132 |
+
audio = audio * target_rms / rms
|
133 |
+
if sr != target_sample_rate:
|
134 |
+
resampler = torchaudio.transforms.Resample(sr, target_sample_rate)
|
135 |
+
audio = resampler(audio)
|
136 |
+
offset = 0
|
137 |
+
audio_ = torch.zeros(1, 0)
|
138 |
+
edit_mask = torch.zeros(1, 0, dtype=torch.bool)
|
139 |
+
for part in parts_to_edit:
|
140 |
+
start, end = part
|
141 |
+
part_dur = end - start if fix_duration is None else fix_duration.pop(0)
|
142 |
+
part_dur = part_dur * target_sample_rate
|
143 |
+
start = start * target_sample_rate
|
144 |
+
audio_ = torch.cat((audio_, audio[:, round(offset) : round(start)], torch.zeros(1, round(part_dur))), dim=-1)
|
145 |
+
edit_mask = torch.cat(
|
146 |
+
(
|
147 |
+
edit_mask,
|
148 |
+
torch.ones(1, round((start - offset) / hop_length), dtype=torch.bool),
|
149 |
+
torch.zeros(1, round(part_dur / hop_length), dtype=torch.bool),
|
150 |
+
),
|
151 |
+
dim=-1,
|
152 |
+
)
|
153 |
+
offset = end * target_sample_rate
|
154 |
+
# audio = torch.cat((audio_, audio[:, round(offset):]), dim = -1)
|
155 |
+
edit_mask = F.pad(edit_mask, (0, audio.shape[-1] // hop_length - edit_mask.shape[-1] + 1), value=True)
|
156 |
+
audio = audio.to(device)
|
157 |
+
edit_mask = edit_mask.to(device)
|
158 |
+
|
159 |
+
# Text
|
160 |
+
text_list = [target_text]
|
161 |
+
if tokenizer == "pinyin":
|
162 |
+
final_text_list = convert_char_to_pinyin(text_list)
|
163 |
+
else:
|
164 |
+
final_text_list = [text_list]
|
165 |
+
print(f"text : {text_list}")
|
166 |
+
print(f"pinyin: {final_text_list}")
|
167 |
+
|
168 |
+
# Duration
|
169 |
+
ref_audio_len = 0
|
170 |
+
duration = audio.shape[-1] // hop_length
|
171 |
+
|
172 |
+
# Inference
|
173 |
+
with torch.inference_mode():
|
174 |
+
generated, trajectory = model.sample(
|
175 |
+
cond=audio,
|
176 |
+
text=final_text_list,
|
177 |
+
duration=duration,
|
178 |
+
steps=nfe_step,
|
179 |
+
cfg_strength=cfg_strength,
|
180 |
+
sway_sampling_coef=sway_sampling_coef,
|
181 |
+
seed=seed,
|
182 |
+
edit_mask=edit_mask,
|
183 |
+
)
|
184 |
+
print(f"Generated mel: {generated.shape}")
|
185 |
+
|
186 |
+
# Final result
|
187 |
+
generated = generated.to(torch.float32)
|
188 |
+
generated = generated[:, ref_audio_len:, :]
|
189 |
+
gen_mel_spec = generated.permute(0, 2, 1)
|
190 |
+
if mel_spec_type == "vocos":
|
191 |
+
generated_wave = vocoder.decode(gen_mel_spec).cpu()
|
192 |
+
elif mel_spec_type == "bigvgan":
|
193 |
+
generated_wave = vocoder(gen_mel_spec).squeeze(0).cpu()
|
194 |
+
|
195 |
+
if rms < target_rms:
|
196 |
+
generated_wave = generated_wave * rms / target_rms
|
197 |
+
|
198 |
+
save_spectrogram(gen_mel_spec[0].cpu().numpy(), f"{output_dir}/speech_edit_out.png")
|
199 |
+
torchaudio.save(f"{output_dir}/speech_edit_out.wav", generated_wave, target_sample_rate)
|
200 |
+
print(f"Generated wav: {generated_wave.shape}")
|
src/f5_tts/infer/utils_infer.py
ADDED
@@ -0,0 +1,589 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# A unified script for inference process
|
2 |
+
# Make adjustments inside functions, and consider both gradio and cli scripts if need to change func output format
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
from concurrent.futures import ThreadPoolExecutor
|
6 |
+
|
7 |
+
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" # for MPS device compatibility
|
8 |
+
sys.path.append(f"{os.path.dirname(os.path.abspath(__file__))}/../../third_party/BigVGAN/")
|
9 |
+
|
10 |
+
import hashlib
|
11 |
+
import re
|
12 |
+
import tempfile
|
13 |
+
from importlib.resources import files
|
14 |
+
|
15 |
+
import matplotlib
|
16 |
+
|
17 |
+
matplotlib.use("Agg")
|
18 |
+
|
19 |
+
import matplotlib.pylab as plt
|
20 |
+
import numpy as np
|
21 |
+
import torch
|
22 |
+
import torchaudio
|
23 |
+
import tqdm
|
24 |
+
from huggingface_hub import snapshot_download, hf_hub_download
|
25 |
+
from pydub import AudioSegment, silence
|
26 |
+
from transformers import pipeline
|
27 |
+
from vocos import Vocos
|
28 |
+
|
29 |
+
from f5_tts.model import CFM
|
30 |
+
from f5_tts.model.utils import (
|
31 |
+
get_tokenizer,
|
32 |
+
convert_char_to_pinyin,
|
33 |
+
)
|
34 |
+
|
35 |
+
_ref_audio_cache = {}
|
36 |
+
|
37 |
+
device = (
|
38 |
+
"cuda"
|
39 |
+
if torch.cuda.is_available()
|
40 |
+
else "xpu"
|
41 |
+
if torch.xpu.is_available()
|
42 |
+
else "mps"
|
43 |
+
if torch.backends.mps.is_available()
|
44 |
+
else "cpu"
|
45 |
+
)
|
46 |
+
|
47 |
+
# -----------------------------------------
|
48 |
+
|
49 |
+
target_sample_rate = 24000
|
50 |
+
n_mel_channels = 100
|
51 |
+
hop_length = 256
|
52 |
+
win_length = 1024
|
53 |
+
n_fft = 1024
|
54 |
+
mel_spec_type = "vocos"
|
55 |
+
target_rms = 0.1
|
56 |
+
cross_fade_duration = 0.15
|
57 |
+
ode_method = "euler"
|
58 |
+
nfe_step = 32 # 16, 32
|
59 |
+
cfg_strength = 2.0
|
60 |
+
sway_sampling_coef = -1.0
|
61 |
+
speed = 1.0
|
62 |
+
fix_duration = None
|
63 |
+
|
64 |
+
# -----------------------------------------
|
65 |
+
|
66 |
+
|
67 |
+
# chunk text into smaller pieces
|
68 |
+
|
69 |
+
|
70 |
+
def chunk_text(text, max_chars=135):
|
71 |
+
"""
|
72 |
+
Splits the input text into chunks, each with a maximum number of characters.
|
73 |
+
|
74 |
+
Args:
|
75 |
+
text (str): The text to be split.
|
76 |
+
max_chars (int): The maximum number of characters per chunk.
|
77 |
+
|
78 |
+
Returns:
|
79 |
+
List[str]: A list of text chunks.
|
80 |
+
"""
|
81 |
+
chunks = []
|
82 |
+
current_chunk = ""
|
83 |
+
# Split the text into sentences based on punctuation followed by whitespace
|
84 |
+
sentences = re.split(r"(?<=[;:,.!?])\s+|(?<=[;:,。!?])", text)
|
85 |
+
|
86 |
+
for sentence in sentences:
|
87 |
+
if len(current_chunk.encode("utf-8")) + len(sentence.encode("utf-8")) <= max_chars:
|
88 |
+
current_chunk += sentence + " " if sentence and len(sentence[-1].encode("utf-8")) == 1 else sentence
|
89 |
+
else:
|
90 |
+
if current_chunk:
|
91 |
+
chunks.append(current_chunk.strip())
|
92 |
+
current_chunk = sentence + " " if sentence and len(sentence[-1].encode("utf-8")) == 1 else sentence
|
93 |
+
|
94 |
+
if current_chunk:
|
95 |
+
chunks.append(current_chunk.strip())
|
96 |
+
|
97 |
+
return chunks
|
98 |
+
|
99 |
+
|
100 |
+
# load vocoder
|
101 |
+
def load_vocoder(vocoder_name="vocos", is_local=False, local_path="", device=device, hf_cache_dir=None):
|
102 |
+
if vocoder_name == "vocos":
|
103 |
+
# vocoder = Vocos.from_pretrained("charactr/vocos-mel-24khz").to(device)
|
104 |
+
if is_local:
|
105 |
+
print(f"Load vocos from local path {local_path}")
|
106 |
+
config_path = f"{local_path}/config.yaml"
|
107 |
+
model_path = f"{local_path}/pytorch_model.bin"
|
108 |
+
else:
|
109 |
+
print("Download Vocos from huggingface charactr/vocos-mel-24khz")
|
110 |
+
repo_id = "charactr/vocos-mel-24khz"
|
111 |
+
config_path = hf_hub_download(repo_id=repo_id, cache_dir=hf_cache_dir, filename="config.yaml")
|
112 |
+
model_path = hf_hub_download(repo_id=repo_id, cache_dir=hf_cache_dir, filename="pytorch_model.bin")
|
113 |
+
vocoder = Vocos.from_hparams(config_path)
|
114 |
+
state_dict = torch.load(model_path, map_location="cpu", weights_only=True)
|
115 |
+
from vocos.feature_extractors import EncodecFeatures
|
116 |
+
|
117 |
+
if isinstance(vocoder.feature_extractor, EncodecFeatures):
|
118 |
+
encodec_parameters = {
|
119 |
+
"feature_extractor.encodec." + key: value
|
120 |
+
for key, value in vocoder.feature_extractor.encodec.state_dict().items()
|
121 |
+
}
|
122 |
+
state_dict.update(encodec_parameters)
|
123 |
+
vocoder.load_state_dict(state_dict)
|
124 |
+
vocoder = vocoder.eval().to(device)
|
125 |
+
elif vocoder_name == "bigvgan":
|
126 |
+
try:
|
127 |
+
from third_party.BigVGAN import bigvgan
|
128 |
+
except ImportError:
|
129 |
+
print("You need to follow the README to init submodule and change the BigVGAN source code.")
|
130 |
+
if is_local:
|
131 |
+
"""download from https://huggingface.co/nvidia/bigvgan_v2_24khz_100band_256x/tree/main"""
|
132 |
+
vocoder = bigvgan.BigVGAN.from_pretrained(local_path, use_cuda_kernel=False)
|
133 |
+
else:
|
134 |
+
local_path = snapshot_download(repo_id="nvidia/bigvgan_v2_24khz_100band_256x", cache_dir=hf_cache_dir)
|
135 |
+
vocoder = bigvgan.BigVGAN.from_pretrained(local_path, use_cuda_kernel=False)
|
136 |
+
|
137 |
+
vocoder.remove_weight_norm()
|
138 |
+
vocoder = vocoder.eval().to(device)
|
139 |
+
return vocoder
|
140 |
+
|
141 |
+
|
142 |
+
# load asr pipeline
|
143 |
+
|
144 |
+
asr_pipe = None
|
145 |
+
|
146 |
+
|
147 |
+
def initialize_asr_pipeline(device: str = device, dtype=None):
|
148 |
+
if dtype is None:
|
149 |
+
dtype = (
|
150 |
+
torch.float16
|
151 |
+
if "cuda" in device
|
152 |
+
and torch.cuda.get_device_properties(device).major >= 6
|
153 |
+
and not torch.cuda.get_device_name().endswith("[ZLUDA]")
|
154 |
+
else torch.float32
|
155 |
+
)
|
156 |
+
global asr_pipe
|
157 |
+
asr_pipe = pipeline(
|
158 |
+
"automatic-speech-recognition",
|
159 |
+
model="openai/whisper-large-v3-turbo",
|
160 |
+
torch_dtype=dtype,
|
161 |
+
device=device,
|
162 |
+
)
|
163 |
+
|
164 |
+
|
165 |
+
# transcribe
|
166 |
+
|
167 |
+
|
168 |
+
def transcribe(ref_audio, language=None):
|
169 |
+
global asr_pipe
|
170 |
+
if asr_pipe is None:
|
171 |
+
initialize_asr_pipeline(device=device)
|
172 |
+
return asr_pipe(
|
173 |
+
ref_audio,
|
174 |
+
chunk_length_s=30,
|
175 |
+
batch_size=128,
|
176 |
+
generate_kwargs={"task": "transcribe", "language": language} if language else {"task": "transcribe"},
|
177 |
+
return_timestamps=False,
|
178 |
+
)["text"].strip()
|
179 |
+
|
180 |
+
|
181 |
+
# load model checkpoint for inference
|
182 |
+
|
183 |
+
|
184 |
+
def load_checkpoint(model, ckpt_path, device: str, dtype=None, use_ema=True):
|
185 |
+
if dtype is None:
|
186 |
+
dtype = (
|
187 |
+
torch.float16
|
188 |
+
if "cuda" in device
|
189 |
+
and torch.cuda.get_device_properties(device).major >= 6
|
190 |
+
and not torch.cuda.get_device_name().endswith("[ZLUDA]")
|
191 |
+
else torch.float32
|
192 |
+
)
|
193 |
+
model = model.to(dtype)
|
194 |
+
|
195 |
+
ckpt_type = ckpt_path.split(".")[-1]
|
196 |
+
if ckpt_type == "safetensors":
|
197 |
+
from safetensors.torch import load_file
|
198 |
+
|
199 |
+
checkpoint = load_file(ckpt_path, device=device)
|
200 |
+
else:
|
201 |
+
checkpoint = torch.load(ckpt_path, map_location=device, weights_only=True)
|
202 |
+
|
203 |
+
if use_ema:
|
204 |
+
if ckpt_type == "safetensors":
|
205 |
+
checkpoint = {"ema_model_state_dict": checkpoint}
|
206 |
+
checkpoint["model_state_dict"] = {
|
207 |
+
k.replace("ema_model.", ""): v
|
208 |
+
for k, v in checkpoint["ema_model_state_dict"].items()
|
209 |
+
if k not in ["initted", "step"]
|
210 |
+
}
|
211 |
+
|
212 |
+
# patch for backward compatibility, 305e3ea
|
213 |
+
for key in ["mel_spec.mel_stft.mel_scale.fb", "mel_spec.mel_stft.spectrogram.window"]:
|
214 |
+
if key in checkpoint["model_state_dict"]:
|
215 |
+
del checkpoint["model_state_dict"][key]
|
216 |
+
|
217 |
+
model.load_state_dict(checkpoint["model_state_dict"])
|
218 |
+
else:
|
219 |
+
if ckpt_type == "safetensors":
|
220 |
+
checkpoint = {"model_state_dict": checkpoint}
|
221 |
+
model.load_state_dict(checkpoint["model_state_dict"])
|
222 |
+
|
223 |
+
del checkpoint
|
224 |
+
torch.cuda.empty_cache()
|
225 |
+
|
226 |
+
return model.to(device)
|
227 |
+
|
228 |
+
|
229 |
+
# load model for inference
|
230 |
+
|
231 |
+
|
232 |
+
def load_model(
|
233 |
+
model_cls,
|
234 |
+
model_cfg,
|
235 |
+
ckpt_path,
|
236 |
+
mel_spec_type=mel_spec_type,
|
237 |
+
vocab_file="",
|
238 |
+
ode_method=ode_method,
|
239 |
+
use_ema=True,
|
240 |
+
device=device,
|
241 |
+
):
|
242 |
+
if vocab_file == "":
|
243 |
+
vocab_file = str(files("f5_tts").joinpath("infer/examples/vocab.txt"))
|
244 |
+
tokenizer = "custom"
|
245 |
+
|
246 |
+
print("\nvocab : ", vocab_file)
|
247 |
+
print("token : ", tokenizer)
|
248 |
+
print("model : ", ckpt_path, "\n")
|
249 |
+
|
250 |
+
vocab_char_map, vocab_size = get_tokenizer(vocab_file, tokenizer)
|
251 |
+
model = CFM(
|
252 |
+
transformer=model_cls(**model_cfg, text_num_embeds=vocab_size, mel_dim=n_mel_channels),
|
253 |
+
mel_spec_kwargs=dict(
|
254 |
+
n_fft=n_fft,
|
255 |
+
hop_length=hop_length,
|
256 |
+
win_length=win_length,
|
257 |
+
n_mel_channels=n_mel_channels,
|
258 |
+
target_sample_rate=target_sample_rate,
|
259 |
+
mel_spec_type=mel_spec_type,
|
260 |
+
),
|
261 |
+
odeint_kwargs=dict(
|
262 |
+
method=ode_method,
|
263 |
+
),
|
264 |
+
vocab_char_map=vocab_char_map,
|
265 |
+
).to(device)
|
266 |
+
|
267 |
+
dtype = torch.float32 if mel_spec_type == "bigvgan" else None
|
268 |
+
model = load_checkpoint(model, ckpt_path, device, dtype=dtype, use_ema=use_ema)
|
269 |
+
|
270 |
+
return model
|
271 |
+
|
272 |
+
|
273 |
+
def remove_silence_edges(audio, silence_threshold=-42):
|
274 |
+
# Remove silence from the start
|
275 |
+
non_silent_start_idx = silence.detect_leading_silence(audio, silence_threshold=silence_threshold)
|
276 |
+
audio = audio[non_silent_start_idx:]
|
277 |
+
|
278 |
+
# Remove silence from the end
|
279 |
+
non_silent_end_duration = audio.duration_seconds
|
280 |
+
for ms in reversed(audio):
|
281 |
+
if ms.dBFS > silence_threshold:
|
282 |
+
break
|
283 |
+
non_silent_end_duration -= 0.001
|
284 |
+
trimmed_audio = audio[: int(non_silent_end_duration * 1000)]
|
285 |
+
|
286 |
+
return trimmed_audio
|
287 |
+
|
288 |
+
|
289 |
+
# preprocess reference audio and text
|
290 |
+
|
291 |
+
|
292 |
+
def preprocess_ref_audio_text(ref_audio_orig, ref_text, clip_short=True, show_info=print, device=device):
|
293 |
+
show_info("Converting audio...")
|
294 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as f:
|
295 |
+
aseg = AudioSegment.from_file(ref_audio_orig)
|
296 |
+
|
297 |
+
if clip_short:
|
298 |
+
# 1. try to find long silence for clipping
|
299 |
+
non_silent_segs = silence.split_on_silence(
|
300 |
+
aseg, min_silence_len=1000, silence_thresh=-50, keep_silence=1000, seek_step=10
|
301 |
+
)
|
302 |
+
non_silent_wave = AudioSegment.silent(duration=0)
|
303 |
+
for non_silent_seg in non_silent_segs:
|
304 |
+
if len(non_silent_wave) > 6000 and len(non_silent_wave + non_silent_seg) > 12000:
|
305 |
+
show_info("Audio is over 15s, clipping short. (1)")
|
306 |
+
break
|
307 |
+
non_silent_wave += non_silent_seg
|
308 |
+
|
309 |
+
# 2. try to find short silence for clipping if 1. failed
|
310 |
+
if len(non_silent_wave) > 12000:
|
311 |
+
non_silent_segs = silence.split_on_silence(
|
312 |
+
aseg, min_silence_len=100, silence_thresh=-40, keep_silence=1000, seek_step=10
|
313 |
+
)
|
314 |
+
non_silent_wave = AudioSegment.silent(duration=0)
|
315 |
+
for non_silent_seg in non_silent_segs:
|
316 |
+
if len(non_silent_wave) > 6000 and len(non_silent_wave + non_silent_seg) > 12000:
|
317 |
+
show_info("Audio is over 15s, clipping short. (2)")
|
318 |
+
break
|
319 |
+
non_silent_wave += non_silent_seg
|
320 |
+
|
321 |
+
aseg = non_silent_wave
|
322 |
+
|
323 |
+
# 3. if no proper silence found for clipping
|
324 |
+
if len(aseg) > 12000:
|
325 |
+
aseg = aseg[:12000]
|
326 |
+
show_info("Audio is over 15s, clipping short. (3)")
|
327 |
+
|
328 |
+
aseg = remove_silence_edges(aseg) + AudioSegment.silent(duration=50)
|
329 |
+
aseg.export(f.name, format="wav")
|
330 |
+
ref_audio = f.name
|
331 |
+
|
332 |
+
# Compute a hash of the reference audio file
|
333 |
+
with open(ref_audio, "rb") as audio_file:
|
334 |
+
audio_data = audio_file.read()
|
335 |
+
audio_hash = hashlib.md5(audio_data).hexdigest()
|
336 |
+
|
337 |
+
if not ref_text.strip():
|
338 |
+
global _ref_audio_cache
|
339 |
+
if audio_hash in _ref_audio_cache:
|
340 |
+
# Use cached asr transcription
|
341 |
+
show_info("Using cached reference text...")
|
342 |
+
ref_text = _ref_audio_cache[audio_hash]
|
343 |
+
else:
|
344 |
+
show_info("No reference text provided, transcribing reference audio...")
|
345 |
+
ref_text = transcribe(ref_audio)
|
346 |
+
# Cache the transcribed text (not caching custom ref_text, enabling users to do manual tweak)
|
347 |
+
_ref_audio_cache[audio_hash] = ref_text
|
348 |
+
else:
|
349 |
+
show_info("Using custom reference text...")
|
350 |
+
|
351 |
+
# Ensure ref_text ends with a proper sentence-ending punctuation
|
352 |
+
if not ref_text.endswith(". ") and not ref_text.endswith("。"):
|
353 |
+
if ref_text.endswith("."):
|
354 |
+
ref_text += " "
|
355 |
+
else:
|
356 |
+
ref_text += ". "
|
357 |
+
|
358 |
+
print("\nref_text ", ref_text)
|
359 |
+
|
360 |
+
return ref_audio, ref_text
|
361 |
+
|
362 |
+
|
363 |
+
# infer process: chunk text -> infer batches [i.e. infer_batch_process()]
|
364 |
+
|
365 |
+
|
366 |
+
def infer_process(
|
367 |
+
ref_audio,
|
368 |
+
ref_text,
|
369 |
+
gen_text,
|
370 |
+
model_obj,
|
371 |
+
vocoder,
|
372 |
+
mel_spec_type=mel_spec_type,
|
373 |
+
show_info=print,
|
374 |
+
progress=tqdm,
|
375 |
+
target_rms=target_rms,
|
376 |
+
cross_fade_duration=cross_fade_duration,
|
377 |
+
nfe_step=nfe_step,
|
378 |
+
cfg_strength=cfg_strength,
|
379 |
+
sway_sampling_coef=sway_sampling_coef,
|
380 |
+
speed=speed,
|
381 |
+
fix_duration=fix_duration,
|
382 |
+
device=device,
|
383 |
+
):
|
384 |
+
# Split the input text into batches
|
385 |
+
audio, sr = torchaudio.load(ref_audio)
|
386 |
+
max_chars = int(len(ref_text.encode("utf-8")) / (audio.shape[-1] / sr) * (22 - audio.shape[-1] / sr))
|
387 |
+
gen_text_batches = chunk_text(gen_text, max_chars=max_chars)
|
388 |
+
for i, gen_text in enumerate(gen_text_batches):
|
389 |
+
print(f"gen_text {i}", gen_text)
|
390 |
+
print("\n")
|
391 |
+
|
392 |
+
show_info(f"Generating audio in {len(gen_text_batches)} batches...")
|
393 |
+
return next(
|
394 |
+
infer_batch_process(
|
395 |
+
(audio, sr),
|
396 |
+
ref_text,
|
397 |
+
gen_text_batches,
|
398 |
+
model_obj,
|
399 |
+
vocoder,
|
400 |
+
mel_spec_type=mel_spec_type,
|
401 |
+
progress=progress,
|
402 |
+
target_rms=target_rms,
|
403 |
+
cross_fade_duration=cross_fade_duration,
|
404 |
+
nfe_step=nfe_step,
|
405 |
+
cfg_strength=cfg_strength,
|
406 |
+
sway_sampling_coef=sway_sampling_coef,
|
407 |
+
speed=speed,
|
408 |
+
fix_duration=fix_duration,
|
409 |
+
device=device,
|
410 |
+
)
|
411 |
+
)
|
412 |
+
|
413 |
+
|
414 |
+
# infer batches
|
415 |
+
|
416 |
+
|
417 |
+
def infer_batch_process(
|
418 |
+
ref_audio,
|
419 |
+
ref_text,
|
420 |
+
gen_text_batches,
|
421 |
+
model_obj,
|
422 |
+
vocoder,
|
423 |
+
mel_spec_type="vocos",
|
424 |
+
progress=tqdm,
|
425 |
+
target_rms=0.1,
|
426 |
+
cross_fade_duration=0.15,
|
427 |
+
nfe_step=32,
|
428 |
+
cfg_strength=2.0,
|
429 |
+
sway_sampling_coef=-1,
|
430 |
+
speed=1,
|
431 |
+
fix_duration=None,
|
432 |
+
device=None,
|
433 |
+
streaming=False,
|
434 |
+
chunk_size=2048,
|
435 |
+
):
|
436 |
+
audio, sr = ref_audio
|
437 |
+
if audio.shape[0] > 1:
|
438 |
+
audio = torch.mean(audio, dim=0, keepdim=True)
|
439 |
+
|
440 |
+
rms = torch.sqrt(torch.mean(torch.square(audio)))
|
441 |
+
if rms < target_rms:
|
442 |
+
audio = audio * target_rms / rms
|
443 |
+
if sr != target_sample_rate:
|
444 |
+
resampler = torchaudio.transforms.Resample(sr, target_sample_rate)
|
445 |
+
audio = resampler(audio)
|
446 |
+
audio = audio.to(device)
|
447 |
+
|
448 |
+
generated_waves = []
|
449 |
+
spectrograms = []
|
450 |
+
|
451 |
+
if len(ref_text[-1].encode("utf-8")) == 1:
|
452 |
+
ref_text = ref_text + " "
|
453 |
+
|
454 |
+
def process_batch(gen_text):
|
455 |
+
local_speed = speed
|
456 |
+
if len(gen_text.encode("utf-8")) < 10:
|
457 |
+
local_speed = 0.3
|
458 |
+
|
459 |
+
# Prepare the text
|
460 |
+
text_list = [ref_text + gen_text]
|
461 |
+
final_text_list = convert_char_to_pinyin(text_list)
|
462 |
+
|
463 |
+
ref_audio_len = audio.shape[-1] // hop_length
|
464 |
+
if fix_duration is not None:
|
465 |
+
duration = int(fix_duration * target_sample_rate / hop_length)
|
466 |
+
else:
|
467 |
+
# Calculate duration
|
468 |
+
ref_text_len = len(ref_text.encode("utf-8"))
|
469 |
+
gen_text_len = len(gen_text.encode("utf-8"))
|
470 |
+
duration = ref_audio_len + int(ref_audio_len / ref_text_len * gen_text_len / local_speed)
|
471 |
+
|
472 |
+
# inference
|
473 |
+
with torch.inference_mode():
|
474 |
+
generated, _ = model_obj.sample(
|
475 |
+
cond=audio,
|
476 |
+
text=final_text_list,
|
477 |
+
duration=duration,
|
478 |
+
steps=nfe_step,
|
479 |
+
cfg_strength=cfg_strength,
|
480 |
+
sway_sampling_coef=sway_sampling_coef,
|
481 |
+
)
|
482 |
+
del _
|
483 |
+
|
484 |
+
generated = generated.to(torch.float32) # generated mel spectrogram
|
485 |
+
generated = generated[:, ref_audio_len:, :]
|
486 |
+
generated = generated.permute(0, 2, 1)
|
487 |
+
if mel_spec_type == "vocos":
|
488 |
+
generated_wave = vocoder.decode(generated)
|
489 |
+
elif mel_spec_type == "bigvgan":
|
490 |
+
generated_wave = vocoder(generated)
|
491 |
+
if rms < target_rms:
|
492 |
+
generated_wave = generated_wave * rms / target_rms
|
493 |
+
|
494 |
+
# wav -> numpy
|
495 |
+
generated_wave = generated_wave.squeeze().cpu().numpy()
|
496 |
+
|
497 |
+
if streaming:
|
498 |
+
for j in range(0, len(generated_wave), chunk_size):
|
499 |
+
yield generated_wave[j : j + chunk_size], target_sample_rate
|
500 |
+
else:
|
501 |
+
generated_cpu = generated[0].cpu().numpy()
|
502 |
+
del generated
|
503 |
+
yield generated_wave, generated_cpu
|
504 |
+
|
505 |
+
if streaming:
|
506 |
+
for gen_text in progress.tqdm(gen_text_batches) if progress is not None else gen_text_batches:
|
507 |
+
for chunk in process_batch(gen_text):
|
508 |
+
yield chunk
|
509 |
+
else:
|
510 |
+
with ThreadPoolExecutor() as executor:
|
511 |
+
futures = [executor.submit(process_batch, gen_text) for gen_text in gen_text_batches]
|
512 |
+
for future in progress.tqdm(futures) if progress is not None else futures:
|
513 |
+
result = future.result()
|
514 |
+
if result:
|
515 |
+
generated_wave, generated_mel_spec = next(result)
|
516 |
+
generated_waves.append(generated_wave)
|
517 |
+
spectrograms.append(generated_mel_spec)
|
518 |
+
|
519 |
+
if generated_waves:
|
520 |
+
if cross_fade_duration <= 0:
|
521 |
+
# Simply concatenate
|
522 |
+
final_wave = np.concatenate(generated_waves)
|
523 |
+
else:
|
524 |
+
# Combine all generated waves with cross-fading
|
525 |
+
final_wave = generated_waves[0]
|
526 |
+
for i in range(1, len(generated_waves)):
|
527 |
+
prev_wave = final_wave
|
528 |
+
next_wave = generated_waves[i]
|
529 |
+
|
530 |
+
# Calculate cross-fade samples, ensuring it does not exceed wave lengths
|
531 |
+
cross_fade_samples = int(cross_fade_duration * target_sample_rate)
|
532 |
+
cross_fade_samples = min(cross_fade_samples, len(prev_wave), len(next_wave))
|
533 |
+
|
534 |
+
if cross_fade_samples <= 0:
|
535 |
+
# No overlap possible, concatenate
|
536 |
+
final_wave = np.concatenate([prev_wave, next_wave])
|
537 |
+
continue
|
538 |
+
|
539 |
+
# Overlapping parts
|
540 |
+
prev_overlap = prev_wave[-cross_fade_samples:]
|
541 |
+
next_overlap = next_wave[:cross_fade_samples]
|
542 |
+
|
543 |
+
# Fade out and fade in
|
544 |
+
fade_out = np.linspace(1, 0, cross_fade_samples)
|
545 |
+
fade_in = np.linspace(0, 1, cross_fade_samples)
|
546 |
+
|
547 |
+
# Cross-faded overlap
|
548 |
+
cross_faded_overlap = prev_overlap * fade_out + next_overlap * fade_in
|
549 |
+
|
550 |
+
# Combine
|
551 |
+
new_wave = np.concatenate(
|
552 |
+
[prev_wave[:-cross_fade_samples], cross_faded_overlap, next_wave[cross_fade_samples:]]
|
553 |
+
)
|
554 |
+
|
555 |
+
final_wave = new_wave
|
556 |
+
|
557 |
+
# Create a combined spectrogram
|
558 |
+
combined_spectrogram = np.concatenate(spectrograms, axis=1)
|
559 |
+
|
560 |
+
yield final_wave, target_sample_rate, combined_spectrogram
|
561 |
+
|
562 |
+
else:
|
563 |
+
yield None, target_sample_rate, None
|
564 |
+
|
565 |
+
|
566 |
+
# remove silence from generated wav
|
567 |
+
|
568 |
+
|
569 |
+
def remove_silence_for_generated_wav(filename):
|
570 |
+
aseg = AudioSegment.from_file(filename)
|
571 |
+
non_silent_segs = silence.split_on_silence(
|
572 |
+
aseg, min_silence_len=1000, silence_thresh=-50, keep_silence=500, seek_step=10
|
573 |
+
)
|
574 |
+
non_silent_wave = AudioSegment.silent(duration=0)
|
575 |
+
for non_silent_seg in non_silent_segs:
|
576 |
+
non_silent_wave += non_silent_seg
|
577 |
+
aseg = non_silent_wave
|
578 |
+
aseg.export(filename, format="wav")
|
579 |
+
|
580 |
+
|
581 |
+
# save spectrogram
|
582 |
+
|
583 |
+
|
584 |
+
def save_spectrogram(spectrogram, path):
|
585 |
+
plt.figure(figsize=(12, 4))
|
586 |
+
plt.imshow(spectrogram, origin="lower", aspect="auto")
|
587 |
+
plt.colorbar()
|
588 |
+
plt.savefig(path)
|
589 |
+
plt.close()
|
src/f5_tts/model/__init__.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from f5_tts.model.cfm import CFM
|
2 |
+
|
3 |
+
from f5_tts.model.backbones.unett import UNetT
|
4 |
+
from f5_tts.model.backbones.dit import DiT
|
5 |
+
from f5_tts.model.backbones.mmdit import MMDiT
|
6 |
+
|
7 |
+
from f5_tts.model.trainer import Trainer
|
8 |
+
|
9 |
+
|
10 |
+
__all__ = ["CFM", "UNetT", "DiT", "MMDiT", "Trainer"]
|
src/f5_tts/model/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (462 Bytes). View file
|
|
src/f5_tts/model/__pycache__/cfm.cpython-310.pyc
ADDED
Binary file (5.49 kB). View file
|
|
src/f5_tts/model/__pycache__/dataset.cpython-310.pyc
ADDED
Binary file (8.83 kB). View file
|
|
src/f5_tts/model/__pycache__/modules.cpython-310.pyc
ADDED
Binary file (18.3 kB). View file
|
|
src/f5_tts/model/__pycache__/trainer.cpython-310.pyc
ADDED
Binary file (11.6 kB). View file
|
|
src/f5_tts/model/__pycache__/utils.cpython-310.pyc
ADDED
Binary file (6.27 kB). View file
|
|
src/f5_tts/model/backbones/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Backbones quick introduction
|
2 |
+
|
3 |
+
|
4 |
+
### unett.py
|
5 |
+
- flat unet transformer
|
6 |
+
- structure same as in e2-tts & voicebox paper except using rotary pos emb
|
7 |
+
- possible abs pos emb & convnextv2 blocks for embedded text before concat
|
8 |
+
|
9 |
+
### dit.py
|
10 |
+
- adaln-zero dit
|
11 |
+
- embedded timestep as condition
|
12 |
+
- concatted noised_input + masked_cond + embedded_text, linear proj in
|
13 |
+
- possible abs pos emb & convnextv2 blocks for embedded text before concat
|
14 |
+
- possible long skip connection (first layer to last layer)
|
15 |
+
|
16 |
+
### mmdit.py
|
17 |
+
- stable diffusion 3 block structure
|
18 |
+
- timestep as condition
|
19 |
+
- left stream: text embedded and applied a abs pos emb
|
20 |
+
- right stream: masked_cond & noised_input concatted and with same conv pos emb as unett
|
src/f5_tts/model/backbones/__pycache__/dit.cpython-310.pyc
ADDED
Binary file (6.02 kB). View file
|
|