Skip to content

How can I make bbc/audiowaveform peaks match wavesurfer.js'? #2769

Answered by katspaugh
jvtrigueros asked this question in Q&A
Discussion options

You must be logged in to vote

Wavesurfer does a max value sampling, so waveforms tends to look fat when the data has outliers.
Setting a lower sample rate might help (try passing --pixels-per-second 1 to audiowaveform).

If it doesn't help, try smoothening the data by averaging the values (don't run the Python script in this case):

const averagePeaks = []
const sampleSize = 10
const maxValue = 127 // audiowaveform peaks are -127..127
for (let i = 0; i < peaks.length; i += sampleSize) {
  averagePeaks.push(
    peaks.slice(i, i + sampleSize).reduce((sum, v) => sum + Math.abs(v)) / sampleSize / maxValue
  )
}
return averagePeaks

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by jvtrigueros
Comment options

You must be logged in to vote
1 reply
@katspaugh
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants