

With your virtual environment activated, run the following command, making sure to replace /path/to/basic_rnn.mag with an actual path to the. This refers to how many 16th step durations the generated tune will be. Let's create some melodies using middle C as the starting note, which in this format would be "".Įach melody will be 8 measures in length, corresponding to the -num_steps flag. This can be a MIDI file using the -prime_midi flag, or a format that Magenta uses which is a string representation of a Python list using the -prime_melody flag. When generating a melody, we have to provide a priming melody.

Save it to the current directory you are working in. We're going to use this as a starting point to generate some melodies. mag bundle file for a recurrent neural network that has been trained on thousands of MIDI files. Rather than training our own model, let's use one of the pre-trained melody models provided by the TensorFlow team.įirst, download this file, which is a. For this post, we're going to be using the Melody recurrent neural network model. This will give you access to both the Magenta and TensorFlow Python modules for development, as well as scripts to work with all of the models that Magenta has available. Run the following command to install Magenta in your virtual environment, it's a pretty big library with a good amount of dependencies so it might take a bit of time: I am using Python 3.6.5, but Magenta is compatible with both Python 2 and 3. Make sure you create a virtual environment before installing. Installing Magentaįirst we need to install Magenta, which can be done using pip.

Let's walk through the basics of setting up Magenta and programmatically generating some simple melodies in MIDI file format. I even published a paper talking about it in an undergrad research journal my freshman year of college. Since I started learning how to code, one of the things that has always fascinated me was the concept of computers artificially creating music. Magenta, a Python library built by the TensorFlow team, makes it easier to process music and image data in particular.

Machine Learning is all the rage these days, and with open source frameworks like TensorFlow developers have access to a range of APIs for using machine learning in their projects.
