初めに
音声言語モデリングのための拡散ベースの音声トークナイザーのライブラリが出ていたので触っていきます。今回はライブラリ側で提供されている音声合成機能部分を使います
TaDiCodecには以下の二つが提供されています
- 自己回帰型TTS
- MGM型TTS
精度が比較的高い1を動かしていきます
開発環境
- Windows 11
- uv 0.9.x
環境構築
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 # Windows向けのwheelが公開されているため、こちらを使用 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" # wheelファイル名を標準形式にリネーム(uvの制約のため) 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を設定) UV_SKIP_WHEEL_FILENAME_CHECK=1 uv pip install flash_attn-2.7.4.post1-cp310-cp310-win_amd64.whl # wheelファイルをクリーンアップ rm flash_attn*.whl
音声合成の実行
以下のコードを作成して、実行します
import torch import soundfile as sf import sys import os # Add parent directory to path (works from anywhere) 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(): # Get text from command line argument or use default if len(sys.argv) > 1: text = sys.argv[1] else: text = "こんにちは、これはテストです。" print(f"📝 生成するテキスト: {text}") print("🔄 モデルを読み込んでいます...") # Setup device device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # Load Qwen2.5-3B model (highest quality) pipeline = TTSInferencePipeline.from_pretrained( tadicodec_path="amphion/TaDiCodec", llm_path="amphion/TaDiCodec-TTS-AR-Qwen2.5-3B", device=device, ) print("✅ モデル読み込み完了") print("🎙️ 音声を生成中...") # Set paths relative to script location prompt_audio_path = os.path.join(script_dir, "test_audio", "trump_0.wav") output_path = os.path.join(script_dir, "output.wav") # Generate speech 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, ) # Save audio sf.write(output_path, audio, 24000) print(f"✅ 完了!音声ファイルを保存しました: {output_path}") if __name__ == "__main__": main()
実行することで ARでの音声合成ができます