Spotify - searching for silences in a track
<p>I have been searching everywhere but haven't found any documentation about the <code>analysis_url</code> <code>audio feature</code> on <code>Spotify API</code>, in order to deepen my understanding on the subject.</p>

<p>As far as I'm concerned, it learns the audio by <code>segments</code>, <code>bars</code>, <code>beats</code>, <code>sample rates</code>, <code>fade ins and outs</code>, <code>keys</code>, <code>timbre</code>, <code>mode</code>, <code>time_signature</code>, <code>tempo</code>etc</p>

<p>what I have so far is:</p>

<pre><code>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)
</code></pre>

<p>What I would like to do is find <strong>silences</strong> in a track, such as a 'drop' in electronic music.</p>

<p>how can I do that using the <code>analysis_url</code>?</p>

<p>Analysis comes from a company called EchoNest, which was bought by Spotify some time ago. You can find the documentation for the analysis <a href="http://developer.echonest.com/docs/v4/_static/AnalyzeDocumentation.pdf" rel="nofollow">here</a>.</p>

<p>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:</p>

<pre><code>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)
</code></pre>

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

<pre><code>import json
from matplotlib import pyplot as pp

x, norm_l = normalize_loudness('msJackson.json')
pp.plot(x, norm_l, 'o')
pp.show()
exit()
</code></pre>

<p>Yielding:</p>

<p><img src="https://i.imgur.com/KNoa3PL.png" alt="Miss Jackson"></p>

<p>With that you can easily find the low spots in the music:</p>

<pre><code>print([x[i] for i in range(len(x)) if norm_l[i] &lt; .1])
[0.0, 165.86036]
</code></pre>

python spotify spotipy