.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/musiclang_api/03_generate_from_scratch.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_musiclang_api_03_generate_from_scratch.py: Create a drum'n'bass sample ================================================== In this example : - We directly generate a drum'n'bass sample from scratch using the `generate_from_scratch` method of the MusicLang API - We save the predicted score to a midi file .. GENERATED FROM PYTHON SOURCE LINES 10-26 .. code-block:: Python from maidi import MidiScore from maidi import instrument from maidi.integrations.api import MusicLangAPI import os # Assuming API_URL and MUSICLANG_API_KEY are set in the environment # Call the musiclang API to predict the score api = MusicLangAPI(api_key=os.getenv("MUSICLANG_API_KEY"), verbose=True) instruments = [instrument.DRUMS, instrument.ELECTRIC_BASS_FINGER] nb_bars = 4 time_signature = (4, 4) tempo = 120 predicted_score = api.generate_from_scratch(instruments=instruments, nb_bars=nb_bars, ts=time_signature, tempo=tempo) predicted_score.write("predicted_score.mid") .. _sphx_glr_download_auto_examples_musiclang_api_03_generate_from_scratch.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 03_generate_from_scratch.ipynb <03_generate_from_scratch.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 03_generate_from_scratch.py <03_generate_from_scratch.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 03_generate_from_scratch.zip <03_generate_from_scratch.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_