0

I'm using v1.05 of the Houndify SDK, and their demo app. I'm performing a voice search for music and struggling to understand how to extract the Spotify track ID from the Houndify response.

Houndify responds with a object of HoundDataHoundServer and their example shows processing it for the spoken response like this:

HoundDataCommandResult* commandResult = response.allResults.firstObject;
self.responseTextView.text = commandResult.writtenResponse;

it goes on to dump the whole of the response like this:

NSDictionary* nativeData = commandResult[@"NativeData"];
NSLog(@"NativeData: %@", nativeData);

which, in an example dump, shows this from NSLog:

NativeData: {
    EntitySpecificationType = Explicit;
    MusicCommandNativeDataKind = MusicSearchCommandNativeData;
    OrderToDisplay =     (
        Track,
        Artist,
        Album
    );
    SearchParameters =     {
        MusicSearchTargetType = "MUSIC_SEARCH_TARGET_TYPE_TOP";
        SearchCriteriaType = SearchForTracks;
    };
    Tracks =     (
                {
            AlbumDate = "2009-11-20";
            AlbumID = 300117215516977013;
            AlbumName = "The Fame Monster";
            ArtistID = 200346971627324820;
            ArtistName = "Lady Gaga, Beyonc\U00e9";
            AudioPreviewURL = "http://www.amazon.com/gp/dmusic/aws/sampleTrack.html?clientid=SoundHound&ASIN=B002X07TMC";
            AutoPlayPreview = 1;
            BuyLinks =             (
                                {
                    Store = PlayStore;
                    URL = "https://play.google.com/store/music/album?id=B5t7w66ic4dqvfzfg3lse6v7ncy&tid=song-Tr6zlzmvtxg3bnfhlgyeglwgr24&PAffiliateID=111l3po";
                },
                                {
                    Store = ITunes;
                    URL = "https://itunes.apple.com/us/album/telephone-feat.-beyonce-passion/id382900899?i=382901246&uo=4&at=10lIs&ct=t-100236021077260375_62000USd";
                }
            );
            LyricsURL = "http://www.google.com/m?q=lyrics+Telephone+Lady+Gaga";
            MusicThirdPartyIds =             (
                                {
                    DeepLinks =                     (
                        "spotify:track:1IaYWv32nFFMdljBIjMY5T"
                    );
                    Ids =                     (
                        "spotify:track:1IaYWv32nFFMdljBIjMY5T"
                    );
                    MusicThirdParty =                     {
                        Name = Spotify;
                    };
                },
                                {
                    DeepLinks =                     (
                        "https://itunes.apple.com/us/album/telephone-feat.-beyonce-passion/id382900899?i=382901246&uo=4&at=10lIs&ct=listen_on_apple_music&app=music"
                    );
                    Ids =                     (
                        382901246
                    );
                    MusicThirdParty =                     {
                        Name = AppleMusic;
                    };
                },
                                {
                    DeepLinks =                     (
                    );
                    Ids =                     (
                        382901246,
                        52725806,
                        25273502
                    );
                    MusicThirdParty =                     {
                        Name = Default;
                    };
                },
                                {
                    DeepLinks =                     (
                        "pandorav2:/createStation?artist=Lady+Gaga&song=Telephone&type=artist&partnerCode=2&trackingCode=x-009427-0035-1149&adId="
                    );
                    Ids =                     (
                    );
                    MusicThirdParty =                     {
                        Name = Pandora;
                    };
                }
            );
            PreviewLinks =             (
                                {
                    Source = itunes;
                    Url = "http://a1638.phobos.apple.com/us/r2000/020/Music/v4/fb/0a/3b/fb0a3b7b-c144-6d87-ffa7-10946e9bf255/mzaf_5123017562781646582.aac.m4a";
                },
                                {
                    Source = itunes;
                    Url = "http://a1638.phobos.apple.com/us/r2000/020/Music/v4/fb/0a/3b/fb0a3b7b-c144-6d87-ffa7-10946e9bf255/mzaf_5123017562781646582.aac.m4a";
                },
                                {
                    Source = itunes;
                    Url = "http://a1638.phobos.apple.com/us/r2000/020/Music/v4/fb/0a/3b/fb0a3b7b-c144-6d87-ffa7-10946e9bf255/mzaf_5123017562781646582.aac.m4a";
                }
            );
            TrackID = 100236021077260375;
            TrackName = Telephone;
        }
    );
    UserRequestedAutoPlay = 1;
}
2016-05-27 12:42:24.604 HoundifySDK Test Application[5834:2094266] {
    DeepLinks =     (
        "spotify:track:1IaYWv32nFFMdljBIjMY5T"
    );
    Ids =     (
        "spotify:track:1IaYWv32nFFMdljBIjMY5T"
    );
    MusicThirdParty =     {
        Name = Spotify;
    };
}

I've tried accessing the spotify ID with this:

NSDictionary *test = commandResult[@"NativeData"][@"Tracks"][0][@"MusicThirdPartyIds"][0];

but although the NSLog shows keys and values for the SpotifyID under "Tracks" when I try to extract it with the test variable above, the key for the SpotifyID is reported as like this (in xcode):

test    __NSDictionaryM *   3 key/value pairs   0x000000013d5aa910
[0] = (no summary) : @"1 element"   
[1] @"MusicThirdParty" : 1 key/value pair   
[2] (no summary) : @"1 element" 

so the key I want is "no summary":

[2] (null)  (no summary) : @"1 element" 
    key NSTaggedPointerString * 0xa000000007364493
    value   __NSArrayM *    @"1 element"    0x000000013d5aaca0
        [0] __NSCFString *  @"spotify:track:1IaYWv32nFFMdljBIjMY5T" 0x000000013d5aad50

I'm clearly misunderstanding how I should access the data. Can anyone please advise? Thanks.

Martin Harrison
  • 145
  • 2
  • 11

1 Answers1

1

You can try this: commandResult[@"NativeData"][@"Tracks"][0][@"MusicThirdPartyIds"][0][@"Ids"][0];

James
  • 138
  • 4
  • Thanks James. That worked - I still need to work out why but thank you for getting me progressed. – Martin Harrison May 31 '16 at 20:33
  • Hello, I try to do the same think (audio identification with SoundHound domain) with iOS SDK 1.1.3. When I try the application sample provided by the SDK and say "what is this music". The answer is "This client does not support sound identification...". Can you please help me ? – fvisticot Jun 14 '17 at 20:24