General-Purpose Speech Multitask Engine

Description

General-purpose speech multitask engine.

Version

1.0

Media Requirements

Supported audio formats: WAV, M4A, MP4, MP3, AAC, and others.

API URL

Production environment: https://openapi.meitu.com
Task submission endpoint: https://openapi.meitu.com/api/v1/sdk/sync/push
Task name (`task`): /v1/ai_audio_engine/481991
Task type (`task_type`): formula

Method

POST

Content-Type: application/json

Authentication

Open Platform API Signing

Request Parameters

RequiredParameterTypeDescription
RequiredtaskString/v1/ai_audio_engine/481991
Requiredtask_typeStringformula
Requiredinit_imagesObject[]Multimedia files
RequiredparamsStringInference parameters
Optionalsync_timeoutIntDefault: 30. Synchronous timeout. If the API times out, status is 9; use the Task Query API to retrieve the result.

The structure of each multimedia item in init_images is described below.

RequiredParameterTypeDescription
RequiredurlStringAudio URL or base64 data
RequiredprofileobjectAudio attribute information

The profile object is described below.

RequiredParameterTypeDescription
Requiredmedia_profilesobjectAudio attribute information
RequiredversionstringFixed value: v1

The fields in media_profiles are described below.

RequiredParameterTypeDescription
Requiredmedia_data_typeStringurl indicates a URL; the corresponding audio type indicates base64 data.

params is a JSON string whose decoded structure is described below.

RequiredParameterTypeDescription
Optionalrsp_media_typeStringDefault: url
RequiredparameterobjectInference parameters

The fields in parameter are described below.

RequiredParameterTypeDescription
Requiredtask_typeStringTask type. Supported values are listed below.

Supported task_type values:

ValueDescriptionDependencies
lufsRetrieve audio loudness-
trans_audioTranscribe and translate audio; return the translation and transcription-
duckingVocal-ducking keyframes-
trainTrain and save a voice profileai-audio-timbre, ai-audio-spliter, ai-audio-asr
synthGenerate audio using an existing voice profileai-audio-timbre, ai-audio-spliter, ai-audio-asr
synth_onceClone and generate once without saving the voice profileai-audio-timbre, ai-audio-spliter, ai-audio-asr
editVoice editingai-audio-timbre, ai-audio-spliter, ai-audio-asr
transTranslate and generate using an existing voice profileai-audio-timbre, ai-audio-spliter, ai-audio-asr
trans_onceExtract a voice profile and translate audio in real timeai-audio-timbre, ai-audio-spliter, ai-audio-asr
conversionVoice conversionai-audio-spliter, ai-audio-conversion

Detailed parameters for each task_type:

1. lufsr (section name in the source document; the task_type value is lufs, which retrieves audio loudness)

RequiredParameterTypeDescription
NoappStringCaller application
NouidStringuid; pass 0 when unavailable
NogidStringgid

2. trans_audio (speech transcription and translation)

RequiredParameterTypeDescription
YesfromStringSource language
YestoStringTarget language
Yesclient_idIntApplication client ID
Noasr_fromStringASR provider; default: tencent
Notrans_typeStringTranslation provider; default: tencent
Noenergy_thresholdDoubleAudio RMS threshold; default: 0, which skips task processing
NoappStringCaller application
NouidStringuid; pass 0 when unavailable
NogidStringgid

3. ducking (vocal-ducking keyframes)

RequiredParameterTypeDescription
NoappStringCaller application
NouidStringuid; pass 0 when unavailable
NogidStringgid

4. train (voice training and voice-profile storage)

RequiredParameterTypeDescription
Noprompt_langStringLanguage of the input audio. The default is zh in China and en outside China; pass en for English.
Nomodel_nameStringSupported values: qwen, index_tts2. The production model is index_tts2.
NoversionStringModel version. Currently supports v1, v2, and v3; default: v1.
Notrain_limitFloatTraining segment length in seconds; default: 10s. Set to 0 to extract features from the entire input audio.
NospliterBoolTrue/False; whether the input requires denoising
Nospliter_typeStringDenoising model type
Noasr_textJSONIf provided, asr_text is used by default.
NoappStringCaller application
NouidStringuid; pass 0 when unavailable
NogidStringgid

