5

I'm trying to test ShazamKit on Android. In the following Kotlin snippet, I load apple-test-wav.wav - a 9 second long, 48khz, 16bit PCM WAV audio snippet of the Food Math example video - and attempt to match it against the FoodMath.shazamsignature custom catalog.

This audio is not captured via a microphone, it's a clean sample directly from the video and I can't get it to match. The output is always: NoMatch

Am I doing something obviously wrong here?

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)

    CoroutineScope(Dispatchers.IO).launch {
        searchCatalog()
    }
}

private suspend fun searchCatalog() {
    val file = context?.assets?.open("apple-test-wav.wav")
    if (file != null) {
        val bytes = file.readBytes()
        file.close()
        val signatureGenerator = (ShazamKit.createSignatureGenerator(AudioSampleRateInHz.SAMPLE_RATE_48000) as ShazamKitResult.Success).data
        signatureGenerator.append(bytes, bytes.size, System.currentTimeMillis())
        val signature = signatureGenerator.generateSignature()

        val inputStream: InputStream? = context?.assets?.open("FoodMath.shazamsignature")
        if (inputStream!= null) {
            val catalog = ShazamKit.createCustomCatalog().apply { addFromCatalog(inputStream) }
            val session = (ShazamKit.createSession(catalog) as ShazamKitResult.Success).data
            val matchResult: MatchResult = session.match(signature)
            println(matchResult.toString())
        }
        else {
            println("no input stream")
        }
    }
}
Gerard
  • 73
  • 4

0 Answers0