Skip to content

Commit

Permalink
Refactor config (#185)
Browse files Browse the repository at this point in the history
* Refactor config

* Update api keys

* Create config

* Update readme

* Update device

* Add require_api_key to check

* Fix issue where saving configuration could result in file being cleared on failure

* Roll Back tty_type Variable to model_type

* fix: filter unsupported languages in get_lang_list

* Update: Support for speaker parameter in Bert-VITS2

* Update: Changed input type of 'port' to text

* Fix: Remove API key

* Fix: Saving tts_models

* Fix: speaker is null

* Update: Add requests_toolbelt to requirements.txt

* Update: bert-vits2 api test

* Fix: null string

* Fix: torch_data_type

* Fix: espeak_library

* Fix: stream_bert_vits2_infer lang error
  • Loading branch information
Artrajz authored Jan 2, 2025
1 parent 58be4fd commit b16654f
Show file tree
Hide file tree
Showing 49 changed files with 1,040 additions and 793 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Starting from version 0.6.6, it is default behavior to automatically load all mo

After the initial startup, a config.yaml configuration file will be generated. You need to change `tts_config.auto_load` to `false` in order to enable manual loading mode.

You can modify the `tts_config.models` in the config.yaml or make modifications in the admin panel in the browser.
You can modify the `tts_model_config.tts_modes` in the config.yaml or make modifications in the admin panel in the browser.

**Note: After version 0.6.6, the model loading path has been modified. Please follow the steps below to configure the model path again!**

Expand All @@ -163,9 +163,9 @@ tts_config:
auto_load: false
models:
- config_path: model1/config.json
model_path: model1/G_1000.pth
vits_path: model1/G_1000.pth
- config_path: model2/config.json
model_path: model2/G_1000.pth
vits_path: model2/G_1000.pth
# GPT-SoVITS
- sovits_path: gpt_sovits1/model1_e8_s11536.pth
gpt_path: gpt_sovits1/model1-e15.ckpt
Expand All @@ -182,7 +182,7 @@ tts_config:
auto_load: false
models:
- config_path: D://model3/config.json
model_path: D://model3/G_1000.pth
vits_path: D://model3/G_1000.pth
```

- models_path: This is the models folder relative to the data directory, with the default value being "models". When auto_load is set to true, all models in the models_path directory will be loaded.
Expand Down Expand Up @@ -367,7 +367,7 @@ Please note that for the Chinese extra version, the version should be changed to

## API KEY

Set `api_key_enabled: true` in `config.yaml` to enable API key authentication. The API key is `api_key: api-key`.
Set `api_key_enabled: true` in `config.yaml` to enable API key authentication.
After enabling it, you need to add the `api_key` parameter in GET requests and add the `X-API-KEY` parameter in the header for POST requests.

# Parameter
Expand Down
10 changes: 5 additions & 5 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ v0.6.6版本之后默认会**自动加载**`data/models`文件夹下的所有模

首次启动之后会生成一个config.yaml配置文件,需要将`tts_config.auto_load`改为`false`以启用手动加载模式。

可以修改配置文件中的`tts_config.models`或者在浏览器中进入管理员后台进行修改。
可以修改配置文件中的`tts_model_config.tts_modes`或者在浏览器中进入管理员后台进行修改。

**注意:v0.6.6版本之后已修改模型读取路径,请重新按照以下步骤配置模型路径!**

Expand All @@ -166,9 +166,9 @@ tts_config:
auto_load: false
models:
- config_path: model1/config.json
model_path: model1/G_1000.pth
vits_path: model1/G_1000.pth
- config_path: model2/config.json
model_path: model2/G_1000.pth
vits_path: model2/G_1000.pth
# GPT-SoVITS则为
- sovits_path: gpt_sovits1/model1_e8_s11536.pth
gpt_path: gpt_sovits1/model1-e15.ckpt
Expand All @@ -186,7 +186,7 @@ tts_config:
auto_load: false
models:
- config_path: D://model3/config.json
model_path: D://model3/G_1000.pth
vits_path: D://model3/G_1000.pth
```
- models_path:是相对于data目录下的模型文件夹,默认为models,auto_load为true时将会加载models_path目录下的所有模型。
Expand Down Expand Up @@ -379,7 +379,7 @@ url中的IP可在API启动后找到,一般使用192.168开头的局域网IP。

## API KEY

在config.yaml中设置`api_key_enabled: true`以启用,api key填写:`api_key: api-key`
在config.yaml中设置`api_key_enabled: true`以启用。

启用后,GET请求中使用需要增加参数api_key,POST请求中使用需要在header中添加参数`X-API-KEY`。

Expand Down
8 changes: 5 additions & 3 deletions api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,12 @@ def vits_json(text, id=0, format="wav", lang="auto", length=1, noise=0.667, nois


# Bert_vits2
def voice_bert_vits2(text, id=0, format="wav", lang="auto", length=1, noise=0.667, noisew=0.8, segment_size=50,
sdp_ratio=0.2, save_audio=True, save_path=None):
def voice_bert_vits2(text, id=0, speaker=None, format="wav", lang="auto", length=1, noise=0.667, noisew=0.8,
segment_size=50, sdp_ratio=0.2, save_audio=True, save_path=None):
fields = {
"text": text,
"id": str(id),
"speaker": str(speaker),
"format": format,
"lang": lang,
"length": str(length),
Expand Down Expand Up @@ -568,8 +569,9 @@ def test_interface(text):

# os.system(path)

# text = "你好“你的修炼速度有些出乎我的意料”"
# text = "你好“这是独处的妙处,我且受用这无边的荷香月色好了。”"
# path = voice_reading_json(text=text, in_model_type="GPT-SOVITS", preset="wz", in_id=2, nr_model_type="BERT-VITS2",
# nr_id=0)

# path = voice_bert_vits2("这是独处的妙处,我且受用这无边的荷香月色好了。", id=0, lang="zh", save_path=cache_path)
# os.system(path)
11 changes: 6 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logger
import logging
import os.path

Expand All @@ -15,7 +16,7 @@
from tts_app.auth.views import auth
from tts_app.admin.views import admin

from contants import config
from config import config, BASE_DIR

app = Flask(__name__, template_folder=os.path.join(os.path.dirname(__file__), 'tts_app', 'templates'),
static_folder=os.path.join(os.path.dirname(__file__), 'tts_app', 'static'))
Expand Down Expand Up @@ -63,16 +64,16 @@ def create_folders(paths):
os.makedirs(path, exist_ok=True)


create_folders([os.path.join(config.abs_path, config.system.upload_folder),
os.path.join(config.abs_path, config.system.cache_path), ])
create_folders([os.path.join(BASE_DIR, config.system.upload_folder),
os.path.join(BASE_DIR, config.system.cache_path), ])


# regular cleaning
@scheduler.task('interval', id='clean_task', seconds=config.system.clean_interval_seconds,
misfire_grace_time=900)
def clean_task():
clean_folder(os.path.join(config.abs_path, config.system.upload_folder))
clean_folder(os.path.join(config.abs_path, config.system.cache_path))
clean_folder(os.path.join(BASE_DIR, config.system.upload_folder))
clean_folder(os.path.join(BASE_DIR, config.system.cache_path))


if __name__ == '__main__':
Expand Down
8 changes: 4 additions & 4 deletions bert_vits2/bert_vits2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
from bert_vits2.text import *
from bert_vits2.text.cleaner import clean_text
from bert_vits2.utils import process_legacy_versions
from contants import config
from config import config
from utils import get_hparams_from_file
from utils.sentence import split_languages


class Bert_VITS2:
def __init__(self, model_path, config, device=torch.device("cpu"), **kwargs):
self.model_path = model_path
def __init__(self, vits_path, config, device=torch.device("cpu"), **kwargs):
self.vits_path = vits_path
self.hps_ms = get_hparams_from_file(config) if isinstance(config, str) else config
self.n_speakers = getattr(self.hps_ms.data, 'n_speakers', 0)
self.speakers = [item[0] for item in
Expand Down Expand Up @@ -220,7 +220,7 @@ def load_model(self, model_handler):
zh_bert_extra=self.zh_bert_extra,
**self.hps_ms.model).to(self.device)
_ = self.net_g.eval()
bert_vits2_utils.load_checkpoint(self.model_path, self.net_g, None, skip_optimizer=True, version=self.version)
bert_vits2_utils.load_checkpoint(self.vits_path, self.net_g, None, skip_optimizer=True, version=self.version)

def get_speakers(self):
return self.speakers
Expand Down
2 changes: 1 addition & 1 deletion bert_vits2/get_emo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Wav2Vec2PreTrainedModel,
)

from contants import config
from config import config


class RegressionHead(nn.Module):
Expand Down
2 changes: 1 addition & 1 deletion bert_vits2/text/chinese_bert.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch

from contants import config
from config import config


def get_bert_feature(text, word2ph, tokenizer, model, device=config.system.device, style_text=None, style_weight=0.7,
Expand Down
2 changes: 1 addition & 1 deletion bert_vits2/text/chinese_bert_extra.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch

from contants import config
from config import config


def get_bert_feature(text, word2ph, tokenizer, model, device=config.system.device, style_text=None, style_weight=0.7,
Expand Down
2 changes: 1 addition & 1 deletion bert_vits2/text/english_bert_mock.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch

from contants import config
from config import config


def get_bert_feature(text, word2ph, tokenizer, model, device=config.system.device, style_text=None, style_weight=0.7,
Expand Down
2 changes: 1 addition & 1 deletion bert_vits2/text/english_bert_mock_v200.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch

from contants import config
from config import config


def get_bert_feature(text, word2ph, tokenizer, model, device=config.system.device, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion bert_vits2/text/japanese_bert.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch

from contants import config
from config import config
from bert_vits2.text.japanese import text2sep_kata

LOCAL_PATH = "./bert/deberta-v2-large-japanese-char-wwm"
Expand Down
2 changes: 1 addition & 1 deletion bert_vits2/text/japanese_bert_extra.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch

from contants import config
from config import config
from bert_vits2.text.japanese import text2sep_kata


Expand Down
2 changes: 1 addition & 1 deletion bert_vits2/text/japanese_bert_v111.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch

from contants import config
from config import config


def get_bert_feature(text, word2ph, tokenizer, model, device=config.system.device, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion bert_vits2/text/japanese_bert_v200.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch

from contants import config
from config import config
from bert_vits2.text.japanese_v200 import text2sep_kata


Expand Down
2 changes: 1 addition & 1 deletion bert_vits2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import torch

from contants import config
from config import config

MATPLOTLIB_FLAG = False

Expand Down
Loading

0 comments on commit b16654f

Please sign in to comment.