This document aims to help users complete the TMP service registration in a very short time after completing the prerequisite activation steps and preparing the relevant input parameters, and generate a directly runnable Python version demo, minimizing the user's development effort as much as possible
Prerequisites
Before formal registration, please complete the following activation steps and prepare the relevant parameters
Activation Steps:
- Create a Tencent Cloud account at https://tencentcloud.com and complete real-name verification (skip if already done), ensure the account has a balance of 30 USD
- Go to the purchase page to activate the music service. https://buy.tencentcloud.com/imusic
- In CAM (https://console.tencentcloud.com/cam), create an AK/SK key pair (i.e., a user with programmatic access, no login or any user permissions required)
- Create a COS bucket, create a COS (Object Storage) bucket (https://console.tencentcloud.com/cos/bucket), and authorize the created programmatic-only user with read and write permissions for the COS bucket in the COS bucket management interface
Prepare Parameters
- operateUin: Tencent Cloud sub-user's account ID
- cosConfig: Object storage related parameters
- secretId: Bucket's secretId
- secretKey: Bucket's secretKey
- bucket: Bucket name
- region: Bucket region, e.g., "ap-guangzhou"
Activation Registration
After completing the prerequisites, initiate a request to register and activate. Expected wait time: about 2 minutes
Initiate Request:
curl -X POST \
https://api.mediax.tencent.com/register \
-H 'Content-Type: application/json' \
-H 'Cache-control: no-cache' \
-d '{
"requestId": "test-regisiter-service",
"action": "Register",
"registerRequest": {
"operateUin": <operateUin>,
"userName": <customedName>,
"cosConfig": {
"secretId": <CosConfig.secretId>,
"secretKey": <CosConfig.secretKey>,
"bucket": <CosConfig.bucket>,
"region": <CosConfig.region>
}
}
}'
Request Result:
After initiating the request, the response is expected to return in about 2 minutes
{
"requestId": "test-regisiter-service",
"registerInfo": {
"tmpContentId": <tmpContentId>,
"tmpSecretId": <tmpSecretId>,
"tmpSecretKey": <tmpSecretKey>,
"apiGateSecretId": <apiGateSecretId>,
"apiGateSecretKey": <apiGateSecretKey>,
"demoCosPath": "UIN_demo/run_musicBeat.py",
"usageDescription": "Please download the Python version demo file [UIN_demo/run_musicBeat.py] from the COS bucket [CosConfig.bucket], replace the input file in the demo, then execute python run_musicBeat.py",
"message": "Registration successful, thank you for registering",
"createdAt": <createdAt>,
"updatedAt": <updatedAt>
}
}
Parameter Description
Request Parameter Description
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| action | Yes | string | Common parameter, here is Register |
| userName | Yes | string | User name, must be letters or numbers, less than or equal to 19 characters, special symbols not supported |
| operateUin | Yes | string | Tencent Cloud account ID, fill in the Tencent Cloud account ID used when activating the music service. If using the main account, fill in the main account ID; if using a sub-account, fill in the sub-account ID |
| - secretId | Yes | string | User SecretId |
| - secretKey | Yes | string | User secretKey |
| - bucket | Yes | string | User COS bucket name |
| - region | Yes | string | User COS bucket region |
| - domain | No | string | User COS bucket domain |
Response Parameter Description
| Parameter Name | Type | Description |
|---|---|---|
| tmpContentId | string | cosConfig registration ID in the Smart Music Platform |
| tmpSecretId | string | Smart Music Platform identity ID |
| tmpSecretKey | string | Smart Music Platform identity key |
| apiGateSecretId | string | API Gateway identity ID |
| apiGateSecretKey | string | API Gateway identity key |
| demoCosPath | string | After the registration request is completed, a Python demo will be stored at this path in the input COS |
| usageDescription | string | Usage description |
| message | string | Prompt message |
Run Verification
After completing the above activation registration service, a Python executable demo using Music Beat Recognition capability as an example will be generated in the demoCosPath directory. Please execute the command python run_musicBeat.py in a networked environment
Python-demo Template:
import requests
import datetime
import hashlib
import hmac
import base64
GMT_FORMAT = "%a, %d %b %Y %H:%M:%S GMT"
API_GATE_SOURCE = "uin_userName"
API_GATE_SECRET_ID = "apiSecretId"
API_GATE_SECRET_KEY = "apiSecretKey"
URL = "https://api.mediax.tencent.com/job"
TMP_CONTENT_ID = "tmpContentId"
TMP_SECRET_ID = "tmpSecretId"
TMP_SECRET_KEY = "tmpSecretKey"
def get_api_gate_signature(source, secret_id, secret_key):
date_time = datetime.datetime.utcnow().strftime(GMT_FORMAT)
auth = (
'hmac id="'
+ secret_id
+ '", algorithm="hmac-sha1", headers="date source", signature="'
)
signStr = "date: " + date_time + "\n" + "source: " + source
sign = hmac.new(secret_key.encode(), signStr.encode(), hashlib.sha1).digest()
sign = base64.b64encode(sign).decode()
sign = auth + sign + '"'
return sign, date_time, source
if __name__ == "__main__":
sign, date_time, source = get_api_gate_signature(
API_GATE_SOURCE, API_GATE_SECRET_ID, API_GATE_SECRET_KEY
)
headers = {
"Content-Type": "application/json",
"Authorization": sign,
"Date": date_time,
"Source": source,
}
request = {
"action": "CreateJob",
"secretId": TMP_SECRET_ID,
"secretKey": TMP_SECRET_KEY,
"createJobRequest": {
"customId": "musicBeat",
"inputs": [
{
"source": {
"contentId": TMP_CONTENT_ID,
"path": "file_path_to_root"
}
}
],
"outputs": [
{
"contentId": TMP_CONTENT_ID,
"destination": "/output/musicBeat",
"inputSelectors": [0],
"smartContentDescriptor": {
"musicBeat": {
"outputType": 4,
"drumType": 2,
"enlargeLevel": 3,
"splitNum": 3,
},
},
}
],
},
}
resp = requests.post(
url=URL,
headers=headers,
json=request,
)
print(resp.text)
Get Task Information
Please refer to the "Get Task Information" section in the corresponding API documentation to query task execution status