![見出し画像](https://assets.st-note.com/production/uploads/images/107806762/rectangle_large_type_2_db4a0c98d553d79d6d00cc86ced2fd80.png?width=1200)
MusicGenで遊ぶメモ
このメモを読むと
・MusicGenを導入できる
・文字から曲を生成できる
・中品質での生成でVRAM7GBくらい必要(推奨は16GB)
検証環境
・Windows11
・VRAM24GB
・ローカル(Anaconda)
・2023/6/B時点
事前準備
Anacondaを使うメモ|おれっち (note.com)
Gitを使うメモ|おれっち (note.com)
MusicGenとは
文字(プロンプト)から曲を生成できます。
導入して遊んでみましょう!
We present MusicGen: A simple and controllable music generation model. MusicGen can be prompted by both text and melody.
— Felix Kreuk (@FelixKreuk) June 9, 2023
We release code (MIT) and models (CC-BY NC) for open research, reproducibility, and for the music community: https://t.co/OkYjL4xDN7 pic.twitter.com/h1l4LGzYgf
MusicGen導入
とても簡単です!
1. ターミナルで好きな名前の仮想環境を作成し、環境を切り替えます。
conda create -n musicgen python=3.10
activate musicgen
2. 下記GitHubからリポジトリのURLをコピーしダウンロードします。
git clone https://github.com/facebookresearch/audiocraft.git 保存先PATH
3. 保存先へ移動し、必要なライブラリををダウンロードします。
cd 保存先PATH
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install -U audiocraft
pip install -U git+https://git@github.com/facebookresearch/audiocraft#egg=audiocraft
pip install gradio
pip install -e .
4. "app.py"を実行します。
python app.py
5. ”Running on local URL: http://127.0.0.1:7860”と案内されます。
![](https://assets.st-note.com/img/1686323142455-o9jrIeXTvz.png?width=1200)
6. 案内されたURLをCtrl+クリックでWebUIを起動します。
※もしくは下記をブラウザURLにコピー
http://127.0.0.1:7860
![](https://assets.st-note.com/img/1686322665932-0qugowVjy3.png?width=1200)
起動できた!
MusicGenを使ってみる
それでは、実際にMusicGenを使って曲を生成してみましょう。
1. Input Textに生成したい曲の特徴を記述し、送信ボタンをクリック。
energetic and emotional performance, A sound that fuses J-POP and rock, Fast rhythm and catchy melody line,
![](https://assets.st-note.com/img/1686322891080-ItBXQGzEIn.png?width=1200)
2. できた!
曲がつくれる~~~~ pic.twitter.com/EZznF3rlMp
— おれっち (@__olender) June 9, 2023
※"Duration"から曲の長さを調整できます。(最大30秒)
![](https://assets.st-note.com/img/1686322874400-aEkhB6KxgY.png)
※Modelを”melody”にし主旋律音源をインプットすることで、それに合った曲も生成できます。
![](https://assets.st-note.com/img/1686322850310-7OKXSci3rD.png)
主旋律も pic.twitter.com/u3AcmGotd1
— おれっち (@__olender) June 9, 2023
Examplesのbach.mp3をインプットしました。
おわり
MusicGenを導入して、曲を生成できました。
Modelによる品質の差はそこまで大きくは感じませんでした。
まだ曲としては実用的なレベルではありませんが、音楽としては聴けるレベルだと思います。すごい!
はばがひろがる~~~~~