5. synth (generation using an existing voice profile)

RequiredParameterTypeDescription
Yesspk_idStringspk_id produced by model training
YestextStringText to synthesize
Nosp_speedFloatSpeed multiplier for output-audio sp; default: 1.0
NospeedFloatOutput-audio speed multiplier; default: 1.0. To double the speed, pass 1/2 = 0.5.
NodurationFloatDesired output-audio duration; default: 0, which preserves the duration generated by the model
Nouse_ssmlBoolTrue/False; whether to enable SSML; default: True
Nogen_langStringOutput-audio language; supports zh and en; default: zh
Nogen_sizeIntSynthesize audio in batches; number of characters per batch
NoappStringCaller application
NouidStringuid; pass 0 when unavailable
NogidStringgid

6. synth_once (one-time cloning and generation without saving the voice profile)

RequiredParameterTypeDescription
YestextStringText to synthesize
Nosp_speedFloatSpeed multiplier for output-audio sp; default: 1.0
NospeedFloatOutput-audio speed multiplier; default: 1.0
NodurationFloatDesired output-audio duration; default: 0, which preserves the duration generated by the model
Nouse_ssmlBoolTrue/False; whether to enable SSML; default: True
Noprompt_langStringLanguage of the input audio. The default is zh in China and en outside China; pass en for English.
Nogen_langStringOutput-audio language; supports zh and en; default: zh
Nogen_sizeIntSynthesize audio in batches; number of characters per batch
Nomodel_nameStringSupported values: qwen, index_tts2. The production model is index_tts2.
NoversionStringModel version. Currently supports v1, v2, and v3; default: v1.
Notrain_limitFloatTraining segment length in seconds; default: 10s. Set to 0 to extract features from the entire input audio.
NospliterBoolTrue/False; whether the input requires denoising
Nospliter_typeStringDenoising model type
Noasr_textJSONIf provided, asr_text is used; otherwise the internal ASR service is invoked.
NoappStringCaller application
NouidStringuid; pass 0 when unavailable
NogidStringgid
Noemo_control_methodintEmotion-control method; default: 0. 0: emotion from reference audio; 1: manual emotion vector; 2: independent emotion reference audio. See below.
Noemo_vecfloat[]Eight-dimensional manual emotion vector; required when emo_control_method=1
Noemo_ref_pathStringEmotion-reference audio URL; required when emo_control_method=2
Noemo_weightfloatEmotion-reference audio weight; optional when emo_control_method=2; default: 1.0; recommended range: 0.0–1.6

Emotion Control

emo_control_method controls the emotion source for synthesized audio and supports the following three modes:

ValueModeDescriptionAdditional parameters
0Reference-audio emotion (default)Extract emotion from the voice reference audio uploaded in init_imagesNone
1Manual emotion vectorPrecisely control emotion intensity with an eight-dimensional vectoremo_vec (required)
2Independent emotion reference audioUse another audio clip to control emotion while retaining the voice from the reference audioemo_ref_path (required), emo_weight (optional)

Order of the eight dimensions in emo_vec: [happiness, anger, sadness, fear, disgust, depression, surprise, calmness]

Constraints:

  • emo_vec must be a numeric array of length 8.
  • The sum of the eight weights must not exceed 1.5.
  • If emo_control_method is omitted, it defaults to 0, meaning the emotion is extracted from the voice reference audio.

7. edit (voice editing)

