Update docs

This commit is contained in:
litagin02
2023-12-31 07:45:40 +09:00
parent 4faef57dd2
commit 9893b899d7
5 changed files with 37 additions and 61 deletions

View File

@@ -17,7 +17,8 @@ This repository is based on [Bert-VITS2](https://github.com/fishaudio/Bert-VITS2
**概要** **概要**
- [Bert-VITS2](https://github.com/fishaudio/Bert-VITS2)のv2.1を元に、正確に感情や発話スタイルを強弱混みで指定して音声を生成することができるようにしたものです。 - [Bert-VITS2](https://github.com/fishaudio/Bert-VITS2)のv2.1を元に、正確に感情や発話スタイルを強弱混みで指定して音声を生成することができるようにしたものです。
- GitやPythonがない人でもWindowsユーザーでNVIDIAのグラボがあるなら)簡単にインストールでき、学習もできます (多くを[EasyBertVits2](https://github.com/Zuntan03/EasyBertVits2/)からお借りしました)。 - GitやPythonがない人でもWindowsユーザーなら簡単にインストールでき、学習もできます (多くを[EasyBertVits2](https://github.com/Zuntan03/EasyBertVits2/)からお借りしました)。
- 音声合成のみに使う場合は、グラボがなくてもCPUで動作します。
## 使い方 ## 使い方
@@ -25,11 +26,13 @@ This repository is based on [Bert-VITS2](https://github.com/fishaudio/Bert-VITS2
### インストール ### インストール
Windows環境で最近のNVIDIA製グラボがあることを前提にしています。
#### GitやPythonに馴染みが無い方 #### GitやPythonに馴染みが無い方
1. [このzipファイル](https://github.com/litagin02/Style-Bert-VITS2/releases/download/1.0/Style-Bert-VITS2.zip)をダウンロードして展開し、中にある`Install-Style-Bert-VITS2.bat`をダブルクリックします。 Windowsを前提としています。
1. [このzipファイル](https://github.com/litagin02/Style-Bert-VITS2/releases/download/1.2/Style-Bert-VITS2.zip)をダウンロードして展開します。
- グラボがある方は、`Install-Style-Bert-VITS2.bat`をダブルクリックします。
- グラボがない方は、`Install-Style-Bert-VITS2-CPU.bat`をダブルクリックします。
2. 待つと自動で必要な環境がインストールされます。 2. 待つと自動で必要な環境がインストールされます。
3. その後、自動的に音声合成するためのWebUIが起動したらインストール成功です。デフォルトのモデルがダウンロードされるているので、そのまま遊ぶことができます。 3. その後、自動的に音声合成するためのWebUIが起動したらインストール成功です。デフォルトのモデルがダウンロードされるているので、そのまま遊ぶことができます。
@@ -37,14 +40,14 @@ Windows環境で最近のNVIDIA製グラボがあることを前提にしてい
#### GitやPython使える人 #### GitやPython使える人
Windowsの通常環境のPython 3.10で動作確認しています。 Windowsの通常環境のPython 3.10で動作確認していますが、他の環境でも動くと思います
```bash ```bash
git clone https://github.com/litagin02/Style-Bert-VITS2.git git clone https://github.com/litagin02/Style-Bert-VITS2.git
cd Style-Bert-VITS2 cd Style-Bert-VITS2
python -m venv venv python -m venv venv
venv\Scripts\activate venv\Scripts\activate
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install -r requirements.txt pip install -r requirements.txt
python initialize.py # 必要なモデルとデフォルトTTSモデルをダウンロード python initialize.py # 必要なモデルとデフォルトTTSモデルをダウンロード
``` ```
@@ -66,7 +69,9 @@ model_assets
└── another_model └── another_model
├── ... ├── ...
``` ```
このように、推論には`config.json``*.safetensors``style_vectors.npy`が必要です。学習の段階で前者の2つは自動で作成されますが、`style_vectors.npy`は自分で作成する必要があります: 下の「スタイルの生成」を参照してください。 このように、推論には`config.json``*.safetensors``style_vectors.npy`が必要です。
`style_vectors.npy`はスタイルを制御するために必要なファイルで、学習の時にデフォルトで平均スタイル「Neutral」が生成されます。
複数スタイルを使いたい方は、下の「スタイルの生成」を参照してください。
### 学習 ### 学習
@@ -74,8 +79,8 @@ model_assets
### スタイルの生成 ### スタイルの生成
- デフォルトスタイル「Neutral」以外のスタイルを使いたい人向けです。
- `Style.bat`をダブルクリックか`python webui_style_vectors.py`するとWebUIが起動します。 - `Style.bat`をダブルクリックか`python webui_style_vectors.py`するとWebUIが起動します。
- この手順は、音声ファイルたちからスタイルを作るのに必要な手順です。
- 学習とは独立しているので、学習中でもできるし、学習が終わっても何度もやりなおせます。 - 学習とは独立しているので、学習中でもできるし、学習が終わっても何度もやりなおせます。
- スタイルについての詳細は[clustering.ipynb](clustering.ipynb)を参照してください。 - スタイルについての詳細は[clustering.ipynb](clustering.ipynb)を参照してください。

View File

@@ -58,8 +58,7 @@
" embs.append(np.expand_dims(xvec, axis=0))\n", " embs.append(np.expand_dims(xvec, axis=0))\n",
" names.append(file)\n", " names.append(file)\n",
"\n", "\n",
"x = np.concatenate(embs, axis=0)\n", "x = np.concatenate(embs, axis=0)"
"x = np.squeeze(x)"
] ]
}, },
{ {

View File

@@ -66,5 +66,5 @@
"use_spectral_norm": false, "use_spectral_norm": false,
"gin_channels": 256 "gin_channels": 256
}, },
"version": "1.0" "version": "1.2"
} }

