I want to create my own custom audio recognition with ShazamKit, when opening the sample project I found the FoodMath.shazamsignature file. I believe there is a way to generate that file based on my audio collections.
How do I create the .shazamsignature file?
Thanks.
You can generate a .shazamsignature file using the SHSignatureGenerator object and then write the dataRepresentation on SHSignature to disk.
When creating a signature, you can use the microphone to record audio and append the PCM buffers to the signature generator. Alternatively, if you have access to the audio source, you can convert that directly into PCM buffers using the AVAudioFile and AVAudioConverter APIs.
For example if you use the microphone, your code might look something like this:
let signatureGenerator = SHSignatureGenerator()
audioEngine.inputNode.installTap(onBus: 0, bufferSize: 1024, format: audioFormat) { (buffer, audioTime) in
do {
try signatureGenerator.append(buffer, at: audioTime)
} catch {
// Handle the error
}
}
Once you finished processing the audio, you can generate the signature and write that to disk:
let fileURL = URL(fileURLWithPath: FileManager.default.currentDirectoryPath).appendingPathComponent("MySignature").appendingPathExtension("shazamsignature")
try signatureGenerator.signature().dataRepresentation.write(to: fileURL, options: .atomic)