Synthesis

muspy.write_audio(path, music, realize_annotations=False, audio_format='auto', soundfont_path=None, rate=44100, gain=1, options=None)[source]

Write a Music object to an audio file.

Supported formats include WAV, AIFF, FLAC and OGA.

Parameters:
  • path (str or Path) – Path to write the audio file.

  • music (muspy.Music) – Music object to write.

  • realize_annotations (bool, default: False) – Should annotations be applied to loudness/timing of notes?

  • audio_format (str, default: 'auto') – File format to write. Defaults to infer from the extension.

  • soundfont_path (str or Path, optional) – Path to the soundfount file. Defaults to the path to the downloaded MuseScore General soundfont.

  • rate (int, default: 44100) – Sample rate (in samples per sec).

  • gain (float, default: 1) – Master gain (-g option) for Fluidsynth. The value must be in between 0 and 10, excluding. This can be used to avoid clipping.

  • options (str, optional) – Additional options to be passed to the FluidSynth call. The full command called is: fluidsynth -ni -F {path} -T {audio_format} -r {rate} -g {gain} -i {soundfont_path} {options} {midi_path}.

muspy.synthesize(music, realize_annotations=False, soundfont_path=None, rate=44100, gain=1, options=None)[source]

Synthesize a Music object to raw audio.

Parameters:
  • music (muspy.Music) – Music object to write.

  • realize_annotations (bool, default: False) – Should annotations be applied to loudness/timing of notes?

  • soundfont_path (str or Path, optional) – Path to the soundfount file. Defaults to the path to the downloaded MuseScore General soundfont.

  • rate (int, default: 44100) – Sample rate (in samples per sec).

  • gain (float, default: 1) – Master gain (-g option) for Fluidsynth. The value must be in between 0 and 10, excluding. This can be used to avoid clipping.

  • options (str, optional) – Additional options to be passed to the FluidSynth call. The full command called is: fluidsynth -T raw -F- -r {rate} -g {gain} -i {soundfont_path} {options} {midi_path}.

Returns:

Synthesized waveform.

Return type:

ndarray, dtype=int16, shape=(?, 2)