RequiredParameterTypeDescription
YestextStringText to synthesize
Yesstart_timeFloatStart time of the audio segment to replace (milliseconds)
Yesend_timeFloatEnd time of the audio segment to replace (milliseconds)
Nosp_speedFloatSpeed multiplier for output-audio sp; default: 1.0
NospeedFloatOutput-audio speed multiplier; default: 1.0
NodurationFloatDesired output-audio duration; default: 0, which preserves the duration generated by the model
Nouse_ssmlBoolTrue/False; whether to enable SSML; default: True
Noprompt_langStringLanguage of the input audio. The default is zh in China and en outside China; pass en for English.
Nogen_langStringOutput-audio language; supports zh and en; default: zh
Nogen_sizeIntSynthesize audio in batches; number of characters per batch
Nomodel_nameStringSupported value: voice_mirror. The production model is voice_mirror.
NoversionStringModel version. Currently supports v1, v2, and v3; default: v3.
Notrain_limitFloatTraining segment length in seconds; default: 10s. Set to 0 to extract features from the entire input audio.
NospliterBoolTrue/False; whether the input requires denoising
Nospliter_typeStringDenoising model type
Noasr_textJSONIf provided, asr_text is used; otherwise the internal ASR service is invoked.
NomixBoolTrue/False; whether to overlay background audio; default: False
NosingleBoolTrue/False; whether to use single-speaker mode. If True, the entire audio is used to extract model features; if False, audio beginning at start_time is used.
NoappStringCaller application
NouidStringuid; pass 0 when unavailable
NogidStringgid

8. trans (translated generation using an existing voice profile)

RequiredParameterTypeDescription
Yesprocess_infoJSON ArraySynthesized-audio information containing start_time, end_time, text, and trans_text
Yesspk_idStringExisting voice-profile ID
YesfromStringSource language; default: Chinese (zh)
YestoStringTarget language; default: English (en)
Nouse_ssmlBoolTrue/False; whether to enable SSML; default: True
Nomodel_nameStringModel name
NoversionStringModel version
NoappStringCaller application
NouidStringuid; pass 0 when unavailable
NogidStringgid

9. trans_once (real-time voice extraction and translation)

RequiredParameterTypeDescription
Yesprocess_infoJSON ArraySynthesized-audio information containing start_time, end_time, text, and trans_text
NofromStringSource language; default: Chinese (zh)
NotoStringTarget language; default: English (en)
Nouse_ssmlBoolTrue/False; whether to enable SSML; default: True
Nomodel_nameStringModel name
NoversionStringModel version
Nosp_speedFloatSpeed multiplier for output-audio sp; default: 1.0
NospeedFloatOutput-audio speed multiplier; default: 1.0
NodurationFloatDesired output-audio duration; default: 0, which preserves the duration generated by the model
Notrain_limitFloatTraining segment length in seconds; default: 10s. Set to 0 to extract features from the entire input audio.
NospliterBoolTrue/False; whether the input requires denoising
Nospliter_typeStringDenoising model type
Noasr_textJSONIf provided, asr_text is used; otherwise the internal ASR service is invoked.
NosingleBoolTrue/False; whether to use single-speaker mode. If True, the entire audio is used to extract model features; if False, audio beginning at start_time is used.
NoappStringCaller application
NouidStringuid; pass 0 when unavailable
NogidStringgid

10. conversion (voice conversion)

RequiredParameterTypeDescription
Nospk_idStringVoice-profile ID (supported values: ziwei, silang, wukong, baishe)
NosuffixStringReturned audio format; default: mp3. Pass wav to return WAV audio.
NoappStringCaller application
NouidStringuid; pass 0 when unavailable
NogidStringgid

Request Examples

  1. Voice cloning — default mode (use emotion from the reference audio)
{
	"task": "/v1/ai_audio_engine/481991",
	"task_type": "formula",
	"init_images": [{
		"url": "http://action-public.meitudata.com/voice_clone/68c12c8a20160928587d19j69h5423.mp3",
		"profile": {
			"media_profiles": {
				"media_data_type": "url"
			},
			"version": "v1"
		}
	}],
	"params": "{\"rsp_media_type\":\"url\",\"parameter\":{\"task_type\":\"synth_once\",\"text\":\"我是你克隆的专属声音,快来用我制作视频吧。This is the voice of your clone, please use it to create videos.\"}}",
	"sync_timeout": 30
}
  1. Voice cloning — manual emotion vector (primarily sadness)
{
	"task": "/v1/ai_audio_engine/481991",
	"task_type": "formula",
	"init_images": [{
		"url": "http://action-public.meitudata.com/voice_clone/68c12c8a20160928587d19j69h5423.mp3",
		"profile": {
			"media_profiles": {
				"media_data_type": "url"
			},
			"version": "v1"
		}
	}],
	"params": "{\"rsp_media_type\":\"url\",\"parameter\":{\"task_type\":\"synth_once\",\"text\":\"今天天气真不错,你怎么知道的?\",\"emo_control_method\":1,\"emo_vec\":[0,0,0.55,0,0,0,0,0]}}",
	"sync_timeout": 30
}
  1. Voice cloning — independent emotion reference audio
{
	"task": "/v1/ai_audio_engine/481991",
	"task_type": "formula",
	"init_images": [{
		"url": "http://action-public.meitudata.com/voice_clone/68c12c8a20160928587d19j69h5423.mp3",
		"profile": {
			"media_profiles": {
				"media_data_type": "url"
			},
			"version": "v1"
		}
	}],
	"params": "{\"rsp_media_type\":\"url\",\"parameter\":{\"task_type\":\"synth_once\",\"text\":\"今天天气真不错,你怎么知道的?\",\"emo_control_method\":2,\"emo_ref_path\":\"https://example.com/emo_ref.wav\",\"emo_weight\":0.8}}",
	"sync_timeout": 30
}

Response Fields

Generated results are periodically deleted. Download and save them promptly.
FieldTypeDescription
request_idstringRequest identifier
trace_idstringTrace ID
codeintBusiness status code returned by the API. 0 indicates success; a nonzero value indicates failure.
error_codeintDetailed error code (normally used with code); 0 indicates no error.
messagestringAPI message; normally "success" on success and an error description on failure.
tipsanyAdditional tips; may be null
dataobjectBusiness data

Fields in the data object

FieldTypeDescription
statusintStatus: -1 task not found; 0 created; 1 processing; 2 failed; 9 timed out—use the Task Query API to retrieve the result; 10 succeeded
resultobjectTask result information
progressnumberTask progress
predict_elapsedintEstimated processing time in milliseconds
create_timeint64Task creation timestamp in milliseconds
task_idstringSystem-generated task ID that uniquely identifies the task
custom_task_idstringUser-defined task ID (if supplied when creating the task)
trace_idstringTrace ID
client_infostringClient information
init_imagesobject[]/nullEchoed input media

Fields in the result object

FieldTypeDescription
idstring in the example; the source parameter table specifies intTask ID
parametersobjectTask result information
dataobject in the example; the source parameter table specifies intThe source parameter table describes predicted processing time in seconds; the response example uses a task metadata object.
msgstring in the example; the source parameter table specifies longTask information
msg_idstringMessage ID

Fields in the parameters object

FieldTypeDescription
codeint0 indicates a normal response; nonzero values indicate errors
nameStringThe user parameter from the request
idStringJob_ID
created_timeStringTask execution creation time
updated_timeStringTask execution completion time
msgStringTask execution information
out_srcStringGenerated audio file
textStringText to synthesize

Response Examples

Successful Response Example

Response status: 200

Content-Type: application/json; charset=utf-8

