我试图从iOS上读取16位16KHz wav(20秒长)并执行指纹识别。我尝试按照指南" GNSDK-for-Mobile-iOS-Developers-Guide"但它没有第53页的Objective-c示例(只有C#)。我的代码读入整个文件,然后将2K块写入函数fingerprintWrite(我也尝试将指针传递给整个文件)。变量"结果'永远不会设置为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]);
}
答案 0 :(得分:2)
20秒可能还不够,因为识别过程需要足够数量的&#34; 可用&#34;音频继续。此外,在进行MusicID文件识别时,需要从歌曲的开头获得音频文件。如果您的用例仅提供歌曲的一部分且歌曲不从头开始,则很可能无效。您需要使用MusicID Stream。