musicbento-audio-to-midi
Audio to MIDI conversion for Python using Spotify Basic Pitch.
Built by MusicBento.com, with an interactive Audio to MIDI Converter.
Install
pip install musicbento-audio-to-midi
Python 3.10 and 3.11 are supported. Spotify Basic Pitch 0.4.0 currently depends on runtime packages that do not support Python 3.12+ consistently, so this package declares the compatible range explicitly.
Convert a file
from musicbento_audio_to_midi import convert_audio_to_midi
result = convert_audio_to_midi(
"input.wav",
"output.mid",
)
print(result.note_count)
print(result.duration_seconds)
Work with bytes
from musicbento_audio_to_midi import convert_audio_to_midi
with open("input.mp3", "rb") as file:
audio_bytes = file.read()
result = convert_audio_to_midi(
audio_bytes,
source_name="input.mp3",
)
with open(result.filename, "wb") as file:
file.write(result.midi_bytes)
str paths, pathlib.Path, bytes, bytearray, BytesIO, and binary file-like objects are supported.
For raw bytes, pass source_name when you know the original file name. It is used for format validation, the temporary file suffix, and the generated MIDI filename.
Reuse the loaded model
Loading the transcription model is relatively expensive. For multiple conversions, reuse one converter:
from musicbento_audio_to_midi import AudioToMidiConverter
converter = AudioToMidiConverter()
converter.load()
first = converter.convert("first.wav")
second = converter.convert("second.wav")
The model is loaded once and reused by subsequent conversions.
Settings
from musicbento_audio_to_midi import (
AudioToMidiConverter,
AudioToMidiSettings,
)
settings = AudioToMidiSettings(
onset_threshold=0.5,
frame_threshold=0.3,
minimum_note_length_ms=127.7,
midi_tempo=120,
minimum_frequency_hz=55,
maximum_frequency_hz=1760,
)
converter = AudioToMidiConverter(settings)
result = converter.convert("input.wav")
Defaults include:
- maximum file size: 100 MB
- maximum duration: 8 minutes
- onset threshold: 0.5
- frame threshold: 0.3
- minimum note length: 127.7 ms
- MIDI tempo: 120 BPM
Result
Every conversion returns an AudioToMidiResult:
result.title
result.filename
result.note_count
result.duration_seconds
result.midi_bytes
result.mime_type
result.output_path
result.notes
Each item in result.notes contains start/end time, MIDI pitch, amplitude, and optional pitch bends.
Supported audio
MusicBento recognizes these file extensions:
- MP3
- WAV
- M4A
- AAC
- OGG
- FLAC
- WebM
Actual decoding support depends on the audio libraries available in the Python environment. WAV is the most portable choice. Compressed formats can depend on libsndfile or FFmpeg support on the host system.
Errors
Failures raise AudioToMidiError with a machine-readable code.
from musicbento_audio_to_midi import AudioToMidiError, convert_audio_to_midi
try:
convert_audio_to_midi("input.wav")
except AudioToMidiError as error:
print(error.code)
Examples include file-too-large, audio-too-long, decode-failed, model-load-failed, transcription-failed, and no-notes-detected.
Privacy
Audio transcription and MIDI generation run locally in the Python process. This package does not upload audio content to MusicBento.com.
For a ready-to-use browser tool, visit MusicBento.com Audio to MIDI Converter.
Basic Pitch
This package uses Spotify Basic Pitch, distributed separately under the Apache License 2.0 through its own PyPI package.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file musicbento_audio_to_midi-1.0.1.tar.gz.
File metadata
- Download URL: musicbento_audio_to_midi-1.0.1.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ea316650c72a2fbd595709d030190c539ce22c678424ba2e1137c6ac0591b27
|
|
| MD5 |
2fe178570d82cf60cd95acb075cf27f2
|
|
| BLAKE2b-256 |
4409686a74bfe246116dcd9c9276f5c66741c195e21240a2e8185d23aedf453d
|
File details
Details for the file musicbento_audio_to_midi-1.0.1-py3-none-any.whl.
File metadata
- Download URL: musicbento_audio_to_midi-1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
808a71fdb004ae17c06ff7c52e89a4b67ca421e35d259ebc2906e6674c3f5d41
|
|
| MD5 |
c6c8a321d55dbf2ae78fe52e508cfc3b
|
|
| BLAKE2b-256 |
f669ef5022cbb02f5f8ee8ed621a69326696889d818d19e8086551cf481de5ed
|