"It would be fun if we could create music with AI," he says. "But I have no musical knowledge or experience composing."
Do you have such concerns?
Using Python, Google Colab, and free tools called Magenta,Anyone can easily create music automatically using AIcan.
In this article,How to create an AI music composition tool that even programming beginners can useWe will introduce it in an easy-to-understand manner.
All codes are published and explained.
Even if you're not confident in composing,An era where original melodies can be created with the power of AIis.
How to make music with Python
conclusion
In Python, by using a library called Magenta, AI can learn the rules of music and automatically generate melodies and rhythms.
reason
Magenta is a "music x AI" research project developed by Google.
We learn the characteristics of music created by humans from large amounts of music data.
It is especially useful for the following reasons:
• Pre-trained models are already available
• Melodies can be generated just by executing the code.
• The whole process is done on Google Colab, so there is no need to install software on your PC.
Examples
Below are the chords to create a piano melody using Magenta.
1 | !pip install magenta !pip install note - seq from note_seq import midi_synth from magenta.models.melody_rnn import melody_rnn_sequence_generator # The following is the model, settings, and generation process (omitted) |
action
In this article, we will introduce such code in an easy-to-understand manner.
Come join us and experience the world of making music with Python.
Basic usage of Magenta
conclusion
Magenta allows you to generate music with just a few lines of code.
reason
Magenta comes with pre-trained models.
Users simply specify which model to use and the length of the song they want to create.
method
You can do this by following the steps below.
• Open Google Colab (it's free to use)
• Install Magenta
• Load the MelodyRNN model
• Generate music and convert it to MIDI or play audio
Supplementary code (partial excerpt)
1 | from magenta.models.melody_rnn import melody_rnn_sequence_generator, configs from magenta.protobuf import generator_pb2 config = configs.CONFIG_MAP[ 'basic_rnn' ] generator = melody_rnn_sequence_generator.MelodyRnnSequenceGenerator( config = config, checkpoint = None , # Specify pre-trained checkpoint steps_per_quarter=4, bundle=config.generator_bundle) # Specify conditions for melody generation generator_options = generator_pb2.GeneratorOptions() |
action
By simply turning these chords into templates and modifying them to your own settings, you can easily create your own original music.
What AI composition can do and its limitations
conclusion
AI is good at things like melody generation, arranging, and converting musical styles, but human ingenuity is needed to create songs that have emotion and a story.
reason
Magenta is based on music theory.
It's still difficult to deeply understand emotions and context and reflect them in songs.This is the current situation.
Benefits and limitations
What you can do:
• Automatic composition of 8 to 32 bars
• Rhythms and chord progressions according to style
• Repeated melody generation
Dislikes:
• The overall story of the song
• Link with lyrics
• Emotionally sensitive expressions
action
Regarding the melody created by AI,You can change the tone and adjust the tempo to suit your tastes.Let's stack them together.
How to play music on Colab
conclusion
With Google Colab, you can play music and output MIDI files using only Python code.
reason
The Magenta and note_seq libraries have built-in functionality for converting music to Wave format and playing it in a browser.
method
1 | from note_seq.sequences_lib import concatenate_sequences from note_seq import midi_io # Save the generated melody midi_io.sequence_proto_to_midi_file(sequence, 'output.mid') # Play (on Colab) note_seq.play_sequence(sequence, synth=midi_synth.fluidsynth) |
In this way, music generation and playbackCompleted in one notebookcan.
action
Write the code and check it immediately! Check how the melody you created sounds on the spot.
Is it okay if I don't have any knowledge of composition?
conclusion
Yes, even if you have no musical knowledge, it is possible to compose music using AI, as long as you have Python and a template.
reason
Magenta generates melodies based on existing music data,The music will come out natural even if the user does not know any music theory.
Safety points for beginners
• Automatically processes scales and chord progressions
• Can be regenerated any number of times even if it fails
• The created melody can be saved in MIDI format.
action
It's important to try it out first. If you find it difficult, try copying and pasting the code in this article and running it.
Summary: The first step in enjoying music with AI
With AI and Python,Anyone can create their own musicis.
Using the free, high-performance tools Magenta and Colab, you can compose music even if you can't read music.
Key points include:
• Easy to use, using only Python and Colab
• Advantages of using pre-trained models in Magenta
• Code can be easily reused by templating
Let's start with one song.
Why not try creating your own melody with AI?