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

Metadata

Release files for musicbento-audio-to-midi 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for musicbento-audio-to-midi 1.0.1
File Size Uploaded Provenance
musicbento_audio_to_midi-1.0.1.tar.gz 11.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for musicbento-audio-to-midi 1.0.1
File Interpreter ABI Platform
musicbento_audio_to_midi-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 kB

Release files / musicbento_audio_to_midi-1.0.1.tar.gz

Download URL musicbento_audio_to_midi-1.0.1.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9ea316650c72a2fbd595709d030190c539ce22c678424ba2e1137c6ac0591b27
BLAKE2b-256 checksum
How to use checksums
4409686a74bfe246116dcd9c9276f5c66741c195e21240a2e8185d23aedf453d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release files / musicbento_audio_to_midi-1.0.1-py3-none-any.whl

Download URL musicbento_audio_to_midi-1.0.1-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
808a71fdb004ae17c06ff7c52e89a4b67ca421e35d259ebc2906e6674c3f5d41
BLAKE2b-256 checksum
How to use checksums
f669ef5022cbb02f5f8ee8ed621a69326696889d818d19e8086551cf481de5ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Security for musicbento-audio-to-midi 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

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