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

Input audio buffer is not mono #9

Closed lannodev closed 1 year ago

lannodev commented 1 year ago

Hi everyone 👋 Documentation say: "While you may use stereo audio as an input to our model, at prediction time, the channels of the input will be down-mixed to mono, and then analyzed and transcribed."

I'm trying to get stereo audio notes using basic-pitch and I got this error: Error: Input audio buffer is not mono! Number of channels is 2. Should be 1

Why this happens?

lannodev commented 1 year ago

I found a solution:

const audioCtx = new AudioContext({
          // This samplerate is required by basic-pitch
          sampleRate: 22050
})
const audioBuffer = await audioCtx.decodeAudioData(buffer);
const mono = audioBuffer.getChannelData(0);