{
    "request_id": "",
    "trace_id": "",
    "code": 0,
    "error_code": 0,
    "message": "success",
    "tips": null,
    "data": {
        "status": 10,
        "result": {
            "id": "t_mt1a3i5n7bca14033a-6268-46ee-823e-c968beeb5b23",
            "parameters": {
                "clone_ori_path": "https://deepnet-baikal.obs.cn-north-4.myhuaweicloud.com/temporary/spliter/vocals_5c0e5136-ba21-42e9-b737-820e414bb0f1.wav",
                "code": 0,
                "create_time": "2025-09-30 17:34:09",
                "duration": 4.07,
                "id": "9939fbd5-7c74-47e1-9a71-d2130719bb71",
                "latency": 1.85,
                "msg": "success",
                "name": "0",
                "out_src": "https://deepnet-baikal.obs.cn-north-4.myhuaweicloud.com/temporary/zeroshot/9939fbd5-7c74-47e1-9a71-d2130719bb71_0.wav",
                "src": "https://action-public-release.obs.cn-north-4.myhuaweicloud.com/voice_clone/68c12c8a20160928587d19j69h5423.mp3?AccessKeyId=7YW1EYVPMUCUAFBLPDIN\u0026Expires=1759311244\u0026Signature=MF5vq%2B9y357Sjn23NmjWS5SHkf4%3D",
                "text": "You’re drinking energy drinks? Babe, it’s time to level up.",
                "ts_info": {

                },
                "updated_time": "2025-09-30 17:34:11"
            },
            "data": {
                "duration": {
                    "alg_process_time": 2087,
                    "created_timestamp": 1759224849,
                    "pull_timestamp": 1759224849,
                    "repost_time": 0,
                    "upload_time": 0,
                    "waiting_time": 78
                },
                "error_code": 0,
                "error_msg": "success",
                "extra": {

                },
                "media_info_list": [

                ],
                "msg_id": "a27d3c85-adb1-44a5-79ff-r0072bef0160",
                "parameter": {
                    "clone_ori_path": "https://deepnet-baikal.obs.cn-north-4.myhuaweicloud.com/temporary/spliter/vocals_5c0e5136-ba21-42e9-b737-820e414bb0f1.wav",
                    "code": 0,
                    "create_time": "2025-09-30 17:34:09",
                    "duration": 4.07,
                    "id": "9939fbd5-7c74-47e1-9a71-d2130719bb71",
                    "latency": 1.85,
                    "msg": "success",
                    "name": "0",
                    "out_src": "https://deepnet-baikal.obs.cn-north-4.myhuaweicloud.com/temporary/zeroshot/9939fbd5-7c74-47e1-9a71-d2130719bb71_0.wav",
                    "src": "https://action-public-release.obs.cn-north-4.myhuaweicloud.com/voice_clone/68c12c8a20160928587d19j69h5423.mp3?AccessKeyId=7YW1EYVPMUCUAFBLPDIN\u0026Expires=1759311244\u0026Signature=MF5vq%2B9y357Sjn23NmjWS5SHkf4%3D",
                    "text": "You’re drinking energy drinks? Babe, it’s time to level up.",
                    "ts_info": {

                    },
                    "updated_time": "2025-09-30 17:34:11"
                }
            },
            "msg": "success",
            "msg_id": "a27d3c85-adb1-44a5-79ff-r0072bef0160"
        },
        "progress": 1,
        "predict_elapsed": 10000,
        "create_time": 1759224844659,
        "task_id": "t_mt1a3i5n7bca14033a-6268-46ee-823e-c968beeb5b23",
        "custom_task_id": "",
        "trace_id": "e69535d2-23cd-40e3-bb27-addf15cd1457",
        "client_info": "",
        "init_images": null
    }
}

Pending Response Example

Use the Task Query API to retrieve the result. Response status: 200

Content-Type: application/json; charset=utf-8

{
    "request_id": "",
    "trace_id": "",
    "code": 0,
    "error_code": 0,
    "message": "success",
    "tips": null,
    "data": {
        "status": 9,
        "result": {
            "id": "t_mt1a3i5n7b3da6d589-46b5-4f66-a0bb-8dd22f2a172e"
        },
        "progress": 0,
        "predict_elapsed": 10000,
        "create_time": 1759202368761,
        "task_id": "t_mt1a3i5n7b3da6d589-46b5-4f66-a0bb-8dd22f2a172e",
        "custom_task_id": "",
        "trace_id": "9129a3a2-99c4-46ce-8731-0e100e2fbee7",
        "client_info": "",
        "init_images": null
    }
}

