![見出し画像](https://assets.st-note.com/production/uploads/images/107859374/rectangle_large_type_2_26979f80f2416be790c32581cf0a75ac.png?width=1200)
MusicGenを活用して作業用BGMを作ろう
Hugging Face版
MusicGen - a Hugging Face Space by facebook
を使って作っていきます。
Describe your musicにプロンプト的なものを入れていきましょう。
作業用bgmを表す英単語などはないようなので、music for work and studyを入力してみましょう。
少々待つと、Generated Musicに生成結果が出てきます。
こんな感じ。音楽だけどmp4。ループ再生で何分も普通に聞けるレベル。
Google Colab版
Google Colab版を試してみましょう。
GitHub - facebookresearch/audiocraft: Audiocraft is a library for audio processing and generation with deep learning. It features the state-of-the-art EnCodec audio compressor / tokenizer, along with MusicGen, a simple and controllable music generation LM with textual and melodic conditioning.
のOpen in Colabから使うことができます。
![](https://assets.st-note.com/img/1686381137700-Er499wJd0O.png?width=1200)
open in colabをしたらまずは、ランタイム→ランタイムのタイプを変更でランタイムのタイプをGPUにします。
![](https://assets.st-note.com/img/1686381116655-28kUnB9fXz.png?width=1200)
変更ができたら、1と2を実行。
次に3と4を書き換えます。
書き換える場所は、
3のmediumと4のオレンジ色の部分。
(3は任意です。)
git hubにも書いてある通り、MusicGenには四つのモデルがあります
We provide a simple API and 4 pre-trained models. The pre trained models are:
small: 300M model, text to music only - 🤗 Hub
medium: 1.5B model, text to music only - 🤗 Hub
melody: 1.5B model, text to music and text+melody to music - 🤗 Hub
large: 3.3B model, text to music only - 🤗 Hub
(日本語訳)
シンプルなAPIと4つの学習済みモデルを提供します。事前に学習されたモデルは
small: 300M モデル、テキストから音楽への変換のみ - 🤗 ハブ
medium: 1.5Bのモデル、テキストから音楽への変換のみ - 🤗 Hub
メロディ 1.5Bモデル、テキストから音楽、テキスト+メロディから音楽 - 🤗 Hub
ラージ 3.3B モデル、テキストから音楽への変換のみ - 🤗 ハブ
初期状態ではmediumモデルが使われています。
モデルを変えたい人は四つの中から変えて選んでください。
モデルが決まったら実行してokです
![](https://assets.st-note.com/img/1686381864080-9iNAbA44xG.png?width=1200)
![](https://assets.st-note.com/img/1686381866414-la9H0t3DvM.png?width=1200)
続いて4を書き換えましょう。
ここはDescribe your musicみたいなもの。
'crazy EDM, heavy bang',
'classic reggae track with an electronic guitar solo',
'lofi slow bpm electro chill with organic samples',
'rock with saturated guitars, a heavy bass line and crazy drum break and fills.',
'earthy tones, environmentally conscious, ukulele-infused, harmonic, breezy, easygoing, organic instrumentation, gentle grooves',
ここの部分で作ってほしい曲を決めます。
例えばmusic for work and studyを作ってほしいなら
![](https://assets.st-note.com/img/1686382052583-cc8ewQwbcS.png?width=1200)
![](https://assets.st-note.com/img/1686382063092-8gtUv9wdlD.png?width=1200)
ここまで来れば終わりです。実行してみましょう。
できました。
noteには容量の関係で掲載できませんでしたが、ループ再生で普通に聞けるレベルです。
![](https://assets.st-note.com/img/1686382505028-5rXrQIjQKB.png?width=1200)
画像ばっかり作ってないで気分転換に音楽作ってみよう