Spotify - searching for silences in a track

社会主义新天地 提交于 2019-12-08 03:52:23

问题


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, tempoetc

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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!