Audio Separation
本文档参考 Tencent Cloud 官方文档 Audio Separation Integration。
从输入视频或音频中分离出人声(语音)、伴奏与背景音,并输出为独立轨道。它与画质增强使用同一 ProcessMedia 流程,通过 EnhanceConfig.AudioEnhance.Separate 配置生效。
API 信息
| 项目 | 值 |
|---|---|
| 服务 | MPS |
| API Action | ProcessMedia |
| 端点 | mps.tencentcloudapi.com |
| API 版本 | 2019-06-12 |
| 处理方式 | 异步(获取 TaskId 后查询结果) |
认证方面,所有 API 统一使用 TC3-HMAC-SHA256(SecretId/SecretKey)签名。签名生成方法请参考 Quick Start 的 TokenHub 文档。
可通过 DescribeTaskDetail 或完成回调获取结果。
请求参数
| 参数 | 类型 | 必填 | 示例 | 说明 |
|---|---|---|---|---|
| InputInfo | Object | 必填 | {"Type":"COS","CosInputInfo":{"Bucket":"mybucket-125xxx","Region":"ap-guangzhou","Object":"/input/video.mp4"}} | 输入媒体信息。Type 为 URL 或 COS |
| OutputStorage | Object | 选填 | {"Type":"COS","CosOutputStorage":{"Bucket":"mybucket-125xxx","Region":"ap-guangzhou"}} | 输出存储。指定 COS Bucket 与 Region |
| OutputDir | String | 选填 | /output/enhance/ | 输出目录。须以 / 开头并以 / 结尾 |
| MediaProcessTask.TranscodeTaskSet.N.RawParameter | Object | 必填 | 参见下方调用示例 | 音频分离仅在自定义参数模式下支持 |
| RawParameter.EnhanceConfig.AudioEnhance.Separate.Switch | String | 必填 | ON | 启用音频分离 |
| RawParameter.EnhanceConfig.AudioEnhance.Separate.Type | String | 必填 | normal | 分离类型。normal(人声 / 背景音分离)或 music(伴奏分离) |
| RawParameter.EnhanceConfig.AudioEnhance.Separate.Track | String | 必填 | vocal | 输出轨道。vocal(人声)或 background(背景)。默认值 — |
| RawParameter.Container | String | 选填 | mp4 | 输出封装格式:mp4 / hls / flv |
| RawParameter.AudioTemplate.Codec | String | 选填 | aac | 输出音频编解码器:aac / mp3 / copy |
| RawParameter.AudioTemplate.Bitrate | Integer | 选填 | 128 | 输出音频码率(kbps) |
| TaskNotifyConfig.NotifyUrl | String | 选填 | https://example.com/callback | 任务完成回调 URL。NotifyType 为 URL |
分离对象与参数组合的对应关系如下。
| 分离对象 | Type | Track |
|---|---|---|
| 提取人声(去除背景音乐) | normal | vocal |
| 提取背景音(去除人声) | normal | background |
| 提取伴奏(去除人声,保留音乐) | music | background |
响应参数
| 参数 | 类型 | 必填 | 示例 | 说明 |
|---|---|---|---|---|
| TaskId | String | 总是 | 1250017490-20260318152230-abcdef123456 | 下发的任务 ID。用于查询结果 |
| RequestId | String | 总是 | 3c140219-cfe9-470e-b241-907877d6fb03 | 请求标识 |
调用示例
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/video.mp4"}
},
"OutputStorage": {
"Type": "COS",
"CosOutputStorage": {"Bucket": "mybucket-125xxx", "Region": "ap-guangzhou"}
},
"OutputDir": "/output/enhance/",
"MediaProcessTask": {
"TranscodeTaskSet": [{
"RawParameter": {
"Container": "mp4",
"RemoveVideo": 0,
"RemoveAudio": 0,
"VideoTemplate": {
"Codec": "h265", "Fps": 0, "Bitrate": 0,
"Width": 1920, "Height": 0,
"ResolutionAdaptive": "open", "FillType": "black",
"ScenarioBased": 1, "CompressType": "standard_compress"
},
"AudioTemplate": {
"Codec": "aac", "Bitrate": 128,
"SampleRate": 44100, "AudioChannel": 2
},
"TEHDConfig": {"Type": "TEHD-100", "MaxVideoBitrate": 0},
"EnhanceConfig": {
"AudioEnhance": {
"Separate": {"Switch": "ON", "Type": "normal", "Track": "vocal"}
}
}
}
}]
}
}
req = models.ProcessMediaRequest
req.from_json_string(json.dumps(params))
resp = client.ProcessMedia(req)
print(resp.to_json_string)响应示例
json
{
"TaskId": "1250017490-20260318152230-abcdef123456",
"RequestId": "3c140219-cfe9-470e-b241-907877d6fb03"
}使用说明
提取人声时 Separate.Track 指定为 vocal,提取背景音时指定为 background。
音频分离与画质增强分别由各自的任务构成。
若同时需要人声与伴奏,请分别提交两个 Separate 配置不同的任务。结果查询使用 Task Query 的 DescribeTaskDetail。