Post

Replies

Boosts

Views

Activity

Reply to How do I create the .shazamsignature file?
Hi @Frameworks Engineer, thank you for your response!  I was successfully generate the .signature file, but when I use it in the project I got this error: Error Domain=com.apple.ShazamKit Code=201 "The provided signature duration is outside the valid range" UserInfo={NSDebugDescription=The provided signature duration is outside the valid range, NSLocalizedFailureReason=The minimum signature duration allowed is 1.00 secs, this signature is only 0.00 secs}  I believe I miss something in my code, could you help me to check what's wrong on this code: import AVFoundation import ShazamKit import PlaygroundSupport func generateSignature() {     let path: String = Bundle.main.path(forResource: "alfatihah.mp3", ofType:nil)!     let url = URL(fileURLWithPath: path)                    let signatureGenerator = SHSignatureGenerator()          do {         let audioFile = try AVAudioFile(forReading: url)         let sampleRate = audioFile.processingFormat.sampleRate         let sampleTime = audioFile.length                  let time = AVAudioTime(hostTime: mach_absolute_time(), sampleTime: sampleTime, atRate: sampleRate)                  do {             let data = try Data(contentsOf: url)             let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 44100, channels: 2, interleaved: true)             guard let buffer = AVAudioPCMBuffer(pcmFormat: format!, frameCapacity: AVAudioFrameCount(data.count)) else { return }                          try signatureGenerator.append(buffer, at: time)                          guard let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else {                 print("No documents directory found.")                 return             }                          // Save the signature             let fileURL = documentsDirectory.appendingPathComponent("MySignature").appendingPathExtension("shazamsignature")             try signatureGenerator.signature().dataRepresentation.write(to: fileURL, options: .atomic)                          print("Signature Successfully Generated")         } catch let error as NSError {             print("ERROR HERE", error.localizedDescription)         }     } catch {         print(error)     }           } generateSignature() Thanks!
Jun ’21