How to Use MusicLang for Controllable Symbolic Music Generation

Mar 21, 2024 | Educational

Welcome to the world of MusicLang, your ultimate tool for generating controllable and symbolic music that you can export directly to your favorite Digital Audio Workstation (DAW) in MIDI format. Whether you want to experiment with chord progressions or generate creative musical ideas, MusicLang is your copilot in this musical journey!

Getting Started with MusicLang

To begin using MusicLang, you can either try it out in a Google Colab environment or install the package directly on your machine.

Try It Out in Google Colab

  • Click on this link to access the interactive Open In Colab.
  • Explore various examples of music generation.

Install the MusicLang Package

If you prefer to work locally, you can easily install the MusicLang package by running the following command in your terminal:

pip install musiclang_predict

Generating Music in Just a Few Lines

Once you have your environment set up, you can start generating music using just a few lines of code. Here’s a simple analogy to help you understand how MusicLang works.

Imagine you’re a chef looking to create a unique dish. You have a recipe (the code) with specific ingredients (parameters) that will guide you in making something delicious (the generated music). Each time you cook, you can decide how spicy (temperature) it will be, how many servings (tokens) you’ll prepare, and even tweak it for a special dinner (chord progression).

Basic Music Generation Example

Here’s how you can generate music:

from musiclang_predict import MusicLangPredictor

nb_tokens = 1024
temperature = 0.9  # Be cautious and stay below 1.0!
top_p = 1.0
seed = 16

ml = MusicLangPredictor("musiclang/musiclang-v2")
score = ml.predict(
    nb_tokens=nb_tokens,
    temperature=temperature,
    topp=top_p,
    rng_seed=seed
)
score.to_midi("test.mid")  # Export to MIDI

Controlling Chord Progressions

Are you thinking about a specific harmony? You can gain fine control over the chord progression of the generated music by specifying it in the form of a string!

from musiclang_predict import MusicLangPredictor

# Control the chord progression
chord_progression = "Am CM Dm E7 Am"
time_signature = (4, 4)  # Standard time signature

ml = MusicLangPredictor("musiclang/musiclang-v2")
score = ml.predict_chords(
    chord_progression,
    time_signature=time_signature,
    temperature=0.8,
    topp=1.0,
    rng_seed=42
)
score.to_midi("test.mid", tempo=120, time_signature=(4, 4))

Troubleshooting MusicLang

In case you encounter any issues, here are some tips:

  • Make sure you have installed the latest version of the musiclang_predict package.
  • Check if your Python environment supports the necessary libraries.
  • If an error occurs while generating music, ensure your temperature and top_p values are set within the recommended range.

For additional help, feel free to reach out. For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Working with Music Templates

MusicLang also allows you to use existing music pieces as templates. For instance, you can continue a Bach composition with a chosen chord progression:

from musiclang_predict import MusicLangPredictor

chord_progression = "Cm C7 E Fm F#dim G7 Cm"
song_name = "bach_847"  # Specify your song

ml = MusicLangPredictor("musiclang/musiclang-v2")
score = ml.predict_chords(
    chord_progression,
    score=corpus.get_midi_path_from_corpus(song_name),
    time_signature=(4, 4),
    nb_tokens=1024
)
score.to_midi("test.mid", tempo=110, time_signature=(4, 4))

Future Developments and Conclusion

MusicLang has exciting features on the horizon, such as control over instruments, performance improvements, and real-time generation capabilities. To learn more about how MusicLang works, visit our technical blog.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox