ios – is there any code instance of how use ShazamKit in react native?


i already created the bridge however its arduous to know the documention of ShazamKit .
i’m wondering if there was any concept/assist/supply code to assist me detect music by microphone on a react native utility with newest Shazamkit model.
thanks.

i attempted this however i received the error: Can not discover ‘SHMatcher’ in scope

// my swift file
import Basis
import ShazamKit
import AVFoundation
import React

@objc(ShazamBridge)
class ShazamBridge: NSObject {
    personal let audioEngine = AVAudioEngine()
    personal let session = SHSession()
    personal var signatureGenerator = SHSignatureGenerator()

    @objc func startListening(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
        let inputNode = audioEngine.inputNode
        let recordingFormat = inputNode.outputFormat(forBus: 0)
        inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in
            self.signatureGenerator.append(buffer, at: nil)
        }

        audioEngine.put together()
        do {
            attempt audioEngine.begin()
        } catch {
            reject("Error", "Audio engine couldn't begin", error)
        }

        resolve("Listening began")
    }

    @objc func stopListeningAndIdentify(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
        audioEngine.cease()
        audioEngine.inputNode.removeTap(onBus: 0)

        let matcher = SHMatcher()
        let signature = signatureGenerator.signature()
        matcher.addSignature(signature)

        session.match(matcher, completion: { (matches, error) in
            if let error = error {
                reject("Error", "Didn't match audio", error)
            } else if let match = matches?.first {
                resolve(match.mediaItem.title)
            } else {
                resolve(nil)
            }
        })
    }
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles