Composing instrumental music with LLM part 1
This is the first part in a series about making instrumental music with ChatGPT. This might be a one part series...
We’ve seen countless examples of ChatGPT writing lyrics for songs and poems, but can we get an LLM to produce melodies, harmonies, and drum beats? The short answer is yes.
ChatGPT → Musical notes → MIDI → Audio
Audio signals at their core are a time series of values representing the amplitude of a sound wave — a single second of digital audio can contain over a thousand values. LLM’s aren’t equipped to generate this scale of data. However, we can get LLM’s to give us musical notes, which can then be used to create MIDI files, which can then be used to construct audio.
This is what a prompt can look like:
The next step is taking those notes and building a MIDI file.
We can represent each note as a list of tuples. Each tuple tells us what the note is and what time it gets played. This melody looks like this:
melody = [(64, 0), (64, 1), (65, 2), (67, 3), (67, 4), (65, 5), (64, 6), (62,7), (62, 8), (64, 9), (64, 10), (65, 11), (67, 12), (67, 13), (65, 14), (64, 15),(62, 16), (62, 17), (64, 18), (65, 19), (67, 20), (67, 21), (65, 22),(64, 23),(62, 24), (62, 25), (64, 26), (64, 27), (65, 28), (67, 29), (67, 30), (65, 31), (64, 32)]
You can see what the whole process looks like with a link to some Python code here:
Link to Google Colab Notebook
Here is what our simple melody sounds like:
You might notice the first part sounds suspiciously similar to Beethoven’s Symphony No. 9 (Ode to Joy) before trailing off into a random series of notes.
I then wanted to see if ChatGPT could give me something bluesy:
The blues melody (more like a short riff) ended up sounding pretty good! Here it is:
My last exercise was seeing if we could get ChatGPT to create a drum loop.
Notice that not only do we get a new list of values, but we also change the MIDI channel to 9.
Here are the results of our drum loop:
Not too bad! But I don’t think any musicians or composers need be worried. It looks like our good friend ChatGPT makes pretty generic and possibly plagiarized tracks. Apparently Google is sitting on a generative AI music program - very curious to see that released.
I hope you enjoyed seeing what kind of tunes ChatGPT could cook up. I am interested in piecing together a full song - or at least part of a song - using this approach. If it ends up coming together nicely, I’ll release a part 2 of this series. Until next time!