A lightweight yet powerful audio-to-MIDI converter with pitch bend detection
Python audiolightweightmachine-learningmidimusicpitch-detectionpolyphonicpythontranscriptiontypescript
Fix python depedencies and apply formatting to make CI work again (#175)
Pierre Thary33e90c6adbf1
diff --git a/basic_pitch/commandline_printing.py b/basic_pitch/commandline_printing.pyindex 1106ef7..0c21168 100644--- a/basic_pitch/commandline_printing.py+++ b/basic_pitch/commandline_printing.py@@ -43,6 +43,7 @@ def generating_file_message(output_type: str) -> None:"""print(f"\n\n{DEFAULT_PRINT_INDENT}Creating {output_type.replace('_', ' ').lower()}...")+def file_saved_confirmation(output_type: str, save_path: Union[pathlib.Path, str]) -> None:"""Print a confirmation that the file was saved succesfully@@ -54,6 +55,7 @@ def file_saved_confirmation(output_type: str, save_path: Union[pathlib.Path, stremoji = OUTPUT_EMOJIS.get(output_type, "")print(f"{DEFAULT_PRINT_INDENT}{emoji} Saved to {save_path}")+def failed_to_save(output_type: str, save_path: Union[pathlib.Path, str]) -> None:"""Print a failure to save message@@ -64,6 +66,7 @@ def failed_to_save(output_type: str, save_path: Union[pathlib.Path, str]) -> Non"""print(f"\n🚨 Failed to save {output_type.replace('_', ' ').lower()} to {save_path} \n")+@contextmanagerdef no_tf_warnings() -> Iterator[None]:"""diff --git a/basic_pitch/constants.py b/basic_pitch/constants.pyindex 2668704..bf4f632 100644--- a/basic_pitch/constants.py+++ b/basic_pitch/constants.py@@ -20,7 +20,7 @@ import numpy as npfrom enum import Enum-SEMITONES_PER_OCTAVE = 12 # for frequency bin calculations+SEMITONES_PER_OCTAVE = 12 # for frequency bin calculationsFFT_HOP = 256N_FFT = 8 * FFT_HOPdiff --git a/basic_pitch/inference.py b/basic_pitch/inference.pyindex 9bba9e8..24f02ea 100644--- a/basic_pitch/inference.py+++ b/basic_pitch/inference.py@@ -189,6 +189,7 @@ DEFAULT_SONIFICATION_SAMPLERATE = 44100DEFAULT_OVERLAPPING_FRAMES = 30DEFAULT_MIDI_VELOCITY_SCALE = 127+def window_audio_file(audio_original: npt.NDArray[np.float32], hop_size: int) -> Iterable[Tuple[npt.NDArray[np.float32], Dict[str, float]]]:diff --git a/basic_pitch/models.py b/basic_pitch/models.pyindex 87b1c24..61bd66a 100644--- a/basic_pitch/models.py+++ b/basic_pitch/models.py@@ -119,7 +119,11 @@ def onset_loss(return lambda x, y: transcription_loss(x, y, label_smoothing=label_smoothing)-def loss(label_smoothing: float = DEFAULT_LABEL_SMOOTHING, weighted: bool = False, positive_weight: float = DEFAULT_POSITIVE_WEIGHT) -> Dict[str, Any]:+def loss(+ label_smoothing: float = DEFAULT_LABEL_SMOOTHING,+ weighted: bool = False,+ positive_weight: float = DEFAULT_POSITIVE_WEIGHT,+) -> Dict[str, Any]:"""Creates a keras-compatible dictionary of loss functions to calculatethe loss for the contour, note and onset posteriorgrams.diff --git a/basic_pitch/nn.py b/basic_pitch/nn.pyindex 23db0a3..3eaf035 100644--- a/basic_pitch/nn.py+++ b/basic_pitch/nn.py@@ -49,7 +49,8 @@ class HarmonicStacking(tf.keras.layers.Layer):self.bins_per_semitone = bins_per_semitoneself.harmonics = harmonicsself.shifts = [- int(tf.math.round(SEMITONES_PER_OCTAVE * self.bins_per_semitone * log_base_b(float(h), 2))) for h in self.harmonics+ int(tf.math.round(SEMITONES_PER_OCTAVE * self.bins_per_semitone * log_base_b(float(h), 2)))+ for h in self.harmonics]self.n_output_freqs = n_output_freqsdiff --git a/basic_pitch/note_creation.py b/basic_pitch/note_creation.pyindex 862837b..753f5a1 100644--- a/basic_pitch/note_creation.py+++ b/basic_pitch/note_creation.py@@ -257,7 +257,9 @@ def note_events_to_midi(if not pitch_bend:continuepitch_bend_times = np.linspace(start_time, end_time, len(pitch_bend))- pitch_bend_midi_ticks = np.round(np.array(pitch_bend) * PITCH_BEND_SCALE / CONTOURS_BINS_PER_SEMITONE).astype(int)+ pitch_bend_midi_ticks = np.round(np.array(pitch_bend) * PITCH_BEND_SCALE / CONTOURS_BINS_PER_SEMITONE).astype(+ int+ )# This supports pitch bends up to 2 semitones# If we estimate pitch bends above/below 2 semitones, crop them here when adding them to the midi filepitch_bend_midi_ticks[pitch_bend_midi_ticks > N_PITCH_BEND_TICKS - 1] = N_PITCH_BEND_TICKS - 1@@ -270,7 +272,7 @@ def note_events_to_midi(def drop_overlapping_pitch_bends(- note_events_with_pitch_bends: List[Tuple[float, float, int, float, Optional[List[int]]]]+ note_events_with_pitch_bends: List[Tuple[float, float, int, float, Optional[List[int]]]],) -> List[Tuple[float, float, int, float, Optional[List[int]]]]:"""Drop pitch bends from any notes that overlap in time with another note"""note_events = sorted(note_events_with_pitch_bends)diff --git a/pyproject.toml b/pyproject.tomlindex 44db562..48e89cd 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -20,7 +20,9 @@ classifiers = [dependencies = ["coremltools; platform_system == 'Darwin'","librosa>=0.8.0",- "mir_eval>=0.6",+ # TODO: mir_eval 0.8.1+ introduces fixes to sonification that broke our tests+ # Likely we'd like to adapt the tests to release the constraint+ "mir_eval>=0.6,<=0.8.0","numpy>=1.18","onnxruntime; platform_system == 'Windows' and python_version < '3.11'","pretty_midi>=0.2.9",@@ -55,7 +57,9 @@ bp-download = "basic_pitch.data.download:main"data = ["basic_pitch[tf,test]","apache_beam",- "mirdata",+ # TODO: mirdata 0.3.9 moves dataset indexes files which breaks our tests+ # Adapt our codebase to release that constraint+ "mirdata<=0.3.8","smart_open","sox","ffmpeg-python"@@ -65,7 +69,6 @@ test = ["coverage>=5.0.2","pytest>=6.1.1","pytest-mock",- "wave","mido"]tf = [