ランキングに戻る

spotify/basic-pitch

Pythonbasicpitch.io

A lightweight yet powerful audio-to-MIDI converter with pitch bend detection

lightweightmachine-learningmidimusicpitch-detectionpolyphonictranscriptionaudiopythontypescript
スター成長
スター
5.3k
フォーク
480
週間成長
Issue
42
2k4k
2022年5月2023年9月2025年2月2026年7月
成果物PyPIpip install basic-pitch
README

Basic Pitch Logo

License PyPI - Python Version Supported Platforms

Basic Pitch is a Python library for Automatic Music Transcription (AMT), using lightweight neural network developed by Spotify's Audio Intelligence Lab. It's small, easy-to-use, pip install-able and npm install-able via its sibling repo.

Basic Pitch may be simple, but it's is far from "basic"! basic-pitch is efficient and easy to use, and its multipitch support, its ability to generalize across instruments, and its note accuracy competes with much larger and more resource-hungry AMT systems.

Provide a compatible audio file and basic-pitch will generate a MIDI file, complete with pitch bends. Basic pitch is instrument-agnostic and supports polyphonic instruments, so you can freely enjoy transcription of all your favorite music, no matter what instrument is used. Basic pitch works best on one instrument at a time.

Research Paper

This library was released in conjunction with Spotify's publication at ICASSP 2022. You can read more about this research in the paper, A Lightweight Instrument-Agnostic Model for Polyphonic Note Transcription and Multipitch Estimation.

If you use this library in academic research, consider citing it:

@inproceedings{2022_BittnerBRME_LightweightNoteTranscription_ICASSP,
  author= {Bittner, Rachel M. and Bosch, Juan Jos\'e and Rubinstein, David and Meseguer-Brocal, Gabriel and Ewert, Sebastian},
  title= {A Lightweight Instrument-Agnostic Model for Polyphonic Note Transcription and Multipitch Estimation},
  booktitle= {Proceedings of the IEEE International Conference on Acoustics, Speech, and Signal Processing (ICASSP)},
  address= {Singapore},
  year= 2022,
}

Note that we have improved Basic Pitch beyond what was presented in this paper. Therefore, if you use the output of Basic Pitch in academic research, we recommend that you cite the version of the code that was used.

Demo

If, for whatever reason, you're not yet completely inspired, or you're just like so totally over the general vibe and stuff, checkout our snappy demo website, basicpitch.io, to experiment with our model on whatever music audio you provide!

Installation

basic-pitch is available via PyPI. To install the current release:

pip install basic-pitch

To update Basic Pitch to the latest version, add --upgrade to the above command.

Compatible Environments:

  • MacOS, Windows and Ubuntu operating systems
  • Python versions 3.7, 3.8, 3.9, 3.10, 3.11
  • For Mac M1 hardware, we currently only support python version 3.10. Otherwise, we suggest using a virtual machine.

Model Runtime

Basic Pitch comes with the original TensorFlow model and the TensorFlow model converted to CoreML, TensorFlowLite, and ONNX. By default, Basic Pitch will not install TensorFlow as a dependency unless you are using Python>=3.11. Instead, by default, CoreML will be installed on MacOS, TensorFlowLite will be installed on Linux and ONNX will be installed on Windows. If you want to install TensorFlow along with the default model inference runtime, you can install TensorFlow via pip install basic-pitch[tf].

Usage

Model Prediction

Model Runtime

By default, Basic Pitch will attempt to load a model in the following order:

  1. TensorFlow
  2. CoreML
  3. TensorFlowLite
  4. ONNX

Additionally, the module variable ICASSP_2022_MODEL_PATH will default to the first available version in the list.

We will explain how to override this priority list below. Because all other model serializations were converted from TensorFlow, we recommend using TensorFlow when possible. N.B. Basic Pitch does not install TensorFlow by default to save the user time when installing and running Basic Pitch.

Command Line Tool

This library offers a command line tool interface. A basic prediction command will generate and save a MIDI file transcription of audio at the <input-audio-path> to the <output-directory>:

basic-pitch <output-directory> <input-audio-path>

For example:

basic-pitch /output/directory/path /input/audio/path

To process more than one audio file at a time:

basic-pitch <output-directory> <input-audio-path-1> <input-audio-path-2> <input-audio-path-3>

Optionally, you may append any of the following flags to your prediction command to save additional formats of the prediction output to the <output-directory>:

  • --sonify-midi to additionally save a .wav audio rendering of the MIDI file.
  • --save-model-outputs to additionally save raw model outputs as an NPZ file.
  • --save-note-events to additionally save the predicted note events as a CSV file.

If you want to use a non-default model type (e.g., use CoreML instead of TF), use the --model-serialization argument. The CLI will change the loaded model to the type you prefer.

To discover more parameter control, run:

basic-pitch --help

Programmatic

predict()

Import basic-pitch into your own Python code and run the predict functions directly, providing an <input-audio-path> and returning the model's prediction results:

from basic_pitch.inference import predict
from basic_pitch import ICASSP_2022_MODEL_PATH

model_output, midi_data, note_events = predict(<input-audio-path>)
  • <minimum-frequency> & <maximum-frequency> (floats) set the maximum and minimum allowed note frequency, in Hz, returned by the model. Pitch events with frequencies outside of this range will be excluded from the prediction results.
  • model_output is the raw model inference output
  • midi_data is the transcribed MIDI data derived from the model_output
  • note_events is a list of note events derived from the model_output

Note: As mentioned previously, ICASSP_2022_MODEL_PATH will default to the runtime first supported in the list TensorFlow, CoreML, TensorFlowLite, ONNX.

predict() in a loop

To run prediction within a loop, you'll want to load the model yourself and provide predict() with the loaded model object itself to be used for repeated prediction calls, in order to avoid redundant and sluggish model loading.

import tensorflow as tf

from basic_pitch.inference import predict, Model
from basic_pitch import ICASSP_2022_MODEL_PATH

basic_pitch_model = Model(ICASSP_2022_MODEL_PATH))

