Gaaaon
PR.ready_
Spotify APIで楽曲の分析データを取得する方法
Data

Spotify APIで楽曲の分析データを取得する方法

Spotify APIで楽曲の分析データを取得・可視化する方法を解説。audio_featuresとaudio_analysisの2種類のデータ取得方法があり、ミリセカンド単位で楽曲特徴量をデータ化。TOP50 JapanをTableauやデータポータルでダッシュボード化する具体的な手順を紹介します。

SHARE

主なポイント

Spotify APIで楽曲の分析データを取得・可視化する方法を解説。audio_featuresとaudio_analysisの2種類のデータ取得方法があり、ミリセカンド単位で楽曲特徴量をデータ化しています。TOP50 JapanをTableauやデータポータルでダッシュボード化する手順も紹介しています。

catch-img

API データ可視化

Spotifyのレコメンデーションは日に日に精度があがり、アルゴリズムに身を委ねる若い人々の生活になくてはならないものとなりつつあるようです。

Z世代の次の世代と言われているα世代は、こうした最新のAIに身を委ねながら(アルゴリズムを1%も疑わず)、メタバース世界で生活していくという、まさにサイバーパンク的世界が当たり前になっていくのかもしれません。

ベートーベンと八代亜紀を一緒にレコメンドするには

今から6年前の2015年、大前研一氏があるイベントの中で「ベートーベンと八代亜紀を一緒におすすめするような音楽レコメンドAIを開発していくのが重要」ということを言っていたのがとても印象的でした。

それから早くも6年が経ち、この問題はそろそろSpotify聖帝が解決してくれそうな勢いです。

レコメンデーションの仕組み

参考までに一般的にレコメンデーションには、

  • 履歴から推奨する「協調ベースフィルタリング」
  • アイテムから推奨する「内容べースフィルタリング」

の二通りがあるようです。

アマゾンでは商品下にある「この商品に関連する商品」が内容ベース(類似商品)、「この商品を買った人はこんな商品も買っています」が協調ベース(いわゆるおむつとビール系)だと思われます。

Spotifyでは履歴から推奨する、協調ベースフィルタリングが基本となっていそうです(この曲とこの曲を聞いた人は、あの曲を聞く確率が高いetc)。

協調ベースフィルタリングだけでは、ベートーベンと八代亜紀を一緒に聞く人がある程度いないとレコメンドは難しいような気がします。

Spotifyではここにディープラーニング(音の周波数を画像に変換し、畳み込み画像処理を行う)と、WEB上から集めたテキスト情報を自然言語処理したものをかけ合わせているそうです(変態!)。

Spotifyのレコメンデーションエンジンの機械学習アルゴリズムについて解説します | 音楽とプログラミングを駆使できる未来のMUSIC TECHNOLIGISTを創出する MUSIC TECH ACADEMY CANPLAY未来の音楽を今創ろう 最新TECHで音楽にイノベーションを 音楽TECH学校 CANPLAY音楽とプログラミングを駆使できる未来のMUSIC TECHNOLIGISTを創出する MUSIC TECH ACADEMY CANPLAY

Spotifyでは更に独自の「プレイリスト」の存在も重要となっているようで、プレイリスト一つ一つをアイテムと捉えれば、内容べースフィルタリングとしても使えそうですし、曲単位/プレイリスト単位でつけられた”いいね”も重要な学習データの一つとなっているようです。

また自動的に生成される「Daily Mix」や「Discover Weekly」といったプレイリストも学習データとすることで、まるで魔法と言われるのような高い精度が実現できているのでしょう。

Spotyfy 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という音楽の長さの単位がミリセカンドだということです。

Spotifyは全ての楽曲を1,000分の1秒単位で細かく分析しているということでしょうか(凄すぎ)。

このButterのデータでは、164.441秒で2.74分(2分44秒)ということになります。

夜に駆けるを可視化する

ここからは邦楽として「夜に駆ける」のデータを取得してみたいと思います。

