2026年11月4日更新:この記事のデータと手順は2021年時点の記録で、取得コードは再実行していません。Spotifyは2024年11月27日から、新規のアプリと開発モードの既存アプリ(拡張の申請中を除く)で、Audio Features、Audio Analysis、Spotifyが編成するプレイリストなどを使えなくしました。2026年2月には開発モードの条件も変わり、Spotify Premiumが必須で、Client IDは1人1つ、利用者は5人までです。本文の手順を新しいアプリでそのまま再現することはできません。
Spotifyのレコメンデーションは日に日に精度があがり、アルゴリズムに身を委ねる若い人々の生活になくてはならないものとなりつつあるようです。
これ凄いわかる。Apple musicじゃなくてSpotifyを選ぶのは、このレコメンド精度の高さ! Go Ando / PREDUCTS @goando Spotifyの今週のワシのDiscover Weeklyの選曲が神がかってて、ここまで自分の趣味をわかってくれてると、もう離れられる気がしない。 これぞパーソナライゼーションであり、プラットフォーマーの強さなのだよな。
— きわ (@kiwa_designer) 午前7:24 · 2019年2月11日
Z世代の次の世代と言われているα世代は、こうした最新のAIに身を委ねながら(アルゴリズムを1%も疑わず)、メタバース世界で生活していくという、まさにサイバーパンク的世界が当たり前になっていくのかもしれません。spotifyは完全にfor you施策が良すぎるな…レコメンドをまとめてくれてるだけだけど、診断コンテンツ然り、私たちって自分のことを知りたい欲求高なので、面白く感じてどんどん使い込みたくなってしまう……私の雑食ぶりがすごい
— りょかち║松田涼花(まつだすずか) (@ryokachii) 午後4:21 · 2021年6月2日
ベートーベンと八代亜紀を一緒にレコメンドするには
今から6年前の2015年、大前研一氏があるイベントの中で「ベートーベンと八代亜紀を一緒におすすめするような音楽レコメンドAIを開発していくのが重要」ということを言っていたのがとても印象的でした。
それから早くも6年が経ち、この問題はそろそろSpotify聖帝が解決してくれそうな勢いです。
レコメンデーションの仕組み
参考までに一般的にレコメンデーションには、
- 履歴から推奨する「協調ベースフィルタリング」
- アイテムから推奨する「内容ベースフィルタリング」
の二通りがあるようです。
アマゾンでは商品下にある「この商品に関連する商品」が内容ベース(類似商品)、「この商品を買った人はこんな商品も買っています」が協調ベース(いわゆるおむつとビール系)だと思われます。
Spotifyでは履歴から推奨する、協調ベースフィルタリングが基本となっていそうです(この曲とこの曲を聞いた人は、あの曲を聞く確率が高いetc)。
協調ベースフィルタリングだけでは、ベートーベンと八代亜紀を一緒に聞く人がある程度いないとレコメンドは難しいような気がします。
Spotifyではここにディープラーニング(音を周波数の図であるスペクトログラムに変換し、畳み込みニューラルネットワークにかける)と、WEB上から集めたテキスト情報を自然言語処理したものをかけ合わせているそうです(変態!)。
Spotifyでは更に独自の「プレイリスト」の存在も重要となっているようで、プレイリスト一つ一つをアイテムと捉えれば、内容ベースフィルタリングとしても使えそうですし、曲単位/プレイリスト単位でつけられた”いいね”も重要な学習データの一つとなっているようです。
また自動的に生成される「Daily Mix」や「Discover Weekly」といったプレイリストも学習データとすることで、まるで魔法と言われるような高い精度が実現できているのでしょう。
Spotify APIで取れるデータ
こうしたSpotifyのデータは Spotify API から取得することができます( spotipy というライブラリを使うと簡単に取得することができます)。
取得コードの解説は長くなってしまうのでこのブログでは省きますが、試しに現在「Top 50 - Japan」1位のBTS「Butter」のデータを取得すると、下記のようなデータが取得できます。
{'added_at': '2021-09-17T09:54:38Z',
'added_by': {'external_urls': {'spotify': 'https://open.spotify.com/user/'},
'href': 'https://api.spotify.com/v1/users/',
'id': '',
'type': 'user',
'uri': 'spotify:user:'},
'is_local': False,
'primary_color': None,
'track': {'album': {'album_type': 'single',
'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/3Nrfpe0tUJi4K4DXYWgMUX'},
'href': 'https://api.spotify.com/v1/artists/3Nrfpe0tUJi4K4DXYWgMUX',
'id': '3Nrfpe0tUJi4K4DXYWgMUX',
'name': 'BTS',
'type': 'artist',
'uri': 'spotify:artist:3Nrfpe0tUJi4K4DXYWgMUX'}],
'available_markets': ['AD'],
'external_urls': {'spotify': 'https://open.spotify.com/album/1HnJKmB4P6Z8RBdLMWx18w'},
'href': 'https://api.spotify.com/v1/albums/1HnJKmB4P6Z8RBdLMWx18w',
'id': '1HnJKmB4P6Z8RBdLMWx18w',
'images': [{'height': 640,
'url': 'https://i.scdn.co/image/ab67616d0000b2736bb2b8231817c8d205d07fb2',
'width': 640},
{'height': 300,
'url': 'https://i.scdn.co/image/ab67616d00001e026bb2b8231817c8d205d07fb2',
'width': 300},
{'height': 64,
'url': 'https://i.scdn.co/image/ab67616d000048516bb2b8231817c8d205d07fb2',
'width': 64}],
'name': 'Butter (Hotter, Sweeter, Cooler)',
'release_date': '2021-06-04',
'release_date_precision': 'day',
'total_tracks': 5,
'type': 'album',
'uri': 'spotify:album:1HnJKmB4P6Z8RBdLMWx18w'},
'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/3Nrfpe0tUJi4K4DXYWgMUX'},
'href': 'https://api.spotify.com/v1/artists/3Nrfpe0tUJi4K4DXYWgMUX',
'id': '3Nrfpe0tUJi4K4DXYWgMUX',
'name': 'BTS',
'type': 'artist',
'uri': 'spotify:artist:3Nrfpe0tUJi4K4DXYWgMUX'}],
'available_markets': ['AD'],
'disc_number': 1,
'duration_ms': 164441,
'episode': False,
'explicit': False,
'external_ids': {'isrc': 'QM6MZ2156864'},
'external_urls': {'spotify': 'https://open.spotify.com/track/2bgTY4UwhfBYhGT4HUYStN'},
'href': 'https://api.spotify.com/v1/tracks/2bgTY4UwhfBYhGT4HUYStN',
'id': '2bgTY4UwhfBYhGT4HUYStN',
'is_local': False,
'name': 'Butter',
'popularity': 92,
'preview_url': 'https://p.scdn.co/mp3-preview/edf24f427483d886b640c5ed9944f9291e0976fc?cid=a93660565a7f4d328ade2b4e098421a6',
'track': True,
'track_number': 1,
'type': 'track',
'uri': 'spotify:track:2bgTY4UwhfBYhGT4HUYStN'},
'video_thumbnail': {'url': None}}
曲の長さはミリ秒で記録されている
SpotifyAPIのデータを見てまず驚くのが、duration_msという音楽の長さの単位がミリセカンドだということです。
これは曲の長さを表す項目の単位で、1,000分の1秒の細かさで分析しているという意味ではありません。
このButterのデータでは、164.441秒で2.74分(2分44秒)ということになります。
夜に駆けるを可視化する
ここからは邦楽として「夜に駆ける」のデータを取得してみたいと思います。
分析データの取得は2種類
音声分析のデータは曲単位で取得できるaudio_features("ID")と、曲中の時系列単位で取得できるaudio_analysis("ID")の2種類があるようです。
audio_features
audio_featuresで取得できる情報は下記の項目となります。
| 取得できる指標 | 内容 |
|---|---|
| acousticness | アコースティック感(0~1) A confidence measure from 0.0 to 1.0 of whether the track is acoustic. 1.0 represents high confidence the track is acoustic. |
| danceability | 踊れる曲かどうか(0~1) Danceability describes how suitable a track is for dancing based on a combination of musical elements including tempo, rhythm stability, beat strength, and overall regularity. A value of 0.0 is least danceable and 1.0 is most danceable. |
| duration_ms | 秒数(ms) The duration of the track in milliseconds. |
| energy | エネルギッシュさ(0~1) Energy is a measure from 0.0 to 1.0 and represents a perceptual measure of intensity and activity. Typically, energetic tracks feel fast, loud, and noisy. For example, death metal has high energy, while a Bach prelude scores low on the scale. Perceptual features contributing to this attribute include dynamic range, perceived loudness, timbre, onset rate, and general entropy. |
| instrumentalness | インスト感(歌声が入っていない/0~1) Predicts whether a track contains no vocals. “Ooh” and “aah” sounds are treated as instrumental in this context. Rap or spoken word tracks are clearly “vocal”. The closer the instrumentalness value is to 1.0, the greater likelihood the track contains no vocal content. Values above 0.5 are intended to represent instrumental tracks, but confidence is higher as the value approaches 1.0. |
| liveness | ライブ感(聴衆がいるか)(0~1/0.8以上でライブ判定) Detects the presence of an audience in the recording. Higher liveness values represent an increased probability that the track was performed live. A value above 0.8 provides strong likelihood that the track is live. |
| loudness | ラウドネス/音量・音圧(dB/-60~0db) The overall loudness of a track in decibels (dB). Loudness values are averaged across the entire track and are useful for comparing relative loudness of tracks. Loudness is the quality of a sound that is the primary psychological correlate of physical strength (amplitude). Values typical range between -60 and 0 db. |
| mode | 短調(マイナー、0)/長調(メジャー、1) Mode indicates the modality (major or minor) of a track, the type of scale from which its melodic content is derived. Major is represented by 1 and minor is 0. |
| speechiness | 言葉がどれくらい入っているか(0~1) Speechiness detects the presence of spoken words in a track. The more exclusively speech-like the recording (e.g. talk show, audio book, poetry), the closer to 1.0 the attribute value. Values above 0.66 describe tracks that are probably made entirely of spoken words. Values between 0.33 and 0.66 describe tracks that may contain both music and speech, either in sections or layered, including such cases as rap music. Values below 0.33 most likely represent music and other non-speech-like tracks. |
| tempo | テンポ(40-200bpm) The overall estimated tempo of a track in beats per minute (BPM). In musical terminology, tempo is the speed or pace of a given piece and derives directly from the average beat duration. |
| key | キー(0がC/0~11) The key the track is in. Integers map to pitches using standard Pitch Class notation . E.g. 0 = C, 1 = C♯/D♭, 2 = D, and so on. |
| time_signature | 拍子(1小節あたり何拍子か) An estimated overall time signature of a track. The time signature (meter) is a notational convention to specify how many beats are in each bar (or measure). |
| valence | 悲観的(0)~楽観的(1) 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). |
| popularity | 相対的人気度(0~100。audio_featuresではなく曲の情報に入っている項目です) The popularity of the track. The value will be between 0 and 100, with 100 being the most popular. The popularity is calculated by algorithm and is based, in the most part, on the total number of plays the track has had and how recent those plays are. |
danceability(踊りやすい曲かどうか)など、Spotify独自の指標があるのが特徴です。
こうした数値を逆引きして曲を検索するWEBアプリ「Nelson | Spotify Recommendations Jukebox」もありました(Glitch 上で公開されていましたが、現在は公開を終了しています)。
audio_analysis
audio_analysisは曲を時間軸で区切って分析したデータとなるようで、「'meta', 'track', 'bars', 'beats', 'sections', 'segments', 'tatums'」という軸でデータが取得できます。
| 取得軸 | 内容 |
| bar | 小節 |
| beat | ビート |
| sections | リズムや音色の大きな変化 |
| segments | 音色とハーモニーが比較的均一な一連のサウンドエンティティ |
| tatums | リズミカルなフレーズの連続する音符間の最小の時間間隔 |
sectionsで取れるもの

segmentsで取れるもの

[{'confidence': 0.476, 'duration': 1.8382, 'start': 1.89899},
{'confidence': 0.777, 'duration': 1.84207, 'start': 3.73719},
{'confidence': 0.399, 'duration': 1.83751, 'start': 5.57926},
開始位置(start)や長さ(duration)は秒の小数点以下5桁まで記録されています。桁数は記録の形で、分析の細かさが10万分の1秒という意味とは限りません。
このaudio_analysisの項目は日本語の解説が少なく分かりづらいですが、下記に一部まとめられていました。
sectionsは曲のパートを抽出しているようで、durationを見てみるとサビや間奏などの場面で分割されていることが分かります。

各特徴量を可視化
ここからは取得した「夜に駆ける」のデータを使って可視化してみます。
夜に駆けるは、spotifyの解析によると「エネルギッシュでポジティブな割と踊れる曲」という結果となりました。
更にaudio_analysis()で取得できる時系列データを可視化したのが↓になります。

Sectionsの色を見ると、しっかりと曲の流れに合わせて色が変化していることが分かります。
これを全ての曲で行っていると考えると、Spotifyがいかに凄いことをしているかに驚きます。
TOP50 japanをダッシュボード化
せっかくなのでSpotifyのTOP50 japanデータを取ってきて、可視化できるようダッシュボードに入れてみます。※音が出るのでご注意ください
Tableauバージョン
Spotify JAPAN TOP50(Tableau Public)
データポータルバージョン
※Spotify APIからデータを抽出しています。各指標の説明は本記事の前半をご参照ください
Spotify Japan TOP50(Looker Studio)
まとめ
当時のSpotify APIで手に入るデータはとにかく膨大でした。
CDなどの音楽ソフトと音楽配信の国内市場だけでも2,700億円余り(2020年、日本レコード協会の発表)あるそうで、特に音楽は「趣味趣向が多様」「繰り返し聞く」「何十年も覚えている」「感情を揺さぶる」「常に新曲が現れる」「(動画コンテンツと異なり)他の作業と並行して聞くことが多い」といった特徴があり、データそのものとしても扱いが面白いジャンルだと思われます。
以上SpotifyのAPI解説でした。
Spotify for Developers にはSpotifyAPIを活用した様々なアプリが公開されていますので、触ってみてはいかがでしょうか。
※当社ではデータ分析や広報の代行業務を行っています。ご依頼の際は、 お問い合せフォーム よりお気軽にお問い合せください。
▼合わせて読みたい
Spotifyのバイラルトップ50が広報担当者にも結構アツいのではないかと思う件
感情分析AI「ML-Ask」をPythonで検証|10種類の感情を3行で抽出
ソーシャルデータから読み解くボヘミアンラプソディの口コミ形成とメディア露出効果






