Documentation Index
Fetch the complete documentation index at: https://mintlify.com/hitenpatel/songprint/llms.txt
Use this file to discover all available pages before exploring further.
RecognitionClient is a thin HTTP wrapper that posts a signature produced by SignatureGenerator to the public Shazam discovery endpoint and returns the raw JSON response body as a String. The class has no third-party dependencies — it uses only java.net.HttpURLConnection from the JDK — and deliberately performs no JSON parsing itself so you can use whichever JSON library your project already has.
Making a recognition call
The full pipeline is three steps: decode and resample the raw PCM, generate the signature, then post it to the endpoint.recognise accepts the signature ByteArray and the number of 16kHz mono samples the signature was generated from. The sample count is used to compute the duration (in milliseconds) sent to the endpoint.
The JSON response
The response is the raw JSON body returned by the Shazam endpoint. No reshaping or validation is performed. When a match is found the response contains atrack object; when there is no match the matches array is empty.
Key fields to extract:
| Field | Description |
|---|---|
matches | Array of match objects. Empty means no song was recognised. |
track.title | Song title. |
track.subtitle | Artist name. |
track.images.coverart | URL to the album cover art image. |
track.share.href | Apple Music / Shazam link for the track. |
org.json (available on Android without extra dependencies):
Null returns
recognise returns null only when the HTTP response code is anything other than 200 — for example a network error, rate-limiting, or an endpoint change. A 200 response with an empty matches array still returns the full JSON string, not null. Your code should inspect matches.length() to distinguish a clean no-match from a transport failure.
Constructor options
RecognitionClient can be constructed with custom endpoint and timeout values:
| Parameter | Default | Description |
|---|---|---|
endpoint | https://amp.shazam.com/discovery/v5/en/GB/android/-/tag | The Shazam discovery URL. |
connectTimeoutMs | 10000 | TCP connect timeout in milliseconds. |
readTimeoutMs | 10000 | Socket read timeout in milliseconds. |
RecognitionClient() uses all three defaults.
Caveats
Running on a background thread
recognise makes a blocking network call using HttpURLConnection. On Android it will throw a NetworkOnMainThreadException if called from the main thread. Always dispatch it to a background thread — for example using Dispatchers.IO in a coroutine: