音乐识别
本文档参考 Tencent Cloud 官方文档 Music Identification Integration。
从输入的音频或视频中识别音乐并识别翻唱歌曲。基于 Tencent Music 的音频指纹算法,返回曲名、专辑、歌手、播放区间。
API 信息
| 项目 | 值 |
|---|---|
| 服务 | MPS |
| API Action | ProcessMedia |
| Endpoint | mps.tencentcloudapi.com |
| API 版本 | 2019-06-12 |
| 处理方式 | 异步(下发 TaskId 后查询结果) |
认证方面,所有 API 统一使用 TC3-HMAC-SHA256(SecretId/SecretKey) 签名。签名生成方法请参考 Quick Start 中的 TokenHub 文档。
请求参数
| 参数 | 类型 | 必填 | 示例 | 说明 |
|---|---|---|---|---|
| InputInfo | Object | 必填 | {"Type":"URL","UrlInputInfo":{"Url":"https://example.com/audio.mp3"}} | 输入媒体。Type 为 URL 或 COS |
| OutputStorage | Object | 必填 | {"Type":"COS","CosOutputStorage":{"Bucket":"mybucket-125xxx","Region":"ap-guangzhou"}} | 输出存储 |
| OutputDir | String | 选填 | /output/music/ | 输出目录 |
| AiAnalysisTask.Definition | Integer | 必填 | 21 | 音乐识别预设模板 ID。固定值 21 |
| AiAnalysisTask.ExtendedParameter | String | 必填 | {"tag":{"process_type":"1102"}} | 扩展参数。process_type 固定为 1102 |
| TaskNotifyConfig.NotifyUrl | String | 选填 | https://example.com/callback | 任务完成回调 URL。NotifyType 为 URL |
调用示例
python
import json
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.mps.v20190612 import mps_client, models
cred = credential.Credential("<SecretId>", "<SecretKey>")
http_profile = HttpProfile
http_profile.endpoint = "mps.tencentcloudapi.com"
client = mps_client.MpsClient(cred, "ap-guangzhou", ClientProfile(httpProfile=http_profile))
params = {
"InputInfo": {
"Type": "URL",
"UrlInputInfo": {"Url": "https://example.com/audio.mp3"}
},
"OutputStorage": {
"Type": "COS",
"CosOutputStorage": {"Bucket": "mybucket-125xxx", "Region": "ap-guangzhou"}
},
"OutputDir": "/output/music/",
"AiAnalysisTask": {
"Definition": 21,
"ExtendedParameter": json.dumps({"tag": {"process_type": "1102"}})
},
"TaskNotifyConfig": {
"NotifyType": "URL",
"NotifyUrl": "https://example.com/callback"
}
}
req = models.ProcessMediaRequest
req.from_json_string(json.dumps(params))
resp = client.ProcessMedia(req)
print(resp.to_json_string)响应示例
结果可在完成回调的 AiAnalysisResultSet 中通过 TagTask.Output.TagSet 查看。
json
{
"AiAnalysisResultSet": [
{
"TagTask": {
"Status": "SUCCESS",
"Output": {
"TagSet": [
{
"Confidence": 100,
"Tag": "An Array of Stars",
"SpecialInfo": "{\"song_mid\":\"000Quzkn4N0CBN\",\"song_id\":521340020,\"reference_start\":30,\"song_name\":\"An Array of Stars\",\"album_name\":\"An Array of Stars\",\"reference_end\":255,\"singer_name\":\"TIA RAY\",\"segment_list\":[[30,165],[180,255]],\"other_singer_list\":[{\"singer_name\":\"Jam Hsiao\"}]}"
}
]
}
},
"Type": "Tag"
}
]
}SpecialInfo 字段
| 字段 | 类型 | 说明 |
|---|---|---|
| song_name | string | 曲名 |
| album_name | string | 专辑名 |
| singer_name | string | 歌手名 |
| other_singer_list | array | 相关歌手列表 |
| reference_start | int | 歌曲的大致起始时间点 |
| reference_end | int | 歌曲的大致结束时间点 |
| segment_list | array | 歌曲出现的时间区间列表 |
使用说明
TagSet 为 `` 时,表示该音频区间没有匹配到歌曲。
reference_start 与 reference_end 仅供参考。实际区间以 segment_list 为准。检测间隔为 15 秒,因此与实际歌曲长度的误差最大为 15 秒。
音乐识别按输入文件长度计费。