Failed Response Example

Response status: 400

Content-Type: application/json; charset=utf-8

{
    "request_id": "",
    "trace_id": "",
    "code": 20001,
    "error_code": 20001,
    "message": "ALGO_MODEL_CRASH",
    "tips": null,
    "data": {
        "status": 2,
        "result": {
            "id": "t_mt1a3i5n7be8d575cc-2ffb-4e0c-85a8-1824110e31b8",
            "code": 20001,
            "data": {
                "duration": {
                    "alg_process_time": 0,
                    "created_timestamp": 1759201989,
                    "pull_timestamp": 1759201989,
                    "repost_time": 0,
                    "upload_time": 0,
                    "waiting_time": 0
                },
                "error_code": 20001,
                "error_msg": "ALGO_MODEL_CRASH",
                "extra": {

                },
                "media_info_list": [

                ],
                "msg_id": "c1b09cb2-6e05-4d21-55ab-r007b1f21bec",
                "parameter": null
            },
            "msg": "ALGO_MODEL_CRASH",
            "msg_id": "c1b09cb2-6e05-4d21-55ab-r007b1f21bec"
        },
        "progress": 1,
        "predict_elapsed": 10000,
        "create_time": 1759201989444,
        "task_id": "t_mt1a3i5n7be8d575cc-2ffb-4e0c-85a8-1824110e31b8",
        "custom_task_id": "",
        "trace_id": "",
        "client_info": "",
        "init_images": null
    }
}

API-Specific Error Codes and Messages

ErrorCodeError messageDescription

General Error Codes

See API Error Codes

SDK Examples

Python

import json

import requests
from sign_sdk import sign

def api_call_example():
    key = "your_api_key"
    secret = "your_api_secret"
    url = "https://openapi.meitu.com/api/v1/sdk/sync/push"
    method = "POST"
    headers = {
        "Content-Type": "application/json",
        sign.HeaderHost: "openapi.meitu.com",
    }
    inner_params = {
        "rsp_media_type": "url",
        "parameter": {
            "task_type": "synth_once",
            "text": "我是你克隆的专属声音,快来用我制作视频吧。",
        },
    }
    payload = {
        "task": "/v1/ai_audio_engine/481991",
        "task_type": "formula",
        "init_images": [{
            "url": "http://action-public.meitudata.com/voice_clone/68c12c8a20160928587d19j69h5423.mp3",
            "profile": {
                "media_profiles": {"media_data_type": "url"},
                "version": "v1",
            },
        }],
        "params": json.dumps(inner_params, ensure_ascii=False),
        "sync_timeout": 30,
    }
    body = json.dumps(payload, ensure_ascii=False)
    signer = sign.Signer(key, secret)
    signed_request = signer.sign(url, method, headers, body)
    response = requests.Session().send(signed_request)
    print(f"Status: {response.status_code}")
    print(f"Response: {response.text}")

if __name__ == "__main__":
    api_call_example()

Go

package main

import (
	"fmt"
	"io"
	"net/http"

	"github.com/mtlab/api/signer"
)

