Skip to main content

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

musicbento_audio_to_midi-1.0.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

musicbento_audio_to_midi-1.0.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file musicbento_audio_to_midi-1.0.0.tar.gz.

File metadata

  • Download URL: musicbento_audio_to_midi-1.0.0.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

Hashes for musicbento_audio_to_midi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 74fc3ec2ff34b9ebc52e945d7bb7b101b2025f64dc9551f5a3f18f575096ae09
MD5 ac3f226627cd06abbead96fe5edcc83d
BLAKE2b-256 cb8d2ef43e23af1e9fbca4de0ac451095d1f8f2aa1835a22d9d6a8a961a7a5cc

See more details on using hashes here.

File details

Details for the file musicbento_audio_to_midi-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for musicbento_audio_to_midi-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55f9ec47a4c4912b80b8f34781a44f3ee7c678f4b31c1654548d9b1340a2d6af
MD5 9327b6cec8425c55fdd91a21396abc37
BLAKE2b-256 3077a4b8fad077ed46ceb642ab860ab8715d562a4058c58c8e0a28db6ee0a83f

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.1

2 files

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page