初めに
音声言語モデリングのための拡散ベースの音声トークナイザーのライブラリが出ていたので触っていきます。今回はライブラリ側で提供されている音声合成機能部分を使います
TaDiCodecには以下の二つが提供されています
- 自己回帰型TTS
- MGM型TTS
精度が比較的高い1を動かしていきます
開発環境
環境構築
uv venv --python 3.10
.\.venv\Scripts\activate
ライブラリをインストールします
uv pip install setuptools wheel psutil packaging ninja numpy hf_xet
uv pip install torch==2.8.0 torchaudio --index-strategy unsafe-best-match --extra-index-url https://download.pytorch.org/whl/cu128
uv pip install transformers==4.42.4 librosa huggingface_hub accelerate scipy json5 resampy tqdm tensorboard einops safetensors omegaconf
uv pip install pyopenjtalk-plus
uv pip install pyworld ruamel.yaml six tensorboardX
Flash Attentionのインストールをインストールします。通常でインストールできれば問題ないですが、試したときにうまくいかなかったので以下のような手順でインストールしました。
curl -L -o flash_attn-2.7.4.post1-cu128-torch2.8.0-cp310-cp310-win_amd64.whl "https://huggingface.co/kim512/flash_attn-2.7.4.post1/resolve/main/flash_attn-2.7.4.post1-cu128-torch2.8.0-cp310-cp310-win_amd64.whl"
cp flash_attn-2.7.4.post1-cu128-torch2.8.0-cp310-cp310-win_amd64.whl flash_attn-2.7.4.post1-cp310-cp310-win_amd64.whl
UV_SKIP_WHEEL_FILENAME_CHECK=1 uv pip install flash_attn-2.7.4.post1-cp310-cp310-win_amd64.whl
rm flash_attn*.whl
以下のコードを作成して、実行します
import torch
import soundfile as sf
import sys
import os
script_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(script_dir)
sys.path.insert(0, parent_dir)
from models.tts.llm_tts.inference_llm_tts import TTSInferencePipeline
def main():
if len(sys.argv) > 1:
text = sys.argv[1]
else:
text = "こんにちは、これはテストです。"
print(f"📝 生成するテキスト: {text}")
print("🔄 モデルを読み込んでいます...")
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
pipeline = TTSInferencePipeline.from_pretrained(
tadicodec_path="amphion/TaDiCodec",
llm_path="amphion/TaDiCodec-TTS-AR-Qwen2.5-3B",
device=device,
)
print("✅ モデル読み込み完了")
print("🎙️ 音声を生成中...")
prompt_audio_path = os.path.join(script_dir, "test_audio", "trump_0.wav")
output_path = os.path.join(script_dir, "output.wav")
audio = pipeline(
text=text,
prompt_text="In short, we embarked on a mission to make America great again, for all Americans.",
prompt_speech_path=prompt_audio_path,
)
sf.write(output_path, audio, 24000)
print(f"✅ 完了!音声ファイルを保存しました: {output_path}")
if __name__ == "__main__":
main()
実行することで ARでの音声合成ができます