我正在使用Houndify SDK的v1.05及其演示应用。我正在对音乐进行语音搜索,并努力了解如何从Houndify响应中提取Spotify曲目ID。
Houndify以HoundDataHoundServer
的对象作为回应,他们的示例显示如此处理语音响应:
HoundDataCommandResult* commandResult = response.allResults.firstObject;
self.responseTextView.text = commandResult.writtenResponse;
继续转储整个响应:
NSDictionary* nativeData = commandResult[@"NativeData"];
NSLog(@"NativeData: %@", nativeData);
,在示例转储中,从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;
};
}
我尝试使用以下方式访问spotify ID:
NSDictionary *test = commandResult[@"NativeData"][@"Tracks"][0][@"MusicThirdPartyIds"][0];
但是,尽管NSLog在" Tracks"下显示了SpotifyID的键和值。当我尝试使用上面的测试变量提取它时,SpotifyID的键被报告为这样(在xcode中):
test __NSDictionaryM * 3 key/value pairs 0x000000013d5aa910
[0] = (no summary) : @"1 element"
[1] @"MusicThirdParty" : 1 key/value pair
[2] (no summary) : @"1 element"
所以我想要的关键是"没有摘要":
[2] (null) (no summary) : @"1 element"
key NSTaggedPointerString * 0xa000000007364493
value __NSArrayM * @"1 element" 0x000000013d5aaca0
[0] __NSCFString * @"spotify:track:1IaYWv32nFFMdljBIjMY5T" 0x000000013d5aad50
我明显误解了我应该如何访问数据。任何人都可以建议吗?感谢。
答案 0 :(得分:1)
你可以试试这个: commandResult [@ “NativeData”] [@ “曲目”] [0] [@ “MusicThirdPartyIds”] [0] [@ “IDS”] [0];