Image Bgm Generation

功能介绍

图片生成音乐能力,可以根据用户输入的图片来进行音乐创作,输出成品音乐等结果

接口说明

请求方式: POST(HTTP)

请求地址: http://service-mqk0mc83-1257411467.bj.apigw.tencentcs.com/release/job

请求头: Content-Type: application/json

请求流程: 接口包括‘创建任务’,‘查询任务’。创建任务后,用户可以主动查询任务来知晓任务结果,也可以在创建任务时输入回调地址(callback),则任务在完成后会自动回调该地址

其他要求: 文件格式:"png", "jpg", "jpeg", "webp"

创建任务

参数说明

参数 是否必选 类型 说明
action string 公共参数,此处为 CreateJob
secretId string 公共参数,用户 SecretId
secretKey string 公共参数,用户 secretKey
createJobRequest object
- inputs Array of Input Input,输入结构体数组
- outputs Array of Output Output,输出结构体数组
- callback string 回调地址,默认:不开启回调
- customId string 用户自定义任务 ID,小于 64 字符
- timeout int 任务超时时间,单位秒。超过超时时间后任务会被置为 ERROR

Input

参数 是否必选 类型 说明
url string 源 url 地址,与 source 字段二选一填写
source object 仓库源设置,与 url 字段二选一填写
- contentId string 仓库 ID
- path string 源路径

Output

参数 是否必选 类型 说明
contentId string 仓库 ID,默认:空
destination string 输出目录,默认:'/' (即根目录)
inputSelectors Array of int 该输出的输入源
smartContentDescriptor SmartContentDescriptor 智能能力的描述,默认:空
- outputPrefix string 输出文件前缀,小于 20 字符,默认:空
- imageBgmGeneration object 图片生成音乐
-- songQuantity int 作曲数量, 范围[1,100]
-- outputType OutputType enum 输出文件类型,默认mp3
-- emotion SongEmotion enum 作曲情绪类型,默认:空
-- genre SongGenre enum 作曲曲风类型,默认:空
-- type SongType enum 音乐类型选择,默认LARGE_MODEL

SongType

含义
1 LARGE_MODEL(大模型,支持设置情绪和风格)
2 MULTITRACK(多乐器,不支持设置风格)

OutputType

含义
1 MP3
2 MP4

SongEmotion

含义
1 HAPPY(喜悦)
2 SAD (伤感)
3 ROMANTIC(浪漫)
4 QUIET(安静)
5 LAZY(慵懒)
6 EXCITING(兴奋)
7 MAGNIFICENT(恢弘)
8 FUNNY(俏皮)
9 FEAR(恐惧)
10 WARM(温暖),仅当songType为MULTITRACK时有效
11 ANGRY(愤怒),仅当songType为MULTITRACK时有效

SongGenre

含义
1 POP(流行)
2 CLASSICAL(古典)
3 CHINA(国风)
4 SOFT(轻音乐)
5 JAZZ(爵士)

请求示例:

{
  "action": "CreateJob",
  "secretId": "{secretId}",
  "secretKey": "{secretKey}",
  "createJobRequest": {
    "customId": "{customId}",
    "callback": "{callback}",
    "inputs": [
      {
        "url": "{url}"
      }
    ],
    "outputs": [
      {
        "contentId": "{contentId}",
        "destination": "/output",
        "inputSelectors": [0],
        "smartContentDescriptor": {
          "outputPrefix": "{outputPrefix}",
          "imageBgmGeneration": {
            "songQuantity": 1
          }
        }
      }
    ]
  }
}

返回示例:

{
  "requestId": "ac004192-110b-46e3-ade8-4e449df84d60",
  "createJobResponse": {
    "job": {
      "id": "13f342e4-6866-450e-b44e-3151431c578b",
      "state": 1,
      "customId": "{customId}",
      "callback": "{callback}",
      "inputs": [
        {
          "url": "{url}"
        }
      ],
      "outputs": [
        {
          "contentId": "{contentId}",
          "destination": "{destination}",
          "inputSelectors": [0],
          "smartContentDescriptor": {
            "outputPrefix": "{outputPrefix}",
            "imageBgmGeneration": {
              "songQuantity": 1
            }
          }
        }
      ],
      "timing": {
        "createdAt": "1603432763000",
        "startedAt": "0",
        "completedAt": "0"
      }
    }
  }
}

