Skip to content

Commit

Permalink
Merge pull request #84 from spotify/jgao/improve_error_handling_and_m…
Browse files Browse the repository at this point in the history
…essaging

#7: Improve error handling and messaging
  • Loading branch information
johngao2 committed May 19, 2023
2 parents 7524efc + 461cfef commit f1ac01f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,6 @@ cython_debug/

# junit
junit.xml

# intellij
.idea/
2 changes: 1 addition & 1 deletion basic_pitch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import pathlib

__author__ = "Spotify"
__version__ = "0.2.4"
__version__ = "0.2.5"
__email__ = "[email protected]"
__demowebsite__ = "https://basicpitch.io"
__description__ = "Basic Pitch, a lightweight yet powerful audio-to-MIDI converter with pitch bend detection."
Expand Down
24 changes: 14 additions & 10 deletions basic_pitch/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import json
import os
import pathlib
import traceback
from typing import Dict, List, Optional, Sequence, Tuple, Union

from tensorflow import Tensor, signal, keras, saved_model
Expand Down Expand Up @@ -405,33 +404,38 @@ def predict_and_save(
try:
np.savez(model_output_path, basic_pitch_model_output=model_output)
file_saved_confirmation(OutputExtensions.MODEL_OUTPUT_NPZ.name, model_output_path)
except Exception:
except Exception as e:
failed_to_save(OutputExtensions.MODEL_OUTPUT_NPZ.name, model_output_path)
raise e

if save_midi:
midi_path = build_output_path(audio_path, output_directory, OutputExtensions.MIDI)
try:
midi_path = build_output_path(audio_path, output_directory, OutputExtensions.MIDI)
except IOError as e:
raise e
try:
midi_data.write(str(midi_path))
file_saved_confirmation(OutputExtensions.MIDI.name, midi_path)
except Exception:
except Exception as e:
failed_to_save(OutputExtensions.MIDI.name, midi_path)
raise e

if sonify_midi:
midi_sonify_path = build_output_path(audio_path, output_directory, OutputExtensions.MIDI_SONIFICATION)
try:
infer.sonify_midi(midi_data, midi_sonify_path, sr=sonification_samplerate)
file_saved_confirmation(OutputExtensions.MIDI_SONIFICATION.name, midi_sonify_path)
except Exception:
except Exception as e:
failed_to_save(OutputExtensions.MIDI_SONIFICATION.name, midi_sonify_path)
raise e

if save_notes:
note_events_path = build_output_path(audio_path, output_directory, OutputExtensions.NOTE_EVENTS)
try:
save_note_events(note_events, note_events_path)
file_saved_confirmation(OutputExtensions.NOTE_EVENTS.name, note_events_path)
except Exception:
except Exception as e:
failed_to_save(OutputExtensions.NOTE_EVENTS.name, note_events_path)
except Exception:
print("🚨 Something went wrong 😔 - see the traceback below for details.")
print("")
print(traceback.format_exc())
raise e
except Exception as e:
raise e
50 changes: 29 additions & 21 deletions basic_pitch/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import argparse
import os
import pathlib
import traceback

from basic_pitch import ICASSP_2022_MODEL_PATH

Expand Down Expand Up @@ -127,27 +128,34 @@ def main() -> None:
for audio_path in audio_path_list:
verify_input_path(audio_path)

predict_and_save(
audio_path_list,
output_dir,
args.save_midi,
args.sonify_midi,
args.save_model_outputs,
args.save_note_events,
pathlib.Path(args.model_path),
args.onset_threshold,
args.frame_threshold,
args.minimum_note_length,
args.minimum_frequency,
args.maximum_frequency,
args.multiple_pitch_bends,
not args.no_melodia,
pathlib.Path(args.debug_file) if args.debug_file else None,
args.sonification_samplerate,
args.midi_tempo,
)

print("\n✨ Done ✨\n")
try:
predict_and_save(
audio_path_list,
output_dir,
args.save_midi,
args.sonify_midi,
args.save_model_outputs,
args.save_note_events,
pathlib.Path(args.model_path),
args.onset_threshold,
args.frame_threshold,
args.minimum_note_length,
args.minimum_frequency,
args.maximum_frequency,
args.multiple_pitch_bends,
not args.no_melodia,
pathlib.Path(args.debug_file) if args.debug_file else None,
args.sonification_samplerate,
args.midi_tempo,
)
print("\n✨ Done ✨\n")
except IOError as ioe:
print(ioe)
except Exception as e:
print("🚨 Something went wrong 😔 - see the traceback below for details.")
print("")
print(e)
print(traceback.format_exc())


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.4
current_version = 0.2.5
commit = True
tag = True

Expand Down

0 comments on commit f1ac01f

Please sign in to comment.