func main() {
	key := "your_api_key"
	secret := "your_api_secret"
	signObj := signer.NewSigner(key, secret)
	url := "https://openapi.meitu.com/api/v1/sdk/sync/push"
	method := http.MethodPost
	headers := make(http.Header)
	headers.Set(signer.HeaderHost, "openapi.meitu.com")
	headers.Set("Content-Type", "application/json")
	body := `{
  "task": "/v1/ai_audio_engine/481991",
  "task_type": "formula",
  "init_images": [{
    "url": "http://action-public.meitudata.com/voice_clone/68c12c8a20160928587d19j69h5423.mp3",
    "profile": {
      "media_profiles": {"media_data_type": "url"},
      "version": "v1"
    }
  }],
  "params": "{\"rsp_media_type\":\"url\",\"parameter\":{\"task_type\":\"synth_once\",\"text\":\"我是你克隆的专属声音,快来用我制作视频吧。\"}}",
  "sync_timeout": 30
}`
	req, err := signObj.Sign(url, method, headers, body)
	if err != nil {
		fmt.Println("Failed to sign request:", err)
		return
	}
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		fmt.Println("Failed to send request:", err)
		return
	}
	defer resp.Body.Close()
	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("Read response failed:", err)
		return
	}
	fmt.Println("Response:", resp.StatusCode, string(responseBody))
}

PHP

<?php
require 'signer.php';

$key = 'your_api_key';
$secret = 'your_api_secret';
$signer = new Signer($key, $secret);
$url = 'https://openapi.meitu.com/api/v1/sdk/sync/push';
$method = 'POST';
$headers = ['Content-Type' => 'application/json'];
$innerParams = json_encode([
    'rsp_media_type' => 'url',
    'parameter' => [
        'task_type' => 'synth_once',
        'text' => '我是你克隆的专属声音,快来用我制作视频吧。',
    ],
]);
$body = json_encode([
    'task' => '/v1/ai_audio_engine/481991',
    'task_type' => 'formula',
    'init_images' => [[
        'url' => 'http://action-public.meitudata.com/voice_clone/68c12c8a20160928587d19j69h5423.mp3',
        'profile' => [
            'media_profiles' => ['media_data_type' => 'url'],
            'version' => 'v1',
        ],
    ]],
    'params' => $innerParams,
    'sync_timeout' => 30,
]);
$curl = $signer->sign($url, $method, $headers, $body);
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status === 0) {
    echo 'Error: ' . curl_error($curl);
} else {
    echo "Status: {$status}\n";
    echo "Response: {$response}\n";
}
curl_close($curl);
?>

Java

package com.meitu.openai.common;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) throws Exception {
        Signer signer = new Signer("your_api_key", "your_api_secret");
        String url = "https://openapi.meitu.com/api/v1/sdk/sync/push";
        String method = "POST";
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        headers.put(Signer.HeaderHost, "openapi.meitu.com");
        String body = "{\n" +
                "  \"task\": \"/v1/ai_audio_engine/481991\",\n" +
                "  \"task_type\": \"formula\",\n" +
                "  \"init_images\": [{\n" +
                "    \"url\": \"http://action-public.meitudata.com/voice_clone/68c12c8a20160928587d19j69h5423.mp3\",\n" +
                "    \"profile\": {\n" +
                "      \"media_profiles\": {\"media_data_type\": \"url\"},\n" +
                "      \"version\": \"v1\"\n" +
                "    }\n" +
                "  }],\n" +
                "  \"params\": \"{\\\"rsp_media_type\\\":\\\"url\\\",\\\"parameter\\\":{\\\"task_type\\\":\\\"synth_once\\\",\\\"text\\\":\\\"我是你克隆的专属声音,快来用我制作视频吧。\\\"}}\",\n" +
                "  \"sync_timeout\": 30\n" +
                "}";
        Map<String, String> signedHeaders = signer.sign(url, method, headers, body);
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
        connection.setRequestMethod(method);
        for (Map.Entry<String, String> entry : signedHeaders.entrySet()) {
            connection.setRequestProperty(entry.getKey(), entry.getValue());
        }
        connection.setDoOutput(true);
        connection.getOutputStream().write(body.getBytes(StandardCharsets.UTF_8));
        int status = connection.getResponseCode();
        InputStream stream = status >= 400
                ? connection.getErrorStream()
                : connection.getInputStream();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
            StringBuilder response = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
            System.out.println("Response: " + status + " " + response);
        }
    }
}