State

含义
1 SUBMITTED
2 PROCESSING
3 COMPLETED
4 ERROR
5 CANCELED

获取任务信息

获取方式:分为主动获取和被动回调。

  • 主动获取按照 id 的类别有两种查询接口,一种是根据用户自定义 id 查询,由于平台无法保证该 id 的唯一性,故返回 Job 数组(见 1);另一种是通过创建任务后的回包中的 id 查询(见 2)
  • 被动回调需要在创建任务时填写 callback 字段,平台在任务进入完成态(COMPLETED/ERROR)后会将 Job 结构体发送给 callback 所指的地址(见 3),平台方推荐使用被动回调的方式获取任务结果。

在图片生成音乐能力中,如果查询到的任务成功(state=3),则任务的 Output 中会携带 smartContentResult 结构体,其中的imageBgmGeneration结构体(Arrary of ImageBgmGenerationResult)存储输出文件名信息。用户根据 Output 中的 cos 及 destination 信息可自行拼接出输出文件的 cos 路径。

ImageBgmGenerationResult

参数 类型 说明
songName string 歌曲文件名称
videoName string 视频文件名称

1. 主动查询,根据用户在新建任务时传入的自定义 customId 请求示例:

{
  "action": "ListJobs",
  "secretId": "{secretId}",
  "secretKey": "{secretKey}",
  "listJobsRequest": {
    "customId": "{customId}"
  }
}

返回示例:

{
  "requestId": "c9845a99-34e3-4b0f-80f5-f0a2a0ee8896",
  "listJobsResponse": {
    "jobs": [
      {
        "id": "a95e9d74-6602-4405-a3fc-6408a76bcc98",
        "state": 3,
        "customId": "{customId}",
        "callback": "{callback}",
        "timing": {
          "createdAt": "1610513575000",
          "startedAt": "1610513575000",
          "completedAt": "1610513618000"
        },
        "inputs": [{ "url": "{url}" }],
        "outputs": [
          {
            "contentId": "{contentId}",
            "destination": "{destination}",
            "inputSelectors": [0],
            "smartContentDescriptor": {
              "outputPrefix": "{outputPrefix}",
              "imageBgmGeneration": {
                "songQuantity": 1
              }
            },
            "smartContentResult": {
              "imageBgmGeneration": [{
                "songName": "song.mp3"
              }]
            }
          }
        ]
      }
    ],
    "total": 1
  }
}

2. 主动查询,根据新建任务时回包带的 id 请求示例:

{
  "action": "GetJob",
  "secretId": "{secretId}",
  "secretKey": "{secretKey}",
  "getJobRequest": {
    "id": "{id}"
  }
}

返回示例:

{
  "requestId": "c9845a99-34e3-4b0f-80f5-f0a2a0ee8896",
  "getJobResponse": {
    "job": {
      "id": "a95e9d74-6602-4405-a3fc-6408a76bcc98",
      "state": 3,
      "customId": "{customId}",
      "callback": "{callback}",
      "timing": {
        "createdAt": "1610513575000",
        "startedAt": "1610513575000",
        "completedAt": "1610513618000"
      },
      "inputs": [{ "url": "{url}" }],
      "outputs": [
        {
          "contentId": "{contentId}",
          "destination": "{destination}",
          "inputSelectors": [0],
          "smartContentDescriptor": {
            "outputPrefix": "{outputPrefix}",
            "imageBgmGeneration": {
              "songQuantity": 1
            }
          },
          "smartContentResult": {
            "imageBgmGeneration": [{
              "songName": "song.mp3"
            }]
          }
        }
      ]
    }
  }
}

3. 被动回调

会将进入完成态(COMPLETED/ERROR)的任务的整个 Job 结构体发送到用户在创建任务时指定的 callback 字段对应的地址,Job 结构体见主动查询的示例(getJobResponse 下)

Tencent Media Lab
/
We would like to use performance and analytics cookies (“Cookies”) to help us recognize whether you are a returning visitor and to track the number of website views and visits. For more information about the Cookies we use and your options (including how to change your preferences) see our Cookies Policy.