Using Gracenote SDK (GNSDK) to read a file and perform a fingerprint recognition

∥☆過路亽.° 提交于 2019-12-12 02:49:13

问题


I'm trying to read a 16bit 16KHz wav (20 seconds long) from on iOS and perform a fingerprint identification. I tried following the guide "GNSDK-for-Mobile-iOS-Developers-Guide" but it doesn't have an objective-c example on page 53 (only C#). My code reads in the whole file and then writes 2K blocks to the function fingerprintWrite (I've also tried passing a pointer to the whole file). The variable "result' is never set to 1 - indicating insufficient data has been passed - but 20 seconds should be enough, right? Can anyone help? Thanks.

This is what I have done:

    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]);

    }

回答1:


20 seconds may not be enough because the identification process requires enough amount of "usable" audio to proceed. Also, when doing a MusicID File identification, it is required to have the audio file from the beginning of a song. If your use case provides only part of a song and the song does not start from the beginning, it will most likely not work. You will need to use MusicID Stream instead.



来源:https://stackoverflow.com/questions/35436280/using-gracenote-sdk-gnsdk-to-read-a-file-and-perform-a-fingerprint-recognition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!