I have been searching everywhere but haven't found any documentation about the analysis_url
audio feature
on Spotify API
, in order to deepen my understanding on the subject.
As far as I'm concerned, it learns the audio by segments
, bars
, beats
, sample rates
, fade ins and outs
, keys
, timbre
, mode
, time_signature
, tempo
etc
what I have so far is:
def analysis_url(track_ids):
names = []
tids = []
for id_ in track_ids:
track_id = sp.track(id_)['uri']
tids.append(track_id)
track_name = sp.track(id_)['name']
names.append(track_name)
features = sp.audio_features(tids)
urls = [x['analysis_url'] for x in features if x]
for url in urls:
analysis = sp._get(url)
What I would like to do is find silences in a track, such as a 'drop' in electronic music.
how can I do that using the analysis_url
?
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]
来源:https://stackoverflow.com/questions/39323185/spotify-searching-for-silences-in-a-track