Getting the tempo, key signature, and other audio attributes of a song
Some of the most powerful features of the Echo Nest API are the deep understanding of musical attributes about songs. In this tutorial, you will learn which attributes are available, and how to interpret them.
Requesting audio information
The most straightforward way to get the audio information about a song is to use the song/profile API call, using a song ID as a parameter. (There are other ways, which will be discussed below.) Let's look for the Kanye West song All of the Lights:
Response
{
"response": {
"songs": [
{
"artist_id": "ARRH63Y1187FB47783",
"artist_name": "Kanye West",
"id": "SONWCPE12B3A138A4E",
"title": "All Of The Lights"
},
This gives us a song_id of SONWCPE12B3A138A4E. To then get the song audio information, you will make a song/profile call, and pass in the song ID, as well as a bucket=audio_summary parameter. This will return all of the audio summary data associated with that song.
Response
{
"response": {
"songs": [
{
"artist_id": "ARRH63Y1187FB47783",
"artist_name": "Kanye West",
"audio_summary": {
"analysis_url": "https://echonest-analysis.s3.amazonaws.com:443/TR/TRGZJTI12C5FADB614/3/full.json?Signature=exA%2BA1WQG8WOgLBWQaNu06nxg2U%3D&Expires=1307983235&AWSAccessKeyId=AKIAJRDFEY23UEVW42BQ",
"audio_md5": "3d259ac6ba130478d52aea7278457922",
"danceability": 0.50804858585626766,
"duration": 299.67628000000002,
"energy": 0.55875596003809869,
"key": 1,
"loudness": -4.2430000000000003,
"mode": 1,
"tempo": 141.696,
"time_signature": 4
},
"id": "SONWCPE12B3A138A4E",
"title": "All Of The Lights"
}
],
"status": {
"code": 0,
"message": "Success",
"version": "4.2"
}
}
}
Note the audio_summary block returned. This audio summary is generated from the full audio analysis that The Echo Nest has performed. The full analysis data is available, by following the analysis_url link, but many summary attributes are provided here since that is frequently all that is desired.
Understanding audio_summary results
The tempo field represents the BPM of the song in question. In this case, it's 142 BPM. Other interesting attributes are:
- danceability: A number that ranges from 0 to 1, representing how danceable the Echo Nest thinks this song is.
- duration: Length of the song, in seconds.
- energy: A number that ranges from 0 to 1, representing how energetic the Echo Nest thinks this song is.
- key: The key signature that The Echo Nest believes the song is in. Key signatures start at C and ascend the chromatic scale. In this case, a key: 1 represents a song in D-flat.
- loudness: The overall loudness of a track in decibels (dB).
- mode: Number representing whether the song is major (0) or minor (1) key.
- time_signature: Time signature of the key; how many beats per measure.