Feature Introduction
Intelligent composition capability can create music based on user-input song types and output finished music
API Description
Request Method: POST (HTTP)
Request URL: https://api.mediax.tencent.com/job
Request Header: Content-Type: application/json
Request Flow: The API includes 'Create Task' and 'Query Task'. After creating a task, users can actively query the task to know the result, or input a callback address when creating the task, and the task will automatically callback to that address after completion
Create Task
Parameter Description
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | Yes | string | Common parameter, here is CreateJob |
| secretId | Yes | string | Common parameter, user SecretId |
| secretKey | Yes | string | Common parameter, user SecretKey |
| createJobRequest | Yes | object | |
| - outputs | Yes | Array of Output | Output, output structure array |
| - callback | No | string | Callback address, default: callback disabled |
| - customId | No | string | User-defined task ID, less than 64 characters |
| - timeout | No | int | Task timeout, in seconds. Task will be set to ERROR after timeout |
Output
| Parameter | Required | Type | Description |
|---|---|---|---|
| contentId | Yes | string | Repository ID, default: empty |
| destination | No | string | Output directory, default: '/' (root directory) |
| smartContentDescriptor | Yes | SmartContentDescriptor | Smart capability description, default: empty |
| - musicCompose | Yes | object | Intelligent composition |
| -- songQuantity | Yes | int | Number of music to output. Range [1,100], default: 1 |
| -- songType | No | SongType enum | Music type selection, default LARGE_MODEL |
| -- emotion | No | SongEmotion enum | Music emotion selection, default not set |
| -- genre | No | SongGenre enum | Music genre selection, only effective when songType is LARGE_MODEL, default not set |
| -- soundEffect | No | SoundEffect enum | Music sound effect selection, default not specified |
SongType
| Value | Meaning |
|---|---|
| 1 | LARGE_MODEL (Large model, supports setting emotion and genre) |
| 2 | MULTITRACK (Multi-instrument, does not support setting genre) |
SongEmotion
| Value | Meaning |
|---|---|
| 1 | HAPPY (Happy) |
| 2 | SAD (Sad) |
| 3 | ROMANTIC (Romantic) |
| 4 | QUIET (Quiet) |
| 5 | LAZY (Lazy) |
| 6 | EXCITING (Exciting) |
| 7 | MAGNIFICENT (Magnificent) |
| 8 | FUNNY (Playful) |
| 9 | FEAR (Fear) |
| 10 | WARM (Warm), only effective when songType is MULTITRACK |
| 11 | ANGRY (Angry), only effective when songType is MULTITRACK |
SongGenre
| Value | Meaning |
|---|---|
| 1 | POP (Pop) |
| 2 | CLASSICAL (Classical) |
| 3 | CHINA (Chinese Style) |
| 4 | SOFT (Easy Listening) |
| 5 | JAZZ (Jazz) |
SongType
| Value | Meaning |
|---|---|
| 1 | SOFT (Soothing) |
| 2 | HAPPY (Upbeat) |
| 3 | ROMANTIC (Romantic) |
| 4 | CHINA (Chinese Style) |
SoundEffect
| Value | Meaning |
|---|---|
| 1 | RAIN |
| 2 | WAVES |
| 3 | RIVER |
| 4 | BIRD |
| 5 | INSECT |
| 6 | GHOST |
Request Example:
{
"action": "CreateJob",
"secretId": "{secretId}",
"secretKey": "{secretKey}",
"createJobRequest": {
"customId": "{customId}",
"callback": "{callback}",
"outputs": [
{
"contentId": "{contentId}",
"destination": "/output",
"inputSelectors": [0],
"smartContentDescriptor": {
"musicCompose": {
"songQuantity": 1
}
}
}
]
}
}
Response Example:
{
"requestId": "ac004192-110b-46e3-ade8-4e449df84d60",
"createJobResponse": {
"job": {
"id": "13f342e4-6866-450e-b44e-3151431c578b",
"state": 1,
"customId": "{customId}",
"callback": "{callback}",
"outputs": [
{
"contentId": "{contentId}",
"destination": "{destination}",
"smartContentDescriptor": {
"musicCompose": {
"songQuantity": 1
}
}
}
],
"timing": {
"createdAt": "1603432763000",
"startedAt": "0",
"completedAt": "0"
}
}
}
}
State
| Value | Meaning |
|---|---|
| 1 | SUBMITTED |
| 2 | PROCESSING |
| 3 | COMPLETED |
| 4 | ERROR |
| 5 | CANCELED |
Get Task Information
There are two ways to get information: active query and passive callback.
- Active query has two types of query interfaces based on id category: one is to query based on user-defined id, since the platform cannot guarantee the uniqueness of this id, it returns a Job array (see 1); the other is to query by the id in the response after creating the task (see 2)
- Passive callback requires filling in the callback field when creating the task, the platform will send the Job structure to the address specified by callback after the task enters the completion state (COMPLETED/ERROR) (see 3), the platform recommends using passive callback to get task results.
In the intelligent composition capability, if the queried task is successful (state=3), the task's Output will carry a smartContentResult structure, in which the songName in musicCompose is the output result file name. Users can assemble the COS path of the output file based on the COS and destination information in Output.
1. Active Query, Based on User-Defined customId Passed When Creating Task Request Example:
{
"action": "ListJobs",
"secretId": "{secretId}",
"secretKey": "{secretKey}",
"listJobsRequest": {
"customId": "{customId}"
}
}
Response Example:
{
"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"
},
"outputs": [
{
"contentId": "{contentId}",
"destination": "{destination}",
"smartContentDescriptor": {
"musicCompose": {
"songQuantity": 1
}
},
"smartContentResult": {
"musicCompose": [
{
"songName": "out.mp3"
}
]
}
}
]
}
],
"total": 1
}
}
2. Active Query, Based on id in Response After Creating Task Request Example:
{
"action": "GetJob",
"secretId": "{secretId}",
"secretKey": "{secretKey}",
"getJobRequest": {
"id": "{id}"
}
}
Response Example:
{
"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"
},
"outputs": [
{
"contentId": "{contentId}",
"destination": "{destination}",
"smartContentDescriptor": {
"musicCompose": {
"songQuantity": 1
}
},
"smartContentResult": {
"musicCompose": [
{
"songName": "out.mp3"
}
]
}
}
]
}
}
}
3. Passive Callback
The entire Job structure of the task that enters the completion state (COMPLETED/ERROR) will be sent to the address corresponding to the callback field specified by the user when creating the task. See the active query example (under getJobResponse) for the Job structure