From 3efcb98858003b5577f1c197848964858f491155 Mon Sep 17 00:00:00 2001 From: litagin02 Date: Fri, 15 Mar 2024 20:16:58 +0900 Subject: [PATCH] docs --- colab.ipynb | 4 +-- docs/CHANGELOG.md | 53 +++++++++++++++++++++++++++++ docs/CLI.md | 15 +++++--- library.ipynb | 29 +++++++++++++--- preprocess_text.py | 1 - scripts/Clean.bat | 2 +- scripts/Update-Style-Bert-VITS2.bat | 14 ++++---- webui/dataset.py | 3 +- webui/merge.py | 2 +- 9 files changed, 102 insertions(+), 21 deletions(-) diff --git a/colab.ipynb b/colab.ipynb index 5e80f52..27ccbc1 100644 --- a/colab.ipynb +++ b/colab.ipynb @@ -43,7 +43,7 @@ "!git clone https://github.com/litagin02/Style-Bert-VITS2.git\n", "%cd Style-Bert-VITS2/\n", "!pip install -r requirements.txt\n", - "!apt install libcublas11\n", + "# !apt install libcublas11\n", "!python initialize.py --skip_jvnv" ] }, @@ -121,7 +121,7 @@ "initial_prompt = \"こんにちは。元気、ですかー?ふふっ、私は……ちゃんと元気だよ!\"\n", "\n", "!python slice.py -i {input_dir} --model_name {model_name}\n", - "!python transcribe.py --model_name {model_name} --compute_type float16 --initial_prompt {initial_prompt}" + "!python transcribe.py --model_name {model_name} --initial_prompt {initial_prompt} --use_hf_whisper" ] }, { diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index dee5ee4..3e3ed0c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,58 @@ # Changelog +## v2.4.0 (2024-03-15) + +大規模リファクタリング・日本語処理のワーカー化と機能追加等。データセット作り・学習・音声合成・マージ・スタイルWebUIは全て`app.py` (`App.bat`) へ統一されましたのでご注意ください。 + +### アップデート手順 +- 2.3未満(辞書・エディター追加前)からのアップデートの場合は、[Update-to-Dict-Editor.bat](https://github.com/litagin02/Style-Bert-VITS2/releases/download/2.4.0/Update-to-Dict-Editor.bat)をダウンロードし、`Style-Bert-VITS2`フォルダがある場所(インストールbatファイルとかがあったところ)においてダブルクリックしてください。 +- それ以外の場合は、単純に今までの`Update-Style-Bert-VITS2.bat`でアップデートできます。 +- ただしアップデートにより多くのファイルが移動したり不要になったりしたので、それらを削除したい場合は[Clean.bat](https://github.com/litagin02/Style-Bert-VITS2/releases/download/2.4.0/Clean.bat)を`Update-Style-Bert-VITS2.bat`と同じ場所に保存して実行してください。 + +### 内部改善 + +- [tsukumijimaさんによる大規模リファクタリングのプルリク](https://github.com/litagin02/Style-Bert-VITS2/pull/92) によって、内部コードが非常に整理され可読性が高まりライブラリ化もされた。[tsukumijimaさん](https://github.com/tsukumijima) 大変な作業を本当にありがとうございます! +- ライブラリとして`pip install style-bert-vits2`によりすぐにインストールでき、音声合成部分の機能が使えます(使用例は[/library.ipynb](/library.ipynb)を参照してください) +- その他このプルリクに動機づけられ、多くのコードのリファクタリング・型アノテーションの追加等を行った +- 日本語処理のpyopenjtalkをソケット通信を用いて別プロセス化し、複数同時に学習や音声合成を立ち上げても辞書の競合エラーが起きないように。[kale4eat](https://github.com/kale4eat) さんによる[PR](https://github.com/litagin02/Style-Bert-VITS2/pull/89) で + +### バグ修正 + +- 上記にもある通り、音声合成と学習前処理など、日本語処理を扱うものを2つ以上起動しようとするとエラーが発生する仕様の解決。ユーザー辞書は追加すれば常にどこからでも適応されます。 +- `raw`フォルダの直下でなくサブフォルダ内に音声ファイルがある場合に、`wavs`フォルダでもその構造が保たれてしまい、書き起こしファイルとの整合性が取れなくなる挙動を修正し、常に`wav`フォルダ直下へ`wav`ファイルを保存するように変更 +- スライス時に元ファイル名にピリオド `.` が含まれると、スライス後のファイル名がおかしくなるバグの修正 + +### 機能改善・追加 + +- 各種WebUIを一つ`app.py` `App.bat` に統一 +- その他以下の変更や、軽微なUI・説明文の改善等 + +**データセット作成** + +- スライス処理の高速化(マルチスレッドにした、大量にスライス元ファイルファイルがある場合に高速になります)、またスライス元のファイルを`wav`以外の`mp3`や`ogg`などの形式にも対応 +- スライス処理時に、ファイル名にスライスされた開始終了区間を含めるオプションを追加([aka7774](https://github.com/aka7774) さんによるPRです、ありがとうございます!) +- 書き起こしの高速化、またHugging FaceのWhisperモデルを使うオプションを追加。バッチサイズを上げることでVRAMを食う代わりに速度が大幅に向上します。 + +**学習** + +- 学習元の音声ファイル(`Data/モデル名/raw`にいれるやつ)を、`wav`以外の`mp3`や`ogg`などの形式にも対応(前処理段階で自動的に`wav`ファイルに変換されます)(ただし変わらず1ファイル2-12秒程度の範囲の長さが望ましい) + +**音声合成** + +- 音声合成時に、生成音声の音の高さ(音高)と抑揚の幅を調整できるように(ただし音質が少し劣化する)。`App.bat`や`Editor.bat`のどちらからでも使えます。 +- `Editor.bat`の複数話者モデルでの話者指定を可能に +- `Editor.bat`で、改行を含む文字列をペーストすると自動的に欄が増えるように。また「↑↓」キーで欄を追加・行き来できるように +- `Editor.bat`でモデル一覧のリロードをメニューに追加 + +**API** + +- `server_fastapi.py`の音声合成エンドポイント`/voice`について、GETメソッドに加えてPOSTメソッドを追加。GETメソッドでは多くの制約があるようなのでPOSTを使うことが推奨されます。 + +**CLI** + +- `preprocess_text.py`で、書き起こしファイルでの音声ファイル名を自動的に正しい`Data/モデル名/wavs/`へ書き換える`--correct_path`オプションの追加(WebUIでは今までもこの挙動でした) +- その他上述のデータセット作成の機能追加に伴うCLIのオプションの追加(詳しくは[CLI.md](/docs/CLI.md)を参照) + ## v2.3.1 (2024-02-27) ### バグ修正 diff --git a/docs/CLI.md b/docs/CLI.md index 95ab8b5..537e450 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -24,9 +24,11 @@ Optional: ## 1. Dataset preparation -### 1.1. Slice wavs +### 1.1. Slice audio files + +The following audio formats are supported: ".wav", ".flac", ".mp3", ".ogg", ".opus". ```bash -python slice.py --model_name [-i ] [-m ] [-M ] +python slice.py --model_name [-i ] [-m ] [-M ] [--time_suffix] ``` Required: @@ -36,8 +38,9 @@ Optional: - `input_dir`: Path to the directory containing the audio files to slice (default: `inputs`) - `min_sec`: Minimum duration of the sliced audio files in seconds (default: 2). - `max_sec`: Maximum duration of the sliced audio files in seconds (default: 12). +- `--time_suffix`: Make the filename end with -start_ms-end_ms when saving wav. -### 1.2. Transcribe wavs +### 1.2. Transcribe audio files ```bash python transcribe.py --model_name @@ -50,7 +53,11 @@ Optional - `--device`: `cuda` or `cpu` (default: `cuda`). - `--language`: `jp`, `en`, or `en` (default: `jp`). - `--model`: Whisper model, default: `large-v3` -- `--compute_type`: default: `bfloat16` +- `--compute_type`: default: `bfloat16`. Only used if not `--use_hf_whisper`. +- `--use_hf_whisper`: Use Hugging Face's whisper model instead of default faster-whisper (HF whisper is faster but requires more VRAM). +- `--batch_size`: Batch size (default: 16). Only used if `--use_hf_whisper`. +- `--num_beams`: Beam size (default: 1). +- `--no_repeat_ngram_size`: N-gram size for no repeat (default: 10). ## 2. Preprocess diff --git a/library.ipynb b/library.ipynb index 81a1028..753059a 100644 --- a/library.ipynb +++ b/library.ipynb @@ -6,7 +6,19 @@ "source": [ "# Style-Bert-VITS2ライブラリの使用例\n", "\n", - "`pip install style-bert-vits2`を使った、colabで動く使用例です。" + "`pip install style-bert-vits2`を使った、jupyter notebookでの使用例です。Google colab等でも動きます。" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# PyTorch環境の構築(ない場合)\n", + "# 参照: https://pytorch.org/get-started/locally/\n", + "\n", + "!pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118" ] }, { @@ -17,7 +29,9 @@ }, "outputs": [], "source": [ - "!pip install style-bert-vits2==2.4.dev0" + "# style-bert-vits2のインストール\n", + "\n", + "!pip install style-bert-vits2" ] }, { @@ -28,6 +42,8 @@ }, "outputs": [], "source": [ + "# BERTモデルをロード(ローカルに手動でダウンロードする必要はありません)\n", + "\n", "from style_bert_vits2.nlp import bert_models\n", "from style_bert_vits2.constants import Languages\n", "\n", @@ -48,6 +64,9 @@ }, "outputs": [], "source": [ + "# Hugging Faceから試しにデフォルトモデルをダウンロードしてみて、それを音声合成に使ってみる\n", + "# model_assetsディレクトリにダウンロードされます\n", + "\n", "from pathlib import Path\n", "from huggingface_hub import hf_hub_download\n", "\n", @@ -73,14 +92,16 @@ }, "outputs": [], "source": [ + "# 上でダウンロードしたモデルファイルを指定して音声合成のテスト\n", + "\n", "from style_bert_vits2.tts_model import TTSModel\n", "\n", "assets_root = Path(\"model_assets\")\n", "\n", "model = TTSModel(\n", " model_path=assets_root / model_file,\n", - " config_path = assets_root / config_file,\n", - " style_vec_path = assets_root / style_file,\n", + " config_path=assets_root / config_file,\n", + " style_vec_path=assets_root / style_file,\n", " device=\"cpu\"\n", ")" ] diff --git a/preprocess_text.py b/preprocess_text.py index 65fc77b..c75e230 100644 --- a/preprocess_text.py +++ b/preprocess_text.py @@ -227,7 +227,6 @@ if __name__ == "__main__": parser.add_argument("--correct_path", action="store_true") args = parser.parse_args() - logger.debug(f"args: {args}") transcription_path = Path(args.transcription_path) cleaned_path = Path(args.cleaned_path) if args.cleaned_path else None diff --git a/scripts/Clean.bat b/scripts/Clean.bat index 0a3af34..aed7a1d 100644 --- a/scripts/Clean.bat +++ b/scripts/Clean.bat @@ -28,7 +28,7 @@ echo Style-Bert-VITS2\webui_style_vectors.py echo Style-Bert-VITS2\webui_train.py echo Style-Bert-VITS2\webui.py echo. -set /p delConfirm=削除しますか? (y/n): +set /p delConfirm=以上のフォルダファイルを削除しますか? (y/n): if /I "%delConfirm%"=="Y" goto proceed if /I "%delConfirm%"=="y" goto proceed if "%delConfirm%"=="" goto proceed diff --git a/scripts/Update-Style-Bert-VITS2.bat b/scripts/Update-Style-Bert-VITS2.bat index 04f5937..dc00cea 100644 --- a/scripts/Update-Style-Bert-VITS2.bat +++ b/scripts/Update-Style-Bert-VITS2.bat @@ -10,12 +10,12 @@ if not exist %CURL_CMD% ( pause & popd & exit /b 1 ) -@REM Style-Bert-VITS2.zip をGitHubのdev-refactorの最新のものをダウンロード +@REM Style-Bert-VITS2.zip をGitHubのdevの最新のものをダウンロード %CURL_CMD% -Lo Style-Bert-VITS2.zip^ - https://github.com/litagin02/Style-Bert-VITS2/archive/refs/heads/dev-refactor.zip + https://github.com/litagin02/Style-Bert-VITS2/archive/refs/heads/dev.zip if %errorlevel% neq 0 ( pause & popd & exit /b %errorlevel% ) -@REM Style-Bert-VITS2.zip を解凍(フォルダ名前がBert-VITS2-dev-refactorになる) +@REM Style-Bert-VITS2.zip を解凍(フォルダ名前がBert-VITS2-devになる) %PS_CMD% Expand-Archive -Path Style-Bert-VITS2.zip -DestinationPath . -Force if %errorlevel% neq 0 ( pause & popd & exit /b %errorlevel% ) @@ -23,9 +23,9 @@ if %errorlevel% neq 0 ( pause & popd & exit /b %errorlevel% ) del Style-Bert-VITS2.zip if %errorlevel% neq 0 ( pause & popd & exit /b %errorlevel% ) -@REM Bert-VITS2-dev-refactorの中身をStyle-Bert-VITS2に上書き移動 -xcopy /QSY .\Style-Bert-VITS2-dev-refactor\ .\Style-Bert-VITS2\ -rmdir /s /q Style-Bert-VITS2-dev-refactor +@REM Bert-VITS2-devの中身をStyle-Bert-VITS2に上書き移動 +xcopy /QSY .\Style-Bert-VITS2-dev\ .\Style-Bert-VITS2\ +rmdir /s /q Style-Bert-VITS2-dev if %errorlevel% neq 0 ( pause & popd & exit /b %errorlevel% ) @REM 仮想環境のpip requirements.txtを更新 @@ -37,7 +37,9 @@ if %errorlevel% neq 0 ( pause & popd & exit /b %errorlevel% ) pip install -U -r Style-Bert-VITS2\requirements.txt if %errorlevel% neq 0 ( pause & popd & exit /b %errorlevel% ) +echo ---------------------------------------- echo Update completed. Running Style-Bert-VITS2 Editor... +echo ---------------------------------------- @REM Style-Bert-VITS2フォルダに移動 pushd Style-Bert-VITS2 diff --git a/webui/dataset.py b/webui/dataset.py index fe14030..33da3ff 100644 --- a/webui/dataset.py +++ b/webui/dataset.py @@ -73,8 +73,7 @@ def do_transcribe( cmd.extend(["--batch_size", str(batch_size)]) success, message = run_script_with_log(cmd) if not success: - return f"Error: {message}. しかし何故かエラーが起きても正常に終了している場合がほとんどなので、書き起こし結果を確認して問題なければ学習に使えます。" - return "音声の文字起こしが完了しました。" + return f"Error: {message}. エラーメッセージが空の場合、何も問題がない可能性があるので、書き起こしファイルをチェックして問題なければ無視してください。" how_to_md = """ diff --git a/webui/merge.py b/webui/merge.py index c7f8eee..661f233 100644 --- a/webui/merge.py +++ b/webui/merge.py @@ -38,7 +38,7 @@ def merge_style(model_name_a, model_name_b, weight, output_name, style_triple_li sorted_list = sorted(style_triple_list, key=lambda x: x[2] != DEFAULT_STYLE) else: # 存在しない場合、エラーを発生 - raise ValueError("No element with {DEFAULT_STYLE} output style name found.") + raise ValueError(f"No element with {DEFAULT_STYLE} output style name found.") style_vectors_a = np.load( os.path.join(assets_root, model_name_a, "style_vectors.npy")