| --- | --- | | 取得できる指標 | 内容 | | 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)
The popularity of the artist. The value will be between 0 and 100, with 100 being the most popular. The artist’s popularity is calculated from the popularity of all the artist’s tracks. |

danceability(踊りやすい曲かどうか)など、Spotify独自の指標があるのが特徴です。

こうした数値を逆引きして曲を検索するWEBアプリが↓

Nelson | Spotify Recommendations Jukebox

audio_analysis

audio_analysisは曲を時間軸で区切って分析したデータとなるようで、「'meta', 'track', 'bars', 'beats', 'sections', 'segments', 'tatums'」という軸でデータが取得できます。

取得軸内容
bar小節
beatビート
sectionsリズムや音色の大きな変化
segments音色とハーモニーが比較的均一な一連のサウンドエンティティ
tatumsリズミカルなフレーズの連続する音符間の最小の時間間隔

sectionsで取れるもの

Spotify API sectionsデータ取得結果:start・duration・confidence・loudness・tempo・key・mode・time_signatureの14行テーブル

segmentsで取れるもの

​​​​​​​Spotify Audio Analysis APIのsegmentsデータ取得結果:1103行×9列、start・duration・loudness・pitches・timbreなどの音声特徴量

[{'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},

こちらは更に10万分の1秒単位で時系列で数値化しているようです。

このaudio_analysisの項目は日本語の解説が少なく分かりづらいですが、下記に一部まとめられていました。

Audio Analysis with Spotify's Web APIPresentation video here: https://www.youtube.com/watch?v=goUzHd7cTuA&feature=youtu.be When we talk about the Science of Music, determining useful information a…https://www.slideshare.net/MarkKoh9/audio-analysis-with-spotifys-web-api

sectionsは曲のパートを抽出しているようで、durationを見てみるとサビや間奏などの場面で分割されていることが分かります。

Spotify APIで取得した「夜に駆ける」のセクション分析、0~100%の時間軸でduration値を可視化した横棒グラフ

各特徴量を可視化

ここからは取得した「夜に駆ける」のデータを使って可視化してみます。

夜に駆けるは、spotifyの解析によると「エネルギッシュでポジティブな割と踊れる曲」という結果となりました。

更に こちら のアプリでaudio_analysis()で取得できる時系列データを可視化したのが↓になります。

Spotify Audio AnalysisのSections分析:時系列でカラーコード化された楽曲構造の可視化チャート

Sectionsの色を見ると、しっかりと曲の流れに合わせて色が変化していることが分かります。

これを全ての曲で行っていると考えると、Spotifyがいかに凄いことをしているかに驚きます。

TOP50 japanをダッシュボード化

せっかくなのでSpotifyのTOP50 japanデータを取ってきて、可視化できるようダッシュボードに入れてみます。※音が出るのでご注意ください

Tableauバージョン

Workbook: Spotify JAPAN TOP50

Unexpected Error

An unexpected error occurred. If you continue to receive this error please contact

your Tableau Server Administrator.

Image

Pretender - OFFICIAL HIGE DANDISM | Spotify

Play on Spotify

Pretender

PreviewE

OFFICIAL HIGE DANDISM

Save on Spotify

Privacy Policy· Terms & Conditions

Rank

Tempo

Key

Popularity

Energy

Danceability

Liveness

Loudness

Speechiness

Valence

Acousticness

Energy

0.0

0.5

1.0

Danceability

0.2

0.4

0.6

0.8

Liveness

0.2

0.4

0.6

Ranks

0

20

40

Tempo

0

100

200

key

0

5

10

Loudness

-8

-6

-4

-2

Speechiness

0.0

0.1

0.2

0.3

Valence

0.2

0.4

0.6

0.8

Ranks

0

20

40

Tempo

0

100

200

key

0

5

10

View on Tableau Public

Undo

Redo

Revert

Replay AnimationReplay Speed Options

Download

More options...

リンクは こちら

データポータルバージョン

広報活動ダッシュボードsample › Spotify Japan TOP50

JAPAN TOP 50

※Spotify APIからデータを抽出しています。各指標の説明は こちら をご参照ください

Spotify Japan TOP50

(Page 8 of 17)

Pages

広報活動ダッシュボード

Twitterダッシュボード

Instagramダッシュボード

新聞発行部数推移

雑誌発行部数推移

Googleトレンド(TV局)

Googleトレンド(新聞社)

Spotify Japan TOP50

Netflix Ranking

GAFA_MarketCap

U.S. Stocks PER

TikTok Trending

TikTok Top Chart

経済指数

1人あたりGDP

Japanインバウンド

ビッグマック指数

Add a new page

Privacy

Looker Studio

reCAPTCHA

Recaptcha requires verification.

Privacy - Terms

protected by reCAPTCHA

reCAPTCHA is changing its terms of service. Take action.

Privacy - Terms

Full screen

Open report in Google Looker Studio

More options

Collapse

View applied filters

Chart data is cross-filtered

More

​​​​​​​リンクは こちら

まとめ

Spotify APIで手に入るデータはとにかく膨大です。

音楽市場は国内だけでも2,700億円もあるそうで、特に音楽は「趣味趣向が多様」「繰り返し聞く」「何十年も覚えている」「感情を揺さぶる」「常に新曲が現れる」「(動画コンテンと異なり)他の作業と並行して聞くことが多い」といった特徴があり、データそのものとしても扱いが面白いジャンルだと思われます。

20年の国内音楽市場2727億円、デジタル増も全体は9%減日本レコード協会(東京・港)は10日、2020年の国内のCDなど音楽ソフトと音楽配信の売上高が前年比9%減の2727億円だったと発表した。ストリーミングなどデジタル音楽配信が11%増え、全体の3割を占めた。市場全体では2年連続で減少した。2020年の日本レコード協会に加盟する売り上げ実績を集計した。ダウンロードやストリーミング配信を含むデジタル音楽配信の売上高は前年比11%増の783億円だった日本経済新聞

以上SpotifyのAPI解説でした。

こちら にはSpotifyAPIを活用した様々なアプリが公開されていますので、触ってみてはいかがでしょうか。

※当社ではデータ分析や広報の代行業務を行っています。ご依頼の際は、 お問い合せフォーム よりお気軽にお問い合せください。

▼合わせて読みたい

Spotifyのバイラルトップ50が広報担当者にも結構アツいのではないかと思う件 | 広報・PR支援の株式会社ガーオンSpotifyのバズの芽を発見するアルゴリズムがどうやら凄そうなので、今回はこちらを解説してみたいと思います。広報・PR支援の株式会社ガーオン

【ML-Ask】感情分析AIは実際に使えるのか検証してみる | 広報・PR支援の株式会社ガーオン朝日新聞の記事にも使われている「ML-Ask」という感情分析モデルを実際に使ってみて検証していきたいと思います。広報・PR支援の株式会社ガーオン

ソーシャルデータから読み解くボヘミアンラプソディの口コミ形成とメディア露出効果 | 広報・PR支援の株式会社ガーオンボヘミアン・ラプソディの大ヒットにはSNSやテレビはどのような影響を与えていたのでしょうか。YouTubeとの相乗効果も合わせて検証します。広報・PR支援の株式会社ガーオン

Amazonの人工知能を使ってSNS等の口コミを感情分析する方法 | 広報・PR支援の株式会社ガーオンアマゾンの自然言語処理サービス Amazon Comprehendを使って口コミを分析してみます。広報・PR支援の株式会社ガーオン

【記事に繋がる】プレスリリースの書き方・送り方 | 広報・PR支援の株式会社ガーオンプレスリリースの書き方の”コツ”をPRプランナーがわかりやすく解説します。プレスリリースとはの解説から、7つのポイントや、6W5Hの使い方の他、広報PRにオススメの具体的なツールの紹介や、ヤフーニュースに掲載してもらうポイントを解説します。広報・PR支援の株式会社ガーオン

SHARE
Spotify APIで楽曲の分析データを取得する方法 | 株式会社ガーオン