notes = {
while (ab === undefined || ab.audioBuffer === undefined) {
console.log("waiting for audio to load");
await new Promise((r) => setTimeout(r, 10));
}
const frames = [];
const onsets = [];
const contours = [];
let pct = 0;
const model = "https://unpkg.com/@spotify/basic-pitch@1.0.1/model/model.json";
const basicPitch = new BasicPitch.BasicPitch(model);
await basicPitch.evaluateModel(
ab.audioBuffer,
(f, o, c) => {
frames.push(...f);
onsets.push(...o);
contours.push(...c);
},
(p) => {
pct = p;
}
);
const notes = BasicPitch.noteFramesToTime(
BasicPitch.addPitchBendsToNoteEvents(
contours,
BasicPitch.outputToNotesPoly(frames, onsets, 0.25, 0.25, 5)
)
);
return notes;
}