Error ShazamCustomRecognizer

Hello everyone,

I'm encountering a weird issue. After that I started the catalog match, everything works good and I can obtain live result until I start an AVPlayer audio session.

In specific, I want to play a sound from a remote URL when a specific result is matched.

So when there is this match, I call a "playSound" function and after that, the matcher is not working anymore.

In specific I'm receiving the following error:

ShazamCustomRecognizer[3769:708996] [] [13:48:01.364] itemasync_SetProperty signalled err=-12785 (kCMBaseObjectError_Invalidated) (invalidated) at /Library/Caches/com.apple.xbs/Sources/CoreMedia_MediaToolboxEtc/CoreMedia-2896.2.1.1.6/Prototypes/Player/FigPlayer_Async.c:3466

Any idea? Thanks!

Answered by Apple Designer in 678442022

One suggestion I would make is to try setting up your AVAudioSession like this: AVAudioSession.sharedInstance().setCategory(.playAndRecord) when your app first launches. I think you may be encountering problems switching from .record to .playback.

Could you explain your audio setup in a little more detail? Where are you getting the audio samples from that you're using to perform the catalog match? What platform are you running on? And how have you configured your AVAudioSession? Any code snippets you provide would also be helpful.

Thanks a lot for the reply. In specific:

  1. My app is running the matcher as following (snippet from the code session)
if let catalog = try CatalogProvider.catalog(signaturePath: data) {

                                                try matcher.match(catalog: catalog)

                                            }
  1. At this point the app I'm calling a function called playSounds and I'm passing a URL, that is a remote URL of an .mp3 file hosted on my server.

 func playSounds(soundUrl: URL, atTime: Double) {

        //Remove previous player

        self.audioPlayer?.removeObserver(self, forKeyPath: "timeControlStatus")

        

        //Setup new player

        do {

            try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)

            try AVAudioSession.sharedInstance().setActive(true)

            audioPlayer = AVPlayer(url: soundUrl)

            audioPlayer?.addObserver(self, forKeyPath: "timeControlStatus", options: [.old,.new], context: &playerContext)

            guard let player = audioPlayer

            else

            {

                return

            }

            player.playImmediately(atRate: 1.0)

            player.seek(to: CMTime(seconds: atTime + 2, preferredTimescale: CMTimeScale(1.0)))

        } catch let error {

            print("ERROR AUDIO",error.localizedDescription)

        }

        

    }

  1. After that playSounds function is called, the matcher stop to do any match. It's basically not working and it's returning me the error that I mentioned above.

Platform: iOS 15 on iPhone X.

The match function is below:

func match(catalog: SHCustomCatalog) throws {

        

        session = SHSession(catalog: catalog)

        session?.delegate = self

        

        let audioFormat = AVAudioFormat(standardFormatWithSampleRate: audioEngine.inputNode.outputFormat(forBus: 0).sampleRate,

                                        channels: 1)

        audioEngine.inputNode.installTap(onBus: 0, bufferSize: 2048, format: audioFormat) { [weak session] buffer, audioTime in

            session?.matchStreamingBuffer(buffer, at: audioTime)

        }

        

        try AVAudioSession.sharedInstance().setCategory(.record)

        AVAudioSession.sharedInstance().requestRecordPermission { [weak self] success in

            guard success, let self = self else { return }

            try? self.audioEngine.start()

        }

        

    }
Accepted Answer

One suggestion I would make is to try setting up your AVAudioSession like this: AVAudioSession.sharedInstance().setCategory(.playAndRecord) when your app first launches. I think you may be encountering problems switching from .record to .playback.

Error ShazamCustomRecognizer
 
 
Q