Spotify - searching for silences in a track

喜你入骨 提交于 2019-12-08 15:42:42

Analysis comes from a company called EchoNest, which was bought by Spotify some time ago. You can find the documentation for the analysis here.

Segments include a loudness_max value which indicates the relatively loudness of that specific section of music (in db). Normalize those values over the song and look for segments that have a low relative loudness:

def normalize_loudness(filename):
    d = json.load(open(filename, 'r'))
    x = [_['start'] for _ in d['segments']]
    l = [_['loudness_max'] for _ in d['segments']]
    min_l = min(l)
    max_l = max(l)
    norm_l = [(_ - min_l)/(max_l - min_l) for _ in l]
    return (x, norm_l)

Using this on the song "Miss Jackson" by Panic! At The Disco, we can plot the normalized loudness values:

import json
from matplotlib import pyplot as pp

x, norm_l = normalize_loudness('msJackson.json')
pp.plot(x, norm_l, 'o')
pp.show()
exit()

Yielding:

With that you can easily find the low spots in the music:

print([x[i] for i in range(len(x)) if norm_l[i] < .1])
[0.0, 165.86036]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!