-
-
Save catalinmiron/a3259683a1a54aae9b9e7b4ab95e943e to your computer and use it in GitHub Desktop.
Spotify Waveform Data Generation from Audio Analysis API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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