Skip to content

Latest commit

 

History

History
108 lines (85 loc) · 4.2 KB

README.md

File metadata and controls

108 lines (85 loc) · 4.2 KB

NSynth-MIDI-Renderer

This project is intended to provide a simple way to synthesize any MIDI sequence to an audio file using the notes of the NSynth dataset. It works by substituting each note in the sequence with the specified instrument, pitch and velocity for all the notes in the sequence.

Quick start

Clone this repository to your system.

$ git clone https://github.com/hmartelb/NSynth-MIDI-Renderer.git

To start synthesizing audios, you need to download the NSynth dataset and some MIDI files. Here are two useful links:

The requirements.txt file is built for Python 3.10; for different versions of Python you may need different versions of these packages. Then open a new terminal in the master directory and install the dependencies from requirements.txt by executing this command:

$ pip install -r requirements.txt

How to use it

For the general use case, 3 parameters must be specified:

  1. The path to the NSynth Dataset (audios directory)
  2. The MIDI file (*.mid, *.midi) containing the sequence
  3. The output path and name for the audio (*.wav)

Run from the main

To run the program, execute the following command in your terminal:

$ python NoteSynthesizer.py --db <path_to_nsynth> --seq <midi_filename> --output <audio_filename>

Additionally, there are some optional parameters:

Import the NoteSynthesizer Class into a Python script

It is also possible to use the NoteSynthesizer Class in a Python script to have custom functionality. Here is a generic way to import and use it:

from NoteSynthesizer import NoteSynthesizer

# Initialize variables here
# ...

# Create the NoteSynthesizer instance
synth = NoteSynthesizer(path_to_nsynth, sr, velocities, preload)  

# Generate the audio for a given MIDI sequence
y, _ = synth.render_sequence(sequence, instrument, source_type, preset, transpose, playback_speed, duration_scale)

# Save or process the audio (y)
# ...

Examples

The files in the /output folder have been generated using different instruments, with sample rate 44100, playback speed 1 and duration scale 4, leaving the rest of optional parameters as default. The files are named using the following convention:

<midi_name>_<instrument>_<source_type>_<preset>.wav

Citation

If you use this code in your research, please cite it as below:

@software{Martel_NSynth-MIDI-Renderer_2019,
    author = {Martel, Héctor},
    month = {8},
    title = {{NSynth-MIDI-Renderer: Sample based concatenative synthesizer for the NSynth dataset.}},
    url = {https://github.com/hmartelb/NSynth-MIDI-Renderer},
    version = {1.0.0},
    year = {2019}
}

For questions or further discussions, please write me an email to hmartelb@hotmail.com.

Licence

MIT License
Copyright (c) 2019 Héctor Martel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.