How this BPM finder works
Four steps, none of them requiring a server or any WASM.
First the file is decoded to raw samples. decodeAudioData handles MP3, M4A, WAV,
OGG, FLAC and the audio track of an MP4 or MOV, which is why no conversion step is
needed.
Then the samples are mixed to mono and measured in 10 millisecond windows to produce an amplitude envelope. Mono matters: a kick drum panned to one side would otherwise register at half strength.
Next, peaks in that envelope are compared against a rolling local average rather than a fixed threshold. That is what lets a quiet intro and a loud chorus both contribute onsets, instead of the chorus dominating.
Finally the gaps between onsets are histogrammed. Each gap is converted to a tempo, folded into the 70 to 180 range, and bucketed. The most populated bucket wins, and the share of gaps that agree with it becomes the confidence figure.
A BPM counter that admits when it is unsure
Because a bare number implies certainty this method does not have.
A four-on-the-floor dance track will come back with high agreement, because almost every interval points at the same tempo. A solo piano piece with rubato will come back with a number too, and that number will be close to meaningless.
Reporting the agreement lets you tell those apart. Above roughly 30 percent, trust it. Below, treat it as a starting point and check it by tapping.
To find BPM of a song, half and double are both right
This is inherent to tempo, not a flaw in the detection. A groove at 140 BPM has a half-time feel at 70 and a double-time feel at 280, and all three describe the same music. Which one is "the" tempo depends on where you feel the pulse, which is a musical judgement rather than a measurement.
That is why the result shows the half and double values alongside the main answer. If the number looks wrong by a factor of two, the correct one is right there.
When to tap instead
Automatic detection needs percussive onsets. Give it speech, ambient pads, legato strings or a freely played instrument and there is nothing sharp for it to latch onto.
Tapping works on all of those, because you are supplying the beat perception the algorithm lacks. Three taps is the minimum, more is better, and intervals more than twice the median are discarded so one mistimed tap does not spoil the result.
Using tempo against picture
If you are cutting to music, the tempo is the grid your edits should sit on. At 120 BPM a beat is 0.5 seconds, which is 12 frames at 24fps and 15 at 30fps, and a bar of four is 48 frames at 24fps. Landing cuts on bars rather than beats is most of what makes an edit feel composed.
Everything happens in this tab. The file is decoded locally and never uploaded.