跳到内容

音乐识别 ​

更新时间

本文档参考 Tencent Cloud 官方文档 Music Identification Integration。

从输入的音频或视频中识别音乐并识别翻唱歌曲。基于 Tencent Music 的音频指纹算法,返回曲名、专辑、歌手、播放区间。

API 信息 ​

项目值
服务MPS
API ActionProcessMedia
Endpointmps.tencentcloudapi.com
API 版本2019-06-12
处理方式异步(下发 TaskId 后查询结果)

认证方面,所有 API 统一使用 TC3-HMAC-SHA256(SecretId/SecretKey) 签名。签名生成方法请参考 Quick Start 中的 TokenHub 文档。

请求参数 ​

参数类型必填示例说明
InputInfoObject必填{"Type":"URL","UrlInputInfo":{"Url":"https://example.com/audio.mp3"}}输入媒体。Type 为 URL 或 COS
OutputStorageObject必填{"Type":"COS","CosOutputStorage":{"Bucket":"mybucket-125xxx","Region":"ap-guangzhou"}}输出存储
OutputDirString选填/output/music/输出目录
AiAnalysisTask.DefinitionInteger必填21音乐识别预设模板 ID。固定值 21
AiAnalysisTask.ExtendedParameterString必填{"tag":{"process_type":"1102"}}扩展参数。process_type 固定为 1102
TaskNotifyConfig.NotifyUrlString选填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_namestring曲名
album_namestring专辑名
singer_namestring歌手名
other_singer_listarray相关歌手列表
reference_startint歌曲的大致起始时间点
reference_endint歌曲的大致结束时间点
segment_listarray歌曲出现的时间区间列表

使用说明 ​

TagSet 为 `` 时,表示该音频区间没有匹配到歌曲。

reference_start 与 reference_end 仅供参考。实际区间以 segment_list 为准。检测间隔为 15 秒,因此与实际歌曲长度的误差最大为 15 秒。

音乐识别按输入文件长度计费。

基于 VitePress 构建 · 部署于腾讯云 EdgeOne Pages