Python bindings for using SoundFonts (sf2/sf3/sfo formats), generating audio samples, and playing MIDI songs
Low maintenance activity. Last release 18 months ago, commits in 1 of the last 26 weeks. Weaker on commit activity and recent releases.
pip install tinysoundfontREADME as published on PyPI with version 0.3.7.
TinySoundFont-pybind
This tinysoundfont Python package provides Python bindings for
TinySoundFont and lets you
generate audio using SoundFont instruments (.sf2, .sf3, or .sfo files) in
Python. The audio data can be played by
PyAudio in a separate thread if requested.
This package also includes support for loading and playing MIDI data using a
SoundFont instrument.
What you might want to use this package for:
- Play MIDI files with SoundFonts in Python
- Play MIDI files with modifications and customizations (mute tracks, change instruments, etc.)
- Procedurally generate and play music or sounds
- Play music and sounds in an interactive way in your Python program
Some advantages of this package specifically compared to some others:
- Permissive MIT licensing that works well with commercial products like games
- No dependencies on other installed libraries for audio data generation
Documentation
Main tinysoundfont documentation
The documentation contains:
Installation
This package depends on pyaudio for playing sounds. To install pyaudio and
tinysoundfont for common platforms:
Windows
py -m pip install pyaudio tinysoundfont
macOS
brew install portaudio
pip install pyaudio tinysoundfont
GNU/Linux (Ubuntu)
sudo apt install python3-pyaudio
pip install tinysoundfont
Basic Usage
Here is an example program that plays a chord:
import tinysoundfont
import time
synth = tinysoundfont.Synth()
sfid = synth.sfload("florestan-piano.sf2")
synth.program_select(0, sfid, 0, 0)
synth.start()
time.sleep(0.5)
synth.noteon(0, 48, 100)
synth.noteon(0, 52, 100)
synth.noteon(0, 55, 100)
time.sleep(0.5)
synth.noteoff(0, 48)
synth.noteoff(0, 52)
synth.noteoff(0, 55)
time.sleep(0.5)