Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Spotify Waveform Data Generation from Audio Analysis API
const fs = require('fs')
const data = require('./track.json')
let duration = data.track.duration
let segments = data.segments.map(segment => {
return {
start: segment.start / duration,
duration: segment.duration / duration,
loudness: 1 - (Math.min(Math.max(segment.loudness_max, -35), 0) / -35)
}
})
let min = Math.min(...segments.map(s => s.loudness))
let max = Math.max(...segments.map(s => s.loudness))
let levels = []
for (let i = 0.000; i < 1; i += 0.001) {
let s = segments.find(segment => {
return i <= segment.start + segment.duration
})
let loudness = Math.round((s.loudness / max) * 100) / 100
levels.push(loudness)
}
fs.writeFile('levels.json', JSON.stringify(levels), (err) => {
console.log(err)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment