Shazam Core

PAID
By Tipsters CO | Updated 4 days ago | Music
Popularity

9.9 / 10

Latency

1,880ms

Service Level

100%

Health Check

100%

Back to All Tutorials (1)

Shazam API Tutorial

Shazam API Tutorial

tags: shazam

Hi.
In this tutorial I will provide sample code for identifying a song from a file.
Use an audio file. 2-4 seconds of audio is enough, not more than 2 mb. 500-1500 kb is optimal.

If you have a large audio file, it is best to send in portions until you find a match. Get detailed information on track-by-track recognition of the file.

Example files:
https://disk.yandex.ru/d/0jCEoQP3hkPDzg
https://disk.yandex.ru/d/sepd6XUnhls1aw


PHP code example:

<?php
$curlFile = new CURLFile('StarWars3.wav', 'audio/wav');

$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, 'https://shazam-core.p.rapidapi.com/v1/tracks/recognize');
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, ['file' => $curlFile]);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, CURLOPT_VERBOSE, true);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, [
  'x-rapidapi-host: shazam-core.p.rapidapi.com',
  'x-rapidapi-key: YOU API KEY!!!'
]);

$response = curl_exec($curlHandle);
$error = curl_error($curlHandle);
curl_close($curlHandle);

if ($error) {
  echo 'cURL Error #: ' . $error;
} else {
  echo $response;
}


Python3 code example :

.wav (audio/wav)

import requests 
 
url = "https://shazam-core.p.rapidapi.com/v1/tracks/recognize" 
 
files = {'file': ('StarWars3.wav', open('StarWars3.wav','rb'), 'audio/wav')}
headers = { 
 "X-RapidAPI-Key": "YOU API KEY!!!", 
 "X-RapidAPI-Host": "shazam-core.p.rapidapi.com" 
} 
 
response = requests.request("POST", url, files=files, headers=headers) 
 
print(response.text)

.mp3 (audio/mpeg)

import requests 
 
url = "https://shazam-core.p.rapidapi.com/v1/tracks/recognize" 
 
files = {'file': ('StarWars3.mp3', open('StarWars3.mp3','rb'), 'audio/mpeg')}
headers = { 
 "X-RapidAPI-Key": "YOU API KEY!!!", 
 "X-RapidAPI-Host": "shazam-core.p.rapidapi.com" 
} 
 
response = requests.request("POST", url, files=files, headers=headers) 
 
print(response.text)