Detecting Sadness Based on Your Spotify Listening History

Introducing Sad Boi Detector

Lee Martin
Aug 2, 2019 · 3 min read
Image for post
Image for post
“Sad Boi” logo by Joe Mortimer
A measure from 0.0 to 1.0 describing the musical positiveness conveyed by a track. Tracks with high valence sound more positive (e.g. happy, cheerful, euphoric), while tracks with low valence sound more negative (e.g. sad, depressed, angry).
Image for post
Image for post
  • Medium term: approximately last 6 months
  • Short term: approximately last 4 weeks
const spotify = axios.create({
baseURL: 'https://api.spotify.com/v1/',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
}
}
let term = 'medium-term'spotify.get(`me/top/tracks?limit=50&time_range=${term}`)
.then(response => {
let ids = response.data.items.map(item => item.id).join(",")
})
spotify.get(`audio-features/?ids=${ids}`)
.then(response => {
let features = response.data.audio_features
let mean = _.meanBy(features, f => 1 - feature.valence)
let score = Math.round(mean * 100)
})

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store