我正在尝试在 Android 上测试 ShazamKit。在下面的 Kotlin 片段中,我加载apple-test-wav.wav
了一个 9 秒长、48khz、16 位 PCM WAV 音频片段的 Food Math 示例视频 - 并尝试将其与FoodMath.shazamsignature
自定义目录进行匹配。
此音频不是通过麦克风捕获的,它是直接来自视频的干净样本,我无法匹配。输出总是:NoMatch
我在这里做明显错误的事情吗?
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")
}
}
}