From 1fc82960d023b5c882eb12b26b0406e17c2ad303 Mon Sep 17 00:00:00 2001 From: litagin02 Date: Wed, 27 Dec 2023 19:29:34 +0900 Subject: [PATCH] Update, maybe v1.0 --- README.md | 29 +++++++++++++++-------- app.py | 23 ++++++++++++------ initialize.py | 6 ++--- models.py | 5 +--- modules.py | 5 +--- scripts/Install-Style-Bert-VITS2.bat | 14 ++++------- scripts/Update-Style-Bert-VITS2.bat | 35 ++++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 37 deletions(-) create mode 100644 scripts/Update-Style-Bert-VITS2.bat diff --git a/README.md b/README.md index baca60b..c6526e2 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,14 @@ Bert-VITS2 with more controllable voice styles. This repository is based on [Bert-VITS2](https://github.com/fishaudio/Bert-VITS2) v2.1, so many thanks to the original author! -## これは何? +**概要** + - [Bert-VITS2](https://github.com/fishaudio/Bert-VITS2)のv2.1を元に、正確に感情や発話スタイルを強弱混みで指定して音声を生成することができるようにしたものです。 -- [EasyBertVits2](https://github.com/Zuntan03/EasyBertVits2/)のように、GitやPythonがない人でも簡単にインストールできるやつもあります(まだ少し未検証)。 +- GitやPythonがない人でも(WindowsユーザーでNVIDIAのグラボがあるなら)簡単にインストールでき、学習もできます (多くを[EasyBertVits2](https://github.com/Zuntan03/EasyBertVits2/)からお借りしました)。 ## 使い方 -詳しくは[こちら](docs/tutorial.md)を参照してください。 + ### インストール @@ -18,11 +19,15 @@ Windows環境で最近のNVIDIA製グラボがあることを前提にしてい #### GitやPythonに馴染みが無い方 -[これ](https://github.com/litagin02/Style-Bert-VITS2/raw/master/scripts/Install-Style-Bert-VITS2.bat)をダウンロードして、スペースを含まない英数字のみのパスで実行してください(まだ動作未確認なので後でちゃんとチェックします)。 +1. [このzipファイル](TODO)をダウンロードして展開し、中にある`Install-Style-Bert-VITS2.bat`をダブルクリックします。 +2. 待つと自動で必要な環境がインストールされます。 +3. その後、自動的に音声合成するためのWebUIが起動したらインストール成功です。デフォルトのモデルがダウンロードされるので、そのまま遊ぶことができます。 + +またアップデートをしたい場合は、`Update-Style-Bert-VITS2.bat`をダブルクリックしてください。 #### GitやPython使える人 -Python 3.10で動作確認しています。 +Windowsの通常環境のPython 3.10で動作確認しています。 ```bash git clone https://github.com/litagin02/Style-Bert-VITS2.git @@ -39,7 +44,7 @@ python initialize.py `App.bat`をダブルクリックするとWebUIが起動します。 -ディレクトリ構造: +合成に必要なモデルファイルたちは以下のように配置します。 ``` model_assets ├── your_model @@ -67,11 +72,17 @@ model_assets - `Dataset.bat`をダブルクリックすると、音声ファイルからデータセットを作るためのWebUIが起動します。音声ファイルのみからでもこれを使って学習できます。 -## Bert-VITS2 v2.1と違う点 +## Bert-VITS2 v2.1との関係 + +基本的にはBert-VITS2 v2.1のモデル構造を少し改造しただけです。[事前学習モデル](https://huggingface.co/litagin/style_bert_vits2_jvnv)も、実質Bert-VITS2 v2.1と同じものを使用しています(不要な重みを削ってsafetensorsに変換したもの)。 + +具体的には以下の点が異なります。 + +- [EasyBertVits2](https://github.com/Zuntan03/EasyBertVits2)のように、PythonやGitを知らない人でも簡単に使える。 - 感情埋め込みのモデルを変更([wav2vec2-large-robust-12-ft-emotion-msp-dim](https://huggingface.co/audeering/wav2vec2-large-robust-12-ft-emotion-msp-dim)から[wespeaker-voxceleb-resnet34-LM](https://huggingface.co/pyannote/wespeaker-voxceleb-resnet34-LM)へ、感情埋め込みというより正確には話者埋め込みが近い) - 埋め込みもベクトル量子化を取り払い、単なる全結合層に。 - スタイルベクトルファイル`style_vectors.npy`を作ることで、そのスタイルを使って効果の強さも連続的に指定しつつ音声を生成することができる。 -- 各種WebUIを作成(事前準備・学習・スタイルベクトルの生成・音声合成) +- 各種WebUIを作成 - bf16での学習のサポート - safetensors形式のサポート、デフォルトでsafetensorsを使用するように - その他軽微なbugfixやリファクタリング @@ -81,8 +92,6 @@ model_assets - [ ] 本家のver 2.1, 2.2, 2.3モデルの推論対応?(ver 2.1以外は明らかにめんどいのでたぶんやらない) - [ ] `server_fastapi.py`の対応、とくにAPIで使えるようになると嬉しい人が増えるのかもしれない -## Bert-VITS2 v2.1と同じ点 -- [事前学習モデル](https://huggingface.co/litagin/style_bert_vits2_jvnv)は、実質Bert-VITS2 v2.1と同じものを使用しています(不要な重みを削ってsafetensorsに変換したもの)。 ## 実験したいこと - [ ] 複数話者での学習の実験(原理的にはできるはず、スタイルがどう効くかが未知) diff --git a/app.py b/app.py index cf0ffa2..74d00fa 100644 --- a/app.py +++ b/app.py @@ -1,17 +1,18 @@ import argparse +import datetime import os import sys +import warnings import gradio as gr import numpy as np import torch -import warnings from gradio.processing_utils import convert_to_16_bit_wav import utils +from config import config from infer import get_net_g, infer from tools.log import logger -from config import config is_hf_spaces = os.getenv("SYSTEM") == "spaces" limit = 100 @@ -226,6 +227,8 @@ def tts_fn( assert model_holder.current_model is not None + start_time = datetime.datetime.now() + sr, audio = model_holder.current_model.infer( text=text, language=language, @@ -242,7 +245,10 @@ def tts_fn( style=emotion, emotion_weight=emotion_weight, ) - return "Success", (sr, audio) + + end_time = datetime.datetime.now() + duration = (end_time - start_time).total_seconds() + return f"Success, time: {duration} seconds.", (sr, audio) initial_text = "こんにちは、初めまして。あなたの名前はなんていうの?" @@ -345,7 +351,8 @@ TODO: 現在のところはspeaker_id = 0に固定しており複数話者の合 style_md = """ - プリセットまたは音声ファイルから読み上げの声音・感情・スタイルのようなものを制御できます。 - デフォルトのNeutralでも、十分に読み上げる文に応じた感情で感情豊かに読み上げられます。このスタイル制御は、それを重み付きで上書きするような感じです。 -- 重みを大きくしすぎると発音が変になったり声にならなかったりと崩壊することがあります。 +- 強さを大きくしすぎると発音が変になったり声にならなかったりと崩壊することがあります。 +- どのくらいに強さがいいかはモデルやスタイルによって異なるようです。 - 音声ファイルを入力する場合は、学習データと似た声音の話者(特に同じ性別)でないとよい効果が出ないかもしれません。 """ @@ -415,7 +422,7 @@ if __name__ == "__main__": line_split = gr.Checkbox(label="改行で分けて生成", value=True) split_interval = gr.Slider( - minimum=0.1, + minimum=0.0, maximum=2, value=0.5, step=0.1, @@ -464,11 +471,13 @@ if __name__ == "__main__": value="プリセットから選ぶ", ) style = gr.Dropdown( - label="スタイル(Neutralが平均スタイル)", choices=["モデルをロードしてください"], value=0 + label="スタイル(Neutralが平均スタイル)", + choices=["モデルをロードしてください"], + value="モデルをロードしてください", ) style_weight = gr.Slider( minimum=0, - maximum=20, + maximum=50, value=1, step=0.1, label="スタイルの強さ", diff --git a/initialize.py b/initialize.py index 25f4cca..8cac785 100644 --- a/initialize.py +++ b/initialize.py @@ -47,9 +47,9 @@ def download_jvnv_models(): "jvnv-M1/config.json", "jvnv-M1/jvnv-M1.safetensors", "jvnv-M1/style_vectors.npy", - # "jvnv-M2/config.json", - # "jvnv-M2/jvnv-M2.safetensors", - # "jvnv-M2/style_vectors.npy", + "jvnv-M2/config.json", + "jvnv-M2/jvnv-M2.safetensors", + "jvnv-M2/style_vectors.npy", ] for file in files: if not Path(f"model_assets/{file}").exists(): diff --git a/models.py b/models.py index 9bccc82..eb706fd 100644 --- a/models.py +++ b/models.py @@ -5,6 +5,7 @@ import torch from torch import nn from torch.nn import Conv1d, Conv2d, ConvTranspose1d from torch.nn import functional as F +from torch.nn.utils import remove_weight_norm, spectral_norm, weight_norm import attentions import commons @@ -13,10 +14,6 @@ import monotonic_align from commons import get_padding, init_weights from text import num_languages, num_tones, symbols -with warnings.catch_warnings(): - warnings.simplefilter("ignore") - from torch.nn.utils import remove_weight_norm, spectral_norm, weight_norm - class DurationDiscriminator(nn.Module): # vits2 def __init__( diff --git a/modules.py b/modules.py index d21fed6..86b93b5 100644 --- a/modules.py +++ b/modules.py @@ -5,16 +5,13 @@ import torch from torch import nn from torch.nn import Conv1d from torch.nn import functional as F +from torch.nn.utils import remove_weight_norm, weight_norm import commons from attentions import Encoder from commons import get_padding, init_weights from transforms import piecewise_rational_quadratic_transform -with warnings.catch_warnings(): - warnings.simplefilter("ignore") - from torch.nn.utils import remove_weight_norm, weight_norm - LRELU_SLOPE = 0.1 diff --git a/scripts/Install-Style-Bert-VITS2.bat b/scripts/Install-Style-Bert-VITS2.bat index 2ffc715..1b18349 100644 --- a/scripts/Install-Style-Bert-VITS2.bat +++ b/scripts/Install-Style-Bert-VITS2.bat @@ -1,14 +1,8 @@ chcp 65001 > NUL -@REM ↑文字コードのおまじないらしい +@echo off @REM https://github.com/Zuntan03/EasyBertVits2 より引用・改変 - -@REM 2. Style-Bert-VITS2.zip を解凍(名前がBert-VITS2-masterになる) -@REM 3. Style-Bert-VITS2-master を Style-Bert-VITS2 にリネーム - - -@echo off pushd %~dp0 set PS_CMD=PowerShell -Version 5.1 -ExecutionPolicy Bypass @@ -30,11 +24,13 @@ if %errorlevel% neq 0 ( pause & popd & exit /b %errorlevel% ) %PS_CMD% Expand-Archive -Path Style-Bert-VITS2.zip -DestinationPath . -Force if %errorlevel% neq 0 ( pause & popd & exit /b %errorlevel% ) -@REM 元のzipを削除しStyle-Bert-VITS2-master を Style-Bert-VITS2 にリネーム +@REM 元のzipを削除 del Style-Bert-VITS2.zip if %errorlevel% neq 0 ( pause & popd & exit /b %errorlevel% ) -ren Style-Bert-VITS2-master Style-Bert-VITS2 +@REM Bert-VITS2-masterの中身をStyle-Bert-VITS2に上書き移動 +xcopy /QSY .\Style-Bert-VITS2-master .\Style-Bert-VITS2 +rmdir /s /q Style-Bert-VITS2-master @REM Pythonと仮想環境のセットアップを呼び出す(仮想環境が有効化されて戻ってくる) call Style-Bert-VITS2\scripts\Setup-Python.bat ..\..\lib\python ..\venv diff --git a/scripts/Update-Style-Bert-VITS2.bat b/scripts/Update-Style-Bert-VITS2.bat new file mode 100644 index 0000000..2fe555e --- /dev/null +++ b/scripts/Update-Style-Bert-VITS2.bat @@ -0,0 +1,35 @@ +chcp 65001 > NUL +@echo off + +pushd %~dp0 +set PS_CMD=PowerShell -Version 5.1 -ExecutionPolicy Bypass + +set CURL_CMD=C:\Windows\System32\curl.exe +if not exist %CURL_CMD% ( + echo [ERROR] %CURL_CMD% が見つかりません。 + pause & popd & exit /b 1 +) + +@REM Style-Bert-VITS2.zip をGitHubのmasterの最新のものをダウンロード +%CURL_CMD% -Lo Style-Bert-VITS2.zip^ + https://github.com/litagin02/Style-Bert-VITS2/archive/refs/heads/master.zip +if %errorlevel% neq 0 ( pause & popd & exit /b %errorlevel% ) + +@REM Style-Bert-VITS2.zip を解凍(フォルダ名前がBert-VITS2-masterになる) +%PS_CMD% Expand-Archive -Path Style-Bert-VITS2.zip -DestinationPath . -Force +if %errorlevel% neq 0 ( pause & popd & exit /b %errorlevel% ) + +@REM 元のzipを削除 +del Style-Bert-VITS2.zip +if %errorlevel% neq 0 ( pause & popd & exit /b %errorlevel% ) + +@REM Bert-VITS2-masterの中身をStyle-Bert-VITS2に上書き移動 +xcopy /QSY .\Style-Bert-VITS2-master .\Style-Bert-VITS2 +rmdir /s /q Style-Bert-VITS2-master +if %errorlevel% neq 0 ( pause & popd & exit /b %errorlevel% ) + +echo Style-Bert-VITS2のアップデートが完了しました。 + +pause + +popd \ No newline at end of file