fish speech v1.5 で finetune を試す

オレオレAI Agentを作ろう第三話。
やはりアイデンティティとして声って大事ということで、AI Agentに世界を幸せにするようなヴォイスを授けるべく、以下をやってみる。

環境
WSL2
RTX 4060 Ti VRAM16GB
python -V
Python 3.12.7
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal

何はともあれリポジトリをクローン
git clone https://github.com/fishaudio/fish-speech/tree/main
venv を作成(自分の嗜好に合わせる)
python3 -m venv .venv --clear
. .venv/bin/activate
公式doc に倣う。
pip3 install torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1
apt install libsox-dev ffmpeg
apt install build-essential \
cmake \
libasound-dev \
portaudio19-dev \
libportaudio2 \
libportaudiocpp0
pip3 install -e .
fish speech をインストールできたら、公式Docに従ってデータセットを作成する。
データセットを配置できたら、以下のスクリプトで finetune できる。(面倒なのでスクリプトにしました。)
#!/bin/bash
# check data directory
if [ ! -d "data" ]; then
echo "Data directory not found."
exit 1
fi
# input project name for finetuning
echo -n "Enter the project name:"
read project
echo "Starting finetuning..."
echo "Extracting VQGAN weights..."
python tools/vqgan/extract_vq.py data \
--num-workers 1 --batch-size 16 \
--config-name "firefly_gan_vq" \
--checkpoint-path "checkpoints/fish-speech-1.5/firefly-gan-vq-fsq-8x1024-21hz-generator.pth"
echo "Building dataset..."
python tools/llama/build_dataset.py \
--input "data" \
--output "data/protos" \
--text-extension .lab \
--num-workers 16
echo "Training..."
python fish_speech/train.py --config-name text2semantic_finetune \
project=$project \
+lora@model.model.lora_config=r_8_alpha_16
echo "Training complete."
echo "Merging LORA..."
max_step=$(awk -F": " '/max_steps/ {printf "%09d\n", $2}' ./results/$project/tensorboard/version_0/hparams.yaml)
python tools/llama/merge_lora.py \
--lora-config r_8_alpha_16 \
--base-weight checkpoints/fish-speech-1.5 \
--lora-weight results/$project/checkpoints/step_$max_step.ckpt \
--output checkpoints/fish-speech-1.5-yth-lora-$project/
echo "Finetuning complete."
python -m tools.run_webui \
--llama-checkpoint-path "checkpoints/fish-speech-1.5-yth-lora-$project" \
--decoder-checkpoint-path "checkpoints/fish-speech-1.5/firefly-gan-vq-fsq-8x1024-21hz-generator.pth" \
--decoder-config-name firefly_gan_vq
一応使い方↓
$finetune.sh
Enter the project name:hoge
# web UI が立ち上がる。
気になるfinetune の所要時間ですが、音声データセット2000個、4060Ti (VRAM 16GB) でだいたい1日半程度かかる。
割と良い精度で voice clone 可能なので、オレオレAI Agentに活用したい。体感、10回程度の推論でニアピンな音声を出力してくれる(不自然な間の削除など、多少の手直しは必要。時々全く入力テキストにそぐわない音声を吐いたりするので、LLM使って吐いたテキストを読ませて使う場合は工夫が必要かも。)
なお、2025/02/01 時点で商用利用可能。(2024/12/11 にApache License に変更された模様🎉)
[2025/04/17 追記]
コードのライセンスが Apache License であって、重みはCC-BY-NC-SA-4.0 とのこと。

自動で任意のテキストを読ませる場合にどう工夫するか。
短い区切りで音声を生成してwhisperなどでtext に再び変換して違和感ないかLLM などで判定する方法を試したい。
text→[fish speech]→ voice data →[whisper]→text→[LLM]→OK or NG 的な
whisper をかけることで生成した音声についてる不要な区間を削ることができそう。削られた分不自然になる確率もあるけど。。

[2025/02/23 追記]
結局、リソースかけて fine tune しなくても、voice reference で十分そう。 finetune で作成したモデルと voice reference で生成した音声に大きな違いがない。(学習データの質はありそうだが。)

デモサイトでいろいろ試すことができる。
quotaに限界はあるが、 finetuning も試すことができそう。(未検証)