spotify / basic-pitch-ts

A lightweight yet powerful audio-to-MIDI converter with pitch bend detection.
https://basicpitch.io
Apache License 2.0
212 stars 15 forks source link

Why is the model file not exported by default? #18

Open blakekrammes opened 3 months ago

blakekrammes commented 3 months ago

I'm trying to use Basic Pitch in my Next.js application and struggling to read the model.json file required to initialize the class. Why is the model not baked into the initializer? Why is the model not importable from the Basic Pitch module? Maybe I'm missing something obvious.

Screen Shot 2024-03-12 at 10 41 18 AM

Thanks!

drubinstein commented 3 months ago

When we wrote this, we wanted a way to keep the models versioned and we wanted to additionally serve the model from either a CDN or backend service. We advise you consciously make the decision on which model you want to use and include it yourself. You can find a version of the model in this repo.

blakekrammes commented 3 months ago

Thanks for the quick response. The file you linked to is what I'm trying to initialize the class with. Is there any way to import that model from the node module as is done for the class itself?

import { BasicPitch } from '@spotify/basic-pitch';
blakekrammes commented 3 months ago

So would you recommend just copying the model file to a folder in my application code? I was concerned that if updates were made to it I would have to manually update my application as well. I was hoping I could keep it in sync with the node module itself.

paulrosen commented 3 months ago

What I did is copy both https://raw.githubusercontent.com/spotify/basic-pitch-ts/main/model/model.json and https://raw.githubusercontent.com/spotify/basic-pitch-ts/main/model/group1-shard1of1.binto my public folder and initialize like this:

new BasicPitch(`${baseUrl}model.json`);

I plan to check for updates to those files periodically, but I know nothing has changed because we're not dependent on any other server at runtime.

blakekrammes commented 3 months ago

Thanks, Paul.

What is the 2nd file? ../group1-shard1of1.bin.

Also, I'm a fan of abc.js; I used it in a personal project a few years ago. I guess the JS music world isn't too large.

drubinstein commented 3 months ago

Thanks for the links @paulrosen . If anything changes in a way that would cause a break with basic-pitch-ts, we'd release a new major version. But generally, it's probably good practice not to trust all updates to a model. Sometimes a new version of a model could work worse for tasks it previously worked well with even if there's an overall improvement.