### 3.3.4 Smart Music #### (1) 功能说明 模糊场景下抽取关键词智能推荐相关的音乐。 #### (2) 接口说明 **请求方法** * POST **请求地址** * http://api.ruyi.ai/v1/message **请求参数说明** |参数名 |参数类型 | 是否必须 |参数说明 | :-----| :---| :---:|:----- |q |String| 是| 自然语言表达,例如“想去迪士尼乐园,给我放歌”,”我准备睡觉了,放个歌“等 |app_key| String|是 |应用开发者秘钥,注册开发者后台账号,建立虚拟助理后获得 |user_id |String| 是 |用户唯一标识,便于支持个性化语义解析。建议开发者使用 UUID 字符,且不同用户必须用不同的 user_id,防止意图串。 #### (3) 返回说明 **返回参数说明** |名称 |类型| 说明 |:---|:---|:--- |code |Integer | 返回代码 |msg | String |返回代码描述 |parameters|JSON Object |解析到的实体以及服务说明 |action|String|服务的接口名称 |name| String|匹配的意图名称 |result | JSON Object| 接口返回内容 |outputs| Array| 服务输出结果,微信端使用 type 类型为 wechat 开头的内容;硬件端收到所有内容,依据需求解析使用 **返回代码说明** |返回代码 |错误类型|说明 |:---|:---|:--- |0/200 |成功 |请求成功 |400 |无效请求 |某些必需参数缺失或参数值错误,详见msg字段 |401 |未授权 |授权失败,app_key 缺失或错误 |403 |请求被禁止|有效请求,但服务拒绝响应,请联系contact@ruyi.ai |408 |请求超时 |请求响应超时,一般响应时间设置为2000ms以内 |429 |短时间内大量访问 |短时间内请求数过多 |500 |内部错误 |服务处理异常 |503 |服务不可用|服务异常或正在维护 #### (4) 请求示例 **请求范例** _清晨的空气真好,放一首歌吧_ _早晨起来听得歌有么_ _今天真开心啊,给我放一首歌听听吧_ _好累啊,能给我播放一首歌么_ _今天上班真的是好难过,放首歌给我听吧_ _我在跑步呢,适合听点什么歌呢_ _有适合在迪厅里放的歌吗_ _我要听蔡依林的华语歌曲_ _我失恋了,能放首歌安慰我一下吗_ _今天是大年三十啊,好喜庆呀,来点音乐吧_ **请求示例** * http://api.ruyi.ai/ruyi-api/v1/message?app_key=APP_KEY&user_id=user0&q=我正在跑步,能播放一首歌吗 返回结果 ```json { "code": 0, "msg": "ok", "result": { "_text": "我正在跑步,能播放一首歌吗", "msg_id": "362881f2-2d8e-4d95-a8b9-4e03723158b8", "intents": [ { "parameters": { "tag": "跑步", "service": "music" }, "action": "sys.action.kg/music/smart", "name": "smart music", "result": { "music_list": [ { "name": "All Over", "xiami": "1773487066", "image": "http://img.xiami.net/images/album/img69/9543269/95432751409543276_1.jpg", "artist": "CRUISR" }, { "name": "Brown Eyes", "xiami": "1770322515", "image": "http://img.xiami.net/images/album/img8/92608/4510701310352549_1.jpg", "artist": "Heather Batchelor" }, { "name": "Bach: Cello Suite No.1 in G major,Ⅰ Prelude", "xiami": "1771709960", "image": "http://img.xiami.net/images/album/img33/733/3620435201472659597_1.jpg", "artist": "Yo-Yo Ma" }, { "name": "Whistle For The Choir ", "xiami": "3427286", "image": "http://img.xiami.net/images/album/img11/24911/3096561385609811_1.jpg", "artist": "The Fratellis" }, { "name": "Fire Burning", "xiami": "1773334410", "image": "http://img.xiami.net/images/album/img2/720502/7205021404720502_1.jpg", "artist": "Fraser James" }, { "name": "Wrecking Ball", "xiami": "1769111701", "image": "http://img.xiami.net/images/album/img60/37160/3464571341354346_1.jpg", "artist": "Frankmusik" }, { "name": "You're Hot", "xiami": "2334594", "image": "http://img.xiami.net/images/album/img84/193984/i37224q2htv_1.jpg", "artist": "Sneaky Sound System" }, { "name": "Hunting For You", "xiami": "1771287734", "image": "http://img.xiami.net/images/album/img47/13247/5399331393392184_1.jpg", "artist": "Robbie Williams" }, { "name": "Put Out The Fire", "xiami": "1771746070", "image": "http://img.xiami.net/images/album/img64/275564/2755641363275564_1.jpg", "artist": "Abby Victor" }, { "name": "On The Radio", "xiami": "1770322194", "image": "http://img.xiami.net/images/album/img77/23477/4510431383620824_1.jpg", "artist": "Groove Coverage" }, { "name": "Radioactive", "xiami": "1771826011", "image": "http://img.xiami.net/images/album/img31/88831/18664786141366484000_1.jpg", "artist": "Imagine Dragons" }, { "name": "Can't Feel My Face", "xiami": "1776339768", "image": "http://img.xiami.net/images/album/img58/23258/21003798101471331019_1.jpg", "artist": "The Weeknd" }, { "name": "Numb Encore", "xiami": "1770087845", "image": "http://img.xiami.net/images/album/img66/11766/4305301300160789_1.jpg", "artist": "Eminem,Linkin Park,Dr. Dre,Jay Z,50 Cent" }, { "name": "Apocalyptica", "xiami": "1771132034", "image": "http://img.xiami.net/images/album/img88/112888/5251141341222708_1.jpg", "artist": "Nais" }, { "name": "Say Somethin", "xiami": "1770035708", "image": "http://img.xiami.net/images/album/img73/11573/4259021375328453.jpeg", "artist": "Mariah Carey,Snoop Dogg" }, { "name": "Turn Me On", "xiami": "1770804700", "image": "http://img.xiami.net/images/album/img16/27516/4937121376644000.jpeg", "artist": "Nicki Minaj,David Guetta" }, { "name": "My Feelings For You", "xiami": "1771080133", "image": "http://img.xiami.net/images/album/img83/81683/5202661339568916_1.jpg", "artist": "Avicii,Sebastien Drums" }, { "name": "Belisha Beacon", "xiami": "1769476352", "image": "http://img.xiami.net/images/album/img42/682442/1271682442_1.jpg", "artist": "Funki Porcini" }, { "name": "Bossa 24", "xiami": "1769455677", "image": "http://img.xiami.net/images/album/img26/73026/3758161270611400_1.jpg", "artist": "Ivana Parnasso" }, { "name": "You Are Dj", "xiami": "175438", "image": "http://img.xiami.net/images/album/img36/2636/14205_1.jpg", "artist": "芭比" } ], "msg": "ok", "text": "正在为您播放【CRUISR】的【All Over】,资源来自虾米。", "type": "dialog" }, "outputs": [ { "type": "wechat.text", "property": { "text": "正在为您播放【CRUISR】的【All Over】,资源来自虾米。" } }, { "type": "dialog", "property": { "text": "正在为您播放【CRUISR】的【All Over】,资源来自虾米。", "emotion": "calm" } } ], "score": "1.0", "scoreColor": "c4", "is_match": 1, "skill_id": "bbb934f6-b869-4a91-9fd1-27bd7d0c0d0d", "id": "2df8a38f-380d-4625-85ed-121e576b72ea" } ], "meta_process_milliseconds": 252 } } ``` **详细参数说明** |名称 |类型| 说明 |:---|:---|:--- |service| String |服务名称 |artist|String |歌手名 |music_list|Array|返回的歌曲列表 |id|String |源网站歌曲ID |pic| String |歌曲封面地址 |name|String |歌曲名称