### CLI Prediction Example Source: https://github.com/spotify/basic-pitch/blob/main/README.md An example of how to use the basic-pitch command-line tool with specific directory paths. ```bash basic-pitch /output/directory/path /input/audio/path ``` -------------------------------- ### Install Basic Pitch with TensorFlow Source: https://github.com/spotify/basic-pitch/blob/main/README.md Install Basic Pitch with TensorFlow as the model inference runtime. This is recommended if you want to use TensorFlow explicitly. ```bash pip install basic-pitch[tf] ``` -------------------------------- ### Install Basic Pitch Source: https://github.com/spotify/basic-pitch/blob/main/README.md Install the current release of Basic Pitch using pip. Add `--upgrade` to update to the latest version. ```bash pip install basic-pitch ``` ```bash pip install basic-pitch --upgrade ``` -------------------------------- ### Run All Tests with Tox Source: https://github.com/spotify/basic-pitch/blob/main/CONTRIBUTING.md Execute this command to run all end-to-end tests for the project using tox. Ensure tox is installed in your environment. ```shell tox ``` -------------------------------- ### Build Debug Version of Basic Pitch Source: https://github.com/spotify/basic-pitch/blob/main/CONTRIBUTING.md Use this command to compile the package locally and install a symbolic link for debugging purposes. This allows for using debuggers like gdb or lldb. ```shell python3 setup.py build develop ``` -------------------------------- ### Programmatic Prediction Source: https://github.com/spotify/basic-pitch/blob/main/README.md Import and use the predict function directly in your Python code. Provide the input audio path to get model output, MIDI data, and note events. ```python from basic_pitch.inference import predict from basic_pitch import ICASSP_2022_MODEL_PATH model_output, midi_data, note_events = predict() ``` -------------------------------- ### CLI Help Command Source: https://github.com/spotify/basic-pitch/blob/main/README.md Run this command to discover all available parameter controls and options for the basic-pitch CLI. ```bash basic-pitch --help ``` -------------------------------- ### Basic Pitch Command Line Tool Source: https://github.com/spotify/basic-pitch/blob/main/README.md The Basic Pitch library provides a command-line interface for transcribing audio files to MIDI. You can specify input audio paths and an output directory, along with optional flags to save additional output formats. ```APIDOC ## Basic Pitch Command Line Tool ### Description This command-line tool transcribes audio files to MIDI format. It takes an output directory and one or more input audio file paths as arguments. Optional flags can be used to save additional output formats. ### Usage ```bash basic-pitch ``` To process multiple files: ```bash basic-pitch ``` ### Optional Flags - `--sonify-midi`: Additionally save a `.wav` audio rendering of the MIDI file. - `--save-model-outputs`: Additionally save raw model outputs as an NPZ file. - `--save-note-events`: Additionally save the predicted note events as a CSV file. - `--model-serialization`: Use a non-default model type (e.g., CoreML instead of TF). ### Help To discover more parameter control, run: ```bash basic-pitch --help ``` ``` -------------------------------- ### CLI Prediction for Multiple Files Source: https://github.com/spotify/basic-pitch/blob/main/README.md Process multiple audio files simultaneously by listing their paths after the output directory. ```bash basic-pitch ``` -------------------------------- ### Basic CLI Prediction Source: https://github.com/spotify/basic-pitch/blob/main/README.md Use this command to generate a MIDI file transcription of audio. Specify the output directory and the input audio file path. ```bash basic-pitch ``` -------------------------------- ### Programmatic Prediction and Saving Source: https://github.com/spotify/basic-pitch/blob/main/README.md Use predict_and_save to automate the generation and saving of various output file types. Specify input paths, output directory, and boolean flags for desired outputs. ```python from basic_pitch.inference import predict_and_save predict_and_save( , , , , , , ) ``` -------------------------------- ### predict() - Programmatic Usage Source: https://github.com/spotify/basic-pitch/blob/main/README.md The `predict()` function from the `basic_pitch.inference` module allows you to transcribe audio directly within your Python code. It returns the raw model output, MIDI data, and note events. ```APIDOC ## predict() ### Description This function transcribes an audio file programmatically. It returns the raw model output, transcribed MIDI data, and a list of note events. Optional parameters can control the frequency range of detected notes. ### Method Signature ```python from basic_pitch.inference import predict from basic_pitch import ICASSP_2022_MODEL_PATH model_output, midi_data, note_events = predict(, minimum_frequency=None, maximum_frequency=None) ``` ### Parameters - ``: Path to the input audio file. - `` (*float*, optional): Sets the minimum allowed note frequency in Hz. Notes below this will be excluded. - `` (*float*, optional): Sets the maximum allowed note frequency in Hz. Notes above this will be excluded. ### Returns - `model_output`: The raw model inference output. - `midi_data`: The transcribed MIDI data. - `note_events`: A list of note events. ### Notes - The default model used is `ICASSP_2022_MODEL_PATH`. - Frequencies are in Hz. ``` -------------------------------- ### predict_and_save() Source: https://github.com/spotify/basic-pitch/blob/main/README.md The `predict_and_save()` function handles both the transcription and saving of various output formats (MIDI, WAV, NPZ, CSV) to a specified directory. ```APIDOC ## predict_and_save() ### Description This function orchestrates the audio transcription process and saves the results in multiple formats to a specified output directory. It simplifies the workflow by handling both prediction and file saving. ### Method Signature ```python from basic_pitch.inference import predict_and_save predict_and_save( , , save_midi=True, sonify_midi=False, save_model_outputs=False, save_notes=False, model_path=None ) ``` ### Parameters - ``: A list of paths to the input audio files. - ``: The directory where output files will be saved. - `save_midi` (*bool*, optional): If True, saves the transcribed MIDI file. Defaults to True. - `sonify_midi` (*bool*, optional): If True, saves a WAV audio rendering of the MIDI file. Defaults to False. - `save_model_outputs` (*bool*, optional): If True, saves raw model outputs as an NPZ file. Defaults to False. - `save_notes` (*bool*, optional): If True, saves predicted note events as a CSV file. Defaults to False. - `model_path` (*str* or *pathlib.Path*, optional): Local path to the model to load. Defaults to `ICASSP_2022_MODEL_PATH` if not provided. ``` -------------------------------- ### predict() in a loop Source: https://github.com/spotify/basic-pitch/blob/main/README.md For repeated predictions, it's more efficient to load the model once and pass the loaded model object to `predict()` to avoid redundant loading. ```APIDOC ## predict() in a loop ### Description To optimize performance when making multiple predictions in succession, load the model once and reuse it across calls to `predict()`. This avoids the overhead of loading the model repeatedly. ### Method Signature ```python 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(num_iterations): # ... process audio file x ... model_output, midi_data, note_events = predict( , basic_pitch_model, ) # ... process results ... ``` ### Parameters - ``: The path to the audio file for the current iteration. - `basic_pitch_model`: The pre-loaded model object. ### Notes - Ensure the `Model` is initialized with the correct model path. ``` -------------------------------- ### BibTeX Citation for Research Paper Source: https://github.com/spotify/basic-pitch/blob/main/README.md Use this BibTeX entry to cite the research paper associated with Basic Pitch if you use it in academic research. ```bibtex @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, } ``` -------------------------------- ### Programmatic Prediction in a Loop Source: https://github.com/spotify/basic-pitch/blob/main/README.md To optimize repeated predictions, load the model once using the Model class and pass the loaded model object to the predict function. This avoids redundant model loading. ```python 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( , basic_pitch_model, ) ... ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.