View File

@@ -1,8 +1,15 @@
# Changelog # Changelog
## v1.1 ## v1.2 (2023-12-30)
- グラボがないCPUユーザーでも音声合成機能は使えるように
- Google colabでの学習をサポート、ートブックを追加
- 前処理のリサンプリング時に音声ファイルの開始・終了部分の無音を削除するオプションを追加(デフォルトでオン)
- 学習時に自動的にデフォルトスタイル Neutral を生成するように。これで学習したらそのまま音声合成を試せます。
## v1.1 (2023-12-29)
- TrainとDatasetのWebUIの改良・調整一括事前処理ボタン等 - TrainとDatasetのWebUIの改良・調整一括事前処理ボタン等
- 前処理のリサンプリング時に音量を正規化するオプションを追加(デフォルトでオン) - 前処理のリサンプリング時に音量を正規化するオプションを追加(デフォルトでオン)
## v1.0 ## v1.0 (2023-12-27)
- 初版 - 初版

View File

@@ -67,7 +67,7 @@ def do_clustering(n_clusters=4, method="KMeans"):
def closest_wav_files(): def closest_wav_files():
# centroidを強調した点からの距離が最も近い音声を選ぶ # centroidを強調した点からの距離が最も近い音声を選ぶ
centroid_enhanced = mean + 10 * (centroids - mean) centroid_enhanced = mean + 5 * (centroids - mean)
closest_wav_files = [] closest_wav_files = []
indices = [] indices = []
for i in range(len(centroids)): for i in range(len(centroids)):
@@ -92,7 +92,7 @@ def do_clustering_gradio(n_clusters=4, method="KMeans"):
x_tsne[y_pred == i, 0], x_tsne[y_pred == i, 0],
x_tsne[y_pred == i, 1], x_tsne[y_pred == i, 1],
color=cmap(i), color=cmap(i),
label=f"Style {i+1}", label=f"Style {i + 1}",
) )
plt.legend() plt.legend()
@@ -112,40 +112,12 @@ def do_clustering_gradio(n_clusters=4, method="KMeans"):
) )
def save_only_mean(model_name):
global mean
if len(x) == 0:
return "Error: スタイルベクトルを読み込んでください。"
result_dir = os.path.join(config.out_dir, model_name)
os.makedirs(result_dir, exist_ok=True)
mean = np.mean(x, axis=0)
style_vectors = np.stack([mean])
style_vector_path = os.path.join(result_dir, "style_vectors.npy")
if os.path.exists(style_vector_path):
return f"{style_vector_path}が既に存在します。削除するか別の名前にバックアップしてください。"
np.save(style_vector_path, style_vectors)
# config.jsonの更新
config_path = os.path.join(result_dir, "config.json")
if not os.path.exists(config_path):
return f"{config_path}が存在しません。"
with open(config_path, "r") as f:
json_dict = json.load(f)
json_dict["data"]["num_styles"] = 1
json_dict["data"]["style2id"] = {"Neutral": 0}
with open(config_path, "w") as f:
json.dump(json_dict, f, indent=2)
return f"成功!\n{style_vector_path}に保存し{config_path}を更新しました。"
def save_style_vectors(model_name, style_names: str): def save_style_vectors(model_name, style_names: str):
"""centerとcentroidsを保存する""" """centerとcentroidsを保存する"""
result_dir = os.path.join(config.out_dir, model_name) result_dir = os.path.join(config.out_dir, model_name)
os.makedirs(result_dir, exist_ok=True) os.makedirs(result_dir, exist_ok=True)
style_vectors = np.stack([mean] + centroids) style_vectors = np.stack([mean] + centroids)
style_vector_path = os.path.join(result_dir, "style_vectors.npy") style_vector_path = os.path.join(result_dir, "style_vectors.npy")
if os.path.exists(style_vector_path):
return f"{style_vector_path}が既に存在します。削除するか別の名前にバックアップしてください。"
np.save(style_vector_path, style_vectors) np.save(style_vector_path, style_vectors)
# config.jsonの更新 # config.jsonの更新
@@ -219,21 +191,20 @@ def save_style_vectors_from_files(model_name, audio_files_text, style_names_text
initial_md = """ initial_md = """
# Style Bert-VITS2 スタイルベクトルの作成 # Style Bert-VITS2 スタイルベクトルの作成
Style-Bert-VITS2で音声合成するには、スタイルベクトルのファイル`style_vectors.npy`が必要です。これをモデルごとに作成する必要があります。 Style-Bert-VITS2でこまかくスタイルを指定して音声合成するには、モデルごとにスタイルベクトルのファイル`style_vectors.npy`を手動で作成する必要があります。
ただし、学習の過程で自動的に平均スタイル「Neutral」のみは作成されるので、それをそのまま使うこともできますその場合はこのWebUIは使いません
このプロセスは学習とは全く関係がないので、何回でも独立して繰り返して試せます。また学習中にもたぶん軽いので動くはずです。 このプロセスは学習とは全く関係がないので、何回でも独立して繰り返して試せます。また学習中にもたぶん軽いので動くはずです。
## 方法 ## 方法
どうやってスタイルベクトルファイルを作るかはいくつか方法があります。 - 方法1: 音声ファイルを自動でスタイル別に分け、その各スタイルの平均を取って保存
- 方法1: めんどくさいから平均スタイルのみを使う使えるスタイルは標準のNeutralのみ - 方法2: スタイルを代表する音声ファイルを手動で選んで、その音声のスタイルベクトルを保存
- 方法2: 音声ファイルを自動でスタイル別に分け、その各スタイルの平均を取って保存 - 方法3: 自分でもっと頑張ってこだわって作るJVNVコーパスなど、もともとスタイルラベル等が利用可能な場合はこれがよいかも
- 方法3: スタイルを代表する音声ファイルを手動で選んで、その音声のスタイルベクトルを保存
- 方法4: 自分でもっと頑張ってこだわって作るJVNVコーパスなど、もともとスタイルラベル等が利用可能な場合はこれがよいかも
基本的には方法2を使うことを、めんどくさかったりあまり感情に幅がないデータセットなら方法1をおすすめします。
""" """
method2 = """ method1 = """
学習の時に取り出したスタイルベクトルを読み込んで、可視化を見ながらスタイルを分けていきます。 学習の時に取り出したスタイルベクトルを読み込んで、可視化を見ながらスタイルを分けていきます。
手順: 手順:
@@ -255,13 +226,7 @@ with gr.Blocks(theme="NoCrypt/miku") as app:
load_button = gr.Button("スタイルベクトルを読み込む", variant="primary") load_button = gr.Button("スタイルベクトルを読み込む", variant="primary")
output = gr.Plot(label="音声スタイルの可視化") output = gr.Plot(label="音声スタイルの可視化")
load_button.click(load, inputs=[model_name], outputs=[output]) load_button.click(load, inputs=[model_name], outputs=[output])
with gr.Tab("方法1: 平均スタイルのみを保存"): with gr.Tab("方法1: スタイル分けを自動で行う"):
gr.Markdown("平均Neutralスタイルのみを保存する場合は、以下のボタンを押してください。")
with gr.Row():
save_button1 = gr.Button("スタイルベクトルを保存", variant="primary")
info1 = gr.Textbox(label="保存結果")
save_button1.click(save_only_mean, inputs=[model_name], outputs=[info1])
with gr.Tab("方法2: スタイル分けを自動で行う"):
n_clusters = gr.Slider( n_clusters = gr.Slider(
minimum=2, minimum=2,
maximum=10, maximum=10,
@@ -318,7 +283,7 @@ with gr.Blocks(theme="NoCrypt/miku") as app:
save_button.click( save_button.click(
save_style_vectors, inputs=[model_name, style_names], outputs=[info2] save_style_vectors, inputs=[model_name, style_names], outputs=[info2]
) )
with gr.Tab("方法3: 手動でスタイルを選ぶ"): with gr.Tab("方法2: 手動でスタイルを選ぶ"):
gr.Markdown("下のテキスト欄に、各スタイルの代表音声のファイル名を`,`区切りで、その横に対応するスタイル名を`,`区切りで入力してください。") gr.Markdown("下のテキスト欄に、各スタイルの代表音声のファイル名を`,`区切りで、その横に対応するスタイル名を`,`区切りで入力してください。")
gr.Markdown("例: `angry.wav, sad.wav, happy.wav`と`Angry, Sad, Happy`") gr.Markdown("例: `angry.wav, sad.wav, happy.wav`と`Angry, Sad, Happy`")
gr.Markdown("注意: Neutralスタイルは自動的に保存されます、手動ではNeutralという名前のスタイルは指定しないでください。") gr.Markdown("注意: Neutralスタイルは自動的に保存されます、手動ではNeutralという名前のスタイルは指定しないでください。")
@@ -337,7 +302,7 @@ with gr.Blocks(theme="NoCrypt/miku") as app:
inputs=[model_name, audio_files_text, style_names_text], inputs=[model_name, audio_files_text, style_names_text],
outputs=[info3], outputs=[info3],
) )
with gr.Tab("方法4: がんばる"): with gr.Tab("方法3: がんばる"):
gr.Markdown( gr.Markdown(
"`clustering.ipynb`にjvnvコーパスの場合の作り方とかクラスタ分けのいろいろを書いています。これを参考に自分で頑張って作ってください。" "`clustering.ipynb`にjvnvコーパスの場合の作り方とかクラスタ分けのいろいろを書いています。これを参考に自分で頑張って作ってください。"
) )