for x in range():
    ...
    model_output, midi_data, note_events = predict(
        <loop-x-input-audio-path>,
        basic_pitch_model,
    )
    ...

predict_and_save()

If you would like basic-pitch orchestrate the generation and saving of our various supported output file types, you may use predict_and_save instead of using predict directly:

from basic_pitch.inference import predict_and_save

predict_and_save(
    <input-audio-path-list>,
    <output-directory>,
    <save-midi>,
    <sonify-midi>,
    <save-model-outputs>,
    <save-notes>,
    <model-path>
)

where:

  • <input-audio-path-list> & <output-directory>
    • directory paths for basic-pitch to read from/write to.
  • <save-midi>
    • bool to control generating and saving a MIDI file to the <output-directory>
  • <sonify-midi>
    • bool to control saving a WAV audio rendering of the MIDI file to the <output-directory>
  • <save-model-outputs>
    • bool to control saving the raw model output as a NPZ file to the <output-directory>
  • <save-notes>
    • bool to control saving predicted note events as a CSV file <output-directory>
  • <model-path>
    • str or pathlib.Path local path from where to load the model, can eg: use the path obtained with from basic_pitch import ICASSP_2022_MODEL_PATH

Model Input

Supported Audio Codecs

basic-pitch accepts all sound files that are compatible with its version of librosa, including:

  • .mp3
  • .ogg
  • .wav
  • .flac
  • .m4a

Mono Channel Audio Only

While you may use stereo audio as an input to our model, at prediction time, the channels of the input will be down-mixed to mono, and then analyzed and transcribed.

File Size/Audio Length

This model can process any size or length of audio, but processing of larger/longer audio files could be limited by your machine's available disk space. To process these files, we recommend streaming the audio of the file, processing windows of audio at a time.

Sample Rate

Input audio maybe be of any sample rate, however, all audio will be resampled to 22050 Hz before processing.

VST

Thanks to DamRsn for developing this working VST version of basic-pitch! - https://github.com/DamRsn/NeuralNote

Contributing

Contributions to basic-pitch are welcomed! See CONTRIBUTING.md for details.

basic-pitch is Copyright 2022 Spotify AB.

This software is licensed under the Apache License, Version 2.0 (the "Apache License"). You may choose either license to govern your use of this software only upon the condition that you accept all of the terms of either the Apache License.

You may obtain a copy of the Apache License at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the Apache License or the GPL License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for the specific language governing permissions and limitations under the Apache License.

関連リポジトリ
bytecodealliance/wasmtime

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Rustcrates.ioApache License 2.0wasmjit
wasmtime.dev
18.4k1.8k
picocss/pico

Minimal CSS Framework for semantic HTML

CSSnpmMIT Licensecsscss-framework
picocss.com
16.7k503
lsdefine/GenericAgent

Self-evolving agent: grows skill tree from 3.3K-line seed, achieving full system control with 6x less token consumption

PythonPyPIMIT Licenseai-agentautomation
github.com/lsdefine/GenericAgent
13.5k1.6k
supertone-inc/supertonic

Lightning-Fast, On-Device, Multilingual TTS — running natively via ONNX.

SwiftMIT Licensecppcsharp
huggingface.co/spaces/Supertone/supertonic-3
13.5k1.4k
picturepan2/spectre

Spectre.css - A Lightweight, Responsive and Modern CSS Framework

CSSnpmMIT Licensespectrecss
picturepan2.github.io/spectre/
11.3k784
leeoniya/uPlot

📈 A small, fast chart for time series, lines, areas, ohlc & bars

JavaScriptnpmMIT Licensetime-seriesohlc
10.3k461
AutoDarkMode/Windows-Auto-Night-Mode

Automatically switches between the dark and light theme of Windows 10 and Windows 11

C#GNU General Public License v3.0windowswindows-10
9.6k303
glidejs/glide

A dependency-free JavaScript ES6 slider and carousel. It’s lightweight, flexible and fast. Designed to slide. No less, no more

JavaScriptnpmMIT Licenseslidercarousel
glidejs.com
7.7k759
MichaIng/DietPi

Lightweight justice for your single-board computer!

ShellGNU General Public License v2.0dietpisbc
dietpi.com
6.2k557
graffle-js/graffle

Simple GraphQL Client for JavaScript. Minimal. Extensible. Type Safe. Runs everywhere.

TypeScriptnpmMIT Licensegraphqlgraphql-client
graffle.js.org
6.1k310
Diorser/LiteMonitor

一款轻量级、高度可定制的 Windows桌面和任务栏硬件性能监控工具,支持监测 CPU、GPU、内存、磁盘、网速、FPS 计数、插件扩展及内存清理。A lightweight, customizable hardware monitor for the Windows desktop & taskbar. Features CPU/GPU/RAM/Network monitoring, FPS counter, plugin support, and memory optimization.

C#cpu-monitorfps-counter
litemonitor.cn
5.8k234
ayn2op/discordo

A lightweight, secure, and feature-rich Discord terminal (TUI) client.

GoGo ModulesGNU General Public License v3.0godiscord
5.7k219