By the end of this guide you will have songprint added to your project, a raw PCM buffer converted to the format the library expects, a binary Shazam-compatible signature generated entirely on-device, and an identification result returned from the public discovery endpoint — all without an API key or any native code.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.
10–12 seconds of audio produces the most reliable matches. Shorter clips do work, but the probability of a correct identification drops with less audio. Aim for at least 10 seconds when you can control the capture window.
Add the JitPack repository
songprint is distributed via JitPack. Add the JitPack Maven repository to your
build.gradle.kts:Add the dependency
Declare the songprint dependency in your Sync your project and the library is ready to use. There are no transitive runtime dependencies to resolve.
dependencies block:Import the classes
songprint exposes three public types. Import all three at the top of your file:
Pcm— static utilities for decoding and resampling raw PCM audioSignatureGenerator— produces the binary fingerprint from 16 kHz mono samplesRecognitionClient— posts the fingerprint to the Shazam discovery endpoint
Prepare your PCM audio
SignatureGenerator requires 16 kHz mono 16-bit PCM as a ShortArray. Use the two Pcm helpers to get there from any common source format.bytesToShorts interprets every two bytes as one little-endian signed 16-bit sample. resampleToMono16k averages all channels to produce mono, then applies linear-interpolation resampling to reach 16 000 Hz. Pass the actual sample rate and channel count of your source audio as the second and third arguments.Generate the signature
Pass the prepared Generation is pure Kotlin and completes in a few milliseconds for a typical 10–12 second clip.
ShortArray to SignatureGenerator.generateSignature. It returns a ByteArray containing the complete binary signature — header, CRC32, and delta-encoded peak data included.generateSignature resets all internal state at the start of each call, so the same SignatureGenerator instance can be reused across multiple clips. Note that SignatureGenerator is not thread-safe — use one instance per thread.Identify the song
Pass the signature and the number of 16 kHz mono samples to Parse
A
RecognitionClient.recognise. It returns the raw JSON response body as a String, or null if the endpoint returned a non-200 status.json with whichever JSON library you already use. The response contains a track object with the following fields of interest:| Field | Content |
|---|---|
track.title | Song title |
track.subtitle | Artist name |
track.images.coverart | Cover art image URL |
track.share.href | Shazam link for the track |
null return value means either no match was found or the request failed. Check track for existence before reading its fields — a successful HTTP response may still carry an empty match.Next Steps
PCM Preparation
Capture audio from the microphone or a media file and feed it to songprint correctly.
Recognition
Handle match results, parse the full JSON response, and deal with no-match cases.
SignatureGenerator API
Full reference for
SignatureGenerator, Pcm, and RecognitionClient.Algorithm
Understand the spectrogram, peak-spreading, banding, and binary encoding pipeline.