SHSession
An object that matches a specific audio recording when a segment of that recording is part of captured sound in the Shazam catalog or your custom catalog.
Declaration
class SHSessionMentioned in
Overview
Prepare to make matches by:
Creating a session for the catalog that contains the reference signatures
Adding your delegate that receives the match results
Search for a match in one of two ways:
Generate a signature for the captured audio and call match(_:)
Call matchStreamingBuffer(_:at:) with a streaming audio buffer, and ShazamKit generates the signature for you
Searching the catalog is asynchronous. The session calls your delegate methods with the result.
Matching audio against the Shazam catalog requires enabling your app to access the catalog. If you are using a custom catalog, you don’t need to enable ShazamKit. For more information on enabling your app, see Enable ShazamKit for an App ID.
The code below shows searching for a match in the Shazam catalog using an existing audio buffer:
// Set up the session.
let session = SHSession()
// Create a signature from the captured audio buffer.
let signatureGenerator = SHSignatureGenerator()
try signatureGenerator.append(buffer, at: audioTime)
let signature = signatureGenerator.signature()
// Check for a match.
let result = await session.result(from: signature)
// Use the result.
switch result {
case .match(let match):
// Match found.
case .noMatch(let signature):
// No match found.
case .error(let error, let signature):
// An error occurred.
}