使用Gracenote SDK(GNSDK)读取文件并执行指纹识别

我试图从iOS上读取16位16KHz的WAV(20秒长),并执行指纹识别。 我试过按照“GNSDK-for-Mobile-iOS-Developers-Guide”的指导,但是它没有第53页的Objective-C例子(只有C#)。 我的代码读取整个文件,然后将2K块写入函数fingerprintWrite(我也尝试将指针传递给整个文件)。 variables“结果”从来没有设置为1 – 表明数据不足已经通过 – 但20秒应该是足够的,对不对?任何人都可以帮忙?谢谢。

这是我所做的:

NSString *filepath = [[NSBundle mainBundle] pathForResource:@"Human.signed.20s.16bit" ofType:@"raw"]; NSData *audioData= [NSData dataWithContentsOfFile:filepath]; BOOL result; if (error) NSLog(@"Error reading file: %@", error.localizedDescription); // for debugging... NSLog(@"contents: %@", audioData); NSLog(@"Done:"); unsigned char buffer[audioData.length]; [audioData getBytes:buffer length:audioData.length]; for (int i = 0; i < audioData.length; i++) { printf("0x%02x ",(unsigned char)buffer[i]); } [self.gnMusicIDFileInfo fingerprintBegin:16000 audioSampleSize:16 audioChannels:1 error:&error]; if (error) { NSLog(@"Error = %@", [error localizedDescription]); } int count = 0; result = 0; while (result==0 && count<sizeof(buffer)-2048) { result = [self.gnMusicIDFileInfo fingerprintWrite:&buffer[count] audioDataSize:2048 error:&error]; NSLog(@"Count = %i",count); count=count+2048; } NSLog(@"result = %i", result); if (error) { NSLog(@"Error = %@", [error localizedDescription]); } [self.gnMusicIDFileInfo fingerprintEnd:&error]; if (error) { NSLog(@"Error = %@", [error localizedDescription]); } [self.gnMusicIDFileInfo fingerprint:&error]; if (error) { NSLog(@"Error = %@", [error localizedDescription]); } 

20秒可能不够,因为识别过程需要足够量的“ 可用 ”audio来进行。 而且,在做MusicID文件识别时,需要从歌曲的开始处获得audio文件。 如果您的使用案例只提供歌曲的一部分,歌曲不会从头开始播放,则很可能不起作用。 您将需要使用MusicIDstream代替。