3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

YuEを使って音楽生成を始めよう! 🎵

Posted at

はじめに

このノートブックでは、オープンソースの音楽生成モデル「YuE(乐)」を使って、歌詞から完全な楽曲を生成する方法を説明します。YuEは歌声トラックと伴奏を含む数分間の完全な楽曲を生成できます。

環境のセットアップ

まず必要な環境をセットアップしましょう。Python 3.8以上を推奨します。

# FlashAttention 2のインストール (重要)
!pip install flash-attn --no-build-isolation

CUDA環境の設定

FlashAttentionを使用するために、CUDA環境を正しく設定する必要があります。以下はCUDA 11.8を使用する場合の例です:

# CUDA環境の設定
import os
os.environ['PATH'] = '/usr/local/cuda-11.8/bin:' + os.environ['PATH']
os.environ['LD_LIBRARY_PATH'] = '/usr/local/cuda-11.8/lib64:' + os.environ['LD_LIBRARY_PATH']

YuEのソースコードの取得

Git LFSをインストールしてからリポジトリをクローンします:

# Git LFSのインストール
!apt-get install git-lfs
!git lfs install

# リポジトリのクローン
!git clone https://github.com/multimodal-art-projection/YuE.git


# 必要なパッケージのインストール
!cd YuE && pip install -r requirements.txt

!cd YuE/inference/ && git clone https://huggingface.co/m-a-p/xcodec_mini_infer
# 既存のprotobufをアンインストール
!pip uninstall -y protobuf

# 互換性のあるバージョンのprotobufをインストール
!pip install protobuf==3.20.0

# TensorFlowを再インストール
!pip install --upgrade tensorflow
# transformersを再インストール
!pip install --upgrade transformers
import sys
import tensorflow as tf
from transformers import AutoFeatureExtractor, WhisperModel

print(f"Python version: {sys.version}")
print(f"TensorFlow version: {tf.__version__}")
#print(f"Protobuf version: {tf.version.PROTOBUF_VERSION}")

基本的な音楽生成

以下のスクリプトで基本的な音楽生成を行えます:

!cd YuE/inference/ && python infer.py \
    --stage1_model m-a-p/YuE-s1-7B-anneal-en-cot \
    --stage2_model m-a-p/YuE-s2-1B-general \
    --genre_txt prompt_examples/genre.txt \
    --lyrics_txt prompt_examples/lyrics.txt \
    --run_n_segments 2 \
    --stage2_batch_size 4 \
    --output_dir ./output \
    --cuda_idx 0 \
    --max_new_tokens 3000
!pwd
!ls -al

オーディオプロンプトを使用した生成

既存の音楽をプロンプトとして使用することもできます:

!cd YuE/inference/ && python infer.py \
    --stage1_model m-a-p/YuE-s1-7B-anneal-en-icl \
    --stage2_model m-a-p/YuE-s2-1B-general \
    --genre_txt prompt_examples/genre.txt \
    --lyrics_txt prompt_examples/lyrics.txt \
    --run_n_segments 2 \
    --stage2_batch_size 4 \
    --output_dir ./output \
    --cuda_idx 0 \
    --max_new_tokens 3000 \
    --audio_prompt_path /content/CatSymphony.mp3 \
    --prompt_start_time 0 \
    --prompt_end_time 30

重要な注意点 ⚠️

  1. GPUメモリの使用について:

    • 24GB以下のGPUメモリの場合: 最大2セッション
    • フルソング生成(4セッション以上)の場合: 80GB以上のGPUメモリを推奨
  2. 実行時間の目安:

    • H800 GPU: 30秒の音声生成に約150秒
    • RTX 4090 GPU: 30秒の音声生成に約360秒
  3. ジャンルタグの設定:

    • 5つの要素を含めることを推奨: ジャンル、楽器、ムード、性別、音色
    • 例: [Genre] inspiring female uplifting pop airy vocal electronic bright vocal vocal
  4. 歌詞セグメントの長さ:

    • max_new_tokens=3000の場合、セグメントの最大長は約30秒
    • 歌詞の長さをこの時間枠に合わせることが重要

これでYuEを使った音楽生成の基本が整いました!実験して素晴らしい音楽を作成